Skip to content

Commit d966a0d

Browse files
oquenchilWyverald
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 #13862 RELNOTES:none PiperOrigin-RevId: 410209862
1 parent 8d5973d commit d966a0d

3 files changed

Lines changed: 38 additions & 2 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1089,7 +1089,7 @@ private static void checkDeprecated(String newApi, String oldApi, StarlarkSemant
10891089
* @param knownLabels List of known labels
10901090
* @return Immutable map with immutable collections as values
10911091
*/
1092-
private static ImmutableMap<Label, ImmutableCollection<Artifact>> makeLabelMap(
1092+
public static ImmutableMap<Label, ImmutableCollection<Artifact>> makeLabelMap(
10931093
Iterable<TransitiveInfoCollection> knownLabels) {
10941094
ImmutableMap.Builder<Label, ImmutableCollection<Artifact>> builder = ImmutableMap.builder();
10951095

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

Lines changed: 16 additions & 1 deletion
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‎

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

0 commit comments

Comments
 (0)