File tree 2 files changed +28
-3
lines changed
main/java/com/google/devtools/build/lib/rules/cpp
test/java/com/google/devtools/build/lib/rules/cpp
2 files changed +28
-3
lines changed Original file line number Diff line number Diff line change @@ -580,19 +580,29 @@ private List<String> getDefinesFromAttribute(String attr) {
580
580
List <String > defines = new ArrayList <>();
581
581
582
582
// collect labels that can be subsituted in defines
583
- ImmutableMap . Builder <Label , ImmutableCollection <Artifact >> builder = ImmutableMap . builder ();
583
+ Map <Label , ImmutableCollection <Artifact >> map = Maps . newLinkedHashMap ();
584
584
585
585
if (ruleContext .attributes ().has ("deps" , LABEL_LIST )) {
586
586
for (TransitiveInfoCollection current : ruleContext .getPrerequisites ("deps" )) {
587
- builder .put (
587
+ map .put (
588
588
AliasProvider .getDependencyLabel (current ),
589
589
current .getProvider (FileProvider .class ).getFilesToBuild ().toList ());
590
590
}
591
591
}
592
592
593
+ if (ruleContext .attributes ().has ("data" , LABEL_LIST )) {
594
+ for (TransitiveInfoCollection current : ruleContext .getPrerequisites ("data" )) {
595
+ Label dataDependencyLabel = AliasProvider .getDependencyLabel (current );
596
+ if (!map .containsKey (dataDependencyLabel )) {
597
+ map .put (
598
+ dataDependencyLabel ,
599
+ current .getProvider (FileProvider .class ).getFilesToBuild ().toList ());
600
+ }
601
+ }
602
+ }
593
603
// tokenize defines and substitute make variables
594
604
for (String define :
595
- ruleContext .getExpander ().withExecLocations (builder . buildOrThrow ( )).list (attr )) {
605
+ ruleContext .getExpander ().withExecLocations (ImmutableMap . copyOf ( map )).list (attr )) {
596
606
List <String > tokens = new ArrayList <>();
597
607
try {
598
608
ShellUtils .tokenize (tokens , define );
Original file line number Diff line number Diff line change @@ -269,6 +269,21 @@ public void testExpandedDefinesAgainstSrcs() throws Exception {
269
269
.containsExactly ("FOO=expanded_defines/defines.cc" );
270
270
}
271
271
272
+ @ Test
273
+ public void testExpandedDefinesAgainstData () throws Exception {
274
+ scratch .file ("data/BUILD" , "filegroup(name = 'data', srcs = ['data.txt'])" );
275
+ ConfiguredTarget expandedDefines =
276
+ scratchConfiguredTarget (
277
+ "expanded_defines" ,
278
+ "expand_srcs" ,
279
+ "cc_library(name = 'expand_srcs'," ,
280
+ " srcs = ['defines.cc']," ,
281
+ " data = ['//data']," ,
282
+ " defines = ['FOO=$(location //data)'])" );
283
+ assertThat (expandedDefines .get (CcInfo .PROVIDER ).getCcCompilationContext ().getDefines ())
284
+ .containsExactly ("FOO=data/data.txt" );
285
+ }
286
+
272
287
@ Test
273
288
public void testStartEndLib () throws Exception {
274
289
getAnalysisMock ()
You can’t perform that action at this time.
0 commit comments