From 63003094c91ab99f4af8d40261e470c72dea960c Mon Sep 17 00:00:00 2001 From: hlopko Date: Tue, 8 Jan 2019 11:46:31 +0100 Subject: [PATCH] Make cc_embed_data.bzl forward compatible with removal of legacy crosstool fields RELNOTES: None PiperOrigin-RevId: 228301880 --- .../migration/legacy_fields_migration_lib.py | 22 +++++++++++++++++++ .../legacy_fields_migration_lib_test.py | 6 +++++ 2 files changed, 28 insertions(+) diff --git a/tools/migration/legacy_fields_migration_lib.py b/tools/migration/legacy_fields_migration_lib.py index 1d29541..247b6b4 100644 --- a/tools/migration/legacy_fields_migration_lib.py +++ b/tools/migration/legacy_fields_migration_lib.py @@ -117,6 +117,13 @@ def migrate_legacy_fields(crosstool): flag_group = flag_set.flag_group.add() 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( toolchain, "ld_embed_flags"): feature = toolchain.feature.add() @@ -127,6 +134,13 @@ def migrate_legacy_fields(crosstool): flag_group = flag_set.flag_group.add() 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 flag_sets = _extract_legacy_link_flag_sets_for(toolchain) @@ -224,6 +238,14 @@ def migrate_legacy_fields(crosstool): 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): """Add flag sets into a feature.""" for flag_set in flag_sets: diff --git a/tools/migration/legacy_fields_migration_lib_test.py b/tools/migration/legacy_fields_migration_lib_test.py index fd9dc31..9357c32 100644 --- a/tools/migration/legacy_fields_migration_lib_test.py +++ b/tools/migration/legacy_fields_migration_lib_test.py @@ -717,6 +717,7 @@ class LegacyFieldsMigrationLibTest(unittest.TestCase): def test_migrating_objcopy_embed_flag(self): crosstool = make_crosstool(""" + tool_path { name: "objcopy" path: "foo/objcopy" } objcopy_embed_flag: "a" objcopy_embed_flag: "b" """) @@ -729,6 +730,8 @@ class LegacyFieldsMigrationLibTest(unittest.TestCase): self.assertEqual(output.feature[0].flag_set[0].flag_group[0].flag[:], ["a", "b"]) 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): crosstool = make_crosstool(""" @@ -743,6 +746,7 @@ class LegacyFieldsMigrationLibTest(unittest.TestCase): def test_migrating_ld_embed_flag(self): crosstool = make_crosstool(""" + tool_path { name: "ld" path: "foo/ld" } ld_embed_flag: "a" ld_embed_flag: "b" """) @@ -754,6 +758,8 @@ class LegacyFieldsMigrationLibTest(unittest.TestCase): self.assertEqual(output.feature[0].flag_set[0].flag_group[0].flag[:], ["a", "b"]) 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): crosstool = make_crosstool("""