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: 239352742
  • Loading branch information
scentini authored and copybara-github committed Mar 20, 2019
1 parent c4d9b9b commit 8b72ef9
Show file tree
Hide file tree
Showing 3 changed files with 205 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ load(
"feature_set",
"flag_group",
"flag_set",
"make_variable",
"tool",
"tool_path",
"with_feature_set",
Expand Down Expand Up @@ -70,6 +71,7 @@ _FEATURE_NAMES = struct(
targets_windows = "targets_windows",
static_link_cpp_runtimes = "static_link_cpp_runtimes",
simple_compile_feature = "simple_compile_feature",
simple_link_feature = "simple_link_feature",
link_env = "link_env",
dynamic_linking_mode = "dynamic_linking_mode",
static_linking_mode = "static_linking_mode",
Expand All @@ -85,6 +87,14 @@ _FEATURE_NAMES = struct(
absolute_path_directories = "absolute_path_directories",
from_package = "from_package",
change_tool = "change_tool",
module_map_without_extern_module = "module_map_without_extern_module",
generate_submodules = "generate_submodules",
foo = "foo_feature",
library_search_directories = "library_search_directories",
runtime_library_search_directories = "runtime_library_search_directories",
uses_ifso_variables = "uses_ifso_variables",
def_feature = "def",
strip_debug_symbols = "strip_debug_symbols",
)

_no_legacy_features_feature = feature(name = _FEATURE_NAMES.no_legacy_features)
Expand Down Expand Up @@ -632,6 +642,18 @@ _simple_compile_feature = feature(
],
)

_simple_link_feature = feature(
name = _FEATURE_NAMES.simple_link_feature,
flag_sets = [
flag_set(
actions = [ACTION_NAMES.cpp_link_executable],
flag_groups = [
flag_group(flags = ["testlinkopt"]),
],
),
],
)

_link_env_feature = feature(
name = _FEATURE_NAMES.link_env,
env_sets = [
Expand Down Expand Up @@ -846,6 +868,14 @@ _change_tool_feature = feature(
name = _FEATURE_NAMES.change_tool,
)

_module_map_without_extern_module_feature = feature(
name = _FEATURE_NAMES.module_map_without_extern_module,
)

_generate_submodules_feature = feature(
name = _FEATURE_NAMES.generate_submodules,
)

_multiple_tools_action_config = action_config(
action_name = ACTION_NAMES.cpp_compile,
tools = [
Expand All @@ -859,6 +889,92 @@ _multiple_tools_action_config = action_config(
],
)

_foo_feature = feature(
name = _FEATURE_NAMES.foo,
)

_library_search_directories_feature = feature(
name = _FEATURE_NAMES.library_search_directories,
enabled = True,
flag_sets = [
flag_set(
actions = [ACTION_NAMES.cpp_link_executable],
flag_groups = [
flag_group(
expand_if_available = "library_search_directories",
iterate_over = "library_search_directories",
flags = ["--library=%{library_search_directories}"],
),
],
),
],
)

_runtime_library_search_directories_feature = feature(
name = _FEATURE_NAMES.runtime_library_search_directories,
enabled = True,
flag_sets = [
flag_set(
actions = [ACTION_NAMES.cpp_link_executable],
flag_groups = [
flag_group(
expand_if_available = "runtime_library_search_directories",
iterate_over = "runtime_library_search_directories",
flags = ["--runtime_library=%{runtime_library_search_directories}"],
),
],
),
],
)

_uses_ifso_variables_feature = feature(
name = _FEATURE_NAMES.uses_ifso_variables,
enabled = True,
flag_sets = [
flag_set(
actions = [ACTION_NAMES.cpp_link_dynamic_library],
flag_groups = [
flag_group(
expand_if_available = "generate_interface_library",
flags = ["--generate_interface_library_was_available"],
),
],
),
],
)

_def_feature = feature(
name = _FEATURE_NAMES.def_feature,
enabled = True,
flag_sets = [
flag_set(
actions = [ACTION_NAMES.cpp_link_executable],
flag_groups = [
flag_group(
expand_if_available = "def_file_path",
flags = ["-qux_%{def_file_path}"],
),
],
),
],
)

_strip_debug_symbols_feature = feature(
name = _FEATURE_NAMES.strip_debug_symbols,
enabled = True,
flag_sets = [
flag_set(
actions = [ACTION_NAMES.cpp_link_executable],
flag_groups = [
flag_group(
expand_if_available = "strip_debug_symbols",
flags = ["-strip_stuff"],
),
],
),
],
)

_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 @@ -892,6 +1008,7 @@ _feature_name_to_feature = {
_FEATURE_NAMES.module_maps: _module_maps_feature,
_FEATURE_NAMES.static_link_cpp_runtimes: _static_link_cpp_runtimes_feature,
_FEATURE_NAMES.simple_compile_feature: _simple_compile_feature,
_FEATURE_NAMES.simple_link_feature: _simple_link_feature,
_FEATURE_NAMES.link_env: _link_env_feature,
_FEATURE_NAMES.static_linking_mode: _static_linking_mode_feature,
_FEATURE_NAMES.dynamic_linking_mode: _dynamic_linking_mode_feature,
Expand All @@ -903,6 +1020,14 @@ _feature_name_to_feature = {
_FEATURE_NAMES.from_package: _from_package_feature,
_FEATURE_NAMES.absolute_path_directories: _absolute_path_directories_feature,
_FEATURE_NAMES.change_tool: _change_tool_feature,
_FEATURE_NAMES.module_map_without_extern_module: _module_map_without_extern_module_feature,
_FEATURE_NAMES.foo: _foo_feature,
_FEATURE_NAMES.library_search_directories: _library_search_directories_feature,
_FEATURE_NAMES.runtime_library_search_directories: _runtime_library_search_directories_feature,
_FEATURE_NAMES.generate_submodules: _generate_submodules_feature,
_FEATURE_NAMES.uses_ifso_variables: _uses_ifso_variables_feature,
_FEATURE_NAMES.def_feature: _def_feature,
_FEATURE_NAMES.strip_debug_symbols: _strip_debug_symbols_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 Down Expand Up @@ -1019,7 +1144,10 @@ def _impl(ctx):
if should_add_multiple_tools_action_config:
action_configs.append(_multiple_tools_action_config)

make_variables = []
make_variables = [
make_variable(name = name, value = value)
for name, value in ctx.attr.make_variables.items()
]

if ctx.attr.tool_paths == {}:
tool_paths = [
Expand Down Expand Up @@ -1090,6 +1218,7 @@ cc_toolchain_config = rule(
"builtin_sysroot": attr.string(default = "/usr/grte/v1"),
"tool_paths": attr.string_dict(),
"cxx_builtin_include_directories": attr.string_list(),
"make_variables": attr.string_dict(),
},
provides = [CcToolchainConfigInfo],
executable = True,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public static final class CcToolchainConfig {
private final ImmutableList<ImmutableList<String>> artifactNamePatterns;
private final ImmutableList<Pair<String, String>> toolPaths;
private final ImmutableList<String> cxxBuiltinIncludeDirectories;
private final ImmutableList<Pair<String, String>> makeVariables;

private CcToolchainConfig(
String cpu,
Expand All @@ -72,7 +73,8 @@ private CcToolchainConfig(
ImmutableList<String> actionConfigs,
ImmutableList<ImmutableList<String>> artifactNamePatterns,
ImmutableList<Pair<String, String>> toolPaths,
ImmutableList<String> cxxBuiltinIncludeDirectories) {
ImmutableList<String> cxxBuiltinIncludeDirectories,
ImmutableList<Pair<String, String>> makeVariables) {
this.cpu = cpu;
this.compiler = compiler;
this.toolchainIdentifier = toolchainIdentifier;
Expand All @@ -87,6 +89,7 @@ private CcToolchainConfig(
this.toolPaths = toolPaths;
this.builtinSysroot = builtinSysroot;
this.cxxBuiltinIncludeDirectories = cxxBuiltinIncludeDirectories;
this.makeVariables = makeVariables;
}

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

public Builder withFeatures(String... features) {
this.features = ImmutableList.copyOf(features);
Expand Down Expand Up @@ -138,6 +142,11 @@ public Builder withCxxBuiltinIncludeDirectories(String... directories) {
return this;
}

public Builder withMakeVariables(Pair<String, String>... makeVariables) {
this.makeVariables = ImmutableList.copyOf(makeVariables);
return this;
}

public CcToolchainConfig build() {
return new CcToolchainConfig(
/* cpu= */ "k8",
Expand All @@ -153,7 +162,8 @@ public CcToolchainConfig build() {
actionConfigs,
artifactNamePatterns,
toolPaths,
cxxBuiltinIncludeDirectories);
cxxBuiltinIncludeDirectories,
makeVariables);
}
}

Expand Down Expand Up @@ -188,7 +198,8 @@ public static CcToolchainConfig getCcToolchainConfigForCpu(String cpu) {
/* actionConfigs= */ ImmutableList.of(),
/* artifactNamePatterns= */ ImmutableList.of(),
/* toolPaths= */ ImmutableList.of(),
/* cxxBuiltinIncludeDirectories= */ ImmutableList.of());
/* cxxBuiltinIncludeDirectories= */ ImmutableList.of(),
/* makeVariables= */ ImmutableList.of());
}

public static CcToolchainConfig getDefaultCcToolchainConfig() {
Expand Down Expand Up @@ -219,6 +230,10 @@ String getCcToolchainConfigRule() {
cxxBuiltinIncludeDirectories.stream()
.map(directory -> "'" + directory + "'")
.collect(ImmutableList.toImmutableList());
ImmutableList<String> makeVariablesList =
makeVariables.stream()
.map(variable -> String.format("'%s': '%s'", variable.first, variable.second))
.collect(ImmutableList.toImmutableList());

return Joiner.on("\n")
.join(
Expand All @@ -240,8 +255,10 @@ String getCcToolchainConfigRule() {
String.format(" tool_paths = {%s},", Joiner.on(",\n ").join(toolPathsList)),
" builtin_sysroot = '" + builtinSysroot + "',",
String.format(
" cxx_builtin_include_directories = [%s]",
" cxx_builtin_include_directories = [%s],",
Joiner.on(",\n ").join(directoriesList)),
String.format(
" make_variables = {%s},", Joiner.on(",\n ").join(makeVariablesList)),
" )");
}
}
Expand Down Expand Up @@ -329,7 +346,8 @@ public void write() throws IOException {
/* actionConfigs= */ ImmutableList.of(),
/* artifactNamePatterns= */ ImmutableList.of(),
/* toolPaths= */ ImmutableList.of(),
/* cxxBuiltinIncludeDirectories= */ ImmutableList.of()));
/* cxxBuiltinIncludeDirectories= */ ImmutableList.of(),
/* makeVariables= */ ImmutableList.of()));
}
ccToolchainConfigs = toolchainConfigInfoBuilder.build();
}
Expand Down
Loading

0 comments on commit 8b72ef9

Please sign in to comment.