Repository: pantsbuild/pants

Issue:
`pants update-build-files` does not fix ersc
**Describe the bug**
```
$ pants update-build-files ::
10:47:16.19 [WARN] DEPRECATED: the target name experimental_run_shell_command is scheduled to be removed in version 2.18.0.dev0.

Instead, use `run_shell_command`, which behaves the same. Run `pants update-build-files` to automatically fix your BUILD files.
10:47:16.20 [WARN] DEPRECATED: the target name experimental_run_shell_command is scheduled to be removed in version 2.18.0.dev0.

Instead, use `run_shell_command`, which behaves the same. Run `pants update-build-files` to automatically fix your BUILD files.
10:47:27.13 [INFO] No required changes to BUILD files found.However, there may still be deprecations that `update-build-files` doesn't know how to fix. See https://www.pantsbuild.org/v2.16/docs/upgrade-tips for upgrade tips.
```

**Pants version**
2.16.0a0

**OS**
Mac M1

**Additional info**
The target is in a macro file.



Discussion:
If possible, this should also update them to have `workdir="/"`, to handle the bug fix #18335 / #18840 that changed the default value to behave like the documentation suggested.
This applies to `experimental_shell_command` too.

Resolving patch:
diff --git a/src/python/pants/backend/build_files/fix/deprecations/renamed_targets_rules.py b/src/python/pants/backend/build_files/fix/deprecations/renamed_targets_rules.py
--- a/src/python/pants/backend/build_files/fix/deprecations/renamed_targets_rules.py
+++ b/src/python/pants/backend/build_files/fix/deprecations/renamed_targets_rules.py
@@ -4,6 +4,7 @@
 from __future__ import annotations
 
 import tokenize
+from dataclasses import dataclass
 
 from pants.backend.build_files.fix.base import FixBuildFilesRequest
 from pants.backend.build_files.fix.deprecations.base import FixBUILDFileRequest, FixedBUILDFile
@@ -22,38 +23,45 @@ class RenameTargetsInFilesRequest(FixBuildFilesRequest):
     tool_subsystem = BUILDDeprecationsFixer
 
 
-class RenameTargetsInFileRequest(FrozenDict[str, str]):
+class RenameTargetsInFileRequest(FixBUILDFileRequest):
     """Deprecated target type names to new names."""
 
 
+@dataclass(frozen=True)
+class RenamedTargetTypes:
+    """Map deprecated field names to their new name, per target."""
+
+    target_renames: FrozenDict[str, str]
+
+
 @rule
 def determine_renamed_target_types(
     target_types: RegisteredTargetTypes,
-) -> RenameTargetsInFileRequest:
-    return RenameTargetsInFileRequest(
-        {
-            tgt.deprecated_alias: tgt.alias
-            for tgt in target_types.types
-            if tgt.deprecated_alias is not None
-        }
+) -> RenamedTargetTypes:
+    return RenamedTargetTypes(
+        FrozenDict(
+            {
+                tgt.deprecated_alias: tgt.alias
+                for tgt in target_types.types
+                if tgt.deprecated_alias is not None
+            }
+        )
     )
 
 
-class RenameRequest(FixBUILDFileRequest):
-    pass
-
-
 @rule
 def fix_single(
-    request: RenameRequest,
-    renamed_target_types: RenameTargetsInFileRequest,
+    request: RenameTargetsInFileRequest,
+    renamed_target_types: RenamedTargetTypes,
 ) -> FixedBUILDFile:
     tokens = request.tokenize()
 
     def should_be_renamed(token: tokenize.TokenInfo) -> bool:
         no_indentation = token.start[1] == 0
         if not (
-            token.type is tokenize.NAME and token.string in renamed_target_types and no_indentation
+            token.type is tokenize.NAME
+            and token.string in renamed_target_types.target_renames
+            and no_indentation
         ):
             return False
         # Ensure that the next token is `(`
@@ -70,7 +78,7 @@ def should_be_renamed(token: tokenize.TokenInfo) -> bool:
         line_index = token.start[0] - 1
         line = updated_text_lines[line_index]
         suffix = line[token.end[1] :]
-        new_symbol = renamed_target_types[token.string]
+        new_symbol = renamed_target_types.target_renames[token.string]
         updated_text_lines[line_index] = f"{new_symbol}{suffix}"
 
     return FixedBUILDFile(request.path, content="".join(updated_text_lines).encode("utf-8"))
@@ -82,7 +90,7 @@ async def fix(
 ) -> FixResult:
     digest_contents = await Get(DigestContents, Digest, request.snapshot.digest)
     fixed_contents = await MultiGet(
-        Get(FixedBUILDFile, RenameRequest(file_content.path, file_content.content))
+        Get(FixedBUILDFile, RenameTargetsInFileRequest(file_content.path, file_content.content))
         for file_content in digest_contents
     )
     snapshot = await Get(
diff --git a/src/python/pants/core/goals/update_build_files.py b/src/python/pants/core/goals/update_build_files.py
--- a/src/python/pants/core/goals/update_build_files.py
+++ b/src/python/pants/core/goals/update_build_files.py
@@ -382,7 +382,7 @@ async def maybe_rename_deprecated_targets(
     old_bytes = "\n".join(request.lines).encode("utf-8")
     new_content = await Get(
         FixedBUILDFile,
-        renamed_fields_rules.RenameFieldsInFileRequest(path=request.path, content=old_bytes),
+        renamed_targets_rules.RenameTargetsInFileRequest(path=request.path, content=old_bytes),
     )
 
     return RewrittenBuildFile(


Test patch:
diff --git a/src/python/pants/backend/build_files/fix/deprecations/renamed_targets_rules_test.py b/src/python/pants/backend/build_files/fix/deprecations/renamed_targets_rules_test.py
--- a/src/python/pants/backend/build_files/fix/deprecations/renamed_targets_rules_test.py
+++ b/src/python/pants/backend/build_files/fix/deprecations/renamed_targets_rules_test.py
@@ -6,10 +6,11 @@
 import pytest
 
 from pants.backend.build_files.fix.deprecations.renamed_targets_rules import (
-    RenameRequest,
+    RenamedTargetTypes,
     RenameTargetsInFileRequest,
     fix_single,
 )
+from pants.util.frozendict import FrozenDict
 
 
 @pytest.mark.parametrize(
@@ -29,8 +30,8 @@
 def test_rename_deprecated_target_types_noops(lines: list[str]) -> None:
     content = "\n".join(lines).encode("utf-8")
     result = fix_single(
-        RenameRequest("BUILD", content=content),
-        RenameTargetsInFileRequest({"deprecated_name": "new_name"}),
+        RenameTargetsInFileRequest("BUILD", content=content),
+        RenamedTargetTypes(FrozenDict({"deprecated_name": "new_name"})),
     )
     assert result.content == content
 
@@ -46,7 +47,7 @@ def test_rename_deprecated_target_types_noops(lines: list[str]) -> None:
 )
 def test_rename_deprecated_target_types_rewrite(lines: list[str], expected: list[str]) -> None:
     result = fix_single(
-        RenameRequest("BUILD", content="\n".join(lines).encode("utf-8")),
-        RenameTargetsInFileRequest({"deprecated_name": "new_name"}),
+        RenameTargetsInFileRequest("BUILD", content="\n".join(lines).encode("utf-8")),
+        RenamedTargetTypes(FrozenDict({"deprecated_name": "new_name"})),
     )
     assert result.content == "\n".join(expected).encode("utf-8")