14
14
15
15
"""starlark macros to generate maven files."""
16
16
17
- load ("@google_bazel_common//tools/javadoc:javadoc.bzl" , "javadoc_library" )
18
17
load ("@google_bazel_common//tools/jarjar:jarjar.bzl" , "jarjar_library" )
18
+ load ("@google_bazel_common//tools/javadoc:javadoc.bzl" , "javadoc_library" )
19
19
load ("@google_bazel_common//tools/maven:pom_file.bzl" , "pom_file" )
20
20
21
21
ExportInfo = provider (
@@ -44,8 +44,8 @@ def _validate_target_libs_rule_impl(ctx):
44
44
artifact.
45
45
"""
46
46
target = ctx .attr .target
47
- expected = [lib .label for lib in target [ExportInfo ].exports .to_list ()]
48
- actual = [lib .label for lib in ctx .attr .actual_target_libs ]
47
+ expected = [lib .label for lib in target [ExportInfo ].exports .to_list () if str ( lib . label ) not in ctx . attr . optional_target_libs ]
48
+ actual = [lib .label for lib in ctx .attr .actual_target_libs if lib . label not in ctx . attr . optional_target_libs ]
49
49
missing = sorted (['"{}"' .format (x ) for x in expected if x not in actual ])
50
50
extra = sorted (['"{}"' .format (x ) for x in actual if x not in expected ])
51
51
if missing or extra :
@@ -60,6 +60,10 @@ _validate_target_libs_rule = rule(
60
60
attrs = {
61
61
"target" : attr .label (aspects = [_collect_exports_aspect ]),
62
62
"actual_target_libs" : attr .label_list (),
63
+
64
+ # This is a string_list instead of label_list to allow exluding
65
+ # transitive exports for which the caller lacks visibility.
66
+ "optional_target_libs" : attr .string_list (),
63
67
},
64
68
)
65
69
@@ -71,6 +75,7 @@ def gen_maven_artifact(
71
75
javadoc_srcs ,
72
76
packaging = "jar" ,
73
77
artifact_target_libs = [],
78
+ optional_artifact_target_libs = [],
74
79
is_extension = False ):
75
80
"""Generates files required for a maven artifact.
76
81
@@ -81,6 +86,10 @@ def gen_maven_artifact(
81
86
artifact_target: The target containing the actual maven target.
82
87
artifact_target_libs: The list of dependencies that should be packaged together with artifact_target,
83
88
corresponding to the list of targets exported by artifact_target.
89
+ optional_artifact_target_libs: The list of labels that are allowed to be
90
+ omitted from artifact_target_libs. Other than these exceptions, all
91
+ transitive exports of artifact_target must be included in
92
+ artifact_target_libs.
84
93
javadoc_srcs: Source files used to generate the Javadoc maven artifact.
85
94
packaging: The packaging used for the artifact, default is "jar".
86
95
is_extension: Whether the maven artifact is a Guice extension or not.
@@ -91,17 +100,24 @@ def gen_maven_artifact(
91
100
name = name + "_validate_target_libs" ,
92
101
target = artifact_target ,
93
102
actual_target_libs = artifact_target_libs ,
103
+ optional_target_libs = optional_artifact_target_libs ,
94
104
)
95
105
96
106
group_id = "com.google.inject"
97
107
if is_extension :
98
108
group_id = "com.google.inject.extensions"
99
109
100
- # TODO: get artifact_target_libs from bazel and remove the need to pass this in explictly.
110
+ # Ideally we would get artifact_target_libs from bazel and remove the need
111
+ # to pass this in explictly. However, this doesn't seem possible in Starlark.
112
+ # A more significant refactoring of how we instantiate the rules here, or
113
+ # extensions to the rule implementation(s), may be necessary.
101
114
artifact_targets = [artifact_target ] + artifact_target_libs
102
115
103
116
pom_file (
104
117
name = "pom" ,
118
+ # pom_file already scans the transitive deps and exports
119
+ # so passing artifact_targets instead of artifact_target seems to be
120
+ # redundant.
105
121
targets = artifact_targets ,
106
122
preferred_group_ids = [
107
123
"com.google.inject" ,
@@ -132,6 +148,9 @@ def gen_maven_artifact(
132
148
name = artifact_id + "-javadoc" ,
133
149
srcs = javadoc_srcs ,
134
150
testonly = 1 ,
151
+ # javadoc_library already collects the transitive deps
152
+ # so passing artifact_targets instead of artifact_target appears to
153
+ # be redundant
135
154
deps = artifact_targets ,
136
155
)
137
156
0 commit comments