From c3151a31cb6aa40e0a7ea792a5d17b5f8ec01768 Mon Sep 17 00:00:00 2001 From: Lukacs Berki Date: Mon, 24 Aug 2015 08:18:59 +0000 Subject: Remove an AnalysisEnvironment.getDerivedArtifact() call from nativedeps. -- MOS_MIGRATED_REVID=101344826 --- .../lib/rules/nativedeps/NativeDepsHelper.java | 70 ++++++++++++---------- 1 file changed, 39 insertions(+), 31 deletions(-) (limited to 'src/main/java') 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 56ed3e02ec..5cd41f3913 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 @@ -20,7 +20,6 @@ import com.google.devtools.build.lib.Constants; import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.actions.Root; import com.google.devtools.build.lib.analysis.RuleContext; -import com.google.devtools.build.lib.analysis.Util; import com.google.devtools.build.lib.analysis.actions.SymlinkAction; import com.google.devtools.build.lib.analysis.config.BuildConfiguration; import com.google.devtools.build.lib.collect.nestedset.NestedSet; @@ -97,10 +96,7 @@ public abstract class NativeDepsHelper { */ public static NativeDepsRunfiles maybeCreateNativeDepsAction(final RuleContext ruleContext, CcLinkParams linkParams, Collection extraLinkOpts, boolean includeMalloc, - BuildConfiguration configuration) { - PathFragment relativePath = Util.getWorkspaceRelativePath(ruleContext.getRule()); - PathFragment nativeDepsPath = relativePath.replaceName( - relativePath.getBaseName() + Constants.NATIVE_DEPS_LIB_SUFFIX + ".so"); + final BuildConfiguration configuration) { if (includeMalloc) { // Add in the custom malloc dependency if it was requested. CcLinkParams.Builder linkParamsBuilder = CcLinkParams.builder(true, true); @@ -108,8 +104,19 @@ public abstract class NativeDepsHelper { linkParamsBuilder.addTransitiveTarget(CppHelper.mallocForTarget(ruleContext)); linkParams = linkParamsBuilder.build(); } - return maybeCreateNativeDepsAction(ruleContext, linkParams, extraLinkOpts, configuration, - CppHelper.getToolchain(ruleContext), nativeDepsPath, + + if (linkParams.getLibraries().isEmpty()) { + return NativeDepsRunfiles.EMPTY; + } + + PathFragment relativePath = new PathFragment(ruleContext.getLabel().getName()); + PathFragment nativeDepsPath = relativePath.replaceName( + relativePath.getBaseName() + Constants.NATIVE_DEPS_LIB_SUFFIX + ".so"); + Artifact nativeDeps = ruleContext.getPackageRelativeArtifact(nativeDepsPath, + configuration.getBinDirectory()); + + return createNativeDepsAction(ruleContext, linkParams, extraLinkOpts, configuration, + CppHelper.getToolchain(ruleContext), nativeDeps, ruleContext.getConfiguration().getBinDirectory()); } @@ -134,24 +141,27 @@ public abstract class NativeDepsHelper { * no native code libraries, its fields are null. */ public static Artifact maybeCreateAndroidNativeDepsAction(final RuleContext ruleContext, - CcLinkParams linkParams, BuildConfiguration configuration, CcToolchainProvider toolchain) { - PathFragment uniquePath = ruleContext.getUniqueDirectory(ANDROID_UNIQUE_DIR); - PathFragment nativeDepsPath = - uniquePath.replaceName("lib" + uniquePath.getBaseName() + ".so"); - return maybeCreateNativeDepsAction( - ruleContext, linkParams, /** extraLinkOpts */ ImmutableList.of(), - configuration, toolchain, nativeDepsPath, configuration.getBinDirectory()).getLibrary(); + CcLinkParams linkParams, final BuildConfiguration configuration, + CcToolchainProvider toolchain) { + if (linkParams.getLibraries().isEmpty()) { + return null; + } + + PathFragment labelName = new PathFragment(ruleContext.getLabel().getName()); + Artifact nativeDeps = ruleContext.getUniqueDirectoryArtifact(ANDROID_UNIQUE_DIR, + labelName.replaceName("lib" + labelName.getBaseName() + ".so"), + configuration.getBinDirectory()); + + return createNativeDepsAction( + ruleContext, linkParams, /** extraLinkOpts */ImmutableList.of(), + configuration, toolchain, nativeDeps, configuration.getBinDirectory()).getLibrary(); } - private static NativeDepsRunfiles maybeCreateNativeDepsAction(final RuleContext ruleContext, + private static NativeDepsRunfiles createNativeDepsAction(final RuleContext ruleContext, CcLinkParams linkParams, Collection extraLinkOpts, BuildConfiguration configuration, - CcToolchainProvider toolchain, PathFragment nativeDepsPath, Root bindirIfShared) { + CcToolchainProvider toolchain, Artifact nativeDeps, Root bindirIfShared) { Preconditions.checkState(ruleContext.isLegalFragment(CppConfiguration.class), "%s does not have access to CppConfiguration", ruleContext.getRule().getRuleClass()); - if (linkParams.getLibraries().isEmpty()) { - return NativeDepsRunfiles.EMPTY; - } - List linkopts = new ArrayList<>(extraLinkOpts); linkopts.addAll(linkParams.flattenedLinkopts()); @@ -163,13 +173,13 @@ public abstract class NativeDepsHelper { boolean shareNativeDeps = configuration.getFragment(CppConfiguration.class).shareNativeDeps(); NestedSet linkerInputs = linkParams.getLibraries(); - PathFragment linkerOutputPath = shareNativeDeps - ? getSharedNativeDepsPath(LinkerInputs.toLibraryArtifacts(linkerInputs), - linkopts, linkstamps.keySet(), buildInfoArtifacts, - ruleContext.getFeatures()) - : nativeDepsPath; - Artifact sharedLibrary = ruleContext.getShareableArtifact( - linkerOutputPath, configuration.getBinDirectory()); + Artifact sharedLibrary = shareNativeDeps + ? ruleContext.getShareableArtifact(getSharedNativeDepsPath( + LinkerInputs.toLibraryArtifacts(linkerInputs), + linkopts, linkstamps.keySet(), buildInfoArtifacts, + ruleContext.getFeatures()), + ruleContext.getConfiguration().getBinDirectory()) + : nativeDeps; CppLinkAction.Builder builder = new CppLinkAction.Builder( ruleContext, sharedLibrary, configuration, toolchain); builder.setLinkArtifactFactory(SHAREABLE_LINK_ARTIFACT_FACTORY); @@ -206,11 +216,9 @@ public abstract class NativeDepsHelper { runtimeSymlinks.add(runtimeSymlink); } - Artifact symlink = ruleContext.getAnalysisEnvironment().getDerivedArtifact( - nativeDepsPath, bindirIfShared); ruleContext.registerAction( - new SymlinkAction(ruleContext.getActionOwner(), linkerOutput, symlink, null)); - return new NativeDepsRunfiles(symlink, runtimeSymlinks); + new SymlinkAction(ruleContext.getActionOwner(), linkerOutput, nativeDeps, null)); + return new NativeDepsRunfiles(nativeDeps, runtimeSymlinks); } return new NativeDepsRunfiles(linkerOutput, runtimeSymlinks); -- cgit v1.2.3