Skip to content

Commit fd727ec

Browse files
oquenchilcopybara-github
authored andcommitted
Do location expansion in copts of objc_library
Roll forward with placing every TransitiveInfoCollection in a set so that duplicate entries are removed. Test has been modified to exercise the duplicate case. Fixes bazelbuild#13862 RELNOTES:none PiperOrigin-RevId: 410209862
1 parent e5b3536 commit fd727ec

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

src/main/java/com/google/devtools/build/lib/analysis/starlark/StarlarkRuleContext.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1103,7 +1103,7 @@ private static void checkDeprecated(String newApi, String oldApi, StarlarkSemant
11031103
* @param knownLabels List of known labels
11041104
* @return Immutable map with immutable collections as values
11051105
*/
1106-
private static ImmutableMap<Label, ImmutableCollection<Artifact>> makeLabelMap(
1106+
public static ImmutableMap<Label, ImmutableCollection<Artifact>> makeLabelMap(
11071107
Iterable<TransitiveInfoCollection> knownLabels) {
11081108
ImmutableMap.Builder<Label, ImmutableCollection<Artifact>> builder = ImmutableMap.builder();
11091109

src/main/java/com/google/devtools/build/lib/rules/objc/ObjcStarlarkInternal.java

+16-1
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@
1818

1919
import com.google.common.collect.ImmutableList;
2020
import com.google.common.collect.ImmutableMap;
21+
import com.google.common.collect.ImmutableSet;
22+
import com.google.common.collect.Iterables;
2123
import com.google.devtools.build.docgen.annot.DocCategory;
2224
import com.google.devtools.build.lib.actions.Artifact;
25+
import com.google.devtools.build.lib.analysis.LocationExpander;
2326
import com.google.devtools.build.lib.analysis.TemplateVariableInfo;
2427
import com.google.devtools.build.lib.analysis.starlark.StarlarkRuleContext;
2528
import com.google.devtools.build.lib.analysis.test.InstrumentedFilesInfo;
@@ -116,7 +119,19 @@ public Sequence<String> expandToolchainAndRuleContextVariables(
116119
ImmutableMap.<String, String>builder().putAll(starlarkRuleContext.var()).build();
117120
List<String> expandedFlags = new ArrayList<>();
118121
for (String flag : Sequence.cast(flags, String.class, "flags")) {
119-
String expandedFlag = expandFlag(flag, toolchainMap, starlarkRuleContextMap);
122+
123+
String expandedFlag =
124+
LocationExpander.withExecPaths(
125+
starlarkRuleContext.getRuleContext(),
126+
StarlarkRuleContext.makeLabelMap(
127+
ImmutableSet.copyOf(
128+
Iterables.concat(
129+
starlarkRuleContext.getRuleContext().getPrerequisites("srcs"),
130+
starlarkRuleContext.getRuleContext().getPrerequisites("non_arc_srcs"),
131+
starlarkRuleContext.getRuleContext().getPrerequisites("hdrs"),
132+
starlarkRuleContext.getRuleContext().getPrerequisites("data")))))
133+
.expand(flag);
134+
expandedFlag = expandFlag(expandedFlag, toolchainMap, starlarkRuleContextMap);
120135
try {
121136
ShellUtils.tokenize(expandedFlags, expandedFlag);
122137
} catch (TokenizationException e) {

src/test/java/com/google/devtools/build/lib/rules/objc/ObjcLibraryTest.java

+21
Original file line numberDiff line numberDiff line change
@@ -2380,4 +2380,25 @@ public void testCompilationPrerequisitesHasHeaders() throws Exception {
23802380
.getOutputGroup(OutputGroupInfo.COMPILATION_PREREQUISITES)))
23812381
.contains("src bin/cc.h");
23822382
}
2383+
2384+
@Test
2385+
public void testCoptsLocationIsExpanded() throws Exception {
2386+
scratch.file(
2387+
"bin/BUILD",
2388+
"objc_library(",
2389+
" name = 'lib',",
2390+
" copts = ['$(rootpath lib1.m) $(location lib2.m) $(location data.data) $(execpath"
2391+
+ " header.h)'],",
2392+
" srcs = ['lib1.m'],",
2393+
" non_arc_srcs = ['lib2.m'],",
2394+
" data = ['data.data', 'lib2.m'],",
2395+
" hdrs = ['header.h'],",
2396+
")");
2397+
2398+
useConfiguration("--apple_platform_type=ios", "--cpu=ios_x86_64");
2399+
2400+
CppCompileAction compileA = (CppCompileAction) compileAction("//bin:lib", "lib1.o");
2401+
assertThat(compileA.compileCommandLine.getCopts())
2402+
.containsAtLeast("bin/lib1.m", "bin/lib2.m", "bin/data.data", "bin/header.h");
2403+
}
23832404
}

0 commit comments

Comments
 (0)