Skip to content

Commit

Permalink
Move interface so building to action configs
Browse files Browse the repository at this point in the history
This cl moves the conditional building of interface libraries from LinkCommandLine to action configs and features. It provides link_dynamic_library.sh to keep blaze backwards compatible. The script and related code can be deleted once all crosstools are updated.

RELNOTES: No.

--
MOS_MIGRATED_REVID=135799041
  • Loading branch information
hlopko authored and hermione521 committed Oct 12, 2016
1 parent 671045b commit 74b9432
Show file tree
Hide file tree
Showing 17 changed files with 688 additions and 410 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
* Implementation for the cc_toolchain rule.
*/
public class CcToolchain implements RuleConfiguredTargetFactory {

/**
* This file (found under the sysroot) may be unconditionally included in every C/C++ compilation.
*/
Expand Down Expand Up @@ -198,6 +199,8 @@ public ConfiguredTarget create(RuleContext ruleContext)
"FDO_DIR", cppConfiguration.getFdoInstrument().getPathString()));
}

Artifact linkDynamicLibraryTool = getLinkDynamicLibraryTool(ruleContext);

CcToolchainProvider provider =
new CcToolchainProvider(
cppConfiguration,
Expand All @@ -220,6 +223,7 @@ public ConfiguredTarget create(RuleContext ruleContext)
getBuildVariables(ruleContext),
getBuiltinIncludes(ruleContext),
coverageEnvironment.build(),
linkDynamicLibraryTool,
getEnvironment(ruleContext));
RuleConfiguredTargetBuilder builder =
new RuleConfiguredTargetBuilder(ruleContext)
Expand Down Expand Up @@ -250,6 +254,10 @@ public NestedSet<TargetLicense> getTransitiveLicenses() {
return builder.build();
}

private Artifact getLinkDynamicLibraryTool(RuleContext ruleContext) {
return ruleContext.getPrerequisiteArtifact("$link_dynamic_library_tool", Mode.TARGET);
}

private ImmutableList<Artifact> getBuiltinIncludes(RuleContext ruleContext) {
ImmutableList.Builder<Artifact> result = ImmutableList.builder();
for (Artifact artifact : inputsForLibc(ruleContext)) {
Expand Down Expand Up @@ -285,6 +293,7 @@ protected NestedSet<Artifact> fullInputsForLink(
return NestedSetBuilder.<Artifact>stableOrder()
.addTransitive(link)
.addTransitive(AnalysisUtils.getMiddlemanFor(ruleContext, ":libc_top"))
.add(getLinkDynamicLibraryTool(ruleContext))
.add(
ruleContext
.getAnalysisEnvironment()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1149,9 +1149,12 @@ public boolean isEnabled(String feature) {
return enabledFeatureNames.contains(feature);
}

/**
* @return whether an action config for the blaze action with the given name is enabled.
*/
/** @return true if tool_path in action_config points to a real tool, not a dummy placeholder */
public boolean hasConfiguredLinkerPathInActionConfig() {
return isEnabled("has_configured_linker_path");
}

/** @return whether an action config for the blaze action with the given name is enabled. */
boolean actionIsConfigured(String actionName) {
return enabledActionConfigActionNames.contains(actionName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,15 @@
import com.google.devtools.build.lib.util.Pair;
import com.google.devtools.build.lib.util.Preconditions;
import com.google.devtools.build.lib.vfs.PathFragment;

import java.util.Map;

import javax.annotation.Nullable;

/**
* Information about a C++ compiler used by the <code>cc_*</code> rules.
*/
@Immutable
public final class CcToolchainProvider implements TransitiveInfoProvider {
/**
* An empty toolchain to be returned in the error case (instead of null).
*/
/** An empty toolchain to be returned in the error case (instead of null). */
public static final CcToolchainProvider EMPTY_TOOLCHAIN_IS_ERROR =
new CcToolchainProvider(
null,
Expand All @@ -60,6 +56,7 @@ public final class CcToolchainProvider implements TransitiveInfoProvider {
ImmutableMap.<String, String>of(),
ImmutableList.<Artifact>of(),
NestedSetBuilder.<Pair<String, String>>emptySet(Order.COMPILE_ORDER),
null,
ImmutableMap.<String, String>of());

@Nullable private final CppConfiguration cppConfiguration;
Expand All @@ -82,6 +79,7 @@ public final class CcToolchainProvider implements TransitiveInfoProvider {
private final ImmutableMap<String, String> buildVariables;
private final ImmutableList<Artifact> builtinIncludeFiles;
private final NestedSet<Pair<String, String>> coverageEnvironment;
@Nullable private final Artifact linkDynamicLibraryTool;
private final ImmutableMap<String, String> environment;

public CcToolchainProvider(
Expand All @@ -105,6 +103,7 @@ public CcToolchainProvider(
Map<String, String> buildVariables,
ImmutableList<Artifact> builtinIncludeFiles,
NestedSet<Pair<String, String>> coverageEnvironment,
Artifact linkDynamicLibraryTool,
ImmutableMap<String, String> environment) {
this.cppConfiguration = cppConfiguration;
this.crosstool = Preconditions.checkNotNull(crosstool);
Expand All @@ -126,6 +125,7 @@ public CcToolchainProvider(
this.buildVariables = ImmutableMap.copyOf(buildVariables);
this.builtinIncludeFiles = builtinIncludeFiles;
this.coverageEnvironment = coverageEnvironment;
this.linkDynamicLibraryTool = linkDynamicLibraryTool;
this.environment = environment;
}

Expand Down Expand Up @@ -283,4 +283,12 @@ public NestedSet<Pair<String, String>> getCoverageEnvironment() {
public ImmutableMap<String, String> getEnvironment() {
return environment;
}

/**
* Returns the tool which should be used for linking dynamic libraries, or in case it's not
* specified by the crosstool this will be @tools_repository/tools/cpp:link_dynamic_library
*/
public Artifact getLinkDynamicLibraryTool() {
return linkDynamicLibraryTool;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,16 @@ public RuleClass build(Builder builder, RuleDefinitionEnvironment env) {
.add(attr("module_map", LABEL).legacyAllowAnyFileType().cfg(HOST))
.add(attr("supports_param_files", BOOLEAN).value(true))
.add(attr("supports_header_parsing", BOOLEAN).value(false))
.add(
attr("$link_dynamic_library_tool", LABEL)
.value(env.getToolsLabel("//tools/cpp:link_dynamic_library")))
// TODO(bazel-team): Should be using the TARGET configuration.
.add(attr(":libc_top", LABEL).cfg(HOST).value(LIBC_TOP))
.add(attr(":lipo_context_collector", LABEL)
.cfg(LipoTransition.LIPO_COLLECTOR)
.value(CppRuleClasses.LIPO_CONTEXT_COLLECTOR)
.skipPrereqValidatorCheck())
.add(
attr(":lipo_context_collector", LABEL)
.cfg(LipoTransition.LIPO_COLLECTOR)
.value(CppRuleClasses.LIPO_CONTEXT_COLLECTOR)
.skipPrereqValidatorCheck())
.build();
}

Expand Down
Loading

0 comments on commit 74b9432

Please sign in to comment.