Skip to content

Commit

Permalink
Fix some more tests before flipping the --incompatible_disable_crosst…
Browse files Browse the repository at this point in the history
…ool_file flag

Issue #5380
Issue #7320
RELNOTES: None.
PiperOrigin-RevId: 240741379
  • Loading branch information
scentini authored and copybara-github committed Mar 28, 2019
1 parent 191c7bd commit e5777ce
Show file tree
Hide file tree
Showing 7 changed files with 817 additions and 614 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ public void testCcTargetsDependOnCcToolchainAutomatically() throws Exception {
useConfiguration(
"--incompatible_enable_cc_toolchain_resolution",
"--experimental_platforms=//a:mock-platform",
"--extra_toolchains=//a:toolchain_b");
"--extra_toolchains=//a:toolchain_b",
"--noincompatible_disable_crosstool_file");

// for cc_library, cc_binary, and cc_test, we check that $(TARGET_CPU) is a valid Make variable
ConfiguredTarget cclibrary =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ public void testCcToolchainLabelFromCpuCompilerAttributes() throws Exception {
"\"\"\"",
")");

useConfiguration("--crosstool_top=//cc:suite", "--cpu=k8", "--host_cpu=k8");
useConfiguration(
"--crosstool_top=//cc:suite",
"--cpu=k8",
"--host_cpu=k8",
"--noincompatible_disable_crosstool_file");
ConfiguredTarget c =
getConfiguredTarget(
ruleClassProvider.getToolsRepository() + "//tools/cpp:current_cc_toolchain");
Expand Down Expand Up @@ -131,7 +135,11 @@ public void testCcToolchainFromToolchainIdentifierOverridesCpuCompiler() throws
"\"\"\"",
")");

useConfiguration("--crosstool_top=//cc:suite", "--cpu=k8", "--host_cpu=k8");
useConfiguration(
"--crosstool_top=//cc:suite",
"--cpu=k8",
"--host_cpu=k8",
"--noincompatible_disable_crosstool_file");
ConfiguredTarget c =
getConfiguredTarget(
ruleClassProvider.getToolsRepository() + "//tools/cpp:current_cc_toolchain");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -917,7 +917,8 @@ public void testCrosstoolNeededWhenStarlarkRuleIsNotPresent() throws Exception {
scratch.file("lib/BUILD", "cc_library(name = 'lib', srcs = ['a.cc'])");
getSimpleStarlarkRule(/* addToolchainConfigAttribute= */ false);

useConfiguration("--cpu=k8", "--crosstool_top=//a:a");
useConfiguration(
"--cpu=k8", "--crosstool_top=//a:a", "--noincompatible_disable_crosstool_file");
ConfiguredTarget target = getConfiguredTarget("//lib:lib");
// Skyframe cannot find the CROSSTOOL file
assertContainsEvent("errors encountered while analyzing target '//lib:lib'");
Expand All @@ -931,7 +932,8 @@ public void testCrosstoolReadWhenStarlarkRuleIsEnabledButNotPresent() throws Exc

scratch.file("a/CROSSTOOL", MockCcSupport.EMPTY_CROSSTOOL);

useConfiguration("--cpu=k8", "--crosstool_top=//a:a");
useConfiguration(
"--cpu=k8", "--crosstool_top=//a:a", "--noincompatible_disable_crosstool_file");
ConfiguredTarget target = getConfiguredTarget("//lib:lib");
assertThat(target).isNotNull();
}
Expand Down
158 changes: 106 additions & 52 deletions src/test/shell/bazel/cc_flags_supplier_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,15 @@ EOF
}

function write_crosstool() {
extra_crosstool_content="$1"
action_configs="$1"
make_variables="$2"
builtin_sysroot="$3"

mkdir -p setup
cat > setup/BUILD <<EOF
package(default_visibility = ["//visibility:public"])
load(":cc_toolchain_config.bzl", "cc_toolchain_config")
cc_library(
name = "malloc",
)
Expand All @@ -68,9 +73,22 @@ cc_toolchain_suite(
},
)
cc_toolchain_config(
name = "local_config",
cpu = "local",
toolchain_identifier = "local",
host_system_name = "local",
target_system_name = "local",
target_libc = "local",
compiler = "local",
abi_version = "local",
abi_libc_version = "local",
)
cc_toolchain(
name = "local",
toolchain_identifier = "local",
toolchain_config = ":local_config",
all_files = ":empty",
ar_files = ":empty",
as_files = ":empty",
Expand All @@ -96,82 +114,118 @@ EOF
cat >> WORKSPACE <<EOF
register_toolchains("//setup:cc-toolchain-local")
EOF
cat > setup/CROSSTOOL <<EOF
major_version: "local"
minor_version: ""
toolchain {
abi_version: "local"
abi_libc_version: "local"
compiler: "compiler"
host_system_name: "local"
target_libc: "local"
target_cpu: "local"
target_system_name: "local"
toolchain_identifier: "local"
${extra_crosstool_content}
}
cat > setup/cc_toolchain_config.bzl <<EOF
load("@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl",
"action_config",
"make_variable",
"flag_set",
"flag_group",
)
def _get_make_variables():
return [${make_variables}]
def _get_action_configs():
return [${action_configs}]
def _impl(ctx):
out = ctx.actions.declare_file(ctx.label.name)
ctx.actions.write(out, "Fake executable")
return [
cc_common.create_cc_toolchain_config_info(
ctx = ctx,
target_cpu = ctx.attr.cpu,
compiler = ctx.attr.compiler,
toolchain_identifier = ctx.attr.toolchain_identifier,
host_system_name = ctx.attr.host_system_name,
target_system_name = ctx.attr.target_system_name,
target_libc = ctx.attr.target_libc,
abi_version = ctx.attr.abi_version,
abi_libc_version = ctx.attr.abi_libc_version,
builtin_sysroot = ${builtin_sysroot},
action_configs = _get_action_configs(),
make_variables = _get_make_variables(),
),
DefaultInfo(
executable = out,
),
]
cc_toolchain_config = rule(
implementation = _impl,
attrs = {
"cpu": attr.string(mandatory = True),
"compiler": attr.string(mandatory = True),
"toolchain_identifier": attr.string(mandatory = True),
"host_system_name": attr.string(mandatory = True),
"target_system_name": attr.string(mandatory = True),
"target_libc": attr.string(mandatory = True),
"abi_version": attr.string(mandatory = True),
"abi_libc_version": attr.string(mandatory = True),
},
provides = [CcToolchainConfigInfo],
executable = True,
)
EOF
}

function test_legacy_make_variable() {
write_crosstool "
make_variable {
name: 'CC_FLAGS'
value: '-test-cflag1 -test-cflag2'
}"
write_crosstool \
"" \
"make_variable(name = 'CC_FLAGS', value = '-test-cflag1 -test-cflag2')" \
"''"

write_test_target
bazel build --cpu local --crosstool_top=//setup:toolchain //:display &> "$TEST_log" || fail "Build failed"
expect_log "CC_FLAGS: -test-cflag1 -test-cflag2"
}

function test_sysroot() {
write_crosstool "builtin_sysroot: '/sys/root'"
write_crosstool \
"" \
"" \
"'/sys/root'"

write_test_target
bazel build --cpu local --crosstool_top=//setup:toolchain //:display &> "$TEST_log" || fail "Build failed"
expect_log "CC_FLAGS: --sysroot=/sys/root"
}

function test_feature_config() {
write_crosstool "
action_config {
action_name: 'cc-flags-make-variable'
config_name: 'cc-flags-make-variable'
flag_set {
flag_group {
flag: 'foo'
flag: 'bar'
flag: 'baz'
}
}
}"
write_crosstool \
"
action_config(
action_name = 'cc-flags-make-variable',
flag_sets = [
flag_set(
flag_groups=[flag_group(flags=['foo', 'bar', 'baz'])],
),
],
),
" \
"" \
"''"

write_test_target
bazel build --cpu local --crosstool_top=//setup:toolchain //:display &> "$TEST_log" || fail "Build failed"
expect_log "CC_FLAGS: foo bar baz"
}

function test_all_sources() {
write_crosstool "
make_variable {
name: 'CC_FLAGS'
value: '-test-cflag1 -test-cflag2'
}
builtin_sysroot: '/sys/root'
action_config {
action_name: 'cc-flags-make-variable'
config_name: 'cc-flags-make-variable'
flag_set {
flag_group {
flag: 'foo'
flag: 'bar'
flag: 'baz'
}
}
}"
write_crosstool \
"
action_config(
action_name = 'cc-flags-make-variable',
flag_sets = [
flag_set(
flag_groups=[flag_group(flags=['foo', 'bar', 'baz'])],
),
],
),
" \
"make_variable(name = 'CC_FLAGS', value = '-test-cflag1 -test-cflag2')" \
"'/sys/root'"

write_test_target
bazel build --cpu local --crosstool_top=//setup:toolchain //:display &> "$TEST_log" || fail "Build failed"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
# by lopping off the name of --crosstool_top and searching for
# 'cc-compiler-${CPU}' in this BUILD file, where CPU is the target CPU
# specified in --cpu.
#

load(":cc_toolchain_config.bzl", "cc_toolchain_config")

# This file group should include
# * all cc_toolchain targets supported
# * all file groups that said cc_toolchain might refer to
Expand Down Expand Up @@ -68,9 +70,12 @@ filegroup(
srcs = [],
)

cc_toolchain_config(name = "armeabi-v7a_config", cpu = "armeabi-v7a")

cc_toolchain(
name = "cc-compiler-armeabi-v7a",
toolchain_identifier = "armeabi-v7a",
toolchain_config = ":armeabi-v7a_config",
all_files = ":linaro_linux_all_files",
ar_files = "//tools/arm_compiler/linaro_linux_gcc:ar",
as_files = "//tools/arm_compiler/linaro_linux_gcc:as",
Expand All @@ -84,9 +89,12 @@ cc_toolchain(
visibility = ["//visibility:public"],
)

cc_toolchain_config(name = "local_config", cpu = "k8")

cc_toolchain(
name = "cc-compiler-k8",
toolchain_identifier = "local",
toolchain_config = ":local_config",
all_files = ":empty",
ar_files = ":empty",
as_files = ":empty",
Expand Down
Loading

0 comments on commit e5777ce

Please sign in to comment.