Automated rollback of commit 4cba428ddb66ece95bbb210fcb1d124c81a9c45c. *** Reason for rollback *** b/116592380 *** Original change description *** C++: Makes Java native deps launcher use linking API. The CppLinkAction.Context provider from CcBinary is no longer needed. Only use remaining is the Python launcher. RELNOTES:none PiperOrigin-RevId: 214447871
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 4bc5b15..8ea59c0 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
@@ -49,9 +49,6 @@ import com.google.devtools.build.lib.collect.nestedset.NestedSet; import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; import com.google.devtools.build.lib.collect.nestedset.Order; -import com.google.devtools.build.lib.packages.BuiltinProvider; -import com.google.devtools.build.lib.packages.NativeInfo; -import com.google.devtools.build.lib.packages.Rule; import com.google.devtools.build.lib.packages.TargetUtils; import com.google.devtools.build.lib.rules.apple.ApplePlatform; import com.google.devtools.build.lib.rules.cpp.CcCommon.CcFlagsSupplier; @@ -63,7 +60,6 @@ import com.google.devtools.build.lib.rules.cpp.Link.LinkingMode; import com.google.devtools.build.lib.rules.cpp.LinkerInputs.LibraryToLink; import com.google.devtools.build.lib.syntax.Type; -import com.google.devtools.build.lib.util.Pair; import com.google.devtools.build.lib.vfs.FileSystemUtils; import com.google.devtools.build.lib.vfs.PathFragment; import java.util.ArrayList; @@ -94,53 +90,6 @@ @VisibleForTesting public static final String INTERMEDIATE_DWP_DIR = "_dwps"; - /** Provider for native deps launchers. DO NOT USE. */ - @Deprecated - public static class CcLauncherInfo extends NativeInfo { - private static final String RESTRICTION_ERROR_MESSAGE = - "This provider is restricted to native.java_binary, native.py_binary and native.java_test. " - + "This is a "; - public static final String PROVIDER_NAME = "CcLauncherInfo"; - public static final Provider PROVIDER = new Provider(); - - private final CcCompilationOutputs ccCompilationOutputs; - private final CcLinkParams staticModeParamsForExecutable; - - public CcLauncherInfo( - CcLinkParams staticModeParamsForExecutable, CcCompilationOutputs ccCompilationOutputs) { - super(PROVIDER); - this.staticModeParamsForExecutable = staticModeParamsForExecutable; - this.ccCompilationOutputs = ccCompilationOutputs; - } - - public CcCompilationOutputs getCcCompilationOutputs(RuleContext ruleContext) { - checkRestrictedUsage(ruleContext); - return ccCompilationOutputs; - } - - public CcLinkParams getStaticModeParamsForExecutable(RuleContext ruleContext) { - checkRestrictedUsage(ruleContext); - return staticModeParamsForExecutable; - } - - private void checkRestrictedUsage(RuleContext ruleContext) { - Rule rule = ruleContext.getRule(); - if (rule.getRuleClassObject().isSkylark() - || (!rule.getRuleClass().equals("java_binary") - && !rule.getRuleClass().equals("java_test") - && !rule.getRuleClass().equals("py_binary"))) { - throw new IllegalStateException(RESTRICTION_ERROR_MESSAGE + rule.getRuleClass()); - } - } - - /** Provider class for {@link CcLauncherInfo} objects. */ - public static class Provider extends BuiltinProvider<CcLauncherInfo> { - private Provider() { - super(PROVIDER_NAME, CcLauncherInfo.class); - } - } - } - private static Runfiles collectRunfiles( RuleContext ruleContext, FeatureConfiguration featureConfiguration, @@ -378,7 +327,7 @@ pdbFile = ruleContext.getRelatedArtifact(binary.getRootRelativePath(), ".pdb"); } - Pair<CcLinkingOutputs, CcLinkingInfo> ccLinkingOutputsAndCcLinkingInfo = + CcLinkingOutputs ccLinkingOutputsBinary = createTransitiveLinkingActions( ruleContext, ccToolchain, @@ -397,17 +346,11 @@ linkingMode, cppConfiguration, linkType, + binaryPath, pdbFile, generatedDefFile, customDefFile); - CcLinkingOutputs ccLinkingOutputsBinary = ccLinkingOutputsAndCcLinkingInfo.first; - - CcLauncherInfo ccLauncherInfo = - new CcLauncherInfo( - ccLinkingOutputsAndCcLinkingInfo.second.getStaticModeParamsForExecutable(), - ccCompilationOutputs); - // Store immutable context for use in other *_binary rules that are implemented by // linking the interpreter (Java, Python, etc.) together with native deps. CppLinkAction.Context linkContext = ccLinkingOutputsBinary.getCppLinkActionContext(); @@ -547,12 +490,11 @@ new DebugPackageProvider(ruleContext.getLabel(), strippedFile, binary, explicitDwpFile)) .setRunfilesSupport(runfilesSupport, binary) .addProvider(CppLinkAction.Context.class, linkContext) - .addNativeDeclaredProvider(ccLauncherInfo) .addSkylarkTransitiveInfo(CcSkylarkApiProvider.NAME, new CcSkylarkApiProvider()) .build(); } - public static Pair<CcLinkingOutputs, CcLinkingInfo> createTransitiveLinkingActions( + public static CcLinkingOutputs createTransitiveLinkingActions( RuleContext ruleContext, CcToolchainProvider ccToolchain, FeatureConfiguration featureConfiguration, @@ -570,18 +512,21 @@ LinkingMode linkingMode, CppConfiguration cppConfiguration, LinkTargetType linkType, + PathFragment binaryPath, Artifact pdbFile, Artifact generatedDefFile, Artifact customDefFile) throws InterruptedException, RuleErrorException { CcLinkingHelper ccLinkingHelper = new CcLinkingHelper( - ruleContext, - cppSemantics, - featureConfiguration, - ccToolchain, - fdoProvider, - ruleContext.getConfiguration()); + ruleContext, + cppSemantics, + featureConfiguration, + ccToolchain, + fdoProvider, + ruleContext.getConfiguration()) + .addNonCodeLinkerInputs(ccCompilationContext.getTransitiveCompilationPrerequisites()) + .addNonCodeLinkerInputs(common.getLinkerScripts()); CcLinkParams.Builder ccLinkParamsBuilder = CcLinkParams.builder(); ccLinkParamsBuilder.addTransitiveArgs(linkParams); @@ -616,20 +561,6 @@ } } - if (linkingMode != Link.LinkingMode.DYNAMIC - && !cppConfiguration.disableEmittingStaticLibgcc()) { - // Only force a static link of libgcc if static runtime linking is enabled (which - // can't be true if runtimeInputs is empty). - // TODO(bazel-team): Move this to CcToolchain. - if (!ccToolchain.getStaticRuntimeLinkInputs(featureConfiguration).isEmpty()) { - ccLinkParamsBuilder.addLinkOpts(ImmutableList.of("-static-libgcc")); - } - } - - ccLinkParamsBuilder - .addNonCodeInputs(ccCompilationContext.getTransitiveCompilationPrerequisites()) - .addNonCodeInputs(common.getLinkerScripts()); - CcLinkParams ccLinkParams = ccLinkParamsBuilder.build(); CcLinkingInfo.Builder ccLinkingInfo = CcLinkingInfo.Builder.create(); ccLinkingInfo.setStaticModeParamsForDynamicLibrary(ccLinkParams); @@ -643,7 +574,7 @@ .setShouldCreateStaticLibraries(false) .setLinkingMode(linkingMode) .setDynamicLinkType(linkType) - .setLinkerOutputArtifact(binary) + .setDynamicLibrary(binary) .setNeverLink(true) .emitInterfaceSharedObjects( isLinkShared(ruleContext) @@ -658,7 +589,17 @@ ccLinkingHelper.setDefFile(generatedDefFile); } - return Pair.of(ccLinkingHelper.link(ccCompilationOutputs), ccLinkingInfo.build()); + if (linkingMode != Link.LinkingMode.DYNAMIC + && !cppConfiguration.disableEmittingStaticLibgcc()) { + // Only force a static link of libgcc if static runtime linking is enabled (which + // can't be true if runtimeInputs is empty). + // TODO(bazel-team): Move this to CcToolchain. + if (!ccToolchain.getStaticRuntimeLinkInputs(featureConfiguration).isEmpty()) { + ccLinkingHelper.addLinkopts(ImmutableList.of("-static-libgcc")); + } + } + + return ccLinkingHelper.link(/* ccOutputs */ ccCompilationOutputs); } /**
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 bf2c3a0..28d44cb 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
@@ -202,7 +202,7 @@ } linkingHelper.setShouldCreateDynamicLibrary(createDynamicLibrary); - linkingHelper.setLinkerOutputArtifact(soImplArtifact); + linkingHelper.setDynamicLibrary(soImplArtifact); // If the reason we're not creating a dynamic library is that the toolchain // doesn't support it, then register an action which complains when triggered,
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkingHelper.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkingHelper.java index 73af843..0b4ee03 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkingHelper.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkingHelper.java
@@ -100,7 +100,7 @@ private final NestedSetBuilder<Artifact> linkstamps = NestedSetBuilder.stableOrder(); private final List<Artifact> linkActionInputs = new ArrayList<>(); - @Nullable private Artifact linkerOutputArtifact; + @Nullable private Artifact dynamicLibrary; private LinkTargetType staticLinkType = LinkTargetType.STATIC_LIBRARY; private LinkTargetType dynamicLinkType = LinkTargetType.NODEPS_DYNAMIC_LIBRARY; private boolean neverlink; @@ -223,8 +223,8 @@ * 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 CcLinkingHelper setLinkerOutputArtifact(@Nullable Artifact linkerOutputArtifact) { - this.linkerOutputArtifact = linkerOutputArtifact; + public CcLinkingHelper setDynamicLibrary(@Nullable Artifact dynamicLibrary) { + this.dynamicLibrary = dynamicLibrary; return this; } @@ -598,7 +598,7 @@ // Create dynamic library. Artifact soImpl; String mainLibraryIdentifier; - if (linkerOutputArtifact == null) { + if (dynamicLibrary == null) { // If the crosstool is configured to select an output artifact, we use that selection. // Otherwise, we use linux defaults. soImpl = getLinkedArtifact(LinkTargetType.NODEPS_DYNAMIC_LIBRARY); @@ -608,7 +608,7 @@ // file is explicitly specified in the BUILD file and as such, is platform-dependent. Thus, // we just hardcode some reasonable logic to compute the library identifier and hope that this // will eventually go away. - soImpl = linkerOutputArtifact; + soImpl = dynamicLibrary; mainLibraryIdentifier = FileSystemUtils.removeExtension(soImpl.getRootRelativePath().getPathString()); }
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcModule.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcModule.java index c71a5ad..c499905 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcModule.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcModule.java
@@ -544,7 +544,7 @@ ruleContext.getConfiguration()) .addLinkopts(linkopts) .setShouldCreateStaticLibraries(shouldCreateStaticLibraries) - .setLinkerOutputArtifact(convertFromNoneable(dynamicLibrary, null)) + .setDynamicLibrary(convertFromNoneable(dynamicLibrary, null)) .addCcLinkingInfos(skylarkCcLinkingInfos) .setNeverLink(neverLink); try {
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 d390b08..4f41338c 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
@@ -1497,9 +1497,6 @@ throws InterruptedException, RuleErrorException { addLinkopts(linkParams.flattenedLinkopts()); addLibraries(linkParams.getLibraries()); - if (linkParams.getNonCodeInputs() != null) { - addNonCodeInputs(linkParams.getNonCodeInputs()); - } ExtraLinkTimeLibraries extraLinkTimeLibraries = linkParams.getExtraLinkTimeLibraries(); if (extraLinkTimeLibraries != null) { for (ExtraLinkTimeLibrary extraLibrary : extraLinkTimeLibraries.getExtraLibraries()) {