Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy aspect files to workspace #7202

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 2 additions & 4 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,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",
mai93 marked this conversation as resolved.
Show resolved Hide resolved
)
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")
Expand Down
7 changes: 0 additions & 7 deletions WORKSPACE.bzlmod
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
93 changes: 67 additions & 26 deletions aspect/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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"])

Expand All @@ -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",
Expand All @@ -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"],
)

Expand All @@ -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' $@",
)

Expand All @@ -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//', $@",
)

Expand All @@ -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,
)
63 changes: 63 additions & 0 deletions aspect/build_defs.bzl
Original file line number Diff line number Diff line change
@@ -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
)
2 changes: 1 addition & 1 deletion aspect/fast_build_info.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
6 changes: 3 additions & 3 deletions aspect/intellij_info_impl.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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",
)
Loading