diff --git a/MODULE.bazel b/MODULE.bazel index cefa544be35..f8e9266593b 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -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", +) diff --git a/MODULE.bazel.lock b/MODULE.bazel.lock index 3eb08482917..c35bab34b81 100644 --- a/MODULE.bazel.lock +++ b/MODULE.bazel.lock @@ -18,7 +18,8 @@ "https://bcr.bazel.build/modules/abseil-py/2.1.0/source.json": "0e8fc4f088ce07099c1cd6594c20c7ddbb48b4b3c0849b7d94ba94be88ff042b", "https://bcr.bazel.build/modules/apple_support/1.11.1/MODULE.bazel": "1843d7cd8a58369a444fc6000e7304425fba600ff641592161d9f15b179fb896", "https://bcr.bazel.build/modules/apple_support/1.15.1/MODULE.bazel": "a0556fefca0b1bb2de8567b8827518f94db6a6e7e7d632b4c48dc5f865bc7c85", - "https://bcr.bazel.build/modules/apple_support/1.15.1/source.json": "517f2b77430084c541bc9be2db63fdcbb7102938c5f64c17ee60ffda2e5cf07b", + "https://bcr.bazel.build/modules/apple_support/1.23.1/MODULE.bazel": "53763fed456a968cf919b3240427cf3a9d5481ec5466abc9d5dc51bc70087442", + "https://bcr.bazel.build/modules/apple_support/1.23.1/source.json": "d888b44312eb0ad2c21a91d026753f330caa48a25c9b2102fae75eb2b0dcfdd2", "https://bcr.bazel.build/modules/aspect_bazel_lib/2.13.0/MODULE.bazel": "af4a546cb88c618f2e241721d2d76b70b7ecfaa1d58fe27b9187d3edb9e418da", "https://bcr.bazel.build/modules/aspect_bazel_lib/2.13.0/source.json": "5538ef77a1ecff41c119e040d4bc0148c83e9e79464a165ec86a1aa3171a5535", "https://bcr.bazel.build/modules/bazel_features/1.1.0/MODULE.bazel": "cfd42ff3b815a5f39554d97182657f8c4b9719568eb7fded2b9135f084bf760b", @@ -32,6 +33,7 @@ "https://bcr.bazel.build/modules/bazel_features/1.21.0/MODULE.bazel": "675642261665d8eea09989aa3b8afb5c37627f1be178382c320d1b46afba5e3b", "https://bcr.bazel.build/modules/bazel_features/1.23.0/MODULE.bazel": "fd1ac84bc4e97a5a0816b7fd7d4d4f6d837b0047cf4cbd81652d616af3a6591a", "https://bcr.bazel.build/modules/bazel_features/1.25.0/MODULE.bazel": "e2e60a10a6da64bbf533f15ca652bf61a033e41c2ed734d79a9a08ba87f68c1a", + "https://bcr.bazel.build/modules/bazel_features/1.27.0/MODULE.bazel": "621eeee06c4458a9121d1f104efb80f39d34deff4984e778359c60eaf1a8cb65", "https://bcr.bazel.build/modules/bazel_features/1.28.0/MODULE.bazel": "4b4200e6cbf8fa335b2c3f43e1d6ef3e240319c33d43d60cc0fbd4b87ece299d", "https://bcr.bazel.build/modules/bazel_features/1.3.0/MODULE.bazel": "cdcafe83ec318cda34e02948e81d790aab8df7a929cec6f6969f13a489ccecd9", "https://bcr.bazel.build/modules/bazel_features/1.30.0/MODULE.bazel": "a14b62d05969a293b80257e72e597c2da7f717e1e69fa8b339703ed6731bec87", @@ -78,6 +80,8 @@ "https://bcr.bazel.build/modules/googletest/1.15.2/MODULE.bazel": "6de1edc1d26cafb0ea1a6ab3f4d4192d91a312fd2d360b63adaa213cd00b2108", "https://bcr.bazel.build/modules/googletest/1.17.0/MODULE.bazel": "dbec758171594a705933a29fcf69293d2468c49ec1f2ebca65c36f504d72df46", "https://bcr.bazel.build/modules/googletest/1.17.0/source.json": "38e4454b25fc30f15439c0378e57909ab1fd0a443158aa35aec685da727cd713", + "https://bcr.bazel.build/modules/hermetic_cc_toolchain/3.1.0/MODULE.bazel": "ea4b3a25a9417a7db57a8a2f9ebdee91d679823c6274b482b817ed128d81c594", + "https://bcr.bazel.build/modules/hermetic_cc_toolchain/3.1.0/source.json": "9d1df0459caefdf41052d360469922a73e219f67c8ce4da0628cc604469822b9", "https://bcr.bazel.build/modules/jsoncpp/1.9.5/MODULE.bazel": "31271aedc59e815656f5736f282bb7509a97c7ecb43e927ac1a37966e0578075", "https://bcr.bazel.build/modules/jsoncpp/1.9.6/MODULE.bazel": "2f8d20d3b7d54143213c4dfc3d98225c42de7d666011528dc8fe91591e2e17b0", "https://bcr.bazel.build/modules/jsoncpp/1.9.6/source.json": "a04756d367a2126c3541682864ecec52f92cdee80a35735a3cb249ce015ca000", @@ -122,8 +126,8 @@ "https://bcr.bazel.build/modules/rules_android/0.6.4/source.json": "95d3c233c81005ad95eadc9382fde7dc6bd2c61752361e463264ee8349c071fb", "https://bcr.bazel.build/modules/rules_apple/3.16.0/MODULE.bazel": "0d1caf0b8375942ce98ea944be754a18874041e4e0459401d925577624d3a54a", "https://bcr.bazel.build/modules/rules_apple/3.16.0/source.json": "d8b5fe461272018cc07cfafce11fe369c7525330804c37eec5a82f84cd475366", - "https://bcr.bazel.build/modules/rules_bazel_integration_test/0.33.2/MODULE.bazel": "5468d45d3b41f1f2e86666808047ee5f757a499fdac27245125463044cd718f8", - "https://bcr.bazel.build/modules/rules_bazel_integration_test/0.33.2/source.json": "6aef2ef3df055c98869aad8503dc6c51ab8c51d4ebd401a2a6de3d077b9b8fff", + "https://bcr.bazel.build/modules/rules_bazel_integration_test/0.34.0/MODULE.bazel": "1a5b5145b5703f05a3ef87b41355a9999a485419ed75555eb9ed2dd93fb0059d", + "https://bcr.bazel.build/modules/rules_bazel_integration_test/0.34.0/source.json": "e307a032218f5e81524435d5502bc776a064aef49f650a331b2bf524bdfdb83b", "https://bcr.bazel.build/modules/rules_cc/0.0.1/MODULE.bazel": "cb2aa0747f84c6c3a78dad4e2049c154f08ab9d166b1273835a8174940365647", "https://bcr.bazel.build/modules/rules_cc/0.0.10/MODULE.bazel": "ec1705118f7eaedd6e118508d3d26deba2a4e76476ada7e0e3965211be012002", "https://bcr.bazel.build/modules/rules_cc/0.0.13/MODULE.bazel": "0e8529ed7b323dad0775ff924d2ae5af7640b23553dfcd4d34344c7e7a867191", @@ -138,7 +142,8 @@ "https://bcr.bazel.build/modules/rules_cc/0.1.1/MODULE.bazel": "2f0222a6f229f0bf44cd711dc13c858dad98c62d52bd51d8fc3a764a83125513", "https://bcr.bazel.build/modules/rules_cc/0.2.0/MODULE.bazel": "b5c17f90458caae90d2ccd114c81970062946f49f355610ed89bebf954f5783c", "https://bcr.bazel.build/modules/rules_cc/0.2.8/MODULE.bazel": "f1df20f0bf22c28192a794f29b501ee2018fa37a3862a1a2132ae2940a23a642", - "https://bcr.bazel.build/modules/rules_cc/0.2.8/source.json": "85087982aca15f31307bd52698316b28faa31bd2c3095a41f456afec0131344c", + "https://bcr.bazel.build/modules/rules_cc/0.2.9/MODULE.bazel": "34263f1dca62ea664265438cef714d7db124c03e1ed55ebb4f1dc860164308d1", + "https://bcr.bazel.build/modules/rules_cc/0.2.9/source.json": "4e49b40effcbd14fbfb233eb929de42dfff7b66538b4ffda310ad501638e7986", "https://bcr.bazel.build/modules/rules_foreign_cc/0.9.0/MODULE.bazel": "c9e8c682bf75b0e7c704166d79b599f93b72cfca5ad7477df596947891feeef6", "https://bcr.bazel.build/modules/rules_fuzzing/0.5.2/MODULE.bazel": "40c97d1144356f52905566c55811f13b299453a14ac7769dfba2ac38192337a8", "https://bcr.bazel.build/modules/rules_go/0.41.0/MODULE.bazel": "55861d8e8bb0e62cbd2896f60ff303f62ffcb0eddb74ecb0e5c0cbe36fc292c8", @@ -247,37 +252,6 @@ }, "selectedYankedVersions": {}, "moduleExtensions": { - "@@apple_support+//crosstool:setup.bzl%apple_cc_configure_extension": { - "general": { - "bzlTransitiveDigest": "p7Ghcq3+nnQxCrf+U3xnhdn7yOSTDbcFyGHK7Ja+rU4=", - "usagesDigest": "EJfdUgbJdIRboG70S9dz8HhGVkL2/s3qFQ9xht8y2Rs=", - "recordedFileInputs": {}, - "recordedDirentsInputs": {}, - "envVariables": {}, - "generatedRepoSpecs": { - "local_config_apple_cc_toolchains": { - "repoRuleId": "@@apple_support+//crosstool:setup.bzl%_apple_cc_autoconf_toolchains", - "attributes": {} - }, - "local_config_apple_cc": { - "repoRuleId": "@@apple_support+//crosstool:setup.bzl%_apple_cc_autoconf", - "attributes": {} - } - }, - "recordedRepoMappingEntries": [ - [ - "apple_support+", - "bazel_tools", - "bazel_tools" - ], - [ - "bazel_tools", - "rules_cc", - "rules_cc+" - ] - ] - } - }, "@@buildifier_prebuilt+//:defs.bzl%buildifier_prebuilt_deps_extension": { "general": { "bzlTransitiveDigest": "izaEjT7NE6vV9H5axiYiPrvmFtCLNkfjhj+bpMolt1A=", @@ -433,6 +407,54 @@ "recordedRepoMappingEntries": [] } }, + "@@hermetic_cc_toolchain+//toolchain:ext.bzl%toolchains": { + "general": { + "bzlTransitiveDigest": "5FjJ3O1ACzyDcgFEEKQfIIjjlsMupNi0K5iLqvAI8qc=", + "usagesDigest": "3HHXhodmHGNPy0Om5qIn141gGr1Cd8M1zvP9BCqUQMQ=", + "recordedFileInputs": {}, + "recordedDirentsInputs": {}, + "envVariables": {}, + "generatedRepoSpecs": { + "zig_sdk": { + "repoRuleId": "@@hermetic_cc_toolchain+//toolchain:defs.bzl%zig_repository", + "attributes": { + "version": "0.12.0", + "url_formats": [ + "https://mirror.bazel.build/ziglang.org/download/{version}/zig-{host_platform}-{version}.{_ext}", + "https://ziglang.org/download/{version}/zig-{host_platform}-{version}.{_ext}" + ], + "host_platform_sha256": { + "linux-aarch64": "754f1029484079b7e0ca3b913a0a2f2a6afd5a28990cb224fe8845e72f09de63", + "linux-x86_64": "c7ae866b8a76a568e2d5cfd31fe89cdb629bdd161fdd5018b29a4a0a17045cad", + "macos-aarch64": "294e224c14fd0822cfb15a35cf39aa14bd9967867999bf8bdfe3db7ddec2a27f", + "macos-x86_64": "4d411bf413e7667821324da248e8589278180dbc197f4f282b7dbb599a689311", + "windows-aarch64": "04c6b92689241ca7a8a59b5f12d2ca2820c09d5043c3c4808b7e93e41c7bf97b", + "windows-x86_64": "2199eb4c2000ddb1fba85ba78f1fcf9c1fb8b3e57658f6a627a8e513131893f5" + }, + "host_platform_ext": { + "linux-aarch64": "tar.xz", + "linux-x86_64": "tar.xz", + "macos-aarch64": "tar.xz", + "macos-x86_64": "tar.xz", + "windows-x86_64": "zip" + } + } + } + }, + "recordedRepoMappingEntries": [ + [ + "hermetic_cc_toolchain+", + "bazel_tools", + "bazel_tools" + ], + [ + "hermetic_cc_toolchain+", + "hermetic_cc_toolchain", + "hermetic_cc_toolchain+" + ] + ] + } + }, "@@pybind11_bazel+//:internal_configure.bzl%internal_configure_extension": { "general": { "bzlTransitiveDigest": "G7xCmtNWXRuBtChRgB5OK5+gmM8Uoy8Mec/B7j3fhqs=", @@ -617,7 +639,7 @@ "@@rules_bazel_integration_test+//:extensions.bzl%bazel_binaries": { "general": { "bzlTransitiveDigest": "XC9nqZ31LIbq8N7cEK+rYa2iXNQLcJ3cyGWw+zPZlc0=", - "usagesDigest": "WiV8cgjEX30yiB9QMWlzuUxvHXNcooNoqoO2J5EIxOk=", + "usagesDigest": "J53MWQfDPhGjiQiEsZDmoLqel3PkfMtkKkiVzgl1cAI=", "recordedFileInputs": {}, "recordedDirentsInputs": {}, "envVariables": {}, @@ -642,10 +664,10 @@ "bazelisk": "@bazel_binaries_bazelisk//:bazelisk" } }, - "build_bazel_bazel_8_4_0": { + "build_bazel_bazel_8_4_1": { "repoRuleId": "@@rules_bazel_integration_test+//bazel_integration_test/private:bazel_binaries.bzl%bazel_binary", "attributes": { - "version": "8.4.0", + "version": "8.4.1", "bazelisk": "@bazel_binaries_bazelisk//:bazelisk" } }, @@ -662,10 +684,10 @@ "version_to_repo": { "6.5.0": "build_bazel_bazel_6_5_0", "7.5.0": "build_bazel_bazel_7_5_0", - "8.4.0": "build_bazel_bazel_8_4_0", + "8.4.1": "build_bazel_bazel_8_4_1", "last_green": "build_bazel_bazel_last_green" }, - "current_version": "8.4.0" + "current_version": "8.4.1" } } }, @@ -675,7 +697,7 @@ "bazel_binaries_bazelisk", "build_bazel_bazel_6_5_0", "build_bazel_bazel_7_5_0", - "build_bazel_bazel_8_4_0", + "build_bazel_bazel_8_4_1", "build_bazel_bazel_last_green", "bazel_binaries" ], diff --git a/aspect/intellij_info_impl.bzl b/aspect/intellij_info_impl.bzl index dccb436dcf4..996ba92c2cd 100644 --- a/aspect/intellij_info_impl.bzl +++ b/aspect/intellij_info_impl.bzl @@ -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): @@ -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, diff --git a/aspect/testing/BUILD b/aspect/testing/BUILD index ed768e306b4..0ccc753d103 100644 --- a/aspect/testing/BUILD +++ b/aspect/testing/BUILD @@ -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", diff --git a/aspect/testing/rules/src/com/google/idea/blaze/aspect/IntellijAspectTest.java b/aspect/testing/rules/src/com/google/idea/blaze/aspect/IntellijAspectTest.java index 835e1c22cb5..f5ba3d0b9d8 100644 --- a/aspect/testing/rules/src/com/google/idea/blaze/aspect/IntellijAspectTest.java +++ b/aspect/testing/rules/src/com/google/idea/blaze/aspect/IntellijAspectTest.java @@ -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 { @@ -69,18 +70,18 @@ protected ImmutableList findAllTargetsWithLabel( .collect(toImmutableList()); } - protected TargetIdeInfo findTarget( - IntellijAspectTestFixture testFixture, String maybeRelativeLabel) { - String label = - isAbsoluteTarget(maybeRelativeLabel) - ? maybeRelativeLabel - : testRelative(maybeRelativeLabel); - return testFixture - .getTargetsList() + protected Stream 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( diff --git a/aspect/testing/tests/src/com/google/idea/blaze/aspect/cpp/transition/BUILD b/aspect/testing/tests/src/com/google/idea/blaze/aspect/cpp/transition/BUILD new file mode 100644 index 00000000000..00ee451d8c5 --- /dev/null +++ b/aspect/testing/tests/src/com/google/idea/blaze/aspect/cpp/transition/BUILD @@ -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", + ], +) diff --git a/aspect/testing/tests/src/com/google/idea/blaze/aspect/cpp/transition/TransitionTest.java b/aspect/testing/tests/src/com/google/idea/blaze/aspect/cpp/transition/TransitionTest.java new file mode 100644 index 00000000000..990e81c58b7 --- /dev/null +++ b/aspect/testing/tests/src/com/google/idea/blaze/aspect/cpp/transition/TransitionTest.java @@ -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 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()); + } +} diff --git a/base/src/com/google/idea/blaze/base/dependencies/AddSourceToProjectHelper.java b/base/src/com/google/idea/blaze/base/dependencies/AddSourceToProjectHelper.java index 5c6022d9bcd..0f22fbe494c 100644 --- a/base/src/com/google/idea/blaze/base/dependencies/AddSourceToProjectHelper.java +++ b/base/src/com/google/idea/blaze/base/dependencies/AddSourceToProjectHelper.java @@ -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) { diff --git a/base/src/com/google/idea/blaze/base/ideinfo/TargetIdeInfo.java b/base/src/com/google/idea/blaze/base/ideinfo/TargetIdeInfo.java index 112d424c854..7dd35618ced 100644 --- a/base/src/com/google/idea/blaze/base/ideinfo/TargetIdeInfo.java +++ b/base/src/com/google/idea/blaze/base/ideinfo/TargetIdeInfo.java @@ -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; @@ -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()) diff --git a/base/src/com/google/idea/blaze/base/ideinfo/TargetKey.java b/base/src/com/google/idea/blaze/base/ideinfo/TargetKey.java index 60c41fa238b..cbeeeadbe95 100644 --- a/base/src/com/google/idea/blaze/base/ideinfo/TargetKey.java +++ b/base/src/com/google/idea/blaze/base/ideinfo/TargetKey.java @@ -15,8 +15,7 @@ */ package com.google.idea.blaze.base.ideinfo; -import com.google.common.base.Joiner; -import com.google.common.base.Objects; +import com.google.auto.value.AutoValue; import com.google.common.collect.ComparisonChain; import com.google.common.collect.ImmutableList; import com.google.common.collect.Ordering; @@ -24,85 +23,65 @@ import com.google.idea.blaze.base.model.primitives.Label; import java.util.List; -/** A key that uniquely identifies a target in the target map */ -public final class TargetKey - implements ProtoWrapper, Comparable { - private final Label label; - private final ImmutableList aspectIds; +/** + * A key that uniquely identifies a target in the target map + */ +@AutoValue +public abstract class TargetKey implements ProtoWrapper, Comparable { - private TargetKey(Label label, ImmutableList aspectIds) { - this.label = label; - this.aspectIds = aspectIds; - } + public abstract Label label(); + + public abstract ImmutableList aspectIds(); + + public abstract String configurationId(); public static TargetKey fromProto(IntellijIdeInfo.TargetKey proto) { return ProjectDataInterner.intern( - new TargetKey( + new AutoValue_TargetKey( Label.fromProto(proto.getLabel()), - ProtoWrapper.internStrings(proto.getAspectIdsList()))); + ProtoWrapper.internStrings(proto.getAspectIdsList()), + ProtoWrapper.internString(proto.getConfigurationId()) + ) + ); } @Override public IntellijIdeInfo.TargetKey toProto() { return IntellijIdeInfo.TargetKey.newBuilder() - .setLabel(label.toProto()) - .addAllAspectIds(aspectIds) + .setLabel(label().toProto()) + .addAllAspectIds(aspectIds()) + .setConfigurationId(configurationId()) .build(); } - public Label getLabel() { - return label; - } - - private ImmutableList getAspectIds() { - return aspectIds; - } - - /** Returns a key identifying a plain target */ + /** + * Returns a key identifying a plain target + */ public static TargetKey forPlainTarget(Label label) { - return forGeneralTarget(label, ImmutableList.of()); + return forGeneralTarget(label, ImmutableList.of(), ""); } - /** Returns a key identifying a general target */ - public static TargetKey forGeneralTarget(Label label, List aspectIds) { - return ProjectDataInterner.intern(new TargetKey(label, ProtoWrapper.internStrings(aspectIds))); + /** + * Returns a key identifying a general target + */ + public static TargetKey forGeneralTarget(Label label, List aspectIds, String configurationId) { + return ProjectDataInterner.intern(new AutoValue_TargetKey( + label, + ProtoWrapper.internStrings(aspectIds), + ProtoWrapper.internString(configurationId) + )); } public boolean isPlainTarget() { - return getAspectIds().isEmpty(); - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - TargetKey key = (TargetKey) o; - return Objects.equal(getLabel(), key.getLabel()) - && Objects.equal(getAspectIds(), key.getAspectIds()); - } - - @Override - public int hashCode() { - return Objects.hashCode(getLabel(), getAspectIds()); - } - - @Override - public String toString() { - if (getAspectIds().isEmpty()) { - return getLabel().toString(); - } - return getLabel().toString() + "#" + Joiner.on('#').join(getAspectIds()); + return aspectIds().isEmpty(); } @Override public int compareTo(TargetKey o) { return ComparisonChain.start() - .compare(getLabel(), o.getLabel()) - .compare(getAspectIds(), o.getAspectIds(), Ordering.natural().lexicographical()) + .compare(label(), o.label()) + .compare(aspectIds(), o.aspectIds(), Ordering.natural().lexicographical()) + .compare(configurationId(), o.configurationId()) .result(); } } diff --git a/base/src/com/google/idea/blaze/base/ideinfo/TargetMap.java b/base/src/com/google/idea/blaze/base/ideinfo/TargetMap.java index 6464c5490c6..057bff71655 100644 --- a/base/src/com/google/idea/blaze/base/ideinfo/TargetMap.java +++ b/base/src/com/google/idea/blaze/base/ideinfo/TargetMap.java @@ -56,7 +56,7 @@ public TargetIdeInfo get(TargetKey key) { public ImmutableList get(Label label) { return targetMap.entrySet() .stream() - .filter(it -> it.getKey().getLabel().equals(label)) + .filter(it -> it.getKey().label().equals(label)) .map(Entry::getValue) .collect(ImmutableList.toImmutableList()); } diff --git a/base/src/com/google/idea/blaze/base/model/AspectSyncProjectData.java b/base/src/com/google/idea/blaze/base/model/AspectSyncProjectData.java index ecafeb52972..1d812289396 100644 --- a/base/src/com/google/idea/blaze/base/model/AspectSyncProjectData.java +++ b/base/src/com/google/idea/blaze/base/model/AspectSyncProjectData.java @@ -129,7 +129,7 @@ private TargetInfo getTargetInfo(Label label) { } // otherwise just return any matching target return map.targets().stream() - .filter(t -> Objects.equals(label, t.getKey().getLabel())) + .filter(t -> Objects.equals(label, t.getKey().label())) .findFirst() .map(TargetIdeInfo::toTargetInfo) .orElse(null); @@ -149,7 +149,7 @@ public BuildTarget getBuildTarget(Label label) { @Override public ImmutableList