aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build
diff options
context:
space:
mode:
authorGravatar Rumou Duan <rduan@google.com>2017-02-21 21:21:49 +0000
committerGravatar Irina Iancu <elenairina@google.com>2017-02-22 08:28:12 +0000
commit7463237970f82ace1864f461034d8570fba647f2 (patch)
treeec7e10e622ab5a5051ea7169c8a79af22bc807e7 /src/main/java/com/google/devtools/build
parent34f47c81fc82bc9c6bd5f24c212d31555fe96bc9 (diff)
Crosstool compilation support for J2ObjcAspect.
Note that I also have to make some changes to cpp files to add the ability to specify a suffix for linked artifacts. This helps to avoid an artifact conflict between proto_library and J2ObjcAspect acting on proto_library, where both will create an archive file. J2ObjcAspect will simply generate a "_j2objc.a" archive instead of ".a" archive. -- PiperOrigin-RevId: 148135630 MOS_MIGRATED_REVID=148135630
Diffstat (limited to 'src/main/java/com/google/devtools/build')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibraryHelper.java26
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java9
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CppModel.java21
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java86
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/objc/CrosstoolCompilationSupport.java44
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/objc/IntermediateArtifacts.java13
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcAspect.java37
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/objc/LegacyCompilationSupport.java9
8 files changed, 197 insertions, 48 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibraryHelper.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibraryHelper.java
index 11fcd4777a..f29682238e 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibraryHelper.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibraryHelper.java
@@ -298,6 +298,7 @@ public final class CcLibraryHelper {
private final FeatureConfiguration featureConfiguration;
private CcToolchainProvider ccToolchain;
private final FdoSupportProvider fdoSupport;
+ private String linkedArtifactNameSuffix = "";
/**
* Creates a CcLibraryHelper.
@@ -817,6 +818,18 @@ public final class CcLibraryHelper {
return this;
}
+ /*
+ * Adds a suffix for paths of linked artifacts. Normally their paths are derived solely from rule
+ * labels. In the case of multiple callers (e.g., aspects) acting on a single rule, they may
+ * generate the same linked artifact and therefore lead to artifact conflicts. This method
+ * provides a way to avoid this artifact conflict by allowing different callers acting on the same
+ * rule to provide a suffix that will be used to scope their own linked artifacts.
+ */
+ public CcLibraryHelper setLinkedArtifactNameSuffix(String suffix) {
+ this.linkedArtifactNameSuffix = Preconditions.checkNotNull(suffix);
+ return this;
+ }
+
/**
* This adds the {@link CcNativeLibraryProvider} to the providers created by this class.
*/
@@ -1086,16 +1099,20 @@ public final class CcLibraryHelper {
if (ruleContext.attributes().get("alwayslink", Type.BOOLEAN)) {
archiveFile.add(
CppHelper.getLinuxLinkedArtifact(
- ruleContext, Link.LinkTargetType.ALWAYS_LINK_STATIC_LIBRARY));
+ ruleContext,
+ Link.LinkTargetType.ALWAYS_LINK_STATIC_LIBRARY,
+ linkedArtifactNameSuffix));
} else {
archiveFile.add(
- CppHelper.getLinuxLinkedArtifact(ruleContext, Link.LinkTargetType.STATIC_LIBRARY));
+ CppHelper.getLinuxLinkedArtifact(
+ ruleContext, Link.LinkTargetType.STATIC_LIBRARY, linkedArtifactNameSuffix));
}
if (!ruleContext.attributes().get("linkstatic", Type.BOOLEAN)
&& !ccOutputs.isEmpty()) {
dynamicLibrary.add(
- CppHelper.getLinuxLinkedArtifact(ruleContext, Link.LinkTargetType.DYNAMIC_LIBRARY));
+ CppHelper.getLinuxLinkedArtifact(
+ ruleContext, Link.LinkTargetType.DYNAMIC_LIBRARY, linkedArtifactNameSuffix));
}
outputGroups.put("archive", archiveFile.build());
@@ -1122,7 +1139,8 @@ public final class CcLibraryHelper {
.setDynamicLibrary(dynamicLibrary)
.addLinkopts(linkopts)
.setFeatureConfiguration(featureConfiguration)
- .addVariablesExtension(variablesExtensions);
+ .addVariablesExtension(variablesExtensions)
+ .setLinkedArtifactNameSuffix(linkedArtifactNameSuffix);
}
@Immutable
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java
index befcb82e13..92df63420e 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java
@@ -344,9 +344,16 @@ public class CppHelper {
/** Returns the linked artifact for linux. */
public static Artifact getLinuxLinkedArtifact(RuleContext ruleContext, LinkTargetType linkType) {
+ return getLinuxLinkedArtifact(ruleContext, linkType, "");
+ }
+
+ /** Returns the linked artifact with the given suffix for linux. */
+ public static Artifact getLinuxLinkedArtifact(RuleContext ruleContext, LinkTargetType linkType,
+ String linkedArtifactNameSuffix) {
PathFragment name = new PathFragment(ruleContext.getLabel().getName());
if (linkType != LinkTargetType.EXECUTABLE) {
- name = name.replaceName("lib" + name.getBaseName() + linkType.getExtension());
+ name = name.replaceName(
+ "lib" + name.getBaseName() + linkedArtifactNameSuffix + linkType.getExtension());
}
return ruleContext.getBinArtifact(name);
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppModel.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppModel.java
index 43eca8af3d..e520f33743 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppModel.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppModel.java
@@ -89,6 +89,7 @@ public final class CppModel {
private List<VariablesExtension> variablesExtensions = new ArrayList<>();
private final CcToolchainProvider ccToolchain;
private final FdoSupportProvider fdoSupport;
+ private String linkedArtifactNameSuffix = "";
public CppModel(RuleContext ruleContext, CppSemantics semantics,
CcToolchainProvider ccToolchain, FdoSupportProvider fdoSupport) {
@@ -265,6 +266,18 @@ public final class CppModel {
return this;
}
+ /*
+ * Adds a suffix for paths of linked artifacts. Normally their paths are derived solely from rule
+ * labels. In the case of multiple callers (e.g., aspects) acting on a single rule, they may
+ * generate the same linked artifact and therefore lead to artifact conflicts. This method
+ * provides a way to avoid this artifact conflict by allowing different callers acting on the same
+ * rule to provide a suffix that will be used to scope their own linked artifacts.
+ */
+ public CppModel setLinkedArtifactNameSuffix(String suffix) {
+ this.linkedArtifactNameSuffix = suffix;
+ return this;
+ }
+
/**
* @returns whether we want to provide header modules for the current target.
*/
@@ -944,10 +957,11 @@ public final class CppModel {
*/
private Artifact getLinkedArtifact(LinkTargetType linkTargetType) throws RuleErrorException {
Artifact result = null;
- Artifact linuxDefault = CppHelper.getLinuxLinkedArtifact(ruleContext, linkTargetType);
+ Artifact linuxDefault = CppHelper.getLinuxLinkedArtifact(
+ ruleContext, linkTargetType, linkedArtifactNameSuffix);
try {
- String maybePicName = ruleContext.getLabel().getName();
+ String maybePicName = ruleContext.getLabel().getName() + linkedArtifactNameSuffix;
if (linkTargetType.picness() == Picness.PIC) {
maybePicName = CppHelper.getArtifactNameForCategory(
ruleContext, ccToolchain, ArtifactCategory.PIC_FILE, maybePicName);
@@ -1102,7 +1116,8 @@ public final class CppModel {
Artifact soInterface = null;
if (cppConfiguration.useInterfaceSharedObjects() && allowInterfaceSharedObjects) {
soInterface =
- CppHelper.getLinuxLinkedArtifact(ruleContext, LinkTargetType.INTERFACE_DYNAMIC_LIBRARY);
+ CppHelper.getLinuxLinkedArtifact(
+ ruleContext, LinkTargetType.INTERFACE_DYNAMIC_LIBRARY, linkedArtifactNameSuffix);
sonameLinkopts = ImmutableList.of("-Wl,-soname=" +
SolibSymlinkAction.getDynamicLibrarySoname(soImpl.getRootRelativePath(), false));
}
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 b9e28b4ffb..ed19ace0c9 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
@@ -65,9 +65,12 @@ import com.google.devtools.build.lib.rules.apple.AppleConfiguration;
import com.google.devtools.build.lib.rules.apple.AppleToolchain;
import com.google.devtools.build.lib.rules.apple.Platform;
import com.google.devtools.build.lib.rules.apple.Platform.PlatformType;
+import com.google.devtools.build.lib.rules.cpp.CcToolchainProvider;
import com.google.devtools.build.lib.rules.cpp.CppFileTypes;
+import com.google.devtools.build.lib.rules.cpp.CppHelper;
import com.google.devtools.build.lib.rules.cpp.CppModuleMap;
import com.google.devtools.build.lib.rules.cpp.CppModuleMapAction;
+import com.google.devtools.build.lib.rules.cpp.FdoSupportProvider;
import com.google.devtools.build.lib.rules.objc.ObjcCommandLineOptions.ObjcCrosstoolMode;
import com.google.devtools.build.lib.rules.objc.XcodeProvider.Builder;
import com.google.devtools.build.lib.rules.test.InstrumentedFilesCollector;
@@ -81,6 +84,7 @@ import com.google.devtools.build.lib.vfs.PathFragment;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
+import javax.annotation.Nullable;
/**
* Support for rules that compile sources. Provides ways to determine files that should be output,
@@ -367,7 +371,7 @@ public abstract class CompilationSupport {
* @param intermediateArtifacts IntermediateArtifacts for deriving artifact paths
* @param compilationAttributes attributes of the calling target
*/
- private static CompilationSupport createWithSelectedImplementation(
+ static CompilationSupport createWithSelectedImplementation(
RuleContext ruleContext,
BuildConfiguration buildConfiguration,
IntermediateArtifacts intermediateArtifacts,
@@ -392,8 +396,12 @@ public abstract class CompilationSupport {
CompilationArtifacts compilationArtifacts,
ObjcProvider objcProvider) throws RuleErrorException, InterruptedException {
return registerCompileAndArchiveActions(
- compilationArtifacts, objcProvider, ExtraCompileArgs.NONE,
- ImmutableList.<PathFragment>of());
+ compilationArtifacts,
+ objcProvider,
+ ExtraCompileArgs.NONE,
+ ImmutableList.<PathFragment>of(),
+ maybeGetCcToolchain(),
+ maybeGetFdoSupport());
}
/**
@@ -447,11 +455,35 @@ public abstract class CompilationSupport {
*/
public CompilationSupport registerFullyLinkAction(
ObjcProvider objcProvider, Artifact outputArchive) throws InterruptedException {
+ return registerFullyLinkAction(
+ objcProvider,
+ outputArchive,
+ maybeGetCcToolchain(),
+ maybeGetFdoSupport());
+ }
+
+ /**
+ * Registers an action to create an archive artifact by fully (statically) linking all transitive
+ * dependencies of this rule.
+ *
+ * @param objcProvider provides all compiling and linking information to create this artifact
+ * @param outputArchive the output artifact for this action
+ * @param ccToolchain the cpp toolchain provider, may be null
+ * @param fdoSupport the cpp FDO support provider, may be null
+ */
+ public CompilationSupport registerFullyLinkAction(
+ ObjcProvider objcProvider, Artifact outputArchive, @Nullable CcToolchainProvider ccToolchain,
+ @Nullable FdoSupportProvider fdoSupport) throws InterruptedException {
ImmutableList<Artifact> inputArtifacts = ImmutableList.<Artifact>builder()
.addAll(objcProvider.getObjcLibraries())
.addAll(objcProvider.get(IMPORTED_LIBRARY))
.addAll(objcProvider.getCcLibraries()).build();
- return registerFullyLinkAction(objcProvider, inputArtifacts, outputArchive);
+ return registerFullyLinkAction(
+ objcProvider,
+ inputArtifacts,
+ outputArchive,
+ ccToolchain,
+ fdoSupport);
}
/**
@@ -480,7 +512,12 @@ public abstract class CompilationSupport {
Iterable<Artifact> inputArtifacts = Iterables.filter(depsArtifacts,
Predicates.not(Predicates.in(avoidsDepsArtifacts.build())));
- return registerFullyLinkAction(objcProvider, inputArtifacts, outputArchive);
+ return registerFullyLinkAction(
+ objcProvider,
+ inputArtifacts,
+ outputArchive,
+ maybeGetCcToolchain(),
+ maybeGetFdoSupport());
}
/**
@@ -619,12 +656,15 @@ public abstract class CompilationSupport {
* @param objcProvider provides all compiling and linking information to register these actions
* @param extraCompileArgs args to be added to compile actions
* @param priorityHeaders priority headers to be included before the dependency headers
+ * @param ccToolchain the cpp toolchain provider, may be null
+ * @param fdoSupport the cpp FDO support provider, may be null
* @return this compilation support
* @throws RuleErrorException for invalid crosstool files
*/
abstract CompilationSupport registerCompileAndArchiveActions(
CompilationArtifacts compilationArtifacts, ObjcProvider objcProvider,
- ExtraCompileArgs extraCompileArgs, Iterable<PathFragment> priorityHeaders)
+ ExtraCompileArgs extraCompileArgs, Iterable<PathFragment> priorityHeaders,
+ @Nullable CcToolchainProvider ccToolchain, @Nullable FdoSupportProvider fdoSupport)
throws RuleErrorException, InterruptedException;
/**
@@ -640,12 +680,16 @@ public abstract class CompilationSupport {
ObjcCommon common, ExtraCompileArgs extraCompileArgs, Iterable<PathFragment> priorityHeaders)
throws RuleErrorException, InterruptedException {
if (common.getCompilationArtifacts().isPresent()) {
- registerCompileAndArchiveActions(common.getCompilationArtifacts().get(),
- common.getObjcProvider(), extraCompileArgs, priorityHeaders);
+ registerCompileAndArchiveActions(
+ common.getCompilationArtifacts().get(),
+ common.getObjcProvider(),
+ extraCompileArgs,
+ priorityHeaders,
+ maybeGetCcToolchain(),
+ maybeGetFdoSupport());
}
return this;
}
-
/**
* Registers any actions necessary to link this rule and its dependencies.
*
@@ -743,10 +787,13 @@ public abstract class CompilationSupport {
* @param objcProvider provides all compiling and linking information to create this artifact
* @param inputArtifacts inputs for this action
* @param outputArchive the output artifact for this action
+ * @param ccToolchain the cpp toolchain provider, may be null
+ * @param fdoSupport the cpp FDO support provider, may be null
* @return this {@link CompilationSupport} instance
*/
protected abstract CompilationSupport registerFullyLinkAction(
- ObjcProvider objcProvider, Iterable<Artifact> inputArtifacts, Artifact outputArchive)
+ ObjcProvider objcProvider, Iterable<Artifact> inputArtifacts, Artifact outputArchive,
+ @Nullable CcToolchainProvider ccToolchain, @Nullable FdoSupportProvider fdoSupport)
throws InterruptedException;
/**
@@ -1028,4 +1075,23 @@ public abstract class CompilationSupport {
.getProvider(FilesToRunProvider.class);
}
+ @Nullable
+ private CcToolchainProvider maybeGetCcToolchain() {
+ // TODO(rduan): Remove this check once all rules are using the crosstool support.
+ if (ruleContext.attributes().has(":cc_toolchain", BuildType.LABEL)) {
+ return CppHelper.getToolchain(ruleContext, ":cc_toolchain");
+ } else {
+ return null;
+ }
+ }
+
+ @Nullable
+ private FdoSupportProvider maybeGetFdoSupport() {
+ // TODO(rduan): Remove this check once all rules are using the crosstool support.
+ if (ruleContext.attributes().has(":cc_toolchain", BuildType.LABEL)) {
+ return CppHelper.getFdoSupport(ruleContext, ":cc_toolchain");
+ } else {
+ return null;
+ }
+ }
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/CrosstoolCompilationSupport.java b/src/main/java/com/google/devtools/build/lib/rules/objc/CrosstoolCompilationSupport.java
index 60f0817478..edaeb543c5 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/CrosstoolCompilationSupport.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/CrosstoolCompilationSupport.java
@@ -21,6 +21,7 @@ import static com.google.devtools.build.lib.rules.objc.ObjcProvider.INCLUDE;
import static com.google.devtools.build.lib.rules.objc.ObjcProvider.INCLUDE_SYSTEM;
import static com.google.devtools.build.lib.rules.objc.ObjcProvider.STATIC_FRAMEWORK_FILE;
+import com.google.common.base.Preconditions;
import com.google.common.base.Predicates;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
@@ -80,8 +81,6 @@ public class CrosstoolCompilationSupport extends CompilationSupport {
"preprocess-assemble",
"c-compile",
"c++-compile");
- @Nullable private final CcToolchainProvider ccToolchain;
- @Nullable private final FdoSupportProvider fdoSupport;
/**
* Creates a new CompilationSupport instance that uses the c++ rule backend
@@ -109,23 +108,17 @@ public class CrosstoolCompilationSupport extends CompilationSupport {
IntermediateArtifacts intermediateArtifacts,
CompilationAttributes compilationAttributes) {
super(ruleContext, buildConfiguration, intermediateArtifacts, compilationAttributes);
- // Note some rules like objc_import do not need to compile anything and therefore do not define
- // any toolchain attribute. However, they still use the base class to set up other actions like
- // the module map action. Here we guard against those cases.
- if (ruleContext.attributes().has(":cc_toolchain", BuildType.LABEL)) {
- this.ccToolchain = CppHelper.getToolchain(ruleContext, ":cc_toolchain");
- this.fdoSupport = CppHelper.getFdoSupport(ruleContext, ":cc_toolchain");
- } else {
- this.ccToolchain = null;
- this.fdoSupport = null;
- }
}
@Override
CompilationSupport registerCompileAndArchiveActions(
CompilationArtifacts compilationArtifacts,
ObjcProvider objcProvider, ExtraCompileArgs extraCompileArgs,
- Iterable<PathFragment> priorityHeaders) throws RuleErrorException, InterruptedException {
+ Iterable<PathFragment> priorityHeaders,
+ @Nullable CcToolchainProvider ccToolchain,
+ @Nullable FdoSupportProvider fdoSupport) throws RuleErrorException, InterruptedException {
+ Preconditions.checkNotNull(ccToolchain);
+ Preconditions.checkNotNull(fdoSupport);
ObjcVariablesExtension.Builder extension = new ObjcVariablesExtension.Builder()
.setRuleContext(ruleContext)
.setObjcProvider(objcProvider)
@@ -142,11 +135,15 @@ public class CrosstoolCompilationSupport extends CompilationSupport {
extension.addVariableCategory(VariableCategory.ARCHIVE_VARIABLES);
- helper = createCcLibraryHelper(objcProvider, compilationArtifacts, extension.build())
- .setLinkType(LinkTargetType.OBJC_ARCHIVE)
- .addLinkActionInput(objList);
+ helper =
+ createCcLibraryHelper(
+ objcProvider, compilationArtifacts, extension.build(), ccToolchain, fdoSupport)
+ .setLinkType(LinkTargetType.OBJC_ARCHIVE)
+ .addLinkActionInput(objList);
} else {
- helper = createCcLibraryHelper(objcProvider, compilationArtifacts, extension.build());
+ helper =
+ createCcLibraryHelper(
+ objcProvider, compilationArtifacts, extension.build(), ccToolchain, fdoSupport);
}
helper.build();
@@ -156,8 +153,11 @@ public class CrosstoolCompilationSupport extends CompilationSupport {
@Override
protected CompilationSupport registerFullyLinkAction(
- ObjcProvider objcProvider, Iterable<Artifact> inputArtifacts, Artifact outputArchive)
+ ObjcProvider objcProvider, Iterable<Artifact> inputArtifacts, Artifact outputArchive,
+ @Nullable CcToolchainProvider ccToolchain, @Nullable FdoSupportProvider fdoSupport)
throws InterruptedException {
+ Preconditions.checkNotNull(ccToolchain);
+ Preconditions.checkNotNull(fdoSupport);
PathFragment labelName = new PathFragment(ruleContext.getLabel().getName());
String libraryIdentifier =
ruleContext
@@ -172,7 +172,6 @@ public class CrosstoolCompilationSupport extends CompilationSupport {
.setFullyLinkArchive(outputArchive)
.addVariableCategory(VariableCategory.FULLY_LINK_VARIABLES)
.build();
-
CppLinkAction fullyLinkAction =
new CppLinkActionBuilder(
ruleContext, outputArchive, ccToolchain, fdoSupport.getFdoSupport())
@@ -236,6 +235,8 @@ public class CrosstoolCompilationSupport extends CompilationSupport {
.build();
Artifact binaryToLink = getBinaryToLink();
+ CcToolchainProvider ccToolchain = CppHelper.getToolchain(ruleContext, ":cc_toolchain");
+ FdoSupportProvider fdoSupport = CppHelper.getFdoSupport(ruleContext, ":cc_toolchain");
CppLinkAction executableLinkAction =
new CppLinkActionBuilder(ruleContext, binaryToLink, ccToolchain, fdoSupport.getFdoSupport())
.setMnemonic("ObjcLink")
@@ -257,7 +258,8 @@ public class CrosstoolCompilationSupport extends CompilationSupport {
return this;
}
private CcLibraryHelper createCcLibraryHelper(ObjcProvider objcProvider,
- CompilationArtifacts compilationArtifacts, VariablesExtension extension) {
+ CompilationArtifacts compilationArtifacts, VariablesExtension extension,
+ CcToolchainProvider ccToolchain, FdoSupportProvider fdoSupport) {
PrecompiledFiles precompiledFiles = new PrecompiledFiles(ruleContext);
Collection<Artifact> arcSources = ImmutableSortedSet.copyOf(compilationArtifacts.getSrcs());
Collection<Artifact> nonArcSources =
@@ -295,6 +297,7 @@ public class CrosstoolCompilationSupport extends CompilationSupport {
.addCopts(ruleContext.getFragment(ObjcConfiguration.class).getCoptsForCompilationMode())
.addSystemIncludeDirs(objcProvider.get(INCLUDE_SYSTEM))
.setCppModuleMap(intermediateArtifacts.moduleMap())
+ .setLinkedArtifactNameSuffix(intermediateArtifacts.archiveFileNameSuffix())
.setPropagateModuleMapToCompileAction(false)
.setNeverLink(true)
.addVariableExtension(extension);
@@ -311,7 +314,6 @@ public class CrosstoolCompilationSupport extends CompilationSupport {
private static FeatureConfiguration getFeatureConfiguration(RuleContext ruleContext,
BuildConfiguration configuration) {
-
ImmutableList.Builder<String> activatedCrosstoolSelectables =
ImmutableList.<String>builder()
.addAll(ACTIVATED_ACTIONS)
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 e9b795b4c1..620010edd4 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
@@ -21,6 +21,7 @@ import com.google.devtools.build.lib.analysis.RuleContext;
import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.rules.cpp.CppCompileAction.DotdFile;
+import com.google.devtools.build.lib.rules.cpp.CppHelper;
import com.google.devtools.build.lib.rules.cpp.CppModuleMap;
import com.google.devtools.build.lib.util.Preconditions;
import com.google.devtools.build.lib.vfs.FileSystemUtils;
@@ -80,6 +81,13 @@ public final class IntermediateArtifacts {
}
/**
+ * Returns the archive file name suffix.
+ */
+ public String archiveFileNameSuffix() {
+ return archiveFileNameSuffix;
+ }
+
+ /**
* Returns the location of this target's generated entitlements file.
*/
public Artifact entitlements() {
@@ -243,7 +251,7 @@ public final class IntermediateArtifacts {
* The {@code .a} file which contains all the compiled sources for a rule.
*/
public Artifact archive() {
- // The path will be RULE_PACKAGE/libRULEBASENAME.a
+ // The path will be {RULE_PACKAGE}/lib{RULEBASENAME}{SUFFIX}.a
String basename = new PathFragment(ruleContext.getLabel().getName()).getBaseName();
return scopedArtifact(new PathFragment(String.format(
"lib%s%s.a", basename, archiveFileNameSuffix)));
@@ -263,8 +271,7 @@ public final class IntermediateArtifacts {
*/
public Artifact objFile(Artifact source) {
if (source.isTreeArtifact()) {
- PathFragment rootRelativePath = source.getRootRelativePath().replaceName("obj_files");
- return ruleContext.getTreeArtifact(rootRelativePath, ruleContext.getBinOrGenfilesDirectory());
+ return CppHelper.getCompileOutputTreeArtifact(ruleContext, source);
} else {
return inUniqueObjsDir(source, ".o");
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcAspect.java b/src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcAspect.java
index 36763dc164..e31e44756b 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcAspect.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/J2ObjcAspect.java
@@ -50,6 +50,10 @@ import com.google.devtools.build.lib.packages.Rule;
import com.google.devtools.build.lib.packages.RuleClass.ConfiguredTargetFactory.RuleErrorException;
import com.google.devtools.build.lib.rules.apple.AppleConfiguration;
import com.google.devtools.build.lib.rules.apple.AppleToolchain;
+import com.google.devtools.build.lib.rules.cpp.CcToolchainProvider;
+import com.google.devtools.build.lib.rules.cpp.CppConfiguration;
+import com.google.devtools.build.lib.rules.cpp.CppHelper;
+import com.google.devtools.build.lib.rules.cpp.FdoSupportProvider;
import com.google.devtools.build.lib.rules.java.JavaCompilationArgsProvider;
import com.google.devtools.build.lib.rules.java.JavaGenJarsProvider;
import com.google.devtools.build.lib.rules.java.JavaHelper;
@@ -145,6 +149,7 @@ public class J2ObjcAspect extends NativeAspectClass implements ConfiguredAspectF
ImmutableSet.<Class<?>>of(ProtoSourcesProvider.class)))
.requiresConfigurationFragments(
AppleConfiguration.class,
+ CppConfiguration.class,
J2ObjcConfiguration.class,
ObjcConfiguration.class,
ProtoConfiguration.class)
@@ -203,6 +208,11 @@ public class J2ObjcAspect extends NativeAspectClass implements ConfiguredAspectF
ImmutableList.of(
Label.parseAbsoluteUnchecked(
toolsRepository + "//tools/j2objc:j2objc_proto_blacklist"))))
+ .add(attr(":j2objc_cc_toolchain", LABEL).value(ObjcRuleClasses.APPLE_TOOLCHAIN))
+ .add(
+ attr(":lipo_context_collector", LABEL)
+ .value(ObjcRuleClasses.NULL_LIPO_CONTEXT_COLLECTOR)
+ .skipPrereqValidatorCheck())
.build();
}
@@ -251,10 +261,29 @@ public class J2ObjcAspect extends NativeAspectClass implements ConfiguredAspectF
depAttributes);
try {
- CompilationSupport.create(ruleContext)
- .registerCompileAndArchiveActions(common, EXTRA_COMPILE_ARGS)
- .registerFullyLinkAction(common.getObjcProvider(),
- ruleContext.getImplicitOutputArtifact(CompilationSupport.FULLY_LINKED_LIB));
+ CcToolchainProvider ccToolchain =
+ CppHelper.getToolchain(ruleContext, ":j2objc_cc_toolchain");
+ FdoSupportProvider fdoSupport =
+ CppHelper.getFdoSupport(ruleContext, ":j2objc_cc_toolchain");
+ CompilationSupport compilationSupport = CompilationSupport.createWithSelectedImplementation(
+ ruleContext,
+ ruleContext.getConfiguration(),
+ ObjcRuleClasses.j2objcIntermediateArtifacts(ruleContext),
+ CompilationAttributes.Builder.fromRuleContext(ruleContext).build());
+
+ compilationSupport
+ .registerCompileAndArchiveActions(
+ common.getCompilationArtifacts().get(),
+ common.getObjcProvider(),
+ EXTRA_COMPILE_ARGS,
+ ImmutableList.<PathFragment>of(),
+ ccToolchain,
+ fdoSupport)
+ .registerFullyLinkAction(
+ common.getObjcProvider(),
+ ruleContext.getImplicitOutputArtifact(CompilationSupport.FULLY_LINKED_LIB),
+ ccToolchain,
+ fdoSupport);
} catch (RuleErrorException e) {
ruleContext.ruleError(e.getMessage());
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/LegacyCompilationSupport.java b/src/main/java/com/google/devtools/build/lib/rules/objc/LegacyCompilationSupport.java
index b22a7ec94c..d3c4805f8e 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/objc/LegacyCompilationSupport.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/objc/LegacyCompilationSupport.java
@@ -66,15 +66,18 @@ import com.google.devtools.build.lib.rules.apple.AppleConfiguration;
import com.google.devtools.build.lib.rules.apple.AppleToolchain;
import com.google.devtools.build.lib.rules.apple.DottedVersion;
import com.google.devtools.build.lib.rules.apple.Platform;
+import com.google.devtools.build.lib.rules.cpp.CcToolchainProvider;
import com.google.devtools.build.lib.rules.cpp.CppCompileAction.DotdFile;
import com.google.devtools.build.lib.rules.cpp.CppFileTypes;
import com.google.devtools.build.lib.rules.cpp.CppModuleMap;
+import com.google.devtools.build.lib.rules.cpp.FdoSupportProvider;
import com.google.devtools.build.lib.util.FileTypeSet;
import com.google.devtools.build.lib.util.Preconditions;
import com.google.devtools.build.lib.vfs.FileSystemUtils;
import com.google.devtools.build.lib.vfs.PathFragment;
import java.util.List;
import java.util.Map.Entry;
+import javax.annotation.Nullable;
/**
* Constructs command lines for objc compilation, archiving, and linking. Uses hard-coded
@@ -157,7 +160,8 @@ public class LegacyCompilationSupport extends CompilationSupport {
@Override
CompilationSupport registerCompileAndArchiveActions(
CompilationArtifacts compilationArtifacts, ObjcProvider objcProvider,
- ExtraCompileArgs extraCompileArgs, Iterable<PathFragment> priorityHeaders) {
+ ExtraCompileArgs extraCompileArgs, Iterable<PathFragment> priorityHeaders,
+ @Nullable CcToolchainProvider ccToolchain, @Nullable FdoSupportProvider fdoSupport) {
registerGenerateModuleMapAction(compilationArtifacts);
Optional<CppModuleMap> moduleMap;
if (objcConfiguration.moduleMapsEnabled()) {
@@ -606,7 +610,8 @@ public class LegacyCompilationSupport extends CompilationSupport {
@Override
protected CompilationSupport registerFullyLinkAction(
- ObjcProvider objcProvider, Iterable<Artifact> inputArtifacts, Artifact outputArchive) {
+ ObjcProvider objcProvider, Iterable<Artifact> inputArtifacts, Artifact outputArchive,
+ @Nullable CcToolchainProvider ccToolchain, @Nullable FdoSupportProvider fdoSupport) {
ruleContext.registerAction(
ObjcRuleClasses.spawnAppleEnvActionBuilder(
appleConfiguration, appleConfiguration.getSingleArchPlatform())