Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -250,3 +250,10 @@ http_archive(
"https://github.com/abseil/abseil-cpp/archive/refs/tags/20240722.0.tar.gz",
],
)

# import clwb test project for aspect tests
bazel_dep(name = "clwb_transition_project")
local_path_override(
module_name = "clwb_transition_project",
path = "clwb/tests/projects/transition",
)
104 changes: 63 additions & 41 deletions MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions aspect/intellij_info_impl.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,12 @@ def stringify_label(label):
# okay with the fixture setups.
return s.lstrip("@") if s.startswith("@@//") or s.startswith("@//") else s

def make_target_key(label, aspect_ids):
def make_target_key(ctx, label, aspect_ids):
"""Returns a TargetKey proto struct from a target."""
return struct_omit_none(
aspect_ids = tuple(aspect_ids) if aspect_ids else None,
label = stringify_label(label),
configuration_id = getattr(ctx.configuration, "short_id", ""), # looks like, will be picked to 8.5 and 7.7
)

def make_dep(dep, dependency_type):
Expand Down Expand Up @@ -585,7 +586,7 @@ def intellij_info_aspect_impl(target, ctx, semantics):
file_name = file_name + ".intellij-info.txt"
ide_info_file = ctx.actions.declare_file(file_name)

target_key = make_target_key(target.label, aspect_ids)
target_key = make_target_key(ctx, target.label, aspect_ids)
ide_info = dict(
build_file_artifact_location = build_file_artifact_location(ctx),
features = ctx.features,
Expand Down
1 change: 1 addition & 0 deletions aspect/testing/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ test_suite(
"//aspect/testing/tests/src/com/google/idea/blaze/aspect/cpp/cctest:CcTestTest",
"//aspect/testing/tests/src/com/google/idea/blaze/aspect/cpp/cctoolchain:CcToolchainTest",
"//aspect/testing/tests/src/com/google/idea/blaze/aspect/cpp/coptsmakevars:CoptsMakeVarsTest",
"//aspect/testing/tests/src/com/google/idea/blaze/aspect/cpp/transition:TransitionTest",
"//aspect/testing/tests/src/com/google/idea/blaze/aspect/general/alias:AliasTest",
"//aspect/testing/tests/src/com/google/idea/blaze/aspect/general/analysistest:AnalysisTestTest",
"//aspect/testing/tests/src/com/google/idea/blaze/aspect/general/artifacts:ArtifactTest",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import java.nio.file.Paths;
import java.util.List;
import java.util.Set;
import java.util.stream.Stream;

/** Abstract base class for Intellij aspect tests. */
public abstract class IntellijAspectTest {
Expand Down Expand Up @@ -69,18 +70,18 @@ protected ImmutableList<TargetIdeInfo> findAllTargetsWithLabel(
.collect(toImmutableList());
}

protected TargetIdeInfo findTarget(
IntellijAspectTestFixture testFixture, String maybeRelativeLabel) {
String label =
isAbsoluteTarget(maybeRelativeLabel)
? maybeRelativeLabel
: testRelative(maybeRelativeLabel);
return testFixture
.getTargetsList()
protected Stream<TargetIdeInfo> findTargets(IntellijAspectTestFixture testFixture, String maybeRelativeLabel) {
final var label = isAbsoluteTarget(maybeRelativeLabel)
? maybeRelativeLabel
: testRelative(maybeRelativeLabel);

return testFixture.getTargetsList()
.stream()
.filter(target -> matchTarget(target, label))
.findAny()
.orElse(null);
.filter(target -> matchTarget(target, label));
}

protected TargetIdeInfo findTarget(IntellijAspectTestFixture testFixture, String maybeRelativeLabel) {
return findTargets(testFixture, maybeRelativeLabel).findAny().orElse(null);
}

protected TargetIdeInfo findAspectTarget(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
load("@rules_cc//cc:cc_binary.bzl", "cc_binary")
load("@rules_java//java:defs.bzl", "java_test")
load(
"//aspect/testing/rules:intellij_aspect_test_fixture.bzl",
"intellij_aspect_test_fixture",
)

intellij_aspect_test_fixture(
name = "aspect_fixture",
deps = [
"@clwb_transition_project//main:multi_arch_main",
],
)

java_test(
name = "TransitionTest",
srcs = ["TransitionTest.java"],
data = [":aspect_fixture"],
deps = [
"//aspect/testing:BazelIntellijAspectTest",
"//aspect/testing:guava",
"//aspect/testing/rules:IntellijAspectTest",
"//aspect/testing/rules:intellij_aspect_test_fixture_java_proto",
"//intellij_platform_sdk:test_libs",
"//proto:intellij_ide_info_java_proto",
"//third_party/java/junit",
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright 2025 The Bazel Authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.idea.blaze.aspect.cpp.transition;

import static com.google.common.truth.Truth.assertThat;

import com.google.devtools.intellij.ideinfo.IntellijIdeInfo.TargetIdeInfo;
import com.google.idea.blaze.BazelIntellijAspectTest;
import java.io.IOException;
import java.util.List;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

@RunWith(JUnit4.class)
public class TransitionTest extends BazelIntellijAspectTest {

private List<TargetIdeInfo> getIdeInfos(String targetName) throws IOException {
final var testFixture = loadTestFixture(":aspect_fixture");

return findTargets(testFixture, targetName)
.filter(TargetIdeInfo::hasCIdeInfo)
.toList();
}

@Test
public void testMultipleIdeInfos() throws IOException {
final var ideInfos = getIdeInfos("@@clwb_transition_project+//main:main");
assertThat(ideInfos).hasSize(2);

for (final var ideInfo : ideInfos) {
assertThat(ideInfo.getKindString()).isEqualTo("cc_binary");
assertThat(ideInfo.getKey().getLabel()).isEqualTo("@@clwb_transition_project+//main:main");
assertThat(ideInfo.getKey().getConfigurationId()).isNotEmpty();
}

assertThat(ideInfos.get(0).getKey().getConfigurationId())
.isNotEqualTo(ideInfos.get(1).getKey().getConfigurationId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ private static boolean sourceInProjectTargets(
return true;
}
ImportRoots roots = context.getImportRoots();
return targetsBuildingSource.stream().anyMatch(t -> roots.targetInProject(t.getLabel()));
return targetsBuildingSource.stream().anyMatch(t -> roots.targetInProject(t.label()));
}

static boolean packageCoveredByProjectTargets(LocationContext context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public static TargetIdeInfo fromProto(
}
GoIdeInfo goIdeInfo = null;
if (proto.hasGoIdeInfo()) {
goIdeInfo = GoIdeInfo.fromProto(proto.getGoIdeInfo(), key.getLabel(), kind);
goIdeInfo = GoIdeInfo.fromProto(proto.getGoIdeInfo(), key.label(), kind);
sourcesBuilder.addAll(goIdeInfo.getSources());
}
JsIdeInfo jsIdeInfo = null;
Expand Down Expand Up @@ -367,7 +367,7 @@ public Instant getSyncTime() {
}

public TargetInfo toTargetInfo() {
return TargetInfo.builder(getKey().getLabel(), getKind().getKindString())
return TargetInfo.builder(getKey().label(), getKind().getKindString())
.setTestSize(getTestIdeInfo() != null ? getTestIdeInfo().getTestSize() : null)
.setTestClass(getJavaIdeInfo() != null ? getJavaIdeInfo().getTestClass() : null)
.setSyncTime(getSyncTime())
Expand Down
Loading