diff options
Diffstat (limited to 'src/main/java/com/google')
9 files changed, 149 insertions, 99 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java index 426982e9a6..33a489d813 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java @@ -523,8 +523,13 @@ public final class CcCommon { * @return mangled symlink artifact. */ public Artifact getDynamicLibrarySymlink(Artifact library, boolean preserveName) { - return SolibSymlinkAction.getDynamicLibrarySymlink( - ruleContext, library, preserveName, true, ruleContext.getConfiguration()); + return SolibSymlinkAction.getDynamicLibrarySymlink( + ruleContext, + ccToolchain.getSolibDirectory(), + library, + preserveName, + true, + ruleContext.getConfiguration()); } /** diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchain.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchain.java index 4ae834e254..3fcf418d56 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchain.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchain.java @@ -331,9 +331,13 @@ public class CcToolchain implements RuleConfiguredTargetFactory { .getProvider(FileProvider.class).getFilesToBuild()) { if (CppHelper.SHARED_LIBRARY_FILETYPES.matches(artifact.getFilename())) { dynamicRuntimeLinkInputs.add(artifact); - dynamicRuntimeLinkSymlinksBuilder.add(SolibSymlinkAction.getCppRuntimeSymlink( - ruleContext, artifact, runtimeSolibDirBase, - ruleContext.getConfiguration())); + dynamicRuntimeLinkSymlinksBuilder.add( + SolibSymlinkAction.getCppRuntimeSymlink( + ruleContext, + artifact, + toolchainInfo.getSolibDirectory(), + runtimeSolibDirBase, + ruleContext.getConfiguration())); } } dynamicRuntimeLinkSymlinks = dynamicRuntimeLinkSymlinksBuilder.build(); @@ -347,6 +351,7 @@ public class CcToolchain implements RuleConfiguredTargetFactory { ruleContext, purposePrefix + "dynamic_runtime_link", dynamicRuntimeLinkInputs, + toolchainInfo.getSolibDirectory(), runtimeSolibDirBase, ruleContext.getConfiguration()); dynamicRuntimeLinkMiddleman = dynamicRuntimeLinkMiddlemanSet.isEmpty() diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainProvider.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainProvider.java index 0b4223a843..30ef49edb0 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainProvider.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcToolchainProvider.java @@ -302,7 +302,32 @@ public final class CcToolchainProvider extends ToolchainInfo { public CcToolchainFeatures getFeatures() { return toolchainInfo.getFeatures(); } - + + /** + * Returns whether shared libraries must be compiled with position independent code on this + * platform. + */ + public boolean toolchainNeedsPic() { + return toolchainInfo.toolchainNeedsPic(); + } + + /** + * Returns the run time sysroot, which is where the dynamic linker and system libraries are found + * at runtime. This is usually an absolute path. If the toolchain compiler does not support + * sysroots, then this method returns <code>null</code>. + */ + public PathFragment getRuntimeSysroot() { + return toolchainInfo.getRuntimeSysroot(); + } + + /** + * Return the name of the directory (relative to the bin directory) that holds mangled links to + * shared libraries. This name is always set to the '{@code _solib_<cpu_archictecture_name>}. + */ + public String getSolibDirectory() { + return toolchainInfo.getSolibDirectory(); + } + /** * Returns the compilation mode. */ diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java index efa162908c..b48b0e6a61 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java @@ -645,14 +645,6 @@ public class CppConfiguration extends BuildConfiguration.Fragment { } /** - * Returns whether shared libraries must be compiled with position - * independent code on this platform. - */ - public boolean toolchainNeedsPic() { - return cppToolchainInfo.toolchainNeedsPic(); - } - - /** * Returns whether binaries must be compiled with position independent code. */ public boolean usePicForBinaries() { @@ -714,15 +706,6 @@ public class CppConfiguration extends BuildConfiguration.Fragment { } /** - * Returns the run time sysroot, which is where the dynamic linker - * and system libraries are found at runtime. This is usually an absolute path. If the - * toolchain compiler does not support sysroots, then this method returns <code>null</code>. - */ - public PathFragment getRuntimeSysroot() { - return cppToolchainInfo.getRuntimeSysroot(); - } - - /** * Returns the default options to use for compiling C, C++, and assembler. * This is just the options that should be used for all three languages. * There may be additional C-specific or C++-specific options that should be used, @@ -1238,15 +1221,6 @@ public class CppConfiguration extends BuildConfiguration.Fragment { } /** - * Return the name of the directory (relative to the bin directory) that - * holds mangled links to shared libraries. This name is always set to - * the '{@code _solib_<cpu_archictecture_name>}. - */ - public String getSolibDirectory() { - return cppToolchainInfo.getSolibDirectory(); - } - - /** * Returns the path to the GNU binutils 'objcopy' binary to use for this build. (Corresponds to * $(OBJCOPY) in make-dbg.) Relative paths are relative to the execution root. */ 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 fc7bda0f34..b7942b3b59 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 @@ -584,46 +584,75 @@ public class CppHelper { } /** - * Returns a middleman for all files to build for the given configured target, - * substituting shared library artifacts with corresponding solib symlinks. If - * multiple calls are made, then it returns the same artifact for configurations - * with the same internal directory. + * Returns a middleman for all files to build for the given configured target, substituting shared + * library artifacts with corresponding solib symlinks. If multiple calls are made, then it + * returns the same artifact for configurations with the same internal directory. * - * <p>The resulting middleman only aggregates the inputs and must be expanded - * before populating the set of files necessary to execute an action. + * <p>The resulting middleman only aggregates the inputs and must be expanded before populating + * the set of files necessary to execute an action. */ - static List<Artifact> getAggregatingMiddlemanForCppRuntimes(RuleContext ruleContext, - String purpose, Iterable<Artifact> artifacts, String solibDirOverride, + static List<Artifact> getAggregatingMiddlemanForCppRuntimes( + RuleContext ruleContext, + String purpose, + Iterable<Artifact> artifacts, + String solibDir, + String solibDirOverride, BuildConfiguration configuration) { - return getMiddlemanInternal(ruleContext, ruleContext.getActionOwner(), purpose, - artifacts, true, true, solibDirOverride, configuration); + return getMiddlemanInternal( + ruleContext, + ruleContext.getActionOwner(), + purpose, + artifacts, + true, + true, + solibDir, + solibDirOverride, + configuration); } @VisibleForTesting public static List<Artifact> getAggregatingMiddlemanForTesting( - RuleContext ruleContext, ActionOwner owner, String purpose, Iterable<Artifact> artifacts, - boolean useSolibSymlinks, BuildConfiguration configuration) { + RuleContext ruleContext, + ActionOwner owner, + String purpose, + Iterable<Artifact> artifacts, + boolean useSolibSymlinks, + String solibDir, + BuildConfiguration configuration) { return getMiddlemanInternal( - ruleContext, owner, purpose, artifacts, useSolibSymlinks, false, null, configuration); - } - - /** - * Internal implementation for getAggregatingMiddlemanForCppRuntimes. - */ + ruleContext, + owner, + purpose, + artifacts, + useSolibSymlinks, + false, + solibDir, + null, + configuration); + } + + /** Internal implementation for getAggregatingMiddlemanForCppRuntimes. */ private static List<Artifact> getMiddlemanInternal( - RuleContext ruleContext, ActionOwner actionOwner, String purpose, - Iterable<Artifact> artifacts, boolean useSolibSymlinks, boolean isCppRuntime, - String solibDirOverride, BuildConfiguration configuration) { + RuleContext ruleContext, + ActionOwner actionOwner, + String purpose, + Iterable<Artifact> artifacts, + boolean useSolibSymlinks, + boolean isCppRuntime, + String solibDir, + String solibDirOverride, + BuildConfiguration configuration) { MiddlemanFactory factory = ruleContext.getAnalysisEnvironment().getMiddlemanFactory(); if (useSolibSymlinks) { List<Artifact> symlinkedArtifacts = new ArrayList<>(); for (Artifact artifact : artifacts) { Preconditions.checkState(Link.SHARED_LIBRARY_FILETYPES.matches(artifact.getFilename())); - symlinkedArtifacts.add(isCppRuntime - ? SolibSymlinkAction.getCppRuntimeSymlink( - ruleContext, artifact, solibDirOverride, configuration) - : SolibSymlinkAction.getDynamicLibrarySymlink( - ruleContext, artifact, false, true, configuration)); + symlinkedArtifacts.add( + isCppRuntime + ? SolibSymlinkAction.getCppRuntimeSymlink( + ruleContext, artifact, solibDir, solibDirOverride, configuration) + : SolibSymlinkAction.getDynamicLibrarySymlink( + ruleContext, solibDir, artifact, false, true, configuration)); } artifacts = symlinkedArtifacts; purpose += "_with_solib"; diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionBuilder.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionBuilder.java index 20432a7cd2..59b11dbff6 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionBuilder.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionBuilder.java @@ -1587,7 +1587,7 @@ public class CppLinkActionBuilder { configuration .getBinDirectory(ruleContext.getRule().getRepository()) .getExecPath() - .getRelative(cppConfiguration.getSolibDirectory()); + .getRelative(toolchain.getSolibDirectory()); String runtimeSolibName = runtimeSolibDir != null ? runtimeSolibDir.getBaseName() : null; boolean runtimeRpath = runtimeSolibDir != null @@ -1617,7 +1617,7 @@ public class CppLinkActionBuilder { // and the second could use $ORIGIN/../_solib_[arch]. But since this is a shared // artifact, both are symlinks to the same place, so // there's no *one* RPATH setting that fits all targets involved in the sharing. - rpathRoot = cppConfiguration.getSolibDirectory() + "/"; + rpathRoot = toolchain.getSolibDirectory() + "/"; if (runtimeRpath) { runtimeRpathRoots.add("../" + runtimeSolibName + "/"); } @@ -1635,7 +1635,7 @@ public class CppLinkActionBuilder { rpathRoot = Strings.repeat("../", output.getRootRelativePath().segmentCount() - 1) - + cppConfiguration.getSolibDirectory() + + toolchain.getSolibDirectory() + "/"; if (isNativeDeps) { 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 e1ded8a7ea..c4bf33f17a 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 @@ -1500,6 +1500,7 @@ public final class CppModel { Artifact libraryLink = SolibSymlinkAction.getDynamicLibrarySymlink( ruleContext, + ccToolchain.getSolibDirectory(), interfaceLibrary.getArtifact(), /* preserveName= */ false, /* prefixConsumer= */ false, @@ -1509,6 +1510,7 @@ public final class CppModel { Artifact implLibraryLink = SolibSymlinkAction.getDynamicLibrarySymlink( ruleContext, + ccToolchain.getSolibDirectory(), dynamicLibrary.getArtifact(), /* preserveName= */ false, /* prefixConsumer= */ false, diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/LinkCommandLine.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/LinkCommandLine.java index c3607a1ccc..c7ab4bb993 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/LinkCommandLine.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/LinkCommandLine.java @@ -587,7 +587,7 @@ public final class LinkCommandLine extends CommandLine { CppModel.PREPROCESSOR_DEFINES_VARIABLE_NAME, computeAllLinkstampDefines()); // For dynamic libraries, produce position independent code. - if (linkTargetType == LinkTargetType.DYNAMIC_LIBRARY && cppConfiguration.toolchainNeedsPic()) { + if (linkTargetType == LinkTargetType.DYNAMIC_LIBRARY && ccProvider.toolchainNeedsPic()) { linkstampVariables.addStringVariable(CppModel.PIC_VARIABLE_NAME, ""); } return linkstampVariables.build(); diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/SolibSymlinkAction.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/SolibSymlinkAction.java index 48b12a80ac..90ef9c8ec0 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/SolibSymlinkAction.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/SolibSymlinkAction.java @@ -87,44 +87,54 @@ public final class SolibSymlinkAction extends AbstractAction { } /** - * Replaces shared library artifact with mangled symlink and creates related - * symlink action. For artifacts that should retain filename (e.g. libraries - * with SONAME tag), link is created to the parent directory instead. + * Replaces shared library artifact with mangled symlink and creates related symlink action. For + * artifacts that should retain filename (e.g. libraries with SONAME tag), link is created to the + * parent directory instead. * - * This action is performed to minimize number of -rpath entries used during - * linking process (by essentially "collecting" as many shared libraries as - * possible in the single directory), since we will be paying quadratic price - * for each additional entry on the -rpath. + * <p>This action is performed to minimize number of -rpath entries used during linking process + * (by essentially "collecting" as many shared libraries as possible in the single directory), + * since we will be paying quadratic price for each additional entry on the -rpath. * * @param ruleContext rule context, that requested symlink. + * @param solibDir String giving the solib directory * @param library Shared library artifact that needs to be mangled. * @param preserveName whether to preserve the name of the library - * @param prefixConsumer whether to prefix the output artifact name with the label of the - * consumer + * @param prefixConsumer whether to prefix the output artifact name with the label of the consumer * @return mangled symlink artifact. */ - public static Artifact getDynamicLibrarySymlink(final RuleContext ruleContext, - final Artifact library, - boolean preserveName, - boolean prefixConsumer, - BuildConfiguration configuration) { - PathFragment mangledName = getMangledName( - ruleContext, library.getRootRelativePath(), preserveName, prefixConsumer, - configuration.getFragment(CppConfiguration.class)); + public static Artifact getDynamicLibrarySymlink( + final RuleContext ruleContext, + String solibDir, + final Artifact library, + boolean preserveName, + boolean prefixConsumer, + BuildConfiguration configuration) { + PathFragment mangledName = + getMangledName( + ruleContext, + solibDir, + library.getRootRelativePath(), + preserveName, + prefixConsumer, + configuration.getFragment(CppConfiguration.class)); return getDynamicLibrarySymlinkInternal( ruleContext, library, mangledName, configuration); } - /** + /** * Version of {@link #getDynamicLibrarySymlink} for the special case of C++ runtime libraries. * These are handled differently than other libraries: neither their names nor directories are * mangled, i.e. libstdc++.so.6 is symlinked from _solib_[arch]/libstdc++.so.6 */ - public static Artifact getCppRuntimeSymlink(RuleContext ruleContext, Artifact library, - String solibDirOverride, BuildConfiguration configuration) { - PathFragment solibDir = PathFragment.create(solibDirOverride != null - ? solibDirOverride - : configuration.getFragment(CppConfiguration.class).getSolibDirectory()); + public static Artifact getCppRuntimeSymlink( + RuleContext ruleContext, + Artifact library, + String toolchainProvidedSolibDir, + String solibDirOverride, + BuildConfiguration configuration) { + PathFragment solibDir = + PathFragment.create( + solibDirOverride != null ? solibDirOverride : toolchainProvidedSolibDir); PathFragment symlinkName = solibDir.getRelative(library.getRootRelativePath().getBaseName()); return getDynamicLibrarySymlinkInternal(ruleContext, library, symlinkName, configuration); } @@ -147,35 +157,35 @@ public final class SolibSymlinkAction extends AbstractAction { } /** - * Returns the name of the symlink that will be created for a library, given - * its name. + * Returns the name of the symlink that will be created for a library, given its name. * * @param ruleContext rule context that requests symlink + * @param solibDir a String giving the solib directory * @param libraryPath the root-relative path of the library * @param preserveName true if filename should be preserved * @param prefixConsumer true if the result should be prefixed with the label of the consumer * @returns root relative path name */ - public static PathFragment getMangledName(RuleContext ruleContext, - PathFragment libraryPath, - boolean preserveName, - boolean prefixConsumer, - CppConfiguration cppConfiguration) { + public static PathFragment getMangledName( + RuleContext ruleContext, + String solibDir, + PathFragment libraryPath, + boolean preserveName, + boolean prefixConsumer, + CppConfiguration cppConfiguration) { String escapedRulePath = Actions.escapedPath( "_" + ruleContext.getLabel()); String soname = getDynamicLibrarySoname(libraryPath, preserveName); - PathFragment solibDir = PathFragment.create(cppConfiguration.getSolibDirectory()); + PathFragment solibDirPath = PathFragment.create(solibDir); if (preserveName) { String escapedLibraryPath = Actions.escapedPath("_" + libraryPath.getParentDirectory().getPathString()); - PathFragment mangledDir = solibDir.getRelative(prefixConsumer - ? escapedRulePath + "__" + escapedLibraryPath - : escapedLibraryPath); + PathFragment mangledDir = + solibDirPath.getRelative( + prefixConsumer ? escapedRulePath + "__" + escapedLibraryPath : escapedLibraryPath); return mangledDir.getRelative(soname); } else { - return solibDir.getRelative(prefixConsumer - ? escapedRulePath + "__" + soname - : soname); + return solibDirPath.getRelative(prefixConsumer ? escapedRulePath + "__" + soname : soname); } } |