@@ -522,6 +522,31 @@ def _extract(mrctx, *, archive, supports_whl_extraction = False, **kwargs):
522522 if not mrctx .delete (archive ):
523523 fail ("Failed to remove the symlink after extracting" )
524524
525+ def _rename (mrctx , src , dest ):
526+ """Rename a file or directory.
527+
528+ TODO: remove when the earliest supported bazel version is at least 8.0.
529+
530+ Args:
531+ mrctx: The repository context.
532+ src: The source path.
533+ dest: The destination path.
534+ """
535+ if hasattr (mrctx , "rename" ):
536+ mrctx .rename (src , dest )
537+ return
538+
539+ # Fallback for Bazel versions that don't have mrctx.rename.
540+ os_name = _get_platforms_os_name (mrctx )
541+ if os_name == "windows" :
542+ # On Windows, use 'cmd.exe /c move'
543+ result = mrctx .execute (["cmd.exe" , "/C" , "move" , "/Y" , str (src ), str (dest )])
544+ else :
545+ result = mrctx .execute (["mv" , str (src ), str (dest )])
546+
547+ if result .return_code != 0 :
548+ fail ("Failed to rename {} to {}: {}" .format (src , dest , result .stderr ))
549+
525550repo_utils = struct (
526551 # keep sorted
527552 execute_checked = _execute_checked ,
@@ -535,6 +560,7 @@ repo_utils = struct(
535560 mkdir = _mkdir ,
536561 norm_path = _norm_path ,
537562 relative_to = _relative_to ,
563+ rename = _rename ,
538564 is_relative_to = _is_relative_to ,
539565 repo_root_relative_path = _repo_root_relative_path ,
540566 which_checked = _which_checked ,
0 commit comments