Skip to content

Commit

Permalink
Remove unused test constants
Browse files Browse the repository at this point in the history
    Can't use them if they're not there

    RELNOTES: None.
    PiperOrigin-RevId: 240515577
  • Loading branch information
Luca Di Grazia committed Sep 4, 2022
1 parent 759124d commit 760ffa7
Showing 1 changed file with 61 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@
import com.google.devtools.build.lib.cmdline.PackageIdentifier;
import com.google.devtools.build.lib.cmdline.RepositoryName;
import com.google.devtools.build.lib.packages.util.Crosstool.CcToolchainConfig;
import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.ExpansionException;
import com.google.devtools.build.lib.rules.cpp.CcToolchainVariables;
import com.google.devtools.build.lib.rules.cpp.CppRuleClasses;
import com.google.devtools.build.lib.rules.cpp.Link.LinkTargetType;
import com.google.devtools.build.lib.rules.cpp.LinkBuildVariables;
import com.google.devtools.build.lib.rules.cpp.LinkCommandLine;
import com.google.devtools.build.lib.testutil.TestConstants;
import com.google.devtools.build.lib.vfs.PathFragment;
import com.google.devtools.build.lib.view.config.crosstool.CrosstoolConfig;
import com.google.devtools.build.lib.view.config.crosstool.CrosstoolConfig.CToolchain;
import com.google.protobuf.TextFormat;
import java.io.IOException;

/**
Expand Down Expand Up @@ -58,6 +57,9 @@ public boolean apply(Artifact artifact) {
/** This feature will prevent bazel from patching the crosstool. */
public static final String NO_LEGACY_FEATURES_FEATURE = "feature { name: 'no_legacy_features' }";

public static final String SUPPORTS_DYNAMIC_LINKER_FEATURE =
"feature { name: '" + CppRuleClasses.SUPPORTS_DYNAMIC_LINKER + "' enabled: true}";

public static final String SUPPORTS_INTERFACE_SHARED_LIBRARIES_FEATURE =
"feature { name: '" + CppRuleClasses.SUPPORTS_INTERFACE_SHARED_LIBRARIES + "' enabled: true}";

Expand Down Expand Up @@ -88,6 +90,9 @@ public boolean apply(Artifact artifact) {
public static final String EMPTY_EXECUTABLE_ACTION_CONFIG =
emptyActionConfigFor(LinkTargetType.EXECUTABLE.getActionName());

public static final String STATIC_LINK_CPP_RUNTIMES_FEATURE =
"feature { name: 'static_link_cpp_runtimes' enabled: true }";

public static final String EMPTY_CC_TOOLCHAIN =
Joiner.on("\n")
.join(
Expand Down Expand Up @@ -157,18 +162,15 @@ public boolean apply(Label label) {
}
};

/** Returns the additional linker options for this link. */
public static ImmutableList<String> getLinkopts(LinkCommandLine linkCommandLine)
throws ExpansionException {
if (linkCommandLine
.getBuildVariables()
.isAvailable(LinkBuildVariables.USER_LINK_FLAGS.getVariableName())) {
return CcToolchainVariables.toStringList(
linkCommandLine.getBuildVariables(),
LinkBuildVariables.USER_LINK_FLAGS.getVariableName());
} else {
return ImmutableList.of();
public static String mergeCrosstoolConfig(String original, CToolchain toolchain)
throws TextFormat.ParseException {
CrosstoolConfig.CrosstoolRelease.Builder builder =
CrosstoolConfig.CrosstoolRelease.newBuilder();
TextFormat.merge(original, builder);
for (CToolchain.Builder toolchainBuilder : builder.getToolchainBuilderList()) {
toolchainBuilder.mergeFrom(toolchain);
}
return TextFormat.printToString(builder.build());
}

public abstract Predicate<String> labelNameFilter();
Expand All @@ -178,6 +180,25 @@ public static ImmutableList<String> getLinkopts(LinkCommandLine linkCommandLine)
*/
public abstract void setup(MockToolsConfig config) throws IOException;

/**
* Creates a crosstool package by merging {@code toolchain} with the default mock CROSSTOOL file.
*
* @param partialToolchain A string representation of a CToolchain protocol buffer; note that this
* is allowed to be a partial buffer (required fields may be omitted).
*/
public void setupCrosstool(MockToolsConfig config, String... partialToolchain)
throws IOException {
String toolchainString = Joiner.on("\n").join(partialToolchain);

CToolchain.Builder toolchainBuilder = CToolchain.newBuilder();
TextFormat.merge(toolchainString, toolchainBuilder);
String crosstoolFile =
mergeCrosstoolConfig(readCrosstoolFile(), toolchainBuilder.buildPartial());
createCrosstoolPackage(
config,
crosstoolFile);
}

public void setupCcToolchainConfigForCpu(MockToolsConfig config, String... cpus)
throws IOException {
String crosstoolTop = getCrosstoolTopPathForConfig(config);
Expand All @@ -189,7 +210,7 @@ public void setupCcToolchainConfigForCpu(MockToolsConfig config, String... cpus)
for (String cpu : cpus) {
toolchainConfigBuilder.add(CcToolchainConfig.getCcToolchainConfigForCpu(cpu));
}
new Crosstool(config, crosstoolTop)
new Crosstool(config, crosstoolTop, /* disableCrosstool= */ true)
.setCcToolchainFile(readCcToolchainConfigFile())
.setSupportedArchs(getCrosstoolArchs())
.setToolchainConfigs(toolchainConfigBuilder.build())
Expand All @@ -208,7 +229,7 @@ public void setupCcToolchainConfig(
if (config.isRealFileSystem()) {
config.linkTools(getRealFilesystemTools(crosstoolTop));
} else {
new Crosstool(config, crosstoolTop)
new Crosstool(config, crosstoolTop, /* disableCrosstool= */ true)
.setCcToolchainFile(readCcToolchainConfigFile())
.setSupportedArchs(getCrosstoolArchs())
.setToolchainConfigs(ImmutableList.of(ccToolchainConfig.build()))
Expand All @@ -217,6 +238,22 @@ public void setupCcToolchainConfig(
}
}

protected void createCrosstoolPackage(
MockToolsConfig config,
String crosstoolFile)
throws IOException {
String crosstoolTop = getCrosstoolTopPathForConfig(config);
if (config.isRealFileSystem()) {
config.linkTools(getRealFilesystemTools(crosstoolTop));
} else {
new Crosstool(config, crosstoolTop, /* disableCrosstool= */ false)
.setCrosstoolFile(getMockCrosstoolVersion(), crosstoolFile)
.setSupportedArchs(getCrosstoolArchs())
.setSupportsHeaderParsing(true)
.write();
}
}

protected String getCrosstoolTopPathForConfig(MockToolsConfig config) {
if (config.isRealFileSystem()) {
return getRealFilesystemCrosstoolTopPath();
Expand All @@ -238,11 +275,18 @@ public static PackageIdentifier getMockCrosstoolsTop() {
}
}

protected String readCrosstoolFile() throws IOException {
return ResourceLoader.readFromResources(
"com/google/devtools/build/lib/analysis/mock/MOCK_CROSSTOOL");
}

protected String readCcToolchainConfigFile() throws IOException {
return ResourceLoader.readFromResources(
"com/google/devtools/build/lib/analysis/mock/cc_toolchain_config.bzl");
}

public abstract String getMockCrosstoolVersion();

public abstract Label getMockCrosstoolLabel();

protected abstract ImmutableList<String> getCrosstoolArchs();
Expand Down

0 comments on commit 760ffa7

Please sign in to comment.