aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com
diff options
context:
space:
mode:
authorGravatar Lukacs Berki <lberki@google.com>2015-07-31 07:39:29 +0000
committerGravatar Damien Martin-Guillerez <dmarting@google.com>2015-08-04 09:05:56 +0000
commite5cf8a9df0dce674314c5a93aecb6c22ba607612 (patch)
tree83faaff3c1c032bc9332663f42ea0a46adbb425d /src/main/java/com
parent29f527c414e0fdfc74a99a958414ea9151110a38 (diff)
Remove all calls to AnalysisEnvironment.getDerivedArtifact() from the C++ rules that can be removed.
What is left: - The outputs of ExtractInclusionsAction. I think this action is shared between multiple rules that have the same generated file in srcs, so this call site is legitimate. - Creating the solib symlinks. This is not a shared action, but these need to be in the same directory so that the RPATH is not too long, so we must live with this for the time being. - FDO, which is beyond salvation. The artifacts under the FDO root don't really conform to the usual "only under the package directory" convention. -- MOS_MIGRATED_REVID=99551394
Diffstat (limited to 'src/main/java/com')
-rw-r--r--src/main/java/com/google/devtools/build/lib/analysis/actions/ParamFileHelper.java17
-rw-r--r--src/main/java/com/google/devtools/build/lib/analysis/actions/SpawnAction.java2
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java22
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibrary.java24
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibraryHelper.java8
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileActionBuilder.java8
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java14
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkAction.java100
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CppModel.java40
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/nativedeps/NativeDepsHelper.java14
10 files changed, 124 insertions, 125 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/actions/ParamFileHelper.java b/src/main/java/com/google/devtools/build/lib/analysis/actions/ParamFileHelper.java
index e7869e4f2d..e061961671 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/actions/ParamFileHelper.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/actions/ParamFileHelper.java
@@ -58,7 +58,7 @@ public final class ParamFileHelper {
* @param analysisEnvironment the analysis environment
* @param outputs outputs of the action (used to construct a filename for the params file)
*/
- public static Artifact getParamsFile(
+ public static Artifact getParamsFileMaybe(
List<String> executableArgs,
@Nullable Iterable<String> arguments,
@Nullable CommandLine commandLine,
@@ -72,15 +72,22 @@ public final class ParamFileHelper {
return null;
}
- PathFragment paramFilePath = ParameterFile.derivePath(
- Iterables.getFirst(outputs, null).getRootRelativePath());
+ return getParamsFile(analysisEnvironment, configuration, Iterables.getFirst(outputs, null));
+ }
+
+ /**
+ * Returns a params file for the specified output file.
+ */
+ public static Artifact getParamsFile(AnalysisEnvironment analysisEnvironment,
+ BuildConfiguration configuration, Artifact output) {
+ PathFragment paramFilePath = ParameterFile.derivePath(output.getRootRelativePath());
return analysisEnvironment.getDerivedArtifact(paramFilePath, configuration.getBinDirectory());
}
/**
* Creates a command line using an external params file.
*
- * <p>Call this with the result of {@link #getParamsFile} if it is not null.
+ * <p>Call this with the result of {@link #getParamsFileMaybe} if it is not null.
*
* @param executableArgs leading arguments that should never be wrapped in a parameter file
* @param arguments arguments to the command (in addition to executableArgs), OR
@@ -117,7 +124,7 @@ public final class ParamFileHelper {
/**
* Creates a command line without using a params file.
*
- * <p>Call this if {@link #getParamsFile} returns null.
+ * <p>Call this if {@link #getParamsFileMaybe} returns null.
*
* @param executableArgs leading arguments that should never be wrapped in a parameter file
* @param arguments arguments to the command (in addition to executableArgs), OR
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/actions/SpawnAction.java b/src/main/java/com/google/devtools/build/lib/analysis/actions/SpawnAction.java
index 839e0731fc..1475102e3d 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/actions/SpawnAction.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/actions/SpawnAction.java
@@ -513,7 +513,7 @@ public class SpawnAction extends AbstractAction {
Iterable<String> arguments = argumentsBuilder.build();
- Artifact paramsFile = ParamFileHelper.getParamsFile(argv, arguments, commandLine,
+ Artifact paramsFile = ParamFileHelper.getParamsFileMaybe(argv, arguments, commandLine,
paramFileInfo, configuration, analysisEnvironment, outputs);
List<Action> actions = new ArrayList<>();
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java
index a74cd00614..636784b432 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java
@@ -179,13 +179,13 @@ public abstract class CcBinary implements RuleConfiguredTargetFactory {
// linkopt "-shared", which causes the result of linking to be a shared
// library. In this case, the name of the executable target should end
// in ".so".
- PathFragment executableName =
- ruleContext
- .getPackageDirectory()
- .getRelative(ruleContext.getTarget().getName() + OsUtils.executableExtension());
+ PathFragment binaryPath =
+ new PathFragment(ruleContext.getTarget().getName() + OsUtils.executableExtension());
+ Artifact binary = ruleContext.getPackageRelativeArtifact(
+ binaryPath, ruleContext.getConfiguration().getBinDirectory());
CppLinkAction.Builder linkActionBuilder = determineLinkerArguments(
ruleContext, common, cppConfiguration, ccCompilationOutputs,
- cppCompilationContext.getCompilationPrerequisites(), fake, executableName);
+ cppCompilationContext.getCompilationPrerequisites(), fake, binary);
linkActionBuilder.setUseTestOnlyFlags(useTestOnlyFlags);
linkActionBuilder.addNonLibraryInputs(ccCompilationOutputs.getHeaderTokenFiles());
@@ -211,6 +211,12 @@ public abstract class CcBinary implements RuleConfiguredTargetFactory {
linkActionBuilder.setLinkStaticness(linkStaticness);
linkActionBuilder.setFake(fake);
+ if (CppLinkAction.enableSymbolsCounts(cppConfiguration, fake, linkType)) {
+ linkActionBuilder.setSymbolCountsOutput(ruleContext.getPackageRelativeArtifact(
+ CppLinkAction.symbolCountsFileName(binaryPath),
+ ruleContext.getConfiguration().getBinDirectory()));
+ }
+
// store immutable context now, recreate builder later
CppLinkAction.Context linkContext = new CppLinkAction.Context(linkActionBuilder);
@@ -222,7 +228,7 @@ public abstract class CcBinary implements RuleConfiguredTargetFactory {
Artifact executable = outputLibrary.getArtifact();
CcLinkingOutputs.Builder linkingOutputsBuilder = new CcLinkingOutputs.Builder();
if (isLinkShared(ruleContext)) {
- if (CppFileTypes.SHARED_LIBRARY.matches(executableName)) {
+ if (CppFileTypes.SHARED_LIBRARY.matches(binary.getFilename())) {
linkingOutputsBuilder.addDynamicLibrary(outputLibrary);
linkingOutputsBuilder.addExecutionDynamicLibrary(outputLibrary);
} else {
@@ -338,8 +344,8 @@ public abstract class CcBinary implements RuleConfiguredTargetFactory {
private static CppLinkAction.Builder determineLinkerArguments(RuleContext context,
CcCommon common, CppConfiguration cppConfiguration, CcCompilationOutputs compilationOutputs,
ImmutableSet<Artifact> compilationPrerequisites,
- boolean fake, PathFragment executableName) {
- CppLinkAction.Builder builder = new CppLinkAction.Builder(context, executableName)
+ boolean fake, Artifact binary) {
+ CppLinkAction.Builder builder = new CppLinkAction.Builder(context, binary)
.setCrosstoolInputs(CppHelper.getToolchain(context).getLink())
.addNonLibraryInputs(compilationPrerequisites);
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibrary.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibrary.java
index beee64a4b2..8d671e39f8 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibrary.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibrary.java
@@ -136,17 +136,28 @@ public abstract class CcLibrary implements RuleConfiguredTargetFactory {
helper.addLinkstamps(ruleContext.getPrerequisites("linkstamp", Mode.TARGET));
}
- PathFragment soImplFilename = null;
+ Artifact soImplArtifact = null;
+ boolean createDynamicLibrary =
+ !linkStatic && appearsToHaveObjectFiles(ruleContext.attributes());
if (ruleContext.getRule().isAttrDefined("outs", Type.STRING_LIST)) {
List<String> outs = ruleContext.attributes().get("outs", Type.STRING_LIST);
if (outs.size() > 1) {
ruleContext.attributeError("outs", "must be a singleton list");
} else if (outs.size() == 1) {
- soImplFilename = CppHelper.getLinkedFilename(ruleContext, LinkTargetType.DYNAMIC_LIBRARY);
+ PathFragment soImplFilename = new PathFragment(ruleContext.getLabel().getName());
+ if (LinkTargetType.DYNAMIC_LIBRARY != LinkTargetType.EXECUTABLE) {
+ soImplFilename = soImplFilename.replaceName(
+ "lib" + soImplFilename.getBaseName() + LinkTargetType.DYNAMIC_LIBRARY.getExtension());
+ }
soImplFilename = soImplFilename.replaceName(outs.get(0));
if (!soImplFilename.getPathString().endsWith(".so")) { // Sanity check.
ruleContext.attributeError("outs", "file name must end in '.so'");
}
+
+ if (createDynamicLibrary) {
+ soImplArtifact = ruleContext.getPackageRelativeArtifact(
+ soImplFilename, ruleContext.getConfiguration().getBinDirectory());
+ }
}
}
@@ -166,10 +177,8 @@ public abstract class CcLibrary implements RuleConfiguredTargetFactory {
+ "Did you mean to use 'linkstatic=1' instead?");
}
- boolean createDynamicLibrary =
- !linkStatic && appearsToHaveObjectFiles(ruleContext.attributes());
helper.setCreateDynamicLibrary(createDynamicLibrary);
- helper.setDynamicLibraryPath(soImplFilename);
+ helper.setDynamicLibrary(soImplArtifact);
// If "srcs" is configurable, the .so output is always declared because the logic that
// determines implicit outs doesn't know which value of "srcs" will ultimately get chosen. Here,
@@ -177,9 +186,8 @@ public abstract class CcLibrary implements RuleConfiguredTargetFactory {
// .so with. If that's the case, register a fake generating action to prevent a "no generating
// action for this artifact" error.
if (!createDynamicLibrary && ruleContext.attributes().isConfigurable("srcs", Type.LABEL_LIST)) {
- PathFragment solib = CppHelper.getLinkedFilename(ruleContext, LinkTargetType.DYNAMIC_LIBRARY);
- Artifact solibArtifact = ruleContext.getAnalysisEnvironment()
- .getDerivedArtifact(solib, ruleContext.getBinOrGenfilesDirectory());
+ Artifact solibArtifact = CppHelper.getLinkedArtifact(
+ ruleContext, LinkTargetType.DYNAMIC_LIBRARY);
ruleContext.registerAction(new FailAction(ruleContext.getActionOwner(),
ImmutableList.of(solibArtifact), "configurable \"srcs\" triggers an implicit .so output "
+ "even though there are no sources to compile in this configuration"));
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 062bd979e7..0ea5d1002d 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
@@ -168,7 +168,7 @@ public final class CcLibraryHelper {
private final List<PathFragment> looseIncludeDirs = new ArrayList<>();
private final List<PathFragment> systemIncludeDirs = new ArrayList<>();
private final List<PathFragment> includeDirs = new ArrayList<>();
- @Nullable private PathFragment dynamicLibraryPath;
+ @Nullable private Artifact dynamicLibrary;
private LinkTargetType linkType = LinkTargetType.STATIC_LIBRARY;
private HeadersCheckingMode headersCheckingMode = HeadersCheckingMode.LOOSE;
private boolean neverlink;
@@ -462,8 +462,8 @@ public final class CcLibraryHelper {
* dynamic library is an implicit or explicit output of the rule, i.e., if it is accessible by
* name from other rules in the same package. Set to {@code null} to use the default computation.
*/
- public CcLibraryHelper setDynamicLibraryPath(@Nullable PathFragment dynamicLibraryPath) {
- this.dynamicLibraryPath = dynamicLibraryPath;
+ public CcLibraryHelper setDynamicLibrary(@Nullable Artifact dynamicLibrary) {
+ this.dynamicLibrary = dynamicLibrary;
return this;
}
@@ -620,7 +620,7 @@ public final class CcLibraryHelper {
// configurations --save_temps setting to decide whether to actually save the temps.
.setSaveTemps(true)
.setNoCopts(nocopts)
- .setDynamicLibraryPath(dynamicLibraryPath)
+ .setDynamicLibrary(dynamicLibrary)
.addLinkopts(linkopts)
.setFeatureConfiguration(featureConfiguration);
CppCompilationContext cppCompilationContext =
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileActionBuilder.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileActionBuilder.java
index 3fdda79b5d..41ebc91ac9 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileActionBuilder.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileActionBuilder.java
@@ -189,7 +189,7 @@ public class CppCompileActionBuilder {
* Returns the .dwo output file that matches the specified .o output file. If Fission mode
* isn't enabled for this build, this is null (we don't produce .dwo files in that case).
*/
- private static Artifact getDwoFile(Artifact outputFile, AnalysisEnvironment artifactFactory,
+ private static Artifact getDwoFile(RuleContext ruleContext, Artifact outputFile,
CppConfiguration cppConfiguration) {
// Only create .dwo's for .o compilations (i.e. not .ii or .S).
@@ -198,9 +198,7 @@ public class CppCompileActionBuilder {
// Note configurations can be null for tests.
if (cppConfiguration != null && cppConfiguration.useFission() && isObjectOutput) {
- return artifactFactory.getDerivedArtifact(
- FileSystemUtils.replaceExtension(outputFile.getRootRelativePath(), ".dwo"),
- outputFile.getRoot());
+ return ruleContext.getRelatedArtifact(outputFile.getRootRelativePath(), ".dwo");
} else {
return null;
}
@@ -271,7 +269,7 @@ public class CppCompileActionBuilder {
return new CppCompileAction(owner, ImmutableList.copyOf(features), featureConfiguration,
variables, sourceFile, sourceLabel, realMandatoryInputs, outputFile, dotdFile,
- gcnoFile, getDwoFile(outputFile, analysisEnvironment, cppConfiguration),
+ gcnoFile, getDwoFile(ruleContext, outputFile, cppConfiguration),
optionalSourceFile, configuration, cppConfiguration, context,
actionContext, ImmutableList.copyOf(copts),
ImmutableList.copyOf(pluginOpts),
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 5250665375..45302a4794 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
@@ -297,16 +297,16 @@ public class CppHelper {
}
/**
- * Returns the workspace-relative filename for the linked artifact.
+ * Returns the linked artifact.
*/
- public static PathFragment getLinkedFilename(RuleContext ruleContext,
- LinkTargetType linkType) {
- PathFragment result =
- ruleContext.getPackageDirectory().getRelative(ruleContext.getLabel().getName());
+ public static Artifact getLinkedArtifact(RuleContext ruleContext, LinkTargetType linkType) {
+ PathFragment name = new PathFragment(ruleContext.getLabel().getName());
if (linkType != LinkTargetType.EXECUTABLE) {
- result = result.replaceName("lib" + result.getBaseName() + linkType.getExtension());
+ name = name.replaceName("lib" + name.getBaseName() + linkType.getExtension());
}
- return result;
+
+ return ruleContext.getPackageRelativeArtifact(
+ name, ruleContext.getConfiguration().getBinDirectory());
}
/**
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkAction.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkAction.java
index d62c6bba15..ceeff8cd12 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkAction.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkAction.java
@@ -39,6 +39,7 @@ import com.google.devtools.build.lib.actions.extra.ExtraActionInfo;
import com.google.devtools.build.lib.analysis.AnalysisEnvironment;
import com.google.devtools.build.lib.analysis.RuleContext;
import com.google.devtools.build.lib.analysis.TransitiveInfoProvider;
+import com.google.devtools.build.lib.analysis.actions.ParamFileHelper;
import com.google.devtools.build.lib.analysis.actions.ParameterFileWriteAction;
import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
import com.google.devtools.build.lib.collect.CollectionUtils;
@@ -433,14 +434,18 @@ public final class CppLinkAction extends AbstractAction {
/**
* Determines whether or not this link should output a symbol counts file.
*/
- private static boolean enableSymbolsCounts(CppConfiguration cppConfiguration, boolean fake,
- LinkTargetType linkType) {
+ public static boolean enableSymbolsCounts(
+ CppConfiguration cppConfiguration, boolean fake, LinkTargetType linkType) {
return cppConfiguration.getSymbolCounts()
&& cppConfiguration.supportsGoldLinker()
&& linkType == LinkTargetType.EXECUTABLE
&& !fake;
}
+ public static PathFragment symbolCountsFileName(PathFragment binaryName) {
+ return binaryName.replaceName(binaryName.getBaseName() + ".sc");
+ }
+
/**
* Builder class to construct {@link CppLinkAction}s.
*/
@@ -449,11 +454,12 @@ public final class CppLinkAction extends AbstractAction {
// Null when invoked from tests (e.g. via createTestBuilder).
@Nullable private final RuleContext ruleContext;
private final AnalysisEnvironment analysisEnvironment;
- private final PathFragment outputPath;
+ private final Artifact output;
// can be null for CppLinkAction.createTestBuilder()
@Nullable private final CcToolchainProvider toolchain;
- private PathFragment interfaceOutputPath;
+ private Artifact interfaceOutput;
+ private Artifact symbolCounts;
private PathFragment runtimeSolibDir;
protected final BuildConfiguration configuration;
private final CppConfiguration cppConfiguration;
@@ -480,11 +486,10 @@ public final class CppLinkAction extends AbstractAction {
* Creates a builder that builds {@link CppLinkAction} instances.
*
* @param ruleContext the rule that owns the action
- * @param outputPath the path of the ELF file to be created, relative to the
- * 'bin' directory
+ * @param output the output artifact
*/
- public Builder(RuleContext ruleContext, PathFragment outputPath) {
- this(ruleContext, outputPath, ruleContext.getConfiguration(),
+ public Builder(RuleContext ruleContext, Artifact output) {
+ this(ruleContext, output, ruleContext.getConfiguration(),
ruleContext.getAnalysisEnvironment(), CppHelper.getToolchain(ruleContext));
}
@@ -492,12 +497,11 @@ public final class CppLinkAction extends AbstractAction {
* Creates a builder that builds {@link CppLinkAction} instances.
*
* @param ruleContext the rule that owns the action
- * @param outputPath the path of the ELF file to be created, relative to the
- * 'bin' directory
+ * @param output the output artifact
*/
- public Builder(RuleContext ruleContext, PathFragment outputPath,
+ public Builder(RuleContext ruleContext, Artifact output,
BuildConfiguration configuration, CcToolchainProvider toolchain) {
- this(ruleContext, outputPath, configuration,
+ this(ruleContext, output, configuration,
ruleContext.getAnalysisEnvironment(), toolchain);
}
@@ -505,17 +509,16 @@ public final class CppLinkAction extends AbstractAction {
* Creates a builder that builds {@link CppLinkAction}s.
*
* @param ruleContext the rule that owns the action
- * @param outputPath the path of the ELF file to be created, relative to the
- * 'bin' directory
+ * @param output the output artifact
* @param configuration the configuration used to determine the tool chain
* and the default link options
*/
- private Builder(@Nullable RuleContext ruleContext, PathFragment outputPath,
+ private Builder(@Nullable RuleContext ruleContext, Artifact output,
BuildConfiguration configuration, AnalysisEnvironment analysisEnvironment,
CcToolchainProvider toolchain) {
this.ruleContext = ruleContext;
this.analysisEnvironment = Preconditions.checkNotNull(analysisEnvironment);
- this.outputPath = Preconditions.checkNotNull(outputPath);
+ this.output = Preconditions.checkNotNull(output);
this.configuration = Preconditions.checkNotNull(configuration);
this.cppConfiguration = configuration.getFragment(CppConfiguration.class);
this.toolchain = toolchain;
@@ -528,15 +531,14 @@ public final class CppLinkAction extends AbstractAction {
* Given a Context, creates a Builder that builds {@link CppLinkAction}s.
* Note well: Keep the Builder->Context and Context->Builder transforms consistent!
* @param ruleContext the rule that owns the action
- * @param outputPath the path of the ELF file to be created, relative to the
- * 'bin' directory
+ * @param output the output artifact
* @param linkContext an immutable CppLinkAction.Context from the original builder
*/
- public Builder(RuleContext ruleContext, PathFragment outputPath, Context linkContext,
+ public Builder(RuleContext ruleContext, Artifact output, Context linkContext,
BuildConfiguration configuration) {
// These Builder-only fields get set in the constructor:
// ruleContext, analysisEnvironment, outputPath, configuration, runtimeSolibDir
- this(ruleContext, outputPath, configuration, ruleContext.getAnalysisEnvironment(),
+ this(ruleContext, output, configuration, ruleContext.getAnalysisEnvironment(),
CppHelper.getToolchain(ruleContext));
Preconditions.checkNotNull(linkContext);
@@ -566,7 +568,7 @@ public final class CppLinkAction extends AbstractAction {
// We currently can't split dynamic library links if they have interface outputs. That was
// probably an unintended side effect of the change that introduced interface outputs.
case DYNAMIC_LIBRARY:
- return (interfaceOutputPath == null);
+ return interfaceOutput == null;
case EXECUTABLE:
case STATIC_LIBRARY:
case PIC_STATIC_LIBRARY:
@@ -585,25 +587,15 @@ public final class CppLinkAction extends AbstractAction {
* <p>This method may only be called once.
*/
public CppLinkAction build() {
- if (interfaceOutputPath != null && (fake || linkType != LinkTargetType.DYNAMIC_LIBRARY)) {
+ if (interfaceOutput != null && (fake || linkType != LinkTargetType.DYNAMIC_LIBRARY)) {
throw new RuntimeException("Interface output can only be used "
+ "with non-fake DYNAMIC_LIBRARY targets");
}
- final Artifact output = createArtifact(outputPath);
- final Artifact interfaceOutput = (interfaceOutputPath != null)
- ? createArtifact(interfaceOutputPath)
- : null;
-
final ImmutableList<Artifact> buildInfoHeaderArtifacts = !linkstamps.isEmpty()
? ruleContext.getBuildInfo(CppBuildInfo.KEY)
: ImmutableList.<Artifact>of();
- final Artifact symbolCountOutput = enableSymbolsCounts(cppConfiguration, fake, linkType)
- ? createArtifact(output.getRootRelativePath().replaceName(
- output.getExecPath().getBaseName() + ".sc"))
- : null;
-
boolean needWholeArchive = wholeArchive || needWholeArchive(
linkStaticness, linkType, linkopts, isNativeDeps, cppConfiguration);
@@ -634,20 +626,19 @@ public final class CppLinkAction extends AbstractAction {
outputLibrary.getArtifact(),
linkstampMap.values(),
interfaceOutputLibrary == null ? null : interfaceOutputLibrary.getArtifact(),
- symbolCountOutput);
+ symbolCounts);
@Nullable
- final Artifact paramFile =
- canSplitCommandLine()
- ? createArtifact(
- ParameterFile.derivePath(outputLibrary.getArtifact().getRootRelativePath()))
- : null;
+ final Artifact paramFile = canSplitCommandLine()
+ ? ParamFileHelper.getParamsFile(
+ analysisEnvironment, configuration, outputLibrary.getArtifact())
+ : null;
LinkCommandLine linkCommandLine =
new LinkCommandLine.Builder(configuration, getOwner(), ruleContext)
.setOutput(outputLibrary.getArtifact())
.setInterfaceOutput(interfaceOutput)
- .setSymbolCountsOutput(symbolCountOutput)
+ .setSymbolCountsOutput(symbolCounts)
.setBuildInfoHeaderArtifacts(buildInfoHeaderArtifacts)
.setLinkerInputs(linkerInputs)
.setRuntimeInputs(
@@ -748,7 +739,7 @@ public final class CppLinkAction extends AbstractAction {
*/
public static ImmutableMap<Artifact, Artifact> mapLinkstampsToOutputs(
Collection<Artifact> linkstamps, RuleContext ruleContext, Artifact outputBinary) {
- ImmutableMap.Builder<Artifact, Artifact> mapBuilder = ImmutableMap.builder();
+ ImmutableMap.Builder<Artifact, Artifact> mapBuilder = ImmutableMap.builder();
PathFragment outputBinaryPath = outputBinary.getRootRelativePath();
PathFragment stampOutputDirectory = outputBinaryPath.getParentDirectory().
@@ -758,21 +749,17 @@ public final class CppLinkAction extends AbstractAction {
PathFragment stampOutputPath = stampOutputDirectory.getRelative(
FileSystemUtils.replaceExtension(linkstamp.getRootRelativePath(), ".o"));
mapBuilder.put(linkstamp,
+ // Note that link stamp actions can be shared between link actions that output shared
+ // native dep libraries.
ruleContext.getAnalysisEnvironment().getDerivedArtifact(
stampOutputPath, outputBinary.getRoot()));
}
- return mapBuilder.build();
- }
+ return mapBuilder.build(); }
protected ActionOwner getOwner() {
return ruleContext.getActionOwner();
}
- protected Artifact createArtifact(PathFragment rootRelativePath) {
- return analysisEnvironment.getDerivedArtifact(
- rootRelativePath, configuration.getBinDirectory());
- }
-
protected Artifact getInterfaceSoBuilder() {
return analysisEnvironment.getEmbeddedToolArtifact(CppRuleClasses.BUILD_INTERFACE_SO);
}
@@ -800,8 +787,13 @@ public final class CppLinkAction extends AbstractAction {
* only be provided if the link type is {@code DYNAMIC_LIBRARY}
* and fake is false.
*/
- public Builder setInterfaceOutputPath(PathFragment path) {
- this.interfaceOutputPath = path;
+ public Builder setInterfaceOutput(Artifact interfaceOutput) {
+ this.interfaceOutput = interfaceOutput;
+ return this;
+ }
+
+ public Builder setSymbolCountsOutput(Artifact symbolCounts) {
+ this.symbolCounts = symbolCounts;
return this;
}
@@ -1024,14 +1016,8 @@ public final class CppLinkAction extends AbstractAction {
@VisibleForTesting
public static Builder createTestBuilder(
final ActionOwner owner, final AnalysisEnvironment analysisEnvironment,
- final PathFragment outputPath, BuildConfiguration config) {
- return new Builder(null, outputPath, config, analysisEnvironment, null) {
- @Override
- protected Artifact createArtifact(PathFragment path) {
- return new Artifact(configuration.getBinDirectory().getPath().getRelative(path),
- configuration.getBinDirectory(), configuration.getBinFragment().getRelative(path),
- analysisEnvironment.getOwner());
- }
+ final Artifact output, BuildConfiguration config) {
+ return new Builder(null, output, config, analysisEnvironment, null) {
@Override
protected ActionOwner getOwner() {
return owner;
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 4ea8355e8d..0556819d90 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
@@ -76,7 +76,7 @@ public final class CppModel {
private boolean neverLink;
private boolean allowInterfaceSharedObjects;
private boolean createDynamicLibrary = true;
- private PathFragment soImplFilename;
+ private Artifact soImplArtifact;
private FeatureConfiguration featureConfiguration;
public CppModel(RuleContext ruleContext, CppSemantics semantics) {
@@ -206,8 +206,8 @@ public final class CppModel {
return this;
}
- public CppModel setDynamicLibraryPath(PathFragment soImplFilename) {
- this.soImplFilename = soImplFilename;
+ public CppModel setDynamicLibrary(Artifact soImplFilename) {
+ this.soImplArtifact = soImplFilename;
return this;
}
@@ -568,8 +568,8 @@ public final class CppModel {
//
// Presumably, it is done this way because the .a file is an implicit output of every cc_library
// rule, so we can't use ".pic.a" that in the always-PIC case.
- PathFragment linkedFileName = CppHelper.getLinkedFilename(ruleContext, linkType);
- CppLinkAction maybePicAction = newLinkActionBuilder(linkedFileName)
+ Artifact linkedArtifact = CppHelper.getLinkedArtifact(ruleContext, linkType);
+ CppLinkAction maybePicAction = newLinkActionBuilder(linkedArtifact)
.addNonLibraryInputs(ccOutputs.getObjectFiles(usePicForBinaries))
.addNonLibraryInputs(ccOutputs.getHeaderTokenFiles())
.setLinkType(linkType)
@@ -586,8 +586,8 @@ public final class CppModel {
? LinkTargetType.ALWAYS_LINK_PIC_STATIC_LIBRARY
: LinkTargetType.PIC_STATIC_LIBRARY;
- PathFragment picFileName = CppHelper.getLinkedFilename(ruleContext, picLinkType);
- CppLinkAction picAction = newLinkActionBuilder(picFileName)
+ Artifact picArtifact = CppHelper.getLinkedArtifact(ruleContext, picLinkType);
+ CppLinkAction picAction = newLinkActionBuilder(picArtifact)
.addNonLibraryInputs(ccOutputs.getObjectFiles(true))
.addNonLibraryInputs(ccOutputs.getHeaderTokenFiles())
.setLinkType(picLinkType)
@@ -602,24 +602,26 @@ public final class CppModel {
}
// Create dynamic library.
- if (soImplFilename == null) {
- soImplFilename = CppHelper.getLinkedFilename(ruleContext, LinkTargetType.DYNAMIC_LIBRARY);
+ Artifact soImpl;
+ if (soImplArtifact == null) {
+ soImpl = CppHelper.getLinkedArtifact(ruleContext, LinkTargetType.DYNAMIC_LIBRARY);
+ } else {
+ soImpl = soImplArtifact;
}
+
List<String> sonameLinkopts = ImmutableList.of();
- PathFragment soInterfaceFilename = null;
+ Artifact soInterface = null;
if (cppConfiguration.useInterfaceSharedObjects() && allowInterfaceSharedObjects) {
- soInterfaceFilename =
- CppHelper.getLinkedFilename(ruleContext, LinkTargetType.INTERFACE_DYNAMIC_LIBRARY);
- Artifact dynamicLibrary = env.getDerivedArtifact(
- soImplFilename, configuration.getBinDirectory());
+ soInterface =
+ CppHelper.getLinkedArtifact(ruleContext, LinkTargetType.INTERFACE_DYNAMIC_LIBRARY);
sonameLinkopts = ImmutableList.of("-Wl,-soname=" +
- SolibSymlinkAction.getDynamicLibrarySoname(dynamicLibrary.getRootRelativePath(), false));
+ SolibSymlinkAction.getDynamicLibrarySoname(soImpl.getRootRelativePath(), false));
}
// Should we also link in any libraries that this library depends on?
// That is required on some systems...
- CppLinkAction action = newLinkActionBuilder(soImplFilename)
- .setInterfaceOutputPath(soInterfaceFilename)
+ CppLinkAction action = newLinkActionBuilder(soImpl)
+ .setInterfaceOutput(soInterface)
.addNonLibraryInputs(ccOutputs.getObjectFiles(usePicForSharedLibs))
.addNonLibraryInputs(ccOutputs.getHeaderTokenFiles())
.setLinkType(LinkTargetType.DYNAMIC_LIBRARY)
@@ -657,8 +659,8 @@ public final class CppModel {
return result.build();
}
- private CppLinkAction.Builder newLinkActionBuilder(PathFragment outputPath) {
- return new CppLinkAction.Builder(ruleContext, outputPath)
+ private CppLinkAction.Builder newLinkActionBuilder(Artifact outputArtifact) {
+ return new CppLinkAction.Builder(ruleContext, outputArtifact)
.setCrosstoolInputs(CppHelper.getToolchain(ruleContext).getLink())
.addNonLibraryInputs(context.getCompilationPrerequisites());
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/nativedeps/NativeDepsHelper.java b/src/main/java/com/google/devtools/build/lib/rules/nativedeps/NativeDepsHelper.java
index 09a68241bf..90a10a68a5 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/nativedeps/NativeDepsHelper.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/nativedeps/NativeDepsHelper.java
@@ -150,9 +150,10 @@ public abstract class NativeDepsHelper {
linkopts, linkstamps.keySet(), buildInfoArtifacts,
ruleContext.getFeatures())
: nativeDepsPath;
-
+ Artifact sharedLibrary = ruleContext.getAnalysisEnvironment().getDerivedArtifact(
+ linkerOutputPath, configuration.getBinDirectory());
CppLinkAction.Builder builder = new CppLinkAction.Builder(
- ruleContext, linkerOutputPath, configuration, toolchain);
+ ruleContext, sharedLibrary, configuration, toolchain);
CppLinkAction linkAction = builder
.setCrosstoolInputs(toolchain.getLink())
.addLibraries(linkerInputs)
@@ -197,15 +198,6 @@ public abstract class NativeDepsHelper {
}
/**
- * Returns the path, relative to the runfiles prefix, of the native executable
- * for the specified rule, i.e. "<package>/<rule><NATIVE_DEPS_LIB_SUFFIX>"
- */
- public static PathFragment getExecutablePath(RuleContext ruleContext) {
- PathFragment relativePath = Util.getWorkspaceRelativePath(ruleContext.getRule());
- return relativePath.replaceName(relativePath.getBaseName() + Constants.NATIVE_DEPS_LIB_SUFFIX);
- }
-
- /**
* Returns the path, relative to the runfiles prefix, of a runtime library
* symlink for the native library for the specified rule.
*/