forked from bazelbuild/stardoc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrules_jvm_external.patch
142 lines (124 loc) · 6.69 KB
/
rules_jvm_external.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
commit 569fe4da2530d7b1356265d7cc62ca74f93ec7e5
Author: Yun Peng <[email protected]>
Date: Thu Jan 5 16:37:29 2023 +0800
Add targets to make it easier to vendor the `@maven` repository
This change is required to support Bazel's offline bootstrap build.
More context in https://github.com/bazelbuild/bazel/pull/17112
Instead of checking in jar files in Bazel's source tree, Bazel wants to use rules_jvm_external
to fetch jars dependencies. However, to support Bazel's bootstrap build,
we need to patch rules_jvm_external for vendoring the @maven repository.
- Generate a BUILD.vendor file to be used in the vendored `@maven` repository.
Added a jvm_import and a filegroup rule for each downloaded jar artifact.
The filegroup rule is required by the bootstrap Java toolchain used in Bazel's
bootstrap build. The bootstrap Java toolchain cannot depend on a jvm_import target.
Because the jvm_import rule depends on a java_binary tool "AddJarManifestEntry",
which requires a Java toolchain. Depending on the jar via a filegroup rule helps
avoid this cyclic dependency.
- Added a filegroup rule to collect all sources needed for vendoring `@maven`,
including BUILD.vendor, WORKSPACE and jar files.
diff --git a/coursier.bzl b/coursier.bzl
index a71507a..90b4cb0 100644
--- a/coursier.bzl
+++ b/coursier.bzl
@@ -49,6 +49,12 @@ bzl_library(
)
"""
+_BUILD_VENDOR = """
+load("@rules_jvm_external//private/rules:jvm_import.bzl", "jvm_import")
+
+{vendor_targets}
+"""
+
DEFAULT_AAR_IMPORT_LABEL = "@build_bazel_rules_android//android:rules.bzl"
_AAR_IMPORT_STATEMENT = """\
@@ -473,7 +479,7 @@ def _pinned_coursier_fetch_impl(repository_ctx):
)
repository_ctx.report_progress("Generating BUILD targets..")
- (generated_imports, jar_versionless_target_labels) = parser.generate_imports(
+ (generated_imports, jar_versionless_target_labels, generated_vendor_targets) = parser.generate_imports(
repository_ctx = repository_ctx,
dependencies = importer.get_artifacts(maven_install_json_content),
explicit_artifacts = {
@@ -512,6 +518,14 @@ def _pinned_coursier_fetch_impl(repository_ctx):
executable = False,
)
+ repository_ctx.file(
+ "BUILD.vendor",
+ (_BUILD_VENDOR).format(
+ vendor_targets = generated_vendor_targets,
+ ),
+ executable = False,
+ )
+
_add_outdated_files(repository_ctx, artifacts, repositories)
# Generate a compatibility layer of external repositories for all jar artifacts.
@@ -1036,7 +1050,7 @@ def _coursier_fetch_impl(repository_ctx):
)
repository_ctx.report_progress("Generating BUILD targets..")
- (generated_imports, jar_versionless_target_labels) = parser.generate_imports(
+ (generated_imports, jar_versionless_target_labels, _) = parser.generate_imports(
repository_ctx = repository_ctx,
dependencies = v2_lock_file.get_artifacts(lock_file_contents),
explicit_artifacts = {
diff --git a/private/dependency_tree_parser.bzl b/private/dependency_tree_parser.bzl
index 8eea757..0a53528 100644
--- a/private/dependency_tree_parser.bzl
+++ b/private/dependency_tree_parser.bzl
@@ -107,6 +107,9 @@ def _generate_imports(repository_ctx, dependencies, explicit_artifacts, neverlin
for jetify_include_artifact in repository_ctx.attr.jetify_include_list:
jetify_include_dict[jetify_include_artifact] = None
+ artifact_paths = []
+ vendor_targets = []
+
# Iterate through the list of artifacts, and generate the target declaration strings.
for artifact in dependencies:
artifact_path = artifact["file"]
@@ -347,6 +350,7 @@ def _generate_imports(repository_ctx, dependencies, explicit_artifacts, neverlin
target_import_string.append(")")
all_imports.append("\n".join(target_import_string))
+ vendor_targets.append("\n".join(target_import_string))
# 10. Create a versionless alias target
#
@@ -357,6 +361,9 @@ def _generate_imports(repository_ctx, dependencies, explicit_artifacts, neverlin
versioned_target_alias_label = escape(strip_packaging_and_classifier(artifact["coordinates"]))
all_imports.append("alias(\n\tname = \"%s\",\n\tactual = \"%s\",\n%s)" %
(versioned_target_alias_label, target_label, alias_visibility))
+ file_group_target_string = "filegroup(\n\tname = \"%s\",\n\tsrcs = [\"%s\"],\n%s)" % (target_label + "_file", artifact_path, alias_visibility)
+ all_imports.append(file_group_target_string)
+ vendor_targets.append(file_group_target_string)
# 11. If using maven_install.json, use a genrule to copy the file from the http_file
# repository into this repository.
@@ -370,6 +377,9 @@ def _generate_imports(repository_ctx, dependencies, explicit_artifacts, neverlin
if repository_ctx.attr.maven_install_json:
all_imports.append(_genrule_copy_artifact_from_http_file(artifact, default_visibilities))
+ # 12. collect the artifact_path for the filegroup rule collecting all necessary sources for vendoring
+ artifact_paths.append("\"%s\"" % artifact_path)
+
else: # artifact_path == None:
# Special case for certain artifacts that only come with a POM file.
# Such artifacts "aggregate" their dependencies, so they don't have
@@ -421,7 +431,10 @@ def _generate_imports(repository_ctx, dependencies, explicit_artifacts, neverlin
all_imports.append("alias(\n\tname = \"%s\",\n\tactual = \"%s\",\n%s)" %
(versioned_target_alias_label, target_label, alias_visibility))
- return ("\n".join(all_imports), jar_versionless_target_labels)
+ all_imports.append("filegroup(\n\tname = \"srcs\",\n\tsrcs = [\n\t\t%s,\n\t],\n\tvisibility = [\"//visibility:public\"],\n)" %
+ (",\n\t\t".join(["\"BUILD.vendor\"", "\"defs.bzl\"", "\"WORKSPACE\""] + artifact_paths)))
+
+ return ("\n".join(all_imports), jar_versionless_target_labels, "\n".join(vendor_targets))
parser = struct(
generate_imports = _generate_imports,
diff --git a/private/tools/java/com/github/bazelbuild/rules_jvm_external/BUILD b/private/tools/java/com/github/bazelbuild/rules_jvm_external/BUILD
index 63ce118..84e0417 100644
--- a/private/tools/java/com/github/bazelbuild/rules_jvm_external/BUILD
+++ b/private/tools/java/com/github/bazelbuild/rules_jvm_external/BUILD
@@ -1,10 +1,6 @@
java_library(
name = "rules_jvm_external",
srcs = glob(["*.java"]),
- javacopts = [
- "--release",
- "8",
- ],
visibility = [
"//private/tools/java:__subpackages__",
"//tests/com:__subpackages__",