Skip to content

Commit

Permalink
Flip --incompatible_disable_cc_toolchain_label_from_crosstool_proto
Browse files Browse the repository at this point in the history
Fixes bazelbuild#6382.

RELNOTES: --incompatible_disable_cc_toolchain_label_from_crosstool_proto was flipped.
PiperOrigin-RevId: 218674274
  • Loading branch information
hlopko authored and Copybara-Service committed Oct 25, 2018
1 parent 7dcad73 commit b91d830
Show file tree
Hide file tree
Showing 15 changed files with 235 additions and 4,344 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.google.devtools.build.lib.view.config.crosstool.CrosstoolConfig.CrosstoolRelease;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import javax.annotation.Nullable;

/**
Expand Down Expand Up @@ -211,18 +210,11 @@ private static CToolchain selectToolchainUsingCpuAndMaybeCompiler(
}

if (selectedIdentifier == null) {
HashSet<String> seenCpus = new HashSet<>();
StringBuilder errorMessageBuilder = new StringBuilder();
errorMessageBuilder
.append("No toolchain found for cpu '")
.append(config.getCpu())
.append("'. Valid cpus from default_toolchain entries are: [\n");
for (CrosstoolConfig.DefaultCpuToolchain selector : release.getDefaultToolchainList()) {
if (seenCpus.add(selector.getCpu())) {
errorMessageBuilder.append(" ").append(selector.getCpu()).append(",\n");
}
}
errorMessageBuilder.append("]. Valid toolchains are: ");
.append("'. Valid toolchains are: ");
describeToolchainList(errorMessageBuilder, release.getToolchainList());
throw new InvalidConfigurationException(errorMessageBuilder.toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ public Label getFdoPrefetchHintsLabel() {

@Option(
name = "incompatible_disable_cc_toolchain_label_from_crosstool_proto",
defaultValue = "false",
defaultValue = "true",
documentationCategory = OptionDocumentationCategory.UNDOCUMENTED,
effectTags = {OptionEffectTag.LOADING_AND_ANALYSIS, OptionEffectTag.EAGERNESS_TO_EXIT},
metadataTags = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -451,10 +451,12 @@ public void testNonHostAttributeCannotBeTool() throws Exception {

@Test
public void testCcToolchainLicenseOverride() throws Exception {
scratch.file("c/BUILD",
scratch.file(
"c/BUILD",
"filegroup(name = 'dynamic-runtime-libs-cherry', srcs = [], licenses = ['restricted'])",
"cc_toolchain(",
" name = 'c',",
" toolchain_identifier = 'toolchain-identifier-k8',",
" output_licenses = ['notice'],",
" cpu = 'cherry',",
" ar_files = 'ar-cherry',",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,6 @@

major_version: "1"
minor_version: "42"
default_target_cpu: "k8"

# TODO(bazel-team): We should change these identifiers to match what everyone
# else is using, but that requires rewriting a lot of our tests.
default_toolchain {
cpu: "k8"
toolchain_identifier: "k8"
}
default_toolchain {
cpu: "piii"
toolchain_identifier: "piii"
}
default_toolchain {
cpu: "darwin"
toolchain_identifier: "local_darwin"
}
default_toolchain {
cpu: "ios_x86_64"
toolchain_identifier: "local_ios"
}
default_toolchain {
cpu: "x64_windows"
toolchain_identifier: "local_windows_msys64"
}
default_toolchain {
cpu: "ppc"
toolchain_identifier: "local_linux"
}
default_toolchain {
cpu: "aarch64"
toolchain_identifier: "local_linux"
}

toolchain {
abi_version: "local"
Expand All @@ -53,7 +21,7 @@ toolchain {
target_libc: "local"
target_cpu: "ppc"
target_system_name: "local"
toolchain_identifier: "local_linux"
toolchain_identifier: "toolchain-identifier-ppc"

tool_path { name: "ar" path: "/usr/bin/ar" }
tool_path { name: "compat-ld" path: "/usr/bin/ld" }
Expand Down Expand Up @@ -158,7 +126,7 @@ toolchain {
}

toolchain {
toolchain_identifier: "k8"
toolchain_identifier: "toolchain-identifier-k8"

host_system_name: "local"
target_system_name: "local"
Expand Down Expand Up @@ -504,13 +472,6 @@ toolchain {
supports_interface_shared_objects: true
}

# For Android rules where no Android NDK is specified

default_toolchain {
cpu: "armeabi-v7a"
toolchain_identifier: "stub_armeabi-v7a"
}

toolchain {
abi_version: "armeabi-v7a"
abi_libc_version: "armeabi-v7a"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ public void setup(MockToolsConfig config) throws IOException {
"cc_toolchain_suite(",
" name = 'toolchain',",
" toolchains = {",
" 'local': ':cc-compiler-local',",
" 'k8': ':cc-compiler-k8',",
" 'piii': ':cc-compiler-piii-gcc-4.4.0',",
" 'darwin': ':cc-compiler-darwin',",
" 'ios_x86_64': ':cc-compiler-ios_x86_64',",
" 'armeabi-v7a': ':cc-compiler-armeabi-v7a',",
" 'x64_windows': ':cc-compiler-x64_windows',",
" 'ppc': ':cc-compiler-ppc',",
" 'local|compiler': ':cc-compiler-local',",
" 'k8|compiler': ':cc-compiler-k8',",
" 'k8|compiler_no_dyn_linker': ':cc-no-dyn-linker-k8',",
Expand All @@ -96,6 +104,7 @@ public void setup(MockToolsConfig config) throws IOException {
" 'ppc|compiler': ':cc-compiler-ppc',",
" })",
"cc_toolchain(name = 'cc-compiler-k8', all_files = ':empty', compiler_files = ':empty',",
" toolchain_identifier = 'toolchain-identifier-k8',",
" cpu = 'k8',",
" compiler = 'compiler',",
" dwp_files = ':empty',",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@

import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableList;
import com.google.devtools.build.lib.util.Pair;
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;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

/**
Expand Down Expand Up @@ -113,59 +114,60 @@ public void write() throws IOException {
CrosstoolConfig.CrosstoolRelease.Builder configBuilder =
CrosstoolConfig.CrosstoolRelease.newBuilder();
TextFormat.merge(crosstoolFileContents, configBuilder);

List<CToolchain> toolchainList = configBuilder.build().getToolchainList();
Set<String> seenCpus = new LinkedHashSet<>();
StringBuilder compilerMap = new StringBuilder();
// Remove duplicates
Set<Pair<String, String>> keys = new LinkedHashSet<>();
for (CrosstoolConfig.CToolchain toolchain : configBuilder.build().getToolchainList()) {
Pair<String, String> key = Pair.of(toolchain.getTargetCpu(), toolchain.getCompiler());
if (!keys.contains(key)) {
keys.add(key);
for (CToolchain toolchain : toolchainList) {
// Generate entry to cc_toolchain_suite.toolchains
if (seenCpus.add(toolchain.getTargetCpu())) {
compilerMap.append(
String.format(
"'%s|%s': ':cc-compiler-%s-%s',\n", key.first, key.second, key.first, key.second));
"'%s': ':cc-compiler-%s-%s',\n",
toolchain.getTargetCpu(), toolchain.getTargetCpu(), toolchain.getCompiler()));
}
}

for (Pair<String, String> key : keys) {
String cpu = key.first;
String compiler = key.second;
String compilerRule;
String staticRuntimesString =
staticRuntimesLabel == null ? "" : ", '" + staticRuntimesLabel + "'";
String dynamicRuntimesString =
dynamicRuntimesLabel == null ? "" : ", '" + dynamicRuntimesLabel + "'";
compilerMap.append(
String.format(
"'%s|%s': ':cc-compiler-%s-%s',\n",
toolchain.getTargetCpu(),
toolchain.getCompiler(),
toolchain.getTargetCpu(),
toolchain.getCompiler()));

compilerRule =
// Generate cc_toolchain target
compilationTools.append(
Joiner.on("\n")
.join(
"cc_toolchain(",
" name = 'cc-compiler-" + cpu + "-" + compiler + "',",
" output_licenses = ['unencumbered'],",
" name = 'cc-compiler-"
+ toolchain.getTargetCpu()
+ "-"
+ toolchain.getCompiler()
+ "',",
" toolchain_identifier = '" + toolchain.getToolchainIdentifier() + "',",
" output_licenses = ['unencumbered'],",
addModuleMap ? " module_map = 'crosstool.cppmap'," : "",
" cpu = '" + cpu + "',",
" compiler = '" + compiler + "',",
" ar_files = 'ar-" + cpu + "',",
" as_files = 'as-" + cpu + "',",
" compiler_files = 'compile-" + cpu + "',",
" dwp_files = 'dwp-" + cpu + "',",
" linker_files = 'link-" + cpu + "',",
" strip_files = ':every-file',",
" objcopy_files = 'objcopy-" + cpu + "',",
" all_files = ':every-file',",
" licenses = ['unencumbered'],",
" cpu = '" + toolchain.getTargetCpu() + "',",
" compiler = '" + toolchain.getCompiler() + "',",
" ar_files = 'ar-" + toolchain.getTargetCpu() + "',",
" as_files = 'as-" + toolchain.getTargetCpu() + "',",
" compiler_files = 'compile-" + toolchain.getTargetCpu() + "',",
" dwp_files = 'dwp-" + toolchain.getTargetCpu() + "',",
" linker_files = 'link-" + toolchain.getTargetCpu() + "',",
" strip_files = ':every-file',",
" objcopy_files = 'objcopy-" + toolchain.getTargetCpu() + "',",
" all_files = ':every-file',",
" licenses = ['unencumbered'],",
supportsHeaderParsing ? " supports_header_parsing = 1," : "",
" dynamic_runtime_libs = ['dynamic-runtime-libs-"
+ cpu
+ "'"
+ dynamicRuntimesString
+ "],",
" static_runtime_libs = ['static-runtime-libs-"
+ cpu
+ "'"
+ staticRuntimesString
+ "])");

compilationTools.append(compilerRule + "\n");
" dynamic_runtime_libs = [",
" 'dynamic-runtime-libs-" + toolchain.getTargetCpu() + "',",
" " + dynamicRuntimesLabel == null ? "" : "'" + dynamicRuntimesLabel + "',",
" ],",
" static_runtime_libs = [",
" 'static-runtime-libs-" + toolchain.getTargetCpu() + "',",
" " + staticRuntimesLabel == null ? "" : "'" + staticRuntimesLabel + "',",
"])",
""));
}

String build =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
major_version: "18"
minor_version: "0"
default_target_cpu: "armeabi-v7a"

default_toolchain {
cpu: "armeabi-v7a"
toolchain_identifier: "armeabi-v7a"
}

default_toolchain {
cpu: "x86"
toolchain_identifier: "x86"
}

toolchain {
toolchain_identifier: "armeabi-v7a"
Expand Down
Loading

0 comments on commit b91d830

Please sign in to comment.