Refactor apple_static_library use of split transition
The current way the native code is written cannot be re-written to Starlark. It looks like everything that cannot be done in Starlark can be refactored away. Mainly, the code used to pass the build configuration from each of the list of transitioned deps to lower level APIs that were using that configuration to for example build artifacts in a specific directory (which is unnecessary). In Starlark an action can only output to the directory of the current configured target.
RELNOTES:none
PiperOrigin-RevId: 387330041
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/AppleStaticLibrary.java b/src/main/java/com/google/devtools/build/lib/rules/objc/AppleStaticLibrary.java
index 14da423..0ce9833 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/AppleStaticLibrary.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/AppleStaticLibrary.java
@@ -103,7 +103,7 @@
CcToolchainProvider childToolchain = entry.getValue();
IntermediateArtifacts intermediateArtifacts =
- ObjcRuleClasses.intermediateArtifacts(ruleContext, childToolchainConfig);
+ ObjcRuleClasses.intermediateArtifacts(ruleContext, ruleContext.getConfiguration());
ObjcCommon common =
common(
@@ -120,21 +120,16 @@
.map(CcInfo::getCcLinkingContext)
.collect(ImmutableList.toImmutableList()));
- librariesToLipo.add(intermediateArtifacts.strippedSingleArchitectureLibrary());
+ Artifact archive = intermediateArtifacts.strippedSingleArchitectureLibrary(childCpu);
+ librariesToLipo.add(archive);
CompilationSupport compilationSupport =
new CompilationSupport.Builder(ruleContext, cppSemantics)
- .setConfig(childToolchainConfig)
.setToolchainProvider(childToolchain)
.setOutputGroupCollector(outputGroupCollector)
.build();
- compilationSupport
- .registerCompileAndArchiveActions(
- common.getCompilationArtifacts().get(), ObjcCompilationContext.EMPTY)
- .registerFullyLinkAction(
- objcProvider, intermediateArtifacts.strippedSingleArchitectureLibrary())
- .validateAttributes();
+ compilationSupport.registerFullyLinkAction(objcProvider, archive).validateAttributes();
ruleContext.assertNoErrors();
addTransitivePropagatedKeys(objcProviderBuilder, objcProvider);
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java b/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java
index 6e6bb5e..416136d 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java
@@ -1048,7 +1048,8 @@
new ObjcVariablesExtension.Builder()
.setRuleContext(ruleContext)
.setIntermediateArtifacts(intermediateArtifacts)
- .setConfiguration(buildConfiguration);
+ .setConfiguration(buildConfiguration)
+ .addVariableCategory(VariableCategory.MODULE_MAP_VARIABLES);
CompilationResult compilationResult;
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/IntermediateArtifacts.java b/src/main/java/com/google/devtools/build/lib/rules/objc/IntermediateArtifacts.java
index 94199fd..fbcb557 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/IntermediateArtifacts.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/IntermediateArtifacts.java
@@ -154,8 +154,8 @@
* The artifact which is the fully-linked static library comprised of statically linking compiled
* sources and dependencies together.
*/
- public Artifact strippedSingleArchitectureLibrary() {
- return appendExtension("-fl.a");
+ public Artifact strippedSingleArchitectureLibrary(String childCpu) {
+ return appendExtension("-" + childCpu + "-fl.a");
}
/**
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcVariablesExtension.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcVariablesExtension.java
index 25745cf..e4007ce 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcVariablesExtension.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcVariablesExtension.java
@@ -36,7 +36,6 @@
static final String PCH_FILE_VARIABLE_NAME = "pch_file";
static final String FRAMEWORKS_PATH_NAME = "framework_paths";
- static final String MODULES_MAPS_DIR_NAME = "module_maps_dir";
static final String OBJC_MODULE_CACHE_DIR_NAME = "_objc_module_cache";
static final String OBJC_MODULE_CACHE_KEY = "modules_cache_path";
static final String OBJ_LIST_PATH_VARIABLE_NAME = "obj_list_path";
@@ -121,13 +120,16 @@
EXECUTABLE_LINKING_VARIABLES,
DSYM_VARIABLES,
LINKMAP_VARIABLES,
- BITCODE_VARIABLES
+ BITCODE_VARIABLES,
+ MODULE_MAP_VARIABLES
}
@Override
public void addVariables(CcToolchainVariables.Builder builder) {
addPchVariables(builder);
- addModuleMapVariables(builder);
+ if (activeVariableCategories.contains(VariableCategory.MODULE_MAP_VARIABLES)) {
+ addModuleMapVariables(builder);
+ }
if (activeVariableCategories.contains(VariableCategory.ARCHIVE_VARIABLES)) {
addArchiveVariables(builder);
}
@@ -163,14 +165,6 @@
private void addModuleMapVariables(CcToolchainVariables.Builder builder) {
builder.addStringVariable(
- MODULES_MAPS_DIR_NAME,
- intermediateArtifacts
- .swiftModuleMap()
- .getArtifact()
- .getExecPath()
- .getParentDirectory()
- .toString());
- builder.addStringVariable(
OBJC_MODULE_CACHE_KEY,
buildConfiguration.getGenfilesFragment(ruleContext.getRepository())
+ "/"
diff --git a/src/main/starlark/builtins_bzl/common/objc/compilation_support.bzl b/src/main/starlark/builtins_bzl/common/objc/compilation_support.bzl
index 4804d43..65d8913 100644
--- a/src/main/starlark/builtins_bzl/common/objc/compilation_support.bzl
+++ b/src/main/starlark/builtins_bzl/common/objc/compilation_support.bzl
@@ -30,8 +30,6 @@
if hasattr(ctx.attr, "pch") and ctx.attr.pch != None:
extensions["pch_file"] = ctx.file.pch.path
- extensions["module_maps_dir"] = intermediate_artifacts.swift_module_map.file().path
-
extensions["modules_cache_path"] = ctx.genfiles_dir.path + "/" + "_objc_module_cache"
if "ARCHIVE_VARIABLE" in variable_categories:
diff --git a/src/test/java/com/google/devtools/build/lib/rules/objc/AppleStaticLibraryTest.java b/src/test/java/com/google/devtools/build/lib/rules/objc/AppleStaticLibraryTest.java
index ba99ac9..5da03b6 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/objc/AppleStaticLibraryTest.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/objc/AppleStaticLibraryTest.java
@@ -29,6 +29,7 @@
import com.google.devtools.build.lib.analysis.ConfiguredTarget;
import com.google.devtools.build.lib.analysis.OutputGroupInfo;
import com.google.devtools.build.lib.analysis.actions.SymlinkAction;
+import com.google.devtools.build.lib.cmdline.RepositoryName;
import com.google.devtools.build.lib.packages.util.MockObjcSupport;
import com.google.devtools.build.lib.rules.apple.AppleConfiguration.ConfigurationDistinguisher;
import com.google.devtools.build.lib.rules.cpp.CppRuleClasses;
@@ -124,25 +125,21 @@
useConfiguration("--ios_multi_cpus=i386,x86_64");
CommandAction action = (CommandAction) lipoLibAction("//x:x");
- String i386Lib =
- configurationBin("i386", ConfigurationDistinguisher.APPLEBIN_IOS) + "x/x-fl.a";
- String x8664Lib =
- configurationBin("x86_64", ConfigurationDistinguisher.APPLEBIN_IOS) + "x/x-fl.a";
+ String i386Lib = "x/x-ios_i386-fl.a";
+ String x8664Lib = "x/x-ios_x86_64-fl.a";
- assertThat(Artifact.asExecPaths(action.getInputs()))
- .containsExactly(
- i386Lib, x8664Lib, MOCK_XCRUNWRAPPER_PATH, MOCK_XCRUNWRAPPER_EXECUTABLE_PATH);
+ assertThat(Artifact.toRootRelativePaths(action.getInputs())).containsAtLeast(i386Lib, x8664Lib);
- assertThat(action.getArguments())
- .containsExactly(
- MOCK_XCRUNWRAPPER_EXECUTABLE_PATH,
- LIPO,
- "-create",
- i386Lib,
- x8664Lib,
- "-o",
- execPathEndingWith(action.getOutputs(), "x_lipo.a"))
- .inOrder();
+ assertContainsSublist(
+ action.getArguments(),
+ ImmutableList.of(MOCK_XCRUNWRAPPER_EXECUTABLE_PATH, LIPO, "-create"));
+ String binFragment =
+ removeConfigFragment(targetConfig.getBinFragment(RepositoryName.MAIN) + "/");
+ assertThat(removeConfigFragment(action.getArguments()))
+ .containsAtLeast(binFragment + i386Lib, binFragment + x8664Lib);
+ assertContainsSublist(
+ action.getArguments(),
+ ImmutableList.of("-o", execPathEndingWith(action.getOutputs(), "x_lipo.a")));
assertThat(Artifact.toRootRelativePaths(action.getOutputs()))
.containsExactly("x/x_lipo.a");
@@ -162,8 +159,7 @@
Action lipoAction = lipoLibAction("//package:test");
- String i386Bin =
- configurationBin("i386", ConfigurationDistinguisher.APPLEBIN_WATCHOS) + "package/test-fl.a";
+ String i386Bin = "i386-fl.a";
Artifact libArtifact = getFirstArtifactEndingWith(lipoAction.getInputs(), i386Bin);
CommandAction linkAction = (CommandAction) getGeneratingAction(libArtifact);
CommandAction objcLibCompileAction =
@@ -193,13 +189,11 @@
CommandAction i386BinAction =
(CommandAction)
- getGeneratingAction(
- getFirstArtifactEndingWith(action.getInputs(), i386Prefix + "package/test-fl.a"));
+ getGeneratingAction(getFirstArtifactEndingWith(action.getInputs(), "i386-fl.a"));
CommandAction x8664BinAction =
(CommandAction)
- getGeneratingAction(
- getFirstArtifactEndingWith(action.getInputs(), x8664Prefix + "package/test-fl.a"));
+ getGeneratingAction(getFirstArtifactEndingWith(action.getInputs(), "x86_64-fl.a"));
assertThat(Artifact.asExecPaths(i386BinAction.getInputs()))
.contains(i386Prefix + "package/libcclib.a");
@@ -215,18 +209,18 @@
useConfiguration("--ios_multi_cpus=x86_64", "--ios_cpu=x86_64", "--watchos_cpus=i386,armv7k");
CommandAction action = (CommandAction) lipoLibAction("//x:x");
- String i386Bin = configurationBin("i386", ConfigurationDistinguisher.APPLEBIN_WATCHOS)
- + "x/x-fl.a";
- String armv7kBin = configurationBin("armv7k", ConfigurationDistinguisher.APPLEBIN_WATCHOS)
- + "x/x-fl.a";
+ String i386Bin = "x/x-watchos_i386-fl.a";
+ String armv7kBin = "x/x-watchos_armv7k-fl.a";
- assertThat(Artifact.asExecPaths(action.getInputs()))
- .containsExactly(
- i386Bin, armv7kBin, MOCK_XCRUNWRAPPER_PATH, MOCK_XCRUNWRAPPER_EXECUTABLE_PATH);
+ assertThat(Artifact.toRootRelativePaths(action.getInputs()))
+ .containsAtLeast(i386Bin, armv7kBin);
assertContainsSublist(action.getArguments(), ImmutableList.of(
MOCK_XCRUNWRAPPER_EXECUTABLE_PATH, LIPO, "-create"));
- assertThat(action.getArguments()).containsAtLeast(armv7kBin, i386Bin);
+ String binFragment =
+ removeConfigFragment(targetConfig.getBinFragment(RepositoryName.MAIN) + "/");
+ assertThat(removeConfigFragment(action.getArguments()))
+ .containsAtLeast(binFragment + armv7kBin, binFragment + i386Bin);
assertContainsSublist(action.getArguments(), ImmutableList.of(
"-o", execPathEndingWith(action.getOutputs(), "x_lipo.a")));
@@ -334,8 +328,7 @@
Action lipoAction = lipoLibAction("//x:x");
- String i386Lib =
- configurationBin("i386", ConfigurationDistinguisher.APPLEBIN_WATCHOS) + "x/x-fl.a";
+ String i386Lib = "i386-fl.a";
Artifact binArtifact = getFirstArtifactEndingWith(lipoAction.getInputs(), i386Lib);
CommandAction linkAction = (CommandAction) getGeneratingAction(binArtifact);
@@ -349,9 +342,7 @@
Action lipoAction = lipoLibAction("//x:x");
- String armv7kLib =
- configurationBin("armv7k", ConfigurationDistinguisher.APPLEBIN_WATCHOS)
- + "x/x-fl.a";
+ String armv7kLib = "armv7k-fl.a";
Artifact libArtifact = getFirstArtifactEndingWith(lipoAction.getInputs(), armv7kLib);
CommandAction linkAction = (CommandAction) getGeneratingAction(libArtifact);
@@ -384,8 +375,7 @@
Action lipoAction = lipoLibAction("//package:test");
- String i386Bin =
- configurationBin("i386", ConfigurationDistinguisher.APPLEBIN_WATCHOS) + "package/test-fl.a";
+ String i386Bin = "i386-fl.a";
Artifact binArtifact = getFirstArtifactEndingWith(lipoAction.getInputs(), i386Bin);
CommandAction linkAction = (CommandAction) getGeneratingAction(binArtifact);
diff --git a/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcRuleTestCase.java b/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcRuleTestCase.java
index 3d2ccb4d..054393a 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcRuleTestCase.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/objc/ObjcRuleTestCase.java
@@ -698,7 +698,7 @@
// across a configuration transition.
Action lipoAction = lipoLibAction(libLabel);
if (lipoAction != null) {
- Artifact binArtifact = getFirstArtifactEndingWith(lipoAction.getInputs(), "-fl.a");
+ Artifact binArtifact = getFirstArtifactEndingWith(lipoAction.getInputs(), "fl.a");
linkAction = (CommandAction) getGeneratingAction(binArtifact);
}
}