diff --git a/MODULE.bazel b/MODULE.bazel index 9811cc0ce2f..f287003cd1c 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -57,19 +57,17 @@ bazel_binaries = use_extension( "bazel_binaries", dev_dependency = True, ) -bazel_binaries.download(version = "5.4.1") bazel_binaries.download(version = "6.5.0") bazel_binaries.download( current = True, - version = "7.4.0", + version = "7.4.1", ) use_repo( bazel_binaries, "bazel_binaries", "bazel_binaries_bazelisk", - "build_bazel_bazel_5_4_1", "build_bazel_bazel_6_5_0", - "build_bazel_bazel_7_4_0", + "build_bazel_bazel_7_4_1", ) bazel_dep(name = "rules_jvm_external", version = "6.6") diff --git a/WORKSPACE.bzlmod b/WORKSPACE.bzlmod index 61859f7d244..428a87ee35a 100644 --- a/WORKSPACE.bzlmod +++ b/WORKSPACE.bzlmod @@ -35,10 +35,3 @@ load("@io_bazel_rules_scala//testing:scalatest.bzl", "scalatest_repositories", " scalatest_repositories() scalatest_toolchain() - -load("@bazel_tools//tools/build_defs/repo:local.bzl", "local_repository") - -local_repository( - name = "intellij_aspect_template", - path = "aspect_template" -) diff --git a/aspect/BUILD b/aspect/BUILD index 9f7690b40a8..3ca94ba841c 100644 --- a/aspect/BUILD +++ b/aspect/BUILD @@ -2,10 +2,8 @@ # Description: Bazel aspect bundled with the Bazel IntelliJ plugin. # -load( - ":flag_hack.bzl", - "define_flag_hack", -) +load(":flag_hack.bzl", "define_flag_hack") +load(":build_defs.bzl", "aspect_library") licenses(["notice"]) @@ -26,24 +24,20 @@ filegroup( ) # the aspect files that will be bundled with the final plugin zip -filegroup( - name = "aspect_files", - srcs = [ - ":aspect_files_only", - ":aspect_tools", +aspect_library( + name = "aspect_lib", + deps = [ + ":aspect_files" , + ":aspect_tools" ], visibility = ["//visibility:public"], ) # Separate different targets as they are put into different directories -filegroup( - name = "aspect_files_only", - srcs = [ - "WORKSPACE", +aspect_library( + name = "aspect_files", + files = [ "artifacts.bzl", - "build_compose_dependencies.bzl", - "build_dependencies.bzl", - "build_dependencies_deps.bzl", "fast_build_info_bundled.bzl", "flag_hack.bzl", "intellij_info.bzl", @@ -53,16 +47,29 @@ filegroup( "make_variables.bzl", ":BUILD.bazel", ], + namespace = "aspect/default", visibility = ["//visibility:public"], ) -filegroup( +aspect_library( name = "aspect_tools", - srcs = [ - "//aspect/tools:CreateAar", + files = ["//aspect/tools:CreateAar"], + jars = [ "//aspect/tools:JarFilter_deploy.jar", "//aspect/tools:PackageParser_deploy.jar", ], + namespace = "aspect/default/tools", + visibility = ["//visibility:public"], +) + +aspect_library( + name = "aspect_qsync_lib", + files = [ + "build_compose_dependencies.bzl", + "build_dependencies.bzl", + "build_dependencies_deps.bzl", + ], + namespace = "aspect/qsync", visibility = ["//visibility:public"], ) @@ -89,8 +96,8 @@ genrule( srcs = ["intellij_info.bzl"], outs = ["intellij_info_bundled.bzl"], cmd = "cat $(SRCS) >$@ && " + - "sed -i -e 's,//%s/tools:\" + tool_name,//:\" + tool_name + \"_bin\",g' $@ && " % _dev_aspect_path + - "sed -i -e 's,//%s:flag_hack,//:flag_hack,g' $@ && " % _dev_aspect_path + + "sed -i -e 's,//%s/tools:\" + tool_name,:\" + tool_name + \"_bin\",g' $@ && " % _dev_aspect_path + + "sed -i -e 's,//%s:flag_hack,:flag_hack,g' $@ && " % _dev_aspect_path + "sed -i -e 's,:intellij_info_impl.bzl,:intellij_info_impl_bundled.bzl,g' $@", ) @@ -103,6 +110,7 @@ genrule( cmd = "cat $(SRCS) >$@ && " + "sed -i -e '/BUNDLED-IGNORE-BEGIN/,/BUNDLED-IGNORE-END/d' $@ && " + "sed -i -e '/BUNDLED-INCLUDE-BEGIN/,/BUNDLED-INCLUDE-END/{s/^[#][#]//;}' $@ &&" + + "sed -i -e 's,load(\"//aspect_template:,load(\"ASPECT_TEMPLATE_PATH', $@ &&" + "sed -i -e 's,load(\".*/rules_java/,load(\"@rules_java//', $@", ) @@ -115,11 +123,44 @@ genrule( "sed -i -e 's,:intellij_info_impl.bzl,:intellij_info_impl_bundled.bzl,g' $@", ) +define_flag_hack() + +aspect_library( + name = "aspect_template_lib", + files = [ + "code_generator_info.bzl", + "code_generator_info.template.bzl", + "java_info.bzl", + "java_info.template.bzl", + "python_info.bzl", + "python_info.template.bzl", + ], + namespace = "aspect/template", + visibility = ["//visibility:public"], +) + +STRIP_TEMPLATE_SCRIPT = """cat $(SRCS) >$@ && +sed -i -e '/TEMPLATE-IGNORE-BEGIN/,/TEMPLATE-IGNORE-END/d' $@ && +sed -i -e '/TEMPLATE-INCLUDE-BEGIN/,/TEMPLATE-INCLUDE-END/{s/^[#][#]//;}' $@ +""" + genrule( - name = "create_workspace_file", - outs = ["WORKSPACE"], - srcs = [], - cmd = r"""echo 'workspace(name = "intellij_aspect")' > $@""" + name = "generate_java_info_template", + srcs = ["java_info.bzl"], + outs = ["java_info.template.bzl"], + cmd = STRIP_TEMPLATE_SCRIPT, ) -define_flag_hack() +genrule( + name = "generate_py_info_template", + srcs = ["python_info.bzl"], + outs = ["python_info.template.bzl"], + cmd = STRIP_TEMPLATE_SCRIPT, +) + +genrule( + name = "generate_code_generator_info_template", + srcs = ["code_generator_info.bzl"], + outs = ["code_generator_info.template.bzl"], + cmd = STRIP_TEMPLATE_SCRIPT, +) diff --git a/aspect/build_defs.bzl b/aspect/build_defs.bzl new file mode 100644 index 00000000000..5e5ea21bafc --- /dev/null +++ b/aspect/build_defs.bzl @@ -0,0 +1,63 @@ +load("@rules_pkg//pkg:pkg.bzl", "pkg_zip") +load("@rules_java//java:defs.bzl", "java_import") +load("@bazel_skylib//lib:paths.bzl", "paths") + +def _java_8_transition_impl(settings, attr): + return {"//command_line_option:javacopt": ["-source", "8", "-target", "8"]} + +_java_8_transition = transition( + implementation = _java_8_transition_impl, + inputs = [], + outputs = ["//command_line_option:javacopt"], +) + +def _java_8_cfg_impl(ctx): + files = [] + + for jar in ctx.attr.jars: + files.extend(jar[DefaultInfo].files.to_list()) + + return [DefaultInfo(files = depset(files))] + +_java_8_cfg = rule( + implementation = _java_8_cfg_impl, + attrs = { + "jars": attr.label_list(mandatory = True, allow_files = True, cfg = _java_8_transition), + }, +) + +def aspect_library(name, namespace = "/", files = [], jars = [], **kwargs): + """ + Creates an aspect library for a set of files. + + An aspect library is a zip file imported as a java library to have more precise + control over the file layout. Also configures all included jars to be build with + java 8, to ensure compatability. + + Args: + name (str): The name of the target. Also used to generate the JAR file name. + namespace (str, optional): The parent directory inside the JAR file. + files (list, optional): A list of files to include in the JAR. + jars (list, optional): A list of jars to include in the JAR (configured for java 8). + **kwargs: Additional arguments forwarded to the `java_import` rule. + """ + + cfg_java_name = "%s_java" % name + _java_8_cfg( + name = cfg_java_name, + jars = jars, + ) + + pkg_zip_name = "%s_zip" % name + pkg_zip( + name = pkg_zip_name, + package_file_name = "%s.jar" % name, + package_dir = namespace, + srcs = files + [cfg_java_name], + ) + + java_import( + name = name, + jars = [pkg_zip_name], + **kwargs + ) diff --git a/aspect_template/code_generator_info.bzl b/aspect/code_generator_info.bzl similarity index 100% rename from aspect_template/code_generator_info.bzl rename to aspect/code_generator_info.bzl diff --git a/aspect/fast_build_info.bzl b/aspect/fast_build_info.bzl index 4e40ac3df39..9600f0baae1 100644 --- a/aspect/fast_build_info.bzl +++ b/aspect/fast_build_info.bzl @@ -10,7 +10,7 @@ load( ":intellij_info_impl.bzl", "stringify_label", ) -load("@intellij_aspect_template//:java_info.bzl", "get_java_info") +load(":java_info.bzl", "get_java_info") _DEP_ATTRS = ["deps", "exports", "runtime_deps", "_java_toolchain"] diff --git a/aspect/intellij_info_impl.bzl b/aspect/intellij_info_impl.bzl index 19fd46e40c7..53db832930a 100644 --- a/aspect/intellij_info_impl.bzl +++ b/aspect/intellij_info_impl.bzl @@ -15,11 +15,11 @@ load( ) load(":flag_hack.bzl", "FlagHackInfo") -load("@intellij_aspect_template//:java_info.bzl", "get_java_info", "java_info_in_target", "java_info_reference") +load(":java_info.bzl", "get_java_info", "java_info_in_target", "java_info_reference") -load("@intellij_aspect_template//:python_info.bzl", "get_py_info", "py_info_in_target") +load(":python_info.bzl", "get_py_info", "py_info_in_target") -load("@intellij_aspect_template//:code_generator_info.bzl", "CODE_GENERATOR_RULE_NAMES") +load(":code_generator_info.bzl", "CODE_GENERATOR_RULE_NAMES") load( ":make_variables.bzl", diff --git a/aspect_template/java_info.bzl b/aspect/java_info.bzl similarity index 100% rename from aspect_template/java_info.bzl rename to aspect/java_info.bzl diff --git a/aspect_template/python_info.bzl b/aspect/python_info.bzl similarity index 100% rename from aspect_template/python_info.bzl rename to aspect/python_info.bzl diff --git a/aspect/testing/tests/src/com/google/idea/blaze/aspect/integration/BUILD b/aspect/testing/tests/src/com/google/idea/blaze/aspect/integration/BUILD index ac2031cb31e..9bd0066ca7b 100644 --- a/aspect/testing/tests/src/com/google/idea/blaze/aspect/integration/BUILD +++ b/aspect/testing/tests/src/com/google/idea/blaze/aspect/integration/BUILD @@ -1,30 +1,22 @@ -load( - "@rules_bazel_integration_test//bazel_integration_test:defs.bzl", - "bazel_integration_tests", -) -load("@bazel_binaries//:defs.bzl", "bazel_binaries") +load("//testing:test_defs.bzl", "bazel_integration_tests") java_binary( name = "BazelInvokingIntegrationTestRunner", testonly = True, srcs = ["BazelInvokingIntegrationTestRunner.java"], - data = [ - "//aspect:aspect_files", - "//aspect_template:aspect_files", - ], main_class = "com.google.idea.blaze.aspect.integration.BazelInvokingIntegrationTestRunner", deps = [ "//aspect/testing:guava", "//base", + "//intellij_platform_sdk:jsr305", + "//intellij_platform_sdk:plugin_api_for_tests", + "//intellij_platform_sdk:test_libs", + "//sdkcompat", ], ) bazel_integration_tests( - name = "bazel_invocation_integration_tests", - bazel_versions = bazel_binaries.versions.all, - # set tags = [] because otherwise bazel_integration_tests sets - # tags = ["manual"] and the target is not be detected via test //pkg/... - tags = [], + name = "bazel_invocation_integration_test", test_runner = ":BazelInvokingIntegrationTestRunner", workspace_path = "testdata", ) 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 9d6a68b1393..9230010a452 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 @@ -16,19 +16,20 @@ package com.google.idea.blaze.aspect.integration; import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSet; import com.google.idea.blaze.base.bazel.BazelVersion; import com.google.idea.blaze.base.model.BlazeVersionData; import com.google.idea.blaze.base.model.primitives.LanguageClass; -import com.google.idea.blaze.base.sync.aspects.strategy.AspectStrategy; +import com.google.idea.blaze.base.sync.aspects.storage.AspectRepositoryProvider; import com.google.idea.blaze.base.sync.aspects.strategy.AspectStrategy.OutputGroup; import com.google.idea.blaze.base.sync.aspects.strategy.AspectStrategyBazel; -import com.google.idea.blaze.base.sync.aspects.strategy.OverrideFlags; -import java.io.File; -import java.nio.file.Paths; -import java.util.Collection; -import java.util.HashSet; -import java.util.Set; -import java.util.stream.Collectors; +import java.io.IOException; +import java.nio.file.FileSystems; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.StandardOpenOption; +import java.util.Map; +import org.jetbrains.annotations.Contract; /** * A Bazel-invoking integration test for the bundled IntelliJ aspect. @@ -38,57 +39,30 @@ */ public class BazelInvokingIntegrationTestRunner { + private static final String ASPECT_DIRECTORY = ".ijwb/aspect"; + public static void main(String[] a) throws Exception { - BazelVersion bazelVersion = getBazelVersion(); - if (bazelVersion == null) { - exitWithError( - String.format( - "Failed to get Bazel version from Bazel path (%s)", - System.getenv("BIT_BAZEL_BINARY"))); - } - AspectStrategyBazel aspectStrategyBazel = - new AspectStrategyBazel(BlazeVersionData.builder().setBazelVersion(bazelVersion).build()); - - // Flags for wiring up the plugin aspect from the external @intellij_aspect repository. - ImmutableList aspectFlags = - ImmutableList.of( - aspectStrategyBazel.getAspectFlag().get(), - String.format( - "%s=%s/%s/aspect", - OverrideFlags.overrideRepositoryFlag(false), - System.getenv("TEST_SRCDIR"), - System.getenv("TEST_WORKSPACE")), - String.format( - "%s=%s/%s/aspect_template", - OverrideFlags.overrideRepositoryTemplateFlag(false), - System.getenv("TEST_SRCDIR"), - System.getenv("TEST_WORKSPACE")) - ); - - if (bazelVersion.isAtLeast(6, 0, 0) - && !aspectFlags.contains( - "--aspects=@@intellij_aspect//:intellij_info_bundled.bzl%intellij_info_aspect")) { - exitWithError( - String.format("Incorrect/Missing aspects flag in command args (%s)", aspectFlags)); - } + final var bazelVersion = getBazelVersion(); + final var projectRoot = getProjectRoot(); + + final var aspectDst = projectRoot.resolve(ASPECT_DIRECTORY); + + copyAspects(aspectDst, AspectRepositoryProvider.ASPECT_DIRECTORY); + copyAspects(aspectDst, AspectRepositoryProvider.ASPECT_TEMPLATE_DIRECTORY); ImmutableList.Builder args = ImmutableList.builder(); args.add(System.getenv("BIT_BAZEL_BINARY")); args.add("build"); args.add("//:foo"); args.add("--define=ij_product=intellij-latest"); - args.addAll(aspectFlags); - args.add( - getOutputGroupsFlag( - ImmutableList.of(OutputGroup.INFO), - ImmutableList.of(LanguageClass.GENERIC), - aspectStrategyBazel)); + args.add(String.format("--aspects=//%s:intellij_info_bundled.bzl%%intellij_info_aspect", ASPECT_DIRECTORY)); + args.add(getOutputGroupsFlag(bazelVersion)); ImmutableList command = args.build(); ProcessBuilder processBuilder = new ProcessBuilder() .command(command) - .directory(Paths.get(System.getenv("BIT_WORKSPACE_DIR")).toFile()); + .directory(projectRoot.toFile()); Process bazelInvocation = processBuilder.start(); int exitCode = bazelInvocation.waitFor(); String invocationOutput = new String(bazelInvocation.getErrorStream().readAllBytes()); @@ -107,6 +81,7 @@ public static void main(String[] a) throws Exception { } } + @Contract("_ -> fail") private static void exitWithError(String message) { System.err.println(message); System.exit(1); @@ -119,49 +94,75 @@ private static String getIntelliJInfoTxtFilename(String targetName) { return String.format("%s-%s.intellij-info.txt", targetName, targetName.hashCode()); } - private static String getOutputGroupsFlag( - Collection outputGroups, - Collection languageClassList, - AspectStrategy strategy) { + private static String getOutputGroupsFlag(BazelVersion version) { + final var aspectStrategy = new AspectStrategyBazel( + BlazeVersionData.builder().setBazelVersion(version).build() + ); + // e.g. --output_groups=intellij-info-generic,intellij-resolve-java,intellij-compile-java - Set languageClasses = new HashSet<>(languageClassList); - String outputGroupNames = - outputGroups.stream() - .flatMap( - g -> - strategy - .getBaseOutputGroups(g, languageClasses, /* directDepsOnly= */ false) - .stream()) - .collect(Collectors.joining(",")); - return "--output_groups=" + outputGroupNames; + final var outputGroups = aspectStrategy.getBaseOutputGroups( + OutputGroup.INFO, + ImmutableSet.of(LanguageClass.GENERIC), + /* directDepsOnly= */ false + ); + + return "--output_groups=" + String.join(",", outputGroups); } private static BazelVersion getBazelVersion() { - // The name of the directory containing the bazel binary is formatted as - // build_bazel_bazel_{major}_{minor}_{bugfix}[-pre] for a bazel binary of version - // {major}.{minor}.{bugfix} - String bazelBinaryPath = System.getenv("BIT_BAZEL_BINARY"); - if (bazelBinaryPath == null) { - return null; + final var bitVersion = System.getenv("BIT_BAZEL_VERSION"); + if (bitVersion == null) { + exitWithError("Missing environment variable BIT_BAZEL_VERSION"); } - String bazelDir = new File(bazelBinaryPath).getParentFile().getName(); - // Get the part after last ~ or + (becase of canonicalization with bzlmod) - if (bazelDir.contains("~")) { - bazelDir = bazelDir.substring(bazelDir.lastIndexOf("~") + 1); - } else if (bazelDir.contains("+")) { - bazelDir = bazelDir.substring(bazelDir.lastIndexOf("+") + 1); + + final var version = BazelVersion.parseVersion(bitVersion); + if (version.isAtLeast(999, 0, 0)) { + exitWithError("Unsupported Bazel version: " + bitVersion); } - - String[] parts = bazelDir.split("_|-"); - if (parts.length < 6) { - return null; + + return version; + } + + private static Path getProjectRoot() { + final var bitWorkspace = System.getenv("BIT_WORKSPACE_DIR"); + if (bitWorkspace == null) { + exitWithError("Missing environment variable BIT_WORKSPACE_DIR"); + } + + final var root = Path.of(bitWorkspace); + if (!Files.exists(root)) { + exitWithError("Project root does not exist: " + root); + } + + return root; + } + + private static void copyAspects(Path dst, String src) throws Exception { + final var classLoader = BazelInvokingIntegrationTestRunner.class.getClassLoader(); + + final var srcURL = classLoader.getResource(src); + if (srcURL == null) { + throw new IOException("Cannot resolve source"); } - try { - return new BazelVersion( - Integer.parseInt(parts[3]), Integer.parseInt(parts[4]), Integer.parseInt(parts[5])); - } catch (NumberFormatException e) { - // invalid version - return null; + + final var srcURI = srcURL.toURI(); + + // file system needs to be created manually in this case, VFS cannot be used here :( + try (final var fs = FileSystems.newFileSystem(srcURI, Map.of())) { + final var srcRoot = Path.of(srcURI); + + try (final var stream = Files.walk(srcRoot)) { + for (final var iterator = stream.iterator(); iterator.hasNext(); ) { + final var srcFile = iterator.next(); + final var dstFile = dst.resolve(srcRoot.relativize(srcFile).toString()); + + if (Files.isDirectory(srcFile)) { + Files.createDirectories(dstFile); + } else { + Files.write(dstFile, Files.readAllBytes(srcFile), StandardOpenOption.CREATE); + } + } + } } } -} +} \ No newline at end of file diff --git a/aspect_template/BUILD b/aspect_template/BUILD deleted file mode 100644 index 0ce268dbb73..00000000000 --- a/aspect_template/BUILD +++ /dev/null @@ -1,54 +0,0 @@ -filegroup( - name = "aspect_files", - srcs = [ - "BUILD.bazel", - "WORKSPACE", - "code_generator_info.bzl", - "code_generator_info.template.bzl", - "java_info.bzl", - "java_info.template.bzl", - "python_info.bzl", - "python_info.template.bzl" - ], - visibility = ["//visibility:public"], -) - -STRIP_TEMPLATE_SCRIPT = """cat $(SRCS) >$@ && -sed -i -e '/TEMPLATE-IGNORE-BEGIN/,/TEMPLATE-IGNORE-END/d' $@ && -sed -i -e '/TEMPLATE-INCLUDE-BEGIN/,/TEMPLATE-INCLUDE-END/{s/^[#][#]//;}' $@ -""" - -genrule( - name = "generate_java_info_template", - srcs = ["java_info.bzl"], - outs = ["java_info.template.bzl"], - cmd = STRIP_TEMPLATE_SCRIPT, -) - -genrule( - name = "generate_py_info_template", - srcs = ["python_info.bzl"], - outs = ["python_info.template.bzl"], - cmd = STRIP_TEMPLATE_SCRIPT, -) - -genrule( - name = "generate_code_generator_info_template", - srcs = ["code_generator_info.bzl"], - outs = ["code_generator_info.template.bzl"], - cmd = STRIP_TEMPLATE_SCRIPT, -) - -genrule( - name = "rename_files", - srcs = ["BUILD.aspect"], - outs = ["BUILD.bazel"], - cmd = "cp $< $@", -) - -genrule( - name = "create_workspace_file", - outs = ["WORKSPACE"], - srcs = [], - cmd = r"""echo 'workspace(name = "intellij_aspect_template")' > $@""" -) \ No newline at end of file diff --git a/aspect_template/BUILD.aspect b/aspect_template/BUILD.aspect deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/aspect_template/MODULE.bazel b/aspect_template/MODULE.bazel deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/base/BUILD b/base/BUILD index ee3ca3c6676..7b993edf867 100644 --- a/base/BUILD +++ b/base/BUILD @@ -27,6 +27,9 @@ kt_jvm_library( resource_strip_prefix = "base/src", visibility = PLUGIN_PACKAGES_VISIBILITY, deps = [ + "//aspect:aspect_lib", + "//aspect:aspect_template_lib", + "//aspect:aspect_qsync_lib", "//common/actions", "//common/experiments", "//common/settings", diff --git a/base/src/META-INF/blaze-base.xml b/base/src/META-INF/blaze-base.xml index 55531dc470c..0697e2d168d 100644 --- a/base/src/META-INF/blaze-base.xml +++ b/base/src/META-INF/blaze-base.xml @@ -573,7 +573,7 @@ - + @@ -612,6 +612,7 @@ + @@ -629,11 +630,9 @@ - - @@ -710,6 +709,8 @@ + + diff --git a/base/src/com/google/idea/blaze/base/command/BlazeCommand.java b/base/src/com/google/idea/blaze/base/command/BlazeCommand.java index 1826b4aa80c..2dd9946be07 100644 --- a/base/src/com/google/idea/blaze/base/command/BlazeCommand.java +++ b/base/src/com/google/idea/blaze/base/command/BlazeCommand.java @@ -20,7 +20,6 @@ import com.google.errorprone.annotations.CanIgnoreReturnValue; import com.google.idea.blaze.base.bazel.BuildSystem.BuildInvoker; import com.google.idea.blaze.base.model.primitives.TargetExpression; -import com.google.idea.blaze.base.sync.aspects.strategy.AspectRepositoryProvider; import com.intellij.openapi.project.Project; import java.nio.file.Path; diff --git a/base/src/com/google/idea/blaze/base/plugin/BazelVersionChecker.java b/base/src/com/google/idea/blaze/base/plugin/BazelVersionChecker.java index 4412f0812d3..e58b276cf3f 100644 --- a/base/src/com/google/idea/blaze/base/plugin/BazelVersionChecker.java +++ b/base/src/com/google/idea/blaze/base/plugin/BazelVersionChecker.java @@ -24,7 +24,7 @@ /** Verifies that the available Bazel version is supported by this plugin. */ public class BazelVersionChecker implements BuildSystemVersionChecker { - private static final BazelVersion OLDEST_SUPPORTED_VERSION = new BazelVersion(4, 0, 0); + private static final BazelVersion OLDEST_SUPPORTED_VERSION = new BazelVersion(6, 0, 0); @Override public boolean versionSupported(BlazeContext context, BlazeVersionData version) { diff --git a/base/src/com/google/idea/blaze/base/qsync/BazelDependencyBuilder.java b/base/src/com/google/idea/blaze/base/qsync/BazelDependencyBuilder.java index b388b5b6ee5..725a1858590 100644 --- a/base/src/com/google/idea/blaze/base/qsync/BazelDependencyBuilder.java +++ b/base/src/com/google/idea/blaze/base/qsync/BazelDependencyBuilder.java @@ -53,6 +53,7 @@ import com.google.idea.blaze.base.projectview.ProjectViewSet; import com.google.idea.blaze.base.scope.BlazeContext; import com.google.idea.blaze.base.sync.aspects.BlazeBuildOutputs; +import com.google.idea.blaze.base.sync.aspects.storage.AspectRepositoryProvider; import com.google.idea.blaze.base.vcs.BlazeVcsHandlerProvider.BlazeVcsHandler; import com.google.idea.blaze.common.Context; import com.google.idea.blaze.common.Label; @@ -241,8 +242,8 @@ public OutputInfo build( protected ImmutableMap getAspectFiles() { return ImmutableMap.of( Path.of(".aswb/BUILD"), ByteSource.empty(), - Path.of(".aswb/build_dependencies.bzl"), MoreFiles.asByteSource(getBundledAspectPath("build_dependencies.bzl")), - Path.of(".aswb/build_dependencies_deps.bzl"), MoreFiles.asByteSource(getBundledAspectPath("build_dependencies_deps.bzl")) + Path.of(".aswb/build_dependencies.bzl"), getBundledAspect("build_dependencies.bzl"), + Path.of(".aswb/build_dependencies_deps.bzl"), getBundledAspect("build_dependencies_deps.bzl") ); } @@ -253,27 +254,8 @@ protected Label getGeneratedAspectLabel() { return Label.of("//.aswb:build_dependencies.bzl"); } - protected Path getBundledAspectPath(String dir, String filename) { - String aspectPath = System.getProperty(String.format("qsync.aspect.%s.file", filename)); - if (aspectPath != null) { - return Path.of(aspectPath); - } - PluginDescriptor plugin = checkNotNull(PluginManager.getPluginByClass(getClass())); - Path rootAspectDirectory; - if (Strings.isNotEmpty(aspectLocation.getValue())) { - Path workspaceAbsolutePath = workspaceRoot.absolutePathFor(""); - // NOTE: aspectLocation allows both relative and absolute paths. - rootAspectDirectory = workspaceAbsolutePath.resolve(aspectLocation.getValue()); - logger.info("Using build aspect from: " + rootAspectDirectory); - } - else{ - rootAspectDirectory = plugin.getPluginPath(); - } - return rootAspectDirectory.resolve(dir).resolve(filename); - } - - protected Path getBundledAspectPath(String filename) { - return getBundledAspectPath("aspect", filename); + protected ByteSource getBundledAspect(String filename) { + return AspectRepositoryProvider.aspectQSyncFile(filename); } /** diff --git a/base/src/com/google/idea/blaze/base/qsync/BazelRenderJarBuilder.java b/base/src/com/google/idea/blaze/base/qsync/BazelRenderJarBuilder.java index e4bbd302bb8..84551f17c94 100644 --- a/base/src/com/google/idea/blaze/base/qsync/BazelRenderJarBuilder.java +++ b/base/src/com/google/idea/blaze/base/qsync/BazelRenderJarBuilder.java @@ -15,14 +15,11 @@ */ package com.google.idea.blaze.base.qsync; -import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.collect.ImmutableList.toImmutableList; -import static java.nio.charset.StandardCharsets.UTF_8; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; -import com.google.common.io.CharSource; -import com.google.common.io.MoreFiles; +import com.google.common.io.ByteSource; import com.google.common.util.concurrent.FutureCallback; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; @@ -43,16 +40,16 @@ import com.google.idea.blaze.base.qsync.QuerySyncManager.TaskOrigin; import com.google.idea.blaze.base.scope.BlazeContext; import com.google.idea.blaze.base.sync.aspects.BlazeBuildOutputs; +import com.google.idea.blaze.base.sync.aspects.storage.AspectRepositoryProvider; import com.google.idea.blaze.common.Label; import com.google.idea.blaze.common.artifact.OutputArtifact; import com.google.idea.blaze.exception.BuildException; -import com.intellij.ide.plugins.PluginManager; -import com.intellij.openapi.extensions.PluginDescriptor; import com.intellij.openapi.project.Project; import java.io.IOException; +import java.io.OutputStream; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; +import java.nio.file.StandardOpenOption; import java.util.List; import java.util.Set; import javax.annotation.Nullable; @@ -108,10 +105,6 @@ public RenderJarInfo buildRenderJar(BlazeContext context, Set