diff --git a/aspect/testing/tests/src/com/google/idea/blaze/aspect/integration/BazelInvokingIntegrationTestRunner.java b/aspect/testing/tests/src/com/google/idea/blaze/aspect/integration/BazelInvokingIntegrationTestRunner.java index d2a69301d20..096796ac527 100644 --- a/aspect/testing/tests/src/com/google/idea/blaze/aspect/integration/BazelInvokingIntegrationTestRunner.java +++ b/aspect/testing/tests/src/com/google/idea/blaze/aspect/integration/BazelInvokingIntegrationTestRunner.java @@ -55,12 +55,12 @@ public static void main(String[] a) throws Exception { aspectStrategyBazel.getAspectFlag().get(), String.format( "%s=%s/%s/aspect", - AspectRepositoryProvider.OVERRIDE_REPOSITORY_FLAG, + AspectRepositoryProvider.overrideRepositoryFlag(false), System.getenv("TEST_SRCDIR"), System.getenv("TEST_WORKSPACE")), String.format( "%s=%s/%s/aspect_template", - AspectRepositoryProvider.OVERRIDE_REPOSITORY_TEMPLATE_FLAG, + AspectRepositoryProvider.overrideRepositoryTemplateFlag(false), System.getenv("TEST_SRCDIR"), System.getenv("TEST_WORKSPACE")) ); diff --git a/base/src/com/google/idea/blaze/base/sync/aspects/strategy/AspectRepositoryProvider.java b/base/src/com/google/idea/blaze/base/sync/aspects/strategy/AspectRepositoryProvider.java index dcee540b6fc..c567db3b43b 100644 --- a/base/src/com/google/idea/blaze/base/sync/aspects/strategy/AspectRepositoryProvider.java +++ b/base/src/com/google/idea/blaze/base/sync/aspects/strategy/AspectRepositoryProvider.java @@ -1,5 +1,8 @@ package com.google.idea.blaze.base.sync.aspects.strategy; +import com.google.idea.blaze.base.model.BlazeProjectData; +import com.google.idea.blaze.base.model.BlazeVersionData; +import com.google.idea.blaze.base.sync.data.BlazeProjectDataManager; import com.intellij.openapi.extensions.ExtensionPointName; import com.intellij.openapi.project.Project; @@ -11,8 +14,20 @@ public interface AspectRepositoryProvider { ExtensionPointName EP_NAME = ExtensionPointName.create("com.google.idea.blaze.AspectRepositoryProvider"); - String OVERRIDE_REPOSITORY_FLAG = "--override_repository=intellij_aspect"; - String OVERRIDE_REPOSITORY_TEMPLATE_FLAG = "--override_repository=intellij_aspect_template"; + static String newRepositoryFlag(boolean useInjectedRepository) { + if (useInjectedRepository) { + return "--inject_repository"; + } else { + return "--override_repository"; + } + } + + static String overrideRepositoryFlag(boolean useInjectedRepository) { + return String.format("%s=intellij_aspect", newRepositoryFlag(useInjectedRepository)); + } + static String overrideRepositoryTemplateFlag(boolean useInjectedRepository) { + return String.format("%s=intellij_aspect_template", newRepositoryFlag(useInjectedRepository)); + } Optional aspectDirectory(); @@ -41,17 +56,26 @@ static Optional findAspectTemplateDirectory() { } static Optional[] getOverrideFlags(Project project) { + + BlazeProjectData projectData = + BlazeProjectDataManager.getInstance(project).getBlazeProjectData(); + if(projectData == null) { + throw new RuntimeException("Not synced yet; please sync project"); + } + + BlazeVersionData versionData = projectData.getBlazeVersionData(); + var useInjectedRepository = versionData.bazelIsAtLeastVersion(8, 0 ,0); return new Optional[] { - getOverrideFlagForAspectDirectory(), - getOverrideFlagForProjectAspectDirectory(project), + getOverrideFlagForAspectDirectory(useInjectedRepository), + getOverrideFlagForProjectAspectDirectory(project, useInjectedRepository), }; } - private static Optional getOverrideFlagForAspectDirectory() { - return findAspectDirectory().map(it -> OVERRIDE_REPOSITORY_FLAG + "=" + it.getPath()); + private static Optional getOverrideFlagForAspectDirectory(boolean useInjectedRepository) { + return findAspectDirectory().map(it -> overrideRepositoryFlag(useInjectedRepository) + "=" + it.getPath()); } - private static Optional getOverrideFlagForProjectAspectDirectory(Project project) { - return getProjectAspectDirectory(project).map(it -> OVERRIDE_REPOSITORY_TEMPLATE_FLAG + "=" + it.getPath()); + private static Optional getOverrideFlagForProjectAspectDirectory(Project project, boolean useInjectedRepository) { + return getProjectAspectDirectory(project).map(it -> overrideRepositoryTemplateFlag(useInjectedRepository) + "=" + it.getPath()); } } diff --git a/base/src/com/google/idea/blaze/base/sync/aspects/strategy/AspectStrategyBazel.java b/base/src/com/google/idea/blaze/base/sync/aspects/strategy/AspectStrategyBazel.java index 38f7305e85b..a1f0aa34db6 100644 --- a/base/src/com/google/idea/blaze/base/sync/aspects/strategy/AspectStrategyBazel.java +++ b/base/src/com/google/idea/blaze/base/sync/aspects/strategy/AspectStrategyBazel.java @@ -58,7 +58,10 @@ public Optional aspectTemplateDirectory() { @VisibleForTesting public AspectStrategyBazel(BlazeVersionData versionData) { super(/* aspectSupportsDirectDepsTrimming= */ true); - if (versionData.bazelIsAtLeastVersion(6, 0, 0)) { + boolean useInjectedRepository = versionData.bazelIsAtLeastVersion(8, 0, 0); + if (useInjectedRepository) { + aspectFlag = "--aspects=@intellij_aspect//:intellij_info_bundled.bzl%intellij_info_aspect"; + } else if (versionData.bazelIsAtLeastVersion(6, 0, 0)) { aspectFlag = "--aspects=@@intellij_aspect//:intellij_info_bundled.bzl%intellij_info_aspect"; } else { aspectFlag = "--aspects=@intellij_aspect//:intellij_info_bundled.bzl%intellij_info_aspect"; diff --git a/java/src/com/google/idea/blaze/java/fastbuild/BazelFastBuildAspectStrategy.java b/java/src/com/google/idea/blaze/java/fastbuild/BazelFastBuildAspectStrategy.java index 9c021042383..ad3f987e221 100644 --- a/java/src/com/google/idea/blaze/java/fastbuild/BazelFastBuildAspectStrategy.java +++ b/java/src/com/google/idea/blaze/java/fastbuild/BazelFastBuildAspectStrategy.java @@ -32,7 +32,10 @@ final class BazelFastBuildAspectStrategy extends FastBuildAspectStrategy { @Override protected List getAspectFlags(BlazeVersionData versionData, Project project) { String intellijAspectFile; - if (versionData.bazelIsAtLeastVersion(6, 0, 0)) { + boolean useInjectedRepository = versionData.bazelIsAtLeastVersion(8, 0, 0); + if(useInjectedRepository) { + intellijAspectFile = "--aspects=@intellij_aspect//:fast_build_info_bundled.bzl%fast_build_info_aspect"; + } else if (versionData.bazelIsAtLeastVersion(6, 0, 0)) { intellijAspectFile = "--aspects=@@intellij_aspect//:fast_build_info_bundled.bzl%fast_build_info_aspect"; } else { intellijAspectFile = "--aspects=@intellij_aspect//:fast_build_info_bundled.bzl%fast_build_info_aspect"; diff --git a/java/src/com/google/idea/blaze/java/run/hotswap/JavaClasspathAspectStrategy.java b/java/src/com/google/idea/blaze/java/run/hotswap/JavaClasspathAspectStrategy.java index 8ab97499b3f..2ed73abdfb3 100644 --- a/java/src/com/google/idea/blaze/java/run/hotswap/JavaClasspathAspectStrategy.java +++ b/java/src/com/google/idea/blaze/java/run/hotswap/JavaClasspathAspectStrategy.java @@ -25,7 +25,6 @@ import java.util.Arrays; import java.util.List; import java.util.Optional; -import java.util.stream.Collectors; import java.util.stream.Stream; import javax.annotation.Nullable; @@ -61,9 +60,12 @@ public boolean isApplicable(BlazeVersionData versionData) { @Override public ImmutableList getBuildFlags(BlazeVersionData versionData, Project project) { String intellijAspect; - if (versionData.bazelIsAtLeastVersion(6, 0, 0)) { + boolean useInjectedRepository = versionData.bazelIsAtLeastVersion(8, 0, 0); + if (useInjectedRepository) { + intellijAspect = "--aspects=@intellij_aspect//:java_classpath.bzl%java_classpath_aspect"; + } else if (versionData.bazelIsAtLeastVersion(6, 0, 0)) { intellijAspect = "--aspects=@@intellij_aspect//:java_classpath.bzl%java_classpath_aspect"; - } else { + } else { // #bazel5 we are going to drop bazel 5 support in Feb 2025 intellijAspect = "--aspects=@intellij_aspect//:java_classpath.bzl%java_classpath_aspect"; }