Skip to content

Commit

Permalink
Migrate more tests to use Starlark cc_toolchain configuration
Browse files Browse the repository at this point in the history
Issue #5380

RELNOTES: None.
PiperOrigin-RevId: 239580767
  • Loading branch information
scentini authored and copybara-github committed Mar 21, 2019
1 parent 64cc8e1 commit 5ce7736
Show file tree
Hide file tree
Showing 6 changed files with 206 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ _FEATURE_NAMES = struct(
def_feature = "def",
strip_debug_symbols = "strip_debug_symbols",
disable_pbh = "disable_pbh",
optional_cc_flags_feature = "optional_cc_flags_feature",
)

_disable_pbh_feature = feature(name = _FEATURE_NAMES.disable_pbh)
Expand Down Expand Up @@ -364,6 +365,11 @@ _simple_module_maps_feature = feature(
],
)

_extra_implies_module_maps_feature = feature(
name = "extra",
implies = ["module_maps"],
)

_env_var_feature_configuration = [
_env_feature,
_static_env_feature,
Expand Down Expand Up @@ -485,6 +491,20 @@ _thin_lto_feature = feature(
requires = [feature_set(features = ["nonhost"])],
)

_simple_thin_lto_feature = feature(
name = _FEATURE_NAMES.thin_lto,
flag_sets = [
flag_set(
actions = [ACTION_NAMES.cpp_compile],
flag_groups = [
flag_group(
flags = ["<thin_lto>"],
),
],
),
],
)

_thin_lto_linkstatic_tests_use_shared_nonlto_backends_feature = feature(
name = _FEATURE_NAMES.thin_lto_linkstatic_tests_use_shared_nonlto_backends,
)
Expand Down Expand Up @@ -1019,6 +1039,59 @@ _portable_overrides_configuration = [
),
]

_same_symbol_provided_configuration = [
feature(name = "a1", provides = ["a"]),
feature(name = "a2", provides = ["a"]),
]

_optional_cc_flags_feature = feature(
name = _FEATURE_NAMES.optional_cc_flags_feature,
flag_sets = [
flag_set(
actions = [ACTION_NAMES.cc_flags_make_variable],
flag_groups = [
flag_group(flags = ["optional_feature_flag"]),
],
),
],
)

_layering_check_module_maps_header_modules_simple_features = [
feature(
name = _FEATURE_NAMES.module_maps,
flag_sets = [
flag_set(
actions = [ACTION_NAMES.cpp_compile],
flag_groups = [
flag_group(flags = ["<maps>"]),
],
),
],
),
feature(
name = _FEATURE_NAMES.layering_check,
flag_sets = [
flag_set(
actions = [ACTION_NAMES.cpp_compile],
flag_groups = [
flag_group(flags = ["<layering>"]),
],
),
],
),
feature(
name = _FEATURE_NAMES.header_modules,
flag_sets = [
flag_set(
actions = [ACTION_NAMES.cpp_compile],
flag_groups = [
flag_group(flags = ["<modules>"]),
],
),
],
),
]

_feature_name_to_feature = {
_FEATURE_NAMES.no_legacy_features: _no_legacy_features_feature,
_FEATURE_NAMES.do_not_split_linking_cmdline: _do_not_split_linking_cmdline_feature,
Expand Down Expand Up @@ -1073,6 +1146,7 @@ _feature_name_to_feature = {
_FEATURE_NAMES.def_feature: _def_feature,
_FEATURE_NAMES.strip_debug_symbols: _strip_debug_symbols_feature,
_FEATURE_NAMES.disable_pbh: _disable_pbh_feature,
_FEATURE_NAMES.optional_cc_flags_feature: _optional_cc_flags_feature,
"header_modules_feature_configuration": _header_modules_feature_configuration,
"env_var_feature_configuration": _env_var_feature_configuration,
"host_and_nonhost_configuration": _host_and_nonhost_configuration,
Expand All @@ -1082,6 +1156,42 @@ _feature_name_to_feature = {
"simple_module_maps": _simple_module_maps_feature,
"simple_header_modules": _simple_header_modules_feature,
"portable_overrides_configuration": _portable_overrides_configuration,
"same_symbol_provided_configuration": _same_symbol_provided_configuration,
"simple_thin_lto": _simple_thin_lto_feature,
"extra_implies_module_maps": _extra_implies_module_maps_feature,
"layering_check_module_maps_header_modules_simple_features": _layering_check_module_maps_header_modules_simple_features,
}

_cc_flags_action_config_foo_bar_baz_config = action_config(
action_name = "cc-flags-make-variable",
flag_sets = [
flag_set(
flag_groups = [
flag_group(
flags = ["foo", "bar", "baz"],
),
],
),
],
)

_sysroot_in_action_config = action_config(
action_name = "cc-flags-make-variable",
flag_sets = [
flag_set(
flag_groups = [
flag_group(
expand_if_available = "sysroot",
flags = ["fc-start", "--sysroot=%{sysroot}-from-feature", "fc-end"],
),
],
),
],
)

_action_name_to_action = {
"cc_flags_action_config_foo_bar_baz": _cc_flags_action_config_foo_bar_baz_config,
"sysroot_in_action_config": _sysroot_in_action_config,
}

_tool_for_action_config = {
Expand Down Expand Up @@ -1186,9 +1296,13 @@ def _impl(ctx):
action_configs = []

for name in ctx.attr.action_configs:
action_configs.append(
_get_action_config(name, _tool_for_action_config.get(name, default = "DUMMY_TOOL")),
)
custom_config = _action_name_to_action.get(name, default = None)
if custom_config != None:
action_configs.append(custom_config)
else:
action_configs.append(
_get_action_config(name, _tool_for_action_config.get(name, default = "DUMMY_TOOL")),
)
if should_add_multiple_tools_action_config:
action_configs.append(_multiple_tools_action_config)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.google.devtools.build.lib.analysis.actions.SpawnAction;
import com.google.devtools.build.lib.analysis.util.AnalysisMock;
import com.google.devtools.build.lib.analysis.util.BuildViewTestCase;
import com.google.devtools.build.lib.packages.util.Crosstool.CcToolchainConfig;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.junit.Test;
Expand Down Expand Up @@ -481,19 +482,9 @@ private String getBuildFileWithCommand(String command) {
public void testCcFlagsFromFeatureConfiguration() throws Exception {
AnalysisMock.get()
.ccSupport()
.setupCrosstool(
.setupCcToolchainConfig(
mockToolsConfig,
"action_config {",
" action_name: 'cc-flags-make-variable'",
" config_name: 'cc-flags-make-variable'",
" flag_set {",
" flag_group {",
" flag: 'foo'",
" flag: 'bar'",
" flag: 'baz'",
" }",
" }",
"}");
CcToolchainConfig.builder().withActionConfigs("cc_flags_action_config_foo_bar_baz"));
useConfiguration();
scratch.file(
"foo/BUILD",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public static final class CcToolchainConfig {
private final String abiLibcVersion;
private final String targetLibc;
private final String builtinSysroot;
private final String ccTargetOs;
private final ImmutableList<String> features;
private final ImmutableList<String> actionConfigs;
private final ImmutableList<ImmutableList<String>> artifactNamePatterns;
Expand All @@ -69,6 +70,7 @@ private CcToolchainConfig(
String abiLibcVersion,
String targetLibc,
String builtinSysroot,
String ccTargetOs,
ImmutableList<String> features,
ImmutableList<String> actionConfigs,
ImmutableList<ImmutableList<String>> artifactNamePatterns,
Expand All @@ -90,6 +92,7 @@ private CcToolchainConfig(
this.builtinSysroot = builtinSysroot;
this.cxxBuiltinIncludeDirectories = cxxBuiltinIncludeDirectories;
this.makeVariables = makeVariables;
this.ccTargetOs = ccTargetOs;
}

public static Builder builder() {
Expand All @@ -105,6 +108,7 @@ public static class Builder {
private String builtinSysroot = "/usr/grte/v1";
private ImmutableList<String> cxxBuiltinIncludeDirectories = ImmutableList.of();
private ImmutableList<Pair<String, String>> makeVariables = ImmutableList.of();
private String ccTargetOs = "";

public Builder withFeatures(String... features) {
this.features = ImmutableList.copyOf(features);
Expand Down Expand Up @@ -137,6 +141,11 @@ public Builder withSysroot(String sysroot) {
return this;
}

public Builder withCcTargetOs(String ccTargetOs) {
this.ccTargetOs = ccTargetOs;
return this;
}

public Builder withCxxBuiltinIncludeDirectories(String... directories) {
this.cxxBuiltinIncludeDirectories = ImmutableList.copyOf(directories);
return this;
Expand All @@ -158,6 +167,7 @@ public CcToolchainConfig build() {
/* abiLibcVersion= */ "local",
/* targetLibc= */ "local",
/* builtinSysroot= */ builtinSysroot,
/* ccTargetOs= */ ccTargetOs,
features,
actionConfigs,
artifactNamePatterns,
Expand Down Expand Up @@ -194,6 +204,7 @@ public static CcToolchainConfig getCcToolchainConfigForCpu(String cpu) {
/* abiLibcVersion= */ "mock-abi-libc-for-" + cpu,
/* targetLibc= */ "mock-libc-for-" + cpu,
/* builtinSysroot= */ "",
/* ccTargetOs= */ "",
/* features= */ ImmutableList.of(),
/* actionConfigs= */ ImmutableList.of(),
/* artifactNamePatterns= */ ImmutableList.of(),
Expand Down Expand Up @@ -254,6 +265,7 @@ public String getCcToolchainConfigRule() {
" artifact_name_patterns = {%s},", Joiner.on(",\n ").join(patternsList)),
String.format(" tool_paths = {%s},", Joiner.on(",\n ").join(toolPathsList)),
" builtin_sysroot = '" + builtinSysroot + "',",
" cc_target_os = '" + ccTargetOs + "',",
String.format(
" cxx_builtin_include_directories = [%s],",
Joiner.on(",\n ").join(directoriesList)),
Expand Down Expand Up @@ -340,6 +352,7 @@ public void write() throws IOException {
toolchain.getAbiLibcVersion(),
toolchain.getTargetLibc(),
toolchain.getBuiltinSysroot(),
toolchain.getCcTargetOs(),
toolchain.getFeatureList().stream()
.map(feature -> feature.getName())
.collect(ImmutableList.toImmutableList()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -965,10 +965,9 @@ public void testSymlinkActionIsNotRegisteredWhenIncludePrefixDoesntChangePath()
reporter.removeHandler(failFastHandler);
getAnalysisMock()
.ccSupport()
.setupCrosstool(
.setupCcToolchainConfig(
mockToolsConfig,
"feature { name: 'a1' provides: 'a' }",
"feature { name: 'a2' provides: 'a' }");
CcToolchainConfig.builder().withFeatures("same_symbol_provided_configuration"));
useConfiguration("--features=a1", "--features=a2");

scratch.file("x/BUILD", "cc_library(name = 'foo', srcs = ['a.cc'])");
Expand Down
Loading

0 comments on commit 5ce7736

Please sign in to comment.