Commit a87b8e0 1 parent 3a7236b commit a87b8e0 Copy full SHA for a87b8e0
File tree 5 files changed +48
-14
lines changed
main/java/com/google/devtools/build/lib
5 files changed +48
-14
lines changed Original file line number Diff line number Diff line change 20
20
import com .google .devtools .build .lib .cmdline .Label ;
21
21
import com .google .devtools .build .lib .skyframe .BuildConfigurationKey ;
22
22
import javax .annotation .Nullable ;
23
+ import net .starlark .java .eval .Dict ;
23
24
import net .starlark .java .eval .Structure ;
24
25
25
26
/**
@@ -95,4 +96,13 @@ default Label getOriginalLabel() {
95
96
default ImmutableMap <Label , ConfigMatchingProvider > getConfigConditions () {
96
97
return ImmutableMap .of ();
97
98
}
99
+
100
+ /**
101
+ * This is only intended to be called from the query dialects of Starlark.
102
+ *
103
+ * @return a map of provider names to their values
104
+ */
105
+ default Dict <String , Object > getProvidersDict () {
106
+ return null ;
107
+ }
98
108
}
Original file line number Diff line number Diff line change 35
35
import com .google .devtools .build .lib .skyframe .BuildConfigurationKey ;
36
36
import java .util .function .Consumer ;
37
37
import javax .annotation .Nullable ;
38
- import net .starlark .java .eval .Dict ;
39
38
import net .starlark .java .eval .EvalException ;
40
39
import net .starlark .java .eval .Printer ;
41
40
import net .starlark .java .eval .Starlark ;
@@ -255,12 +254,4 @@ public String getRuleClassString() {
255
254
public void repr (Printer printer ) {
256
255
printer .append ("<unknown target " + getLabel () + ">" );
257
256
}
258
-
259
- /**
260
- * Returns a map of provider names to their values. This is only intended to be called from the
261
- * query dialects of Starlark. Implement in subclasses which can have providers.
262
- */
263
- public Dict <String , Object > getProvidersDict () {
264
- return null ;
265
- }
266
257
}
Original file line number Diff line number Diff line change 21
21
import com .google .devtools .build .lib .analysis .config .BuildConfigurationValue ;
22
22
import com .google .devtools .build .lib .analysis .config .BuildOptions ;
23
23
import com .google .devtools .build .lib .analysis .config .FragmentOptions ;
24
- import com .google .devtools .build .lib .analysis .configuredtargets .AbstractConfiguredTarget ;
25
24
import com .google .devtools .build .lib .cmdline .Label ;
26
25
import com .google .devtools .build .lib .events .Event ;
27
26
import com .google .devtools .build .lib .events .ExtendedEventHandler ;
@@ -121,10 +120,7 @@ public Object buildOptions(ConfiguredTarget target) {
121
120
@ Param (name = "target" ),
122
121
})
123
122
public Object providers (ConfiguredTarget target ) {
124
- if (!(target instanceof AbstractConfiguredTarget )) {
125
- return Starlark .NONE ;
126
- }
127
- Dict <String , Object > ret = ((AbstractConfiguredTarget ) target ).getProvidersDict ();
123
+ Dict <String , Object > ret = target .getProvidersDict ();
128
124
if (ret == null ) {
129
125
return Starlark .NONE ;
130
126
}
Original file line number Diff line number Diff line change 38
38
import com .google .devtools .build .lib .packages .Provider ;
39
39
import com .google .devtools .build .lib .skyframe .BuildConfigurationKey ;
40
40
import javax .annotation .Nullable ;
41
+ import net .starlark .java .eval .Dict ;
41
42
import net .starlark .java .eval .EvalException ;
42
43
import net .starlark .java .eval .Printer ;
43
44
import net .starlark .java .eval .StarlarkSemantics ;
@@ -196,6 +197,11 @@ public Label getOriginalLabel() {
196
197
return label ;
197
198
}
198
199
200
+ @ Override
201
+ public Dict <String , Object > getProvidersDict () {
202
+ return actual .getProvidersDict ();
203
+ }
204
+
199
205
@ Override
200
206
public void repr (Printer printer ) {
201
207
printer .append ("<alias target " + label + " of " + actual .getLabel () + ">" );
Original file line number Diff line number Diff line change @@ -1268,6 +1268,37 @@ EOF
1268
1268
assert_contains " some_value" output
1269
1269
}
1270
1270
1271
+ function test_starlark_output_providers_starlark_provider_for_alias() {
1272
+ local -r pkg=$FUNCNAME
1273
+ mkdir -p $pkg
1274
+ cat > $pkg /BUILD << EOF
1275
+ load(":my_rule.bzl", "my_rule")
1276
+ my_rule(name="myrule")
1277
+ alias(name="myalias", actual="myrule")
1278
+ EOF
1279
+ cat > $pkg /my_rule.bzl << 'EOF '
1280
+ # A no-op rule that manifests a provider
1281
+ MyRuleInfo = provider(fields={"label": "a_rule_label"})
1282
+
1283
+ def _my_rule_impl(ctx):
1284
+ return [MyRuleInfo(label="some_value")]
1285
+
1286
+ my_rule = rule(
1287
+ implementation = _my_rule_impl,
1288
+ attrs = {},
1289
+ )
1290
+ EOF
1291
+ cat > $pkg /outfunc.bzl << EOF
1292
+ def format(target):
1293
+ p = providers(target)
1294
+ return p["//$pkg :my_rule.bzl%MyRuleInfo"].label
1295
+ EOF
1296
+ bazel cquery " //$pkg :myalias" --output=starlark --starlark:file=" $pkg /outfunc.bzl" > output \
1297
+ 2> " $TEST_log " || fail " Expected success"
1298
+
1299
+ assert_contains " some_value" output
1300
+ }
1301
+
1271
1302
function test_bazelignore_error_cquery_nocrash() {
1272
1303
local -r pkg=$FUNCNAME
1273
1304
You can’t perform that action at this time.
0 commit comments