2018-12-18 09:13:15 +00:00
|
|
|
"""Module providing migrate_legacy_fields function.
|
|
|
|
|
|
|
|
migrate_legacy_fields takes parsed CROSSTOOL proto and migrates it (inplace) to
|
|
|
|
use only the features.
|
|
|
|
|
|
|
|
Tracking issue: https://github.com/bazelbuild/bazel/issues/5187
|
|
|
|
|
|
|
|
Since C++ rules team is working on migrating CROSSTOOL from text proto into
|
|
|
|
Starlark, we advise CROSSTOOL owners to wait for the CROSSTOOL -> Starlark
|
|
|
|
migrator before they invest too much time into fixing their pipeline. Tracking
|
|
|
|
issue for the Starlark effort is
|
|
|
|
https://github.com/bazelbuild/bazel/issues/5380.
|
|
|
|
"""
|
|
|
|
|
|
|
|
from third_party.com.github.bazelbuild.bazel.src.main.protobuf import crosstool_config_pb2
|
|
|
|
|
2019-01-11 08:11:20 +00:00
|
|
|
ALL_CC_COMPILE_ACTIONS = [
|
2018-12-18 09:13:15 +00:00
|
|
|
"assemble", "preprocess-assemble", "linkstamp-compile", "c-compile",
|
|
|
|
"c++-compile", "c++-header-parsing", "c++-module-compile",
|
|
|
|
"c++-module-codegen", "lto-backend", "clif-match"
|
|
|
|
]
|
|
|
|
|
2019-01-11 08:11:20 +00:00
|
|
|
ALL_OBJC_COMPILE_ACTIONS = [
|
|
|
|
"objc-compile", "objc++-compile"
|
|
|
|
]
|
|
|
|
|
2018-12-18 09:13:15 +00:00
|
|
|
ALL_CXX_COMPILE_ACTIONS = [
|
2019-01-15 10:09:04 +00:00
|
|
|
action for action in ALL_CC_COMPILE_ACTIONS
|
|
|
|
if action not in ["c-compile", "preprocess-assemble", "assemble"]
|
2018-12-18 09:13:15 +00:00
|
|
|
]
|
|
|
|
|
2019-01-11 08:11:20 +00:00
|
|
|
ALL_CC_LINK_ACTIONS = [
|
2018-12-18 09:13:15 +00:00
|
|
|
"c++-link-executable", "c++-link-dynamic-library",
|
|
|
|
"c++-link-nodeps-dynamic-library"
|
|
|
|
]
|
|
|
|
|
2019-01-11 08:11:20 +00:00
|
|
|
ALL_OBJC_LINK_ACTIONS = [
|
|
|
|
"objc-executable", "objc++-executable",
|
|
|
|
]
|
|
|
|
|
2019-01-03 15:50:32 +00:00
|
|
|
DYNAMIC_LIBRARY_LINK_ACTIONS = [
|
|
|
|
"c++-link-dynamic-library", "c++-link-nodeps-dynamic-library"
|
|
|
|
]
|
|
|
|
|
2019-01-17 08:07:12 +00:00
|
|
|
NODEPS_DYNAMIC_LIBRARY_LINK_ACTIONS = ["c++-link-nodeps-dynamic-library"]
|
|
|
|
|
|
|
|
TRANSITIVE_LINK_ACTIONS = ["c++-link-executable", "c++-link-dynamic-library"]
|
|
|
|
|
2019-02-11 14:47:11 +00:00
|
|
|
CC_LINK_EXECUTABLE = ["c++-link-executable"]
|
|
|
|
|
2019-01-17 08:07:12 +00:00
|
|
|
|
2019-01-11 08:11:20 +00:00
|
|
|
def compile_actions(toolchain):
|
|
|
|
"""Returns compile actions for cc or objc rules."""
|
|
|
|
if _is_objc_toolchain(toolchain):
|
2019-01-15 10:09:04 +00:00
|
|
|
return ALL_CC_COMPILE_ACTIONS + ALL_OBJC_COMPILE_ACTIONS
|
2019-01-11 08:11:20 +00:00
|
|
|
else:
|
2019-01-15 10:09:04 +00:00
|
|
|
return ALL_CC_COMPILE_ACTIONS
|
2019-01-11 08:11:20 +00:00
|
|
|
|
|
|
|
def link_actions(toolchain):
|
|
|
|
"""Returns link actions for cc or objc rules."""
|
|
|
|
if _is_objc_toolchain(toolchain):
|
2019-01-15 10:09:04 +00:00
|
|
|
return ALL_CC_LINK_ACTIONS + ALL_OBJC_LINK_ACTIONS
|
2019-01-11 08:11:20 +00:00
|
|
|
else:
|
2019-01-15 10:09:04 +00:00
|
|
|
return ALL_CC_LINK_ACTIONS
|
2019-01-11 08:11:20 +00:00
|
|
|
|
2019-01-17 08:07:12 +00:00
|
|
|
|
|
|
|
def transitive_link_actions(toolchain):
|
|
|
|
"""Returns transitive link actions for cc or objc rules."""
|
|
|
|
if _is_objc_toolchain(toolchain):
|
|
|
|
return TRANSITIVE_LINK_ACTIONS + ALL_OBJC_LINK_ACTIONS
|
|
|
|
else:
|
|
|
|
return TRANSITIVE_LINK_ACTIONS
|
|
|
|
|
|
|
|
|
2019-01-11 08:11:20 +00:00
|
|
|
def _is_objc_toolchain(toolchain):
|
|
|
|
return any(ac.action_name == "objc-compile" for ac in toolchain.action_config)
|
|
|
|
|
2018-12-18 09:13:15 +00:00
|
|
|
# Map converting from LinkingMode to corresponding feature name
|
|
|
|
LINKING_MODE_TO_FEATURE_NAME = {
|
|
|
|
"FULLY_STATIC": "fully_static_link",
|
|
|
|
"MOSTLY_STATIC": "static_linking_mode",
|
|
|
|
"DYNAMIC": "dynamic_linking_mode",
|
|
|
|
"MOSTLY_STATIC_LIBRARIES": "static_linking_mode_nodeps_library",
|
|
|
|
}
|
|
|
|
|
|
|
|
def migrate_legacy_fields(crosstool):
|
|
|
|
"""Migrates parsed crosstool (inplace) to not use legacy fields."""
|
|
|
|
crosstool.ClearField("default_toolchain")
|
|
|
|
for toolchain in crosstool.toolchain:
|
|
|
|
_ = [_migrate_expand_if_all_available(f) for f in toolchain.feature]
|
|
|
|
_ = [_migrate_expand_if_all_available(ac) for ac in toolchain.action_config]
|
2019-02-08 12:53:38 +00:00
|
|
|
_ = [_migrate_repeated_expands(f) for f in toolchain.feature]
|
|
|
|
_ = [_migrate_repeated_expands(ac) for ac in toolchain.action_config]
|
2018-12-18 09:13:15 +00:00
|
|
|
|
2019-01-03 15:50:32 +00:00
|
|
|
if (toolchain.dynamic_library_linker_flag or
|
2019-02-13 13:40:32 +00:00
|
|
|
_contains_dynamic_flags(toolchain)) and not _get_feature(
|
2019-01-03 15:50:32 +00:00
|
|
|
toolchain, "supports_dynamic_linker"):
|
|
|
|
feature = toolchain.feature.add()
|
|
|
|
feature.name = "supports_dynamic_linker"
|
|
|
|
feature.enabled = True
|
|
|
|
|
2019-02-13 13:40:32 +00:00
|
|
|
if toolchain.supports_start_end_lib and not _get_feature(
|
2019-01-03 15:50:32 +00:00
|
|
|
toolchain, "supports_start_end_lib"):
|
|
|
|
feature = toolchain.feature.add()
|
|
|
|
feature.name = "supports_start_end_lib"
|
|
|
|
feature.enabled = True
|
|
|
|
|
2019-02-13 13:40:32 +00:00
|
|
|
if toolchain.supports_interface_shared_objects and not _get_feature(
|
2019-01-03 15:50:32 +00:00
|
|
|
toolchain, "supports_interface_shared_libraries"):
|
|
|
|
feature = toolchain.feature.add()
|
|
|
|
feature.name = "supports_interface_shared_libraries"
|
|
|
|
feature.enabled = True
|
|
|
|
|
2019-02-13 13:40:32 +00:00
|
|
|
if toolchain.supports_embedded_runtimes and not _get_feature(
|
2019-01-03 15:50:32 +00:00
|
|
|
toolchain, "static_link_cpp_runtimes"):
|
|
|
|
feature = toolchain.feature.add()
|
|
|
|
feature.name = "static_link_cpp_runtimes"
|
|
|
|
feature.enabled = True
|
|
|
|
|
2019-02-13 13:40:32 +00:00
|
|
|
if toolchain.needsPic and not _get_feature(toolchain, "supports_pic"):
|
2019-01-03 15:50:32 +00:00
|
|
|
feature = toolchain.feature.add()
|
|
|
|
feature.name = "supports_pic"
|
|
|
|
feature.enabled = True
|
|
|
|
|
2019-02-13 13:40:32 +00:00
|
|
|
if toolchain.supports_fission and not _get_feature(
|
2019-01-03 15:50:32 +00:00
|
|
|
toolchain, "per_object_debug_info"):
|
|
|
|
# feature {
|
|
|
|
# name: "per_object_debug_info"
|
|
|
|
# flag_set {
|
|
|
|
# action: "assemble"
|
|
|
|
# action: "preprocess-assemble"
|
|
|
|
# action: "c-compile"
|
|
|
|
# action: "c++-compile"
|
|
|
|
# action: "c++-module-codegen"
|
|
|
|
# action: "lto-backend"
|
|
|
|
# flag_group {
|
|
|
|
# expand_if_all_available: 'per_object_debug_info_file'",
|
|
|
|
# flag: "-gsplit-dwarf"
|
|
|
|
# }
|
|
|
|
# }
|
|
|
|
# }
|
|
|
|
feature = toolchain.feature.add()
|
|
|
|
feature.name = "per_object_debug_info"
|
2019-01-24 12:55:01 +00:00
|
|
|
feature.enabled = True
|
2019-01-03 15:50:32 +00:00
|
|
|
flag_set = feature.flag_set.add()
|
|
|
|
flag_set.action[:] = [
|
|
|
|
"c-compile", "c++-compile", "c++-module-codegen", "assemble",
|
|
|
|
"preprocess-assemble", "lto-backend"
|
|
|
|
]
|
|
|
|
flag_group = flag_set.flag_group.add()
|
|
|
|
flag_group.expand_if_all_available[:] = ["per_object_debug_info_file"]
|
|
|
|
flag_group.flag[:] = ["-gsplit-dwarf"]
|
|
|
|
|
2019-02-13 13:40:32 +00:00
|
|
|
if toolchain.objcopy_embed_flag and not _get_feature(
|
2019-01-03 15:50:32 +00:00
|
|
|
toolchain, "objcopy_embed_flags"):
|
|
|
|
feature = toolchain.feature.add()
|
|
|
|
feature.name = "objcopy_embed_flags"
|
|
|
|
feature.enabled = True
|
|
|
|
flag_set = feature.flag_set.add()
|
|
|
|
flag_set.action[:] = ["objcopy_embed_data"]
|
|
|
|
flag_group = flag_set.flag_group.add()
|
|
|
|
flag_group.flag[:] = toolchain.objcopy_embed_flag
|
|
|
|
|
2019-01-08 10:46:31 +00:00
|
|
|
action_config = toolchain.action_config.add()
|
|
|
|
action_config.action_name = "objcopy_embed_data"
|
|
|
|
action_config.config_name = "objcopy_embed_data"
|
|
|
|
action_config.enabled = True
|
|
|
|
tool = action_config.tool.add()
|
|
|
|
tool.tool_path = _find_tool_path(toolchain, "objcopy")
|
|
|
|
|
2019-02-13 13:40:32 +00:00
|
|
|
if toolchain.ld_embed_flag and not _get_feature(
|
2019-01-03 15:50:32 +00:00
|
|
|
toolchain, "ld_embed_flags"):
|
|
|
|
feature = toolchain.feature.add()
|
|
|
|
feature.name = "ld_embed_flags"
|
|
|
|
feature.enabled = True
|
|
|
|
flag_set = feature.flag_set.add()
|
|
|
|
flag_set.action[:] = ["ld_embed_data"]
|
|
|
|
flag_group = flag_set.flag_group.add()
|
|
|
|
flag_group.flag[:] = toolchain.ld_embed_flag
|
|
|
|
|
2019-01-08 10:46:31 +00:00
|
|
|
action_config = toolchain.action_config.add()
|
|
|
|
action_config.action_name = "ld_embed_data"
|
|
|
|
action_config.config_name = "ld_embed_data"
|
|
|
|
action_config.enabled = True
|
|
|
|
tool = action_config.tool.add()
|
|
|
|
tool.tool_path = _find_tool_path(toolchain, "ld")
|
|
|
|
|
2019-01-03 15:50:32 +00:00
|
|
|
|
2018-12-18 09:13:15 +00:00
|
|
|
# Create default_link_flags feature for linker_flag
|
|
|
|
flag_sets = _extract_legacy_link_flag_sets_for(toolchain)
|
|
|
|
if flag_sets:
|
2019-02-13 13:40:32 +00:00
|
|
|
if _get_feature(toolchain, "default_link_flags"):
|
2018-12-18 09:13:15 +00:00
|
|
|
continue
|
2019-02-13 13:40:32 +00:00
|
|
|
if _get_feature(toolchain, "legacy_link_flags"):
|
2019-01-15 10:09:04 +00:00
|
|
|
for f in toolchain.feature:
|
|
|
|
if f.name == "legacy_link_flags":
|
|
|
|
f.ClearField("flag_set")
|
|
|
|
feature = f
|
2019-01-16 09:41:08 +00:00
|
|
|
_rename_feature_in_toolchain(toolchain, "legacy_link_flags",
|
|
|
|
"default_link_flags")
|
2019-01-15 10:09:04 +00:00
|
|
|
break
|
|
|
|
else:
|
|
|
|
feature = _prepend_feature(toolchain)
|
2018-12-18 09:13:15 +00:00
|
|
|
feature.name = "default_link_flags"
|
|
|
|
feature.enabled = True
|
|
|
|
_add_flag_sets(feature, flag_sets)
|
|
|
|
|
|
|
|
# Create default_compile_flags feature for compiler_flag, cxx_flag
|
|
|
|
flag_sets = _extract_legacy_compile_flag_sets_for(toolchain)
|
2019-02-13 13:40:32 +00:00
|
|
|
if flag_sets and not _get_feature(toolchain, "default_compile_flags"):
|
|
|
|
if _get_feature(toolchain, "legacy_compile_flags"):
|
2019-01-15 10:09:04 +00:00
|
|
|
for f in toolchain.feature:
|
|
|
|
if f.name == "legacy_compile_flags":
|
|
|
|
f.ClearField("flag_set")
|
|
|
|
feature = f
|
2019-01-16 09:41:08 +00:00
|
|
|
_rename_feature_in_toolchain(toolchain, "legacy_compile_flags",
|
|
|
|
"default_compile_flags")
|
2019-01-15 10:09:04 +00:00
|
|
|
break
|
|
|
|
else:
|
|
|
|
feature = _prepend_feature(toolchain)
|
2018-12-18 09:13:15 +00:00
|
|
|
feature.enabled = True
|
|
|
|
feature.name = "default_compile_flags"
|
|
|
|
_add_flag_sets(feature, flag_sets)
|
|
|
|
|
|
|
|
# Unfiltered cxx flags have to have their own special feature.
|
|
|
|
# "unfiltered_compile_flags" is a well-known (by Bazel) feature name that is
|
|
|
|
# excluded from nocopts filtering.
|
|
|
|
if toolchain.unfiltered_cxx_flag:
|
|
|
|
# If there already is a feature named unfiltered_compile_flags, the
|
|
|
|
# crosstool is already migrated for unfiltered_compile_flags
|
2019-02-13 13:40:32 +00:00
|
|
|
if _get_feature(toolchain, "unfiltered_compile_flags"):
|
2018-12-18 09:13:15 +00:00
|
|
|
for f in toolchain.feature:
|
|
|
|
if f.name == "unfiltered_compile_flags":
|
2019-01-08 10:06:07 +00:00
|
|
|
for flag_set in f.flag_set:
|
|
|
|
for flag_group in flag_set.flag_group:
|
|
|
|
if flag_group.iterate_over == "unfiltered_compile_flags":
|
|
|
|
flag_group.ClearField("iterate_over")
|
|
|
|
flag_group.ClearField("expand_if_all_available")
|
|
|
|
flag_group.ClearField("flag")
|
|
|
|
flag_group.flag[:] = toolchain.unfiltered_cxx_flag
|
2018-12-18 09:13:15 +00:00
|
|
|
else:
|
2019-02-13 13:40:32 +00:00
|
|
|
if not _get_feature(toolchain, "user_compile_flags"):
|
2019-01-08 10:06:07 +00:00
|
|
|
feature = toolchain.feature.add()
|
|
|
|
feature.name = "user_compile_flags"
|
|
|
|
feature.enabled = True
|
|
|
|
flag_set = feature.flag_set.add()
|
2019-01-11 08:11:20 +00:00
|
|
|
flag_set.action[:] = compile_actions(toolchain)
|
2019-01-08 10:06:07 +00:00
|
|
|
flag_group = flag_set.flag_group.add()
|
|
|
|
flag_group.expand_if_all_available[:] = ["user_compile_flags"]
|
|
|
|
flag_group.iterate_over = "user_compile_flags"
|
|
|
|
flag_group.flag[:] = ["%{user_compile_flags}"]
|
|
|
|
|
2019-02-13 13:40:32 +00:00
|
|
|
if not _get_feature(toolchain, "sysroot"):
|
2019-01-15 10:09:04 +00:00
|
|
|
sysroot_actions = compile_actions(toolchain) + link_actions(toolchain)
|
|
|
|
sysroot_actions.remove("assemble")
|
2019-01-08 10:06:07 +00:00
|
|
|
feature = toolchain.feature.add()
|
|
|
|
feature.name = "sysroot"
|
|
|
|
feature.enabled = True
|
|
|
|
flag_set = feature.flag_set.add()
|
2019-01-15 10:09:04 +00:00
|
|
|
flag_set.action[:] = sysroot_actions
|
2019-01-08 10:06:07 +00:00
|
|
|
flag_group = flag_set.flag_group.add()
|
|
|
|
flag_group.expand_if_all_available[:] = ["sysroot"]
|
|
|
|
flag_group.flag[:] = ["--sysroot=%{sysroot}"]
|
|
|
|
|
2018-12-18 09:13:15 +00:00
|
|
|
feature = toolchain.feature.add()
|
|
|
|
feature.name = "unfiltered_compile_flags"
|
|
|
|
feature.enabled = True
|
2019-01-08 10:06:07 +00:00
|
|
|
flag_set = feature.flag_set.add()
|
2019-01-11 08:11:20 +00:00
|
|
|
flag_set.action[:] = compile_actions(toolchain)
|
2019-01-08 10:06:07 +00:00
|
|
|
flag_group = flag_set.flag_group.add()
|
|
|
|
flag_group.flag[:] = toolchain.unfiltered_cxx_flag
|
2019-01-03 15:50:32 +00:00
|
|
|
|
|
|
|
# clear fields
|
|
|
|
toolchain.ClearField("debian_extra_requires")
|
|
|
|
toolchain.ClearField("gcc_plugin_compiler_flag")
|
|
|
|
toolchain.ClearField("ar_flag")
|
|
|
|
toolchain.ClearField("ar_thin_archives_flag")
|
|
|
|
toolchain.ClearField("gcc_plugin_header_directory")
|
|
|
|
toolchain.ClearField("mao_plugin_header_directory")
|
|
|
|
toolchain.ClearField("supports_normalizing_ar")
|
|
|
|
toolchain.ClearField("supports_thin_archives")
|
|
|
|
toolchain.ClearField("supports_incremental_linker")
|
|
|
|
toolchain.ClearField("supports_dsym")
|
|
|
|
toolchain.ClearField("supports_gold_linker")
|
|
|
|
toolchain.ClearField("default_python_top")
|
|
|
|
toolchain.ClearField("default_python_version")
|
|
|
|
toolchain.ClearField("python_preload_swigdeps")
|
|
|
|
toolchain.ClearField("needsPic")
|
|
|
|
toolchain.ClearField("compilation_mode_flags")
|
|
|
|
toolchain.ClearField("linking_mode_flags")
|
|
|
|
toolchain.ClearField("unfiltered_cxx_flag")
|
|
|
|
toolchain.ClearField("ld_embed_flag")
|
|
|
|
toolchain.ClearField("objcopy_embed_flag")
|
|
|
|
toolchain.ClearField("supports_start_end_lib")
|
|
|
|
toolchain.ClearField("supports_interface_shared_objects")
|
|
|
|
toolchain.ClearField("supports_fission")
|
2019-01-08 10:06:07 +00:00
|
|
|
toolchain.ClearField("supports_embedded_runtimes")
|
2019-01-03 15:50:32 +00:00
|
|
|
toolchain.ClearField("compiler_flag")
|
|
|
|
toolchain.ClearField("cxx_flag")
|
|
|
|
toolchain.ClearField("linker_flag")
|
|
|
|
toolchain.ClearField("static_runtimes_filegroup")
|
|
|
|
toolchain.ClearField("dynamic_runtimes_filegroup")
|
2018-12-18 09:13:15 +00:00
|
|
|
|
2019-02-13 13:40:32 +00:00
|
|
|
# Enable features that were previously enabled by Bazel
|
|
|
|
default_features = [
|
|
|
|
"dependency_file", "random_seed", "module_maps", "module_map_home_cwd",
|
|
|
|
"header_module_compile", "include_paths", "pic", "preprocessor_define"
|
|
|
|
]
|
|
|
|
for feature_name in default_features:
|
|
|
|
feature = _get_feature(toolchain, feature_name)
|
|
|
|
if feature:
|
|
|
|
feature.enabled = True
|
|
|
|
|
2018-12-18 09:13:15 +00:00
|
|
|
|
2019-01-08 10:46:31 +00:00
|
|
|
def _find_tool_path(toolchain, tool_name):
|
|
|
|
"""Returns the tool path of the tool with the given name."""
|
|
|
|
for tool in toolchain.tool_path:
|
|
|
|
if tool.name == tool_name:
|
|
|
|
return tool.path
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
2018-12-18 09:13:15 +00:00
|
|
|
def _add_flag_sets(feature, flag_sets):
|
|
|
|
"""Add flag sets into a feature."""
|
|
|
|
for flag_set in flag_sets:
|
|
|
|
with_feature = flag_set[0]
|
|
|
|
actions = flag_set[1]
|
|
|
|
flags = flag_set[2]
|
2019-01-03 15:50:32 +00:00
|
|
|
expand_if_all_available = flag_set[3]
|
2018-12-18 09:13:15 +00:00
|
|
|
flag_set = feature.flag_set.add()
|
|
|
|
if with_feature is not None:
|
|
|
|
flag_set.with_feature.add().feature[:] = [with_feature]
|
|
|
|
flag_set.action[:] = actions
|
|
|
|
flag_group = flag_set.flag_group.add()
|
2019-01-03 15:50:32 +00:00
|
|
|
flag_group.expand_if_all_available[:] = expand_if_all_available
|
2018-12-18 09:13:15 +00:00
|
|
|
flag_group.flag[:] = flags
|
|
|
|
return feature
|
|
|
|
|
|
|
|
|
|
|
|
def _extract_legacy_compile_flag_sets_for(toolchain):
|
|
|
|
"""Get flag sets for default_compile_flags feature."""
|
|
|
|
result = []
|
|
|
|
if toolchain.compiler_flag:
|
2019-01-17 08:07:12 +00:00
|
|
|
result.append(
|
|
|
|
[None, compile_actions(toolchain), toolchain.compiler_flag, []])
|
2018-12-18 09:13:15 +00:00
|
|
|
|
2019-01-15 10:09:04 +00:00
|
|
|
# Migrate compiler_flag from compilation_mode_flags
|
2018-12-18 09:13:15 +00:00
|
|
|
for cmf in toolchain.compilation_mode_flags:
|
|
|
|
mode = crosstool_config_pb2.CompilationMode.Name(cmf.mode).lower()
|
|
|
|
# coverage mode has been a noop since a while
|
|
|
|
if mode == "coverage":
|
|
|
|
continue
|
|
|
|
|
|
|
|
if (cmf.compiler_flag or
|
2019-02-13 13:40:32 +00:00
|
|
|
cmf.cxx_flag) and not _get_feature(toolchain, mode):
|
2018-12-18 09:13:15 +00:00
|
|
|
feature = toolchain.feature.add()
|
|
|
|
feature.name = mode
|
|
|
|
|
|
|
|
if cmf.compiler_flag:
|
2019-01-11 08:11:20 +00:00
|
|
|
result.append([mode, compile_actions(toolchain), cmf.compiler_flag, []])
|
2018-12-18 09:13:15 +00:00
|
|
|
|
2019-01-15 10:09:04 +00:00
|
|
|
if toolchain.cxx_flag:
|
|
|
|
result.append([None, ALL_CXX_COMPILE_ACTIONS, toolchain.cxx_flag, []])
|
|
|
|
|
|
|
|
# Migrate compiler_flag/cxx_flag from compilation_mode_flags
|
|
|
|
for cmf in toolchain.compilation_mode_flags:
|
|
|
|
mode = crosstool_config_pb2.CompilationMode.Name(cmf.mode).lower()
|
|
|
|
# coverage mode has been a noop since a while
|
|
|
|
if mode == "coverage":
|
|
|
|
continue
|
|
|
|
|
2018-12-18 09:13:15 +00:00
|
|
|
if cmf.cxx_flag:
|
2019-01-03 15:50:32 +00:00
|
|
|
result.append([mode, ALL_CXX_COMPILE_ACTIONS, cmf.cxx_flag, []])
|
2018-12-18 09:13:15 +00:00
|
|
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
def _extract_legacy_link_flag_sets_for(toolchain):
|
|
|
|
"""Get flag sets for default_link_flags feature."""
|
|
|
|
result = []
|
|
|
|
|
|
|
|
# Migrate linker_flag
|
|
|
|
if toolchain.linker_flag:
|
2019-01-11 08:11:20 +00:00
|
|
|
result.append([None, link_actions(toolchain), toolchain.linker_flag, []])
|
2018-12-18 09:13:15 +00:00
|
|
|
|
|
|
|
# Migrate linker_flags from compilation_mode_flags
|
|
|
|
for cmf in toolchain.compilation_mode_flags:
|
|
|
|
mode = crosstool_config_pb2.CompilationMode.Name(cmf.mode).lower()
|
|
|
|
# coverage mode has beed a noop since a while
|
|
|
|
if mode == "coverage":
|
|
|
|
continue
|
|
|
|
|
2019-02-13 13:40:32 +00:00
|
|
|
if cmf.linker_flag and not _get_feature(toolchain, mode):
|
2018-12-18 09:13:15 +00:00
|
|
|
feature = toolchain.feature.add()
|
|
|
|
feature.name = mode
|
|
|
|
|
|
|
|
if cmf.linker_flag:
|
2019-01-11 08:11:20 +00:00
|
|
|
result.append([mode, link_actions(toolchain), cmf.linker_flag, []])
|
2018-12-18 09:13:15 +00:00
|
|
|
|
|
|
|
# Migrate linker_flags from linking_mode_flags
|
|
|
|
for lmf in toolchain.linking_mode_flags:
|
|
|
|
mode = crosstool_config_pb2.LinkingMode.Name(lmf.mode)
|
2019-01-17 08:07:12 +00:00
|
|
|
feature_name = LINKING_MODE_TO_FEATURE_NAME.get(mode)
|
2018-12-18 09:13:15 +00:00
|
|
|
# if the feature is already there, we don't migrate, lmf is not used
|
2019-02-13 13:40:32 +00:00
|
|
|
if _get_feature(toolchain, feature_name):
|
2018-12-18 09:13:15 +00:00
|
|
|
continue
|
|
|
|
|
2019-01-03 15:50:32 +00:00
|
|
|
if lmf.linker_flag:
|
2018-12-18 09:13:15 +00:00
|
|
|
feature = toolchain.feature.add()
|
2019-01-17 08:07:12 +00:00
|
|
|
feature.name = feature_name
|
|
|
|
if mode == "DYNAMIC":
|
|
|
|
result.append(
|
|
|
|
[None, NODEPS_DYNAMIC_LIBRARY_LINK_ACTIONS, lmf.linker_flag, []])
|
|
|
|
result.append([
|
|
|
|
feature_name,
|
|
|
|
transitive_link_actions(toolchain), lmf.linker_flag, []
|
|
|
|
])
|
2019-02-11 14:47:11 +00:00
|
|
|
elif mode == "MOSTLY_STATIC":
|
2019-01-17 08:07:12 +00:00
|
|
|
result.append(
|
2019-02-11 14:47:11 +00:00
|
|
|
[feature_name,
|
|
|
|
CC_LINK_EXECUTABLE, lmf.linker_flag, []])
|
|
|
|
else:
|
2019-02-13 13:40:32 +00:00
|
|
|
result.append(
|
|
|
|
[feature_name,
|
|
|
|
link_actions(toolchain), lmf.linker_flag, []])
|
2019-01-03 15:50:32 +00:00
|
|
|
|
|
|
|
if toolchain.dynamic_library_linker_flag:
|
|
|
|
result.append([
|
|
|
|
None, DYNAMIC_LIBRARY_LINK_ACTIONS,
|
|
|
|
toolchain.dynamic_library_linker_flag, []
|
|
|
|
])
|
|
|
|
|
|
|
|
if toolchain.test_only_linker_flag:
|
|
|
|
result.append([
|
2019-01-17 08:07:12 +00:00
|
|
|
None,
|
|
|
|
link_actions(toolchain), toolchain.test_only_linker_flag,
|
|
|
|
["is_cc_test"]
|
2019-01-03 15:50:32 +00:00
|
|
|
])
|
2018-12-18 09:13:15 +00:00
|
|
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
def _prepend_feature(toolchain):
|
|
|
|
"""Create a new feature and make it be the first in the toolchain."""
|
|
|
|
features = toolchain.feature
|
|
|
|
toolchain.ClearField("feature")
|
|
|
|
new_feature = toolchain.feature.add()
|
|
|
|
toolchain.feature.extend(features)
|
|
|
|
return new_feature
|
|
|
|
|
|
|
|
|
2019-02-13 13:40:32 +00:00
|
|
|
def _get_feature(toolchain, name):
|
|
|
|
"""Returns feature with a given name or None."""
|
|
|
|
for feature in toolchain.feature:
|
|
|
|
if feature.name == name:
|
|
|
|
return feature
|
|
|
|
return None
|
2018-12-18 09:13:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
def _migrate_expand_if_all_available(message):
|
2019-02-08 12:53:38 +00:00
|
|
|
"""Move expand_if_all_available field to flag_groups."""
|
2018-12-18 09:13:15 +00:00
|
|
|
for flag_set in message.flag_set:
|
|
|
|
if flag_set.expand_if_all_available:
|
|
|
|
for flag_group in flag_set.flag_group:
|
|
|
|
new_vars = (
|
|
|
|
flag_group.expand_if_all_available[:] +
|
|
|
|
flag_set.expand_if_all_available[:])
|
|
|
|
flag_group.expand_if_all_available[:] = new_vars
|
|
|
|
flag_set.ClearField("expand_if_all_available")
|
2019-01-03 15:50:32 +00:00
|
|
|
|
|
|
|
|
2019-02-08 12:53:38 +00:00
|
|
|
def _migrate_repeated_expands(message):
|
|
|
|
"""Replace repeated legacy fields with nesting."""
|
|
|
|
todo_queue = []
|
|
|
|
for flag_set in message.flag_set:
|
|
|
|
todo_queue.extend(flag_set.flag_group)
|
|
|
|
while todo_queue:
|
|
|
|
flag_group = todo_queue.pop()
|
|
|
|
todo_queue.extend(flag_group.flag_group)
|
|
|
|
if len(flag_group.expand_if_all_available) <= 1 and len(
|
|
|
|
flag_group.expand_if_none_available) <= 1:
|
|
|
|
continue
|
|
|
|
|
|
|
|
current_children = flag_group.flag_group
|
|
|
|
current_flags = flag_group.flag
|
|
|
|
flag_group.ClearField("flag_group")
|
|
|
|
flag_group.ClearField("flag")
|
|
|
|
|
|
|
|
new_flag_group = flag_group.flag_group.add()
|
|
|
|
new_flag_group.flag_group.extend(current_children)
|
|
|
|
new_flag_group.flag.extend(current_flags)
|
|
|
|
|
|
|
|
if len(flag_group.expand_if_all_available) > 1:
|
|
|
|
expands_to_move = flag_group.expand_if_all_available[1:]
|
|
|
|
flag_group.expand_if_all_available[:] = [
|
|
|
|
flag_group.expand_if_all_available[0]
|
|
|
|
]
|
|
|
|
new_flag_group.expand_if_all_available.extend(expands_to_move)
|
|
|
|
|
|
|
|
if len(flag_group.expand_if_none_available) > 1:
|
|
|
|
expands_to_move = flag_group.expand_if_none_available[1:]
|
|
|
|
flag_group.expand_if_none_available[:] = [
|
|
|
|
flag_group.expand_if_none_available[0]
|
|
|
|
]
|
|
|
|
new_flag_group.expand_if_none_available.extend(expands_to_move)
|
|
|
|
|
|
|
|
todo_queue.append(new_flag_group)
|
|
|
|
todo_queue.append(flag_group)
|
|
|
|
|
|
|
|
|
2019-01-03 15:50:32 +00:00
|
|
|
def _contains_dynamic_flags(toolchain):
|
|
|
|
for lmf in toolchain.linking_mode_flags:
|
|
|
|
mode = crosstool_config_pb2.LinkingMode.Name(lmf.mode)
|
|
|
|
if mode == "DYNAMIC":
|
|
|
|
return True
|
|
|
|
return False
|
2019-01-16 09:41:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
def _rename_feature_in_toolchain(toolchain, from_name, to_name):
|
|
|
|
for f in toolchain.feature:
|
|
|
|
_rename_feature_in(f, from_name, to_name)
|
|
|
|
for a in toolchain.action_config:
|
|
|
|
_rename_feature_in(a, from_name, to_name)
|
|
|
|
|
|
|
|
|
|
|
|
def _rename_feature_in(msg, from_name, to_name):
|
|
|
|
if from_name in msg.implies:
|
|
|
|
msg.implies.remove(from_name)
|
|
|
|
for requires in msg.requires:
|
|
|
|
if from_name in requires.feature:
|
|
|
|
requires.feature.remove(from_name)
|
|
|
|
requires.feature.extend([to_name])
|
|
|
|
for flag_set in msg.flag_set:
|
|
|
|
for with_feature in flag_set.with_feature:
|
|
|
|
if from_name in with_feature.feature:
|
|
|
|
with_feature.feature.remove(from_name)
|
|
|
|
with_feature.feature.extend([to_name])
|
|
|
|
if from_name in with_feature.not_feature:
|
|
|
|
with_feature.not_feature.remove(from_name)
|
|
|
|
with_feature.not_feature.extend([to_name])
|
|
|
|
for env_set in msg.env_set:
|
|
|
|
for with_feature in env_set.with_feature:
|
|
|
|
if from_name in with_feature.feature:
|
|
|
|
with_feature.feature.remove(from_name)
|
|
|
|
with_feature.feature.extend([to_name])
|
|
|
|
if from_name in with_feature.not_feature:
|
|
|
|
with_feature.not_feature.remove(from_name)
|
|
|
|
with_feature.not_feature.extend([to_name])
|