Make cc_embed_data.bzl forward compatible with removal of legacy crosstool fields

RELNOTES: None
PiperOrigin-RevId: 228301880
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 @@
       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 @@
       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 @@
     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 @@
 
   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 @@
     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 @@
 
   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 @@
     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("""