From 10f38e16da5c5c9acd02228ffcf0eb2cff0679f4 Mon Sep 17 00:00:00 2001 From: hlopko Date: Fri, 15 Mar 2019 13:24:56 -0700 Subject: [PATCH] Fix migrator to correctly migrate dynamic linking mode linker_flags This would have not introduced the osx crosstool bug in https://github.com/bazelbuild/bazel/commit/2d0e27e8bc7452758e8f50b51fd470efb8111e1f which was then fixed in unknown commit. RELNOTES: None. PiperOrigin-RevId: 238699176 --- .../migration/legacy_fields_migration_lib.py | 14 +++++++++++ .../legacy_fields_migration_lib_test.py | 23 +++++++++++++------ 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/tools/migration/legacy_fields_migration_lib.py b/tools/migration/legacy_fields_migration_lib.py index 46d5869..7e7c642 100644 --- a/tools/migration/legacy_fields_migration_lib.py +++ b/tools/migration/legacy_fields_migration_lib.py @@ -44,6 +44,8 @@ DYNAMIC_LIBRARY_LINK_ACTIONS = [ NODEPS_DYNAMIC_LIBRARY_LINK_ACTIONS = ["c++-link-nodeps-dynamic-library"] +TRANSITIVE_DYNAMIC_LIBRARY_LINK_ACTIONS = ["c++-link-dynamic-library"] + TRANSITIVE_LINK_ACTIONS = ["c++-link-executable", "c++-link-dynamic-library"] CC_LINK_EXECUTABLE = ["c++-link-executable"] @@ -329,9 +331,14 @@ def _add_flag_sets(feature, flag_sets): actions = flag_set[1] flags = flag_set[2] expand_if_all_available = flag_set[3] + not_feature = None + if len(flag_set) >= 5: + not_feature = flag_set[4] flag_set = feature.flag_set.add() if with_feature is not None: flag_set.with_feature.add().feature[:] = [with_feature] + if not_feature is not None: + flag_set.with_feature.add().not_feature[:] = [not_feature] flag_set.action[:] = actions flag_group = flag_set.flag_group.add() flag_group.expand_if_all_available[:] = expand_if_all_available @@ -413,6 +420,13 @@ def _extract_legacy_link_flag_sets_for(toolchain): if mode == "DYNAMIC": result.append( [None, NODEPS_DYNAMIC_LIBRARY_LINK_ACTIONS, lmf.linker_flag, []]) + result.append([ + None, + TRANSITIVE_DYNAMIC_LIBRARY_LINK_ACTIONS, + lmf.linker_flag, + [], + "static_link_cpp_runtimes", + ]) result.append([ feature_name, transitive_link_actions(toolchain), lmf.linker_flag, [] diff --git a/tools/migration/legacy_fields_migration_lib_test.py b/tools/migration/legacy_fields_migration_lib_test.py index 3049502..a47ad52 100644 --- a/tools/migration/legacy_fields_migration_lib_test.py +++ b/tools/migration/legacy_fields_migration_lib_test.py @@ -9,6 +9,7 @@ from tools.migration.legacy_fields_migration_lib import ALL_OBJC_LINK_ACTIONS from tools.migration.legacy_fields_migration_lib import DYNAMIC_LIBRARY_LINK_ACTIONS from tools.migration.legacy_fields_migration_lib import NODEPS_DYNAMIC_LIBRARY_LINK_ACTIONS from tools.migration.legacy_fields_migration_lib import TRANSITIVE_LINK_ACTIONS +from tools.migration.legacy_fields_migration_lib import TRANSITIVE_DYNAMIC_LIBRARY_LINK_ACTIONS from tools.migration.legacy_fields_migration_lib import CC_LINK_EXECUTABLE from tools.migration.legacy_fields_migration_lib import migrate_legacy_fields @@ -510,23 +511,31 @@ class LegacyFieldsMigrationLibTest(unittest.TestCase): self.assertEqual(output.feature[0].flag_set[3].action, NODEPS_DYNAMIC_LIBRARY_LINK_ACTIONS) - self.assertEqual(output.feature[0].flag_set[4].with_feature[0].feature[0], - "dynamic_linking_mode") + self.assertEqual( + output.feature[0].flag_set[4].with_feature[0].not_feature[0], + "static_link_cpp_runtimes") self.assertEqual(output.feature[0].flag_set[4].flag_group[0].flag, ["lmf-dynamic-flag-4"]) self.assertEqual(output.feature[0].flag_set[4].action, + TRANSITIVE_DYNAMIC_LIBRARY_LINK_ACTIONS) + + self.assertEqual(output.feature[0].flag_set[5].with_feature[0].feature[0], + "dynamic_linking_mode") + self.assertEqual(output.feature[0].flag_set[5].flag_group[0].flag, + ["lmf-dynamic-flag-4"]) + self.assertEqual(output.feature[0].flag_set[5].action, TRANSITIVE_LINK_ACTIONS) - self.assertEqual(output.feature[0].flag_set[5].flag_group[0].flag, + self.assertEqual(output.feature[0].flag_set[6].flag_group[0].flag, ["dl-flag-5"]) - self.assertEqual(output.feature[0].flag_set[5].action, + self.assertEqual(output.feature[0].flag_set[6].action, DYNAMIC_LIBRARY_LINK_ACTIONS) - self.assertEqual(output.feature[0].flag_set[6].flag_group[0].flag, + self.assertEqual(output.feature[0].flag_set[7].flag_group[0].flag, ["to-flag-6"]) - self.assertEqual(output.feature[0].flag_set[6].action, ALL_CC_LINK_ACTIONS) + self.assertEqual(output.feature[0].flag_set[7].action, ALL_CC_LINK_ACTIONS) self.assertEqual( - output.feature[0].flag_set[6].flag_group[0].expand_if_all_available, + output.feature[0].flag_set[7].flag_group[0].expand_if_all_available, ["is_cc_test"]) def test_all_linker_flag_objc_actions(self):