mirror of https://github.com/bazelbuild/rules_cc
Make cc_embed_data.bzl forward compatible with removal of legacy crosstool fields
RELNOTES: None PiperOrigin-RevId: 228301880
This commit is contained in:
parent
f835b8bea2
commit
63003094c9
|
@ -117,6 +117,13 @@ def migrate_legacy_fields(crosstool):
|
||||||
flag_group = flag_set.flag_group.add()
|
flag_group = flag_set.flag_group.add()
|
||||||
flag_group.flag[:] = toolchain.objcopy_embed_flag
|
flag_group.flag[:] = toolchain.objcopy_embed_flag
|
||||||
|
|
||||||
|
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")
|
||||||
|
|
||||||
if toolchain.ld_embed_flag and not _contains_feature(
|
if toolchain.ld_embed_flag and not _contains_feature(
|
||||||
toolchain, "ld_embed_flags"):
|
toolchain, "ld_embed_flags"):
|
||||||
feature = toolchain.feature.add()
|
feature = toolchain.feature.add()
|
||||||
|
@ -127,6 +134,13 @@ def migrate_legacy_fields(crosstool):
|
||||||
flag_group = flag_set.flag_group.add()
|
flag_group = flag_set.flag_group.add()
|
||||||
flag_group.flag[:] = toolchain.ld_embed_flag
|
flag_group.flag[:] = toolchain.ld_embed_flag
|
||||||
|
|
||||||
|
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")
|
||||||
|
|
||||||
|
|
||||||
# Create default_link_flags feature for linker_flag
|
# Create default_link_flags feature for linker_flag
|
||||||
flag_sets = _extract_legacy_link_flag_sets_for(toolchain)
|
flag_sets = _extract_legacy_link_flag_sets_for(toolchain)
|
||||||
|
@ -224,6 +238,14 @@ def migrate_legacy_fields(crosstool):
|
||||||
toolchain.ClearField("dynamic_runtimes_filegroup")
|
toolchain.ClearField("dynamic_runtimes_filegroup")
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
def _add_flag_sets(feature, flag_sets):
|
def _add_flag_sets(feature, flag_sets):
|
||||||
"""Add flag sets into a feature."""
|
"""Add flag sets into a feature."""
|
||||||
for flag_set in flag_sets:
|
for flag_set in flag_sets:
|
||||||
|
|
|
@ -717,6 +717,7 @@ class LegacyFieldsMigrationLibTest(unittest.TestCase):
|
||||||
|
|
||||||
def test_migrating_objcopy_embed_flag(self):
|
def test_migrating_objcopy_embed_flag(self):
|
||||||
crosstool = make_crosstool("""
|
crosstool = make_crosstool("""
|
||||||
|
tool_path { name: "objcopy" path: "foo/objcopy" }
|
||||||
objcopy_embed_flag: "a"
|
objcopy_embed_flag: "a"
|
||||||
objcopy_embed_flag: "b"
|
objcopy_embed_flag: "b"
|
||||||
""")
|
""")
|
||||||
|
@ -729,6 +730,8 @@ class LegacyFieldsMigrationLibTest(unittest.TestCase):
|
||||||
self.assertEqual(output.feature[0].flag_set[0].flag_group[0].flag[:],
|
self.assertEqual(output.feature[0].flag_set[0].flag_group[0].flag[:],
|
||||||
["a", "b"])
|
["a", "b"])
|
||||||
self.assertEqual(len(output.objcopy_embed_flag), 0)
|
self.assertEqual(len(output.objcopy_embed_flag), 0)
|
||||||
|
self.assertEqual(output.action_config[0].action_name, "objcopy_embed_data")
|
||||||
|
self.assertEqual(output.action_config[0].tool[0].tool_path, "foo/objcopy")
|
||||||
|
|
||||||
def test_not_migrating_objcopy_embed_flag_when_feature_present(self):
|
def test_not_migrating_objcopy_embed_flag_when_feature_present(self):
|
||||||
crosstool = make_crosstool("""
|
crosstool = make_crosstool("""
|
||||||
|
@ -743,6 +746,7 @@ class LegacyFieldsMigrationLibTest(unittest.TestCase):
|
||||||
|
|
||||||
def test_migrating_ld_embed_flag(self):
|
def test_migrating_ld_embed_flag(self):
|
||||||
crosstool = make_crosstool("""
|
crosstool = make_crosstool("""
|
||||||
|
tool_path { name: "ld" path: "foo/ld" }
|
||||||
ld_embed_flag: "a"
|
ld_embed_flag: "a"
|
||||||
ld_embed_flag: "b"
|
ld_embed_flag: "b"
|
||||||
""")
|
""")
|
||||||
|
@ -754,6 +758,8 @@ class LegacyFieldsMigrationLibTest(unittest.TestCase):
|
||||||
self.assertEqual(output.feature[0].flag_set[0].flag_group[0].flag[:],
|
self.assertEqual(output.feature[0].flag_set[0].flag_group[0].flag[:],
|
||||||
["a", "b"])
|
["a", "b"])
|
||||||
self.assertEqual(len(output.ld_embed_flag), 0)
|
self.assertEqual(len(output.ld_embed_flag), 0)
|
||||||
|
self.assertEqual(output.action_config[0].action_name, "ld_embed_data")
|
||||||
|
self.assertEqual(output.action_config[0].tool[0].tool_path, "foo/ld")
|
||||||
|
|
||||||
def test_not_migrating_objcopy_embed_flag_when_feature_present(self):
|
def test_not_migrating_objcopy_embed_flag_when_feature_present(self):
|
||||||
crosstool = make_crosstool("""
|
crosstool = make_crosstool("""
|
||||||
|
|
Loading…
Reference in New Issue