From 943183cae80294fde6512ca8c149ca560c1b4cf3 Mon Sep 17 00:00:00 2001 From: rosica Date: Tue, 19 Mar 2019 02:46:12 -0700 Subject: [PATCH] Fix load("//tools/cpp:cc_toolchain_config_lib.bzl") to load("@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl") And add a test checking the full output from the migrator for a simple CROSSTOOL. Issue #5380 RELNOTES: None. PiperOrigin-RevId: 239153961 --- tools/migration/crosstool_to_starlark_lib.go | 2 +- .../crosstool_to_starlark_lib_test.go | 147 ++++++++++++++++++ 2 files changed, 148 insertions(+), 1 deletion(-) diff --git a/tools/migration/crosstool_to_starlark_lib.go b/tools/migration/crosstool_to_starlark_lib.go index 675ab1c..b7b11b0 100644 --- a/tools/migration/crosstool_to_starlark_lib.go +++ b/tools/migration/crosstool_to_starlark_lib.go @@ -27,7 +27,7 @@ type CToolchainIdentifier struct { // Writes the load statement for the cc_toolchain_config_lib func getCcToolchainConfigHeader() string { - return `load("//tools/cpp:cc_toolchain_config_lib.bzl", + return `load("@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl", "action_config", "artifact_name_pattern", "env_entry", diff --git a/tools/migration/crosstool_to_starlark_lib_test.go b/tools/migration/crosstool_to_starlark_lib_test.go index 459cb3a..635616c 100644 --- a/tools/migration/crosstool_to_starlark_lib_test.go +++ b/tools/migration/crosstool_to_starlark_lib_test.go @@ -1530,3 +1530,150 @@ func TestFeatureDeclaration(t *testing.T) { } } } + +func TestRule(t *testing.T) { + simpleToolchain := getSimpleCToolchain("simple") + expected := `load("@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl", + "action_config", + "artifact_name_pattern", + "env_entry", + "env_set", + "feature", + "feature_set", + "flag_group", + "flag_set", + "make_variable", + "tool", + "tool_path", + "variable_with_value", + "with_feature_set", +) +load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES") + +def _impl(ctx): + toolchain_identifier = "id-simple" + + host_system_name = "host-simple" + + target_system_name = "target-simple" + + target_cpu = "cpu-simple" + + target_libc = "libc-simple" + + compiler = "compiler-simple" + + abi_version = "version-simple" + + abi_libc_version = "libc_version-simple" + + cc_target_os = None + + builtin_sysroot = None + + all_compile_actions = [ + ACTION_NAMES.c_compile, + ACTION_NAMES.cpp_compile, + ACTION_NAMES.linkstamp_compile, + ACTION_NAMES.assemble, + ACTION_NAMES.preprocess_assemble, + ACTION_NAMES.cpp_header_parsing, + ACTION_NAMES.cpp_module_compile, + ACTION_NAMES.cpp_module_codegen, + ACTION_NAMES.clif_match, + ACTION_NAMES.lto_backend, + ] + + all_cpp_compile_actions = [ + ACTION_NAMES.cpp_compile, + ACTION_NAMES.linkstamp_compile, + ACTION_NAMES.cpp_header_parsing, + ACTION_NAMES.cpp_module_compile, + ACTION_NAMES.cpp_module_codegen, + ACTION_NAMES.clif_match, + ] + + preprocessor_compile_actions = [ + ACTION_NAMES.c_compile, + ACTION_NAMES.cpp_compile, + ACTION_NAMES.linkstamp_compile, + ACTION_NAMES.preprocess_assemble, + ACTION_NAMES.cpp_header_parsing, + ACTION_NAMES.cpp_module_compile, + ACTION_NAMES.clif_match, + ] + + codegen_compile_actions = [ + ACTION_NAMES.c_compile, + ACTION_NAMES.cpp_compile, + ACTION_NAMES.linkstamp_compile, + ACTION_NAMES.assemble, + ACTION_NAMES.preprocess_assemble, + ACTION_NAMES.cpp_module_codegen, + ACTION_NAMES.lto_backend, + ] + + all_link_actions = [ + ACTION_NAMES.cpp_link_executable, + ACTION_NAMES.cpp_link_dynamic_library, + ACTION_NAMES.cpp_link_nodeps_dynamic_library, + ] + + action_configs = [] + + features = [] + + cxx_builtin_include_directories = [] + + artifact_name_patterns = [] + + make_variables = [] + + tool_paths = [] + + + out = ctx.actions.declare_file(ctx.label.name) + ctx.actions.write(out, "Fake executable") + return [ + cc_common.create_cc_toolchain_config_info( + ctx = ctx, + features = features, + action_configs = action_configs, + artifact_name_patterns = artifact_name_patterns, + cxx_builtin_include_directories = cxx_builtin_include_directories, + toolchain_identifier = toolchain_identifier, + host_system_name = host_system_name, + target_system_name = target_system_name, + target_cpu = target_cpu, + target_libc = target_libc, + compiler = compiler, + abi_version = abi_version, + abi_libc_version = abi_libc_version, + tool_paths = tool_paths, + make_variables = make_variables, + builtin_sysroot = builtin_sysroot, + cc_target_os = cc_target_os + ), + DefaultInfo( + executable = out, + ), + ] +cc_toolchain_config = rule( + implementation = _impl, + attrs = { + "cpu": attr.string(mandatory=True, values=["cpu-simple"]), + }, + provides = [CcToolchainConfigInfo], + executable = True, +) +` + crosstool := makeCrosstool([]string{simpleToolchain}) + got, err := Transform(crosstool) + if err != nil { + t.Fatalf("CROSSTOOL conversion failed: %v", err) + } + if got != expected { + t.Fatalf("Expected:\n%v\nGot:\n%v\nTested CROSSTOOL:\n%v", + expected, got, simpleToolchain) + } +}