def _extract_legacy_link_flag_sets_for()

in tools/migration/legacy_fields_migration_lib.py [0:0]


def _extract_legacy_link_flag_sets_for(toolchain):
  """Get flag sets for default_link_flags feature."""
  result = []

  # Migrate linker_flag
  if toolchain.linker_flag:
    result.append([None, link_actions(toolchain), toolchain.linker_flag, []])

  # 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

    if cmf.linker_flag and not _get_feature(toolchain, mode):
      feature = toolchain.feature.add()
      feature.name = mode

    if cmf.linker_flag:
      result.append([mode, link_actions(toolchain), cmf.linker_flag, []])

  # Migrate linker_flags from linking_mode_flags
  for lmf in toolchain.linking_mode_flags:
    mode = crosstool_config_pb2.LinkingMode.Name(lmf.mode)
    feature_name = LINKING_MODE_TO_FEATURE_NAME.get(mode)
    # if the feature is already there, we don't migrate, lmf is not used
    if _get_feature(toolchain, feature_name):
      continue

    if lmf.linker_flag:
      feature = toolchain.feature.add()
      feature.name = feature_name
      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,
            executable_link_actions(toolchain), lmf.linker_flag, []
        ])
      elif mode == "MOSTLY_STATIC":
        result.append(
            [feature_name,
             CC_LINK_EXECUTABLE, lmf.linker_flag, []])
      else:
        result.append(
           [feature_name,
            link_actions(toolchain), lmf.linker_flag, []])

  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([
        None,
        link_actions(toolchain), toolchain.test_only_linker_flag,
        ["is_cc_test"]
    ])

  return result