From 00f67667998284656d764c6921b3ab06fc7b48cb Mon Sep 17 00:00:00 2001 From: "opencode-agent[bot]" Date: Sat, 24 Jan 2026 17:10:37 +0000 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=90=9B=20fix:=20use=20cross-platform?= =?UTF-8?q?=20file=20copy=20in=20rename=5Ffiles=20rule?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace Windows-specific cmd /c copy with ctx.actions.run_shell() using platform detection. This ensures compatibility with Linux/macOS systems while maintaining Windows support. --- rule/rename_files.bzl | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/rule/rename_files.bzl b/rule/rename_files.bzl index 45bab63..5b4852d 100644 --- a/rule/rename_files.bzl +++ b/rule/rename_files.bzl @@ -15,6 +15,9 @@ def _rename_files_impl(ctx): """Implementation of the rename_files rule.""" output_files = [] + # 检测当前平台是否为 Windows + is_windows = ctx.target_platform_has_constraint(ctx.attr._windows_constraint[platform_common.ConstraintValueInfo]) + for src in ctx.files.srcs: # 创建重命名后的输出文件 if "_processed.mcfunction" in src.basename: @@ -27,15 +30,25 @@ def _rename_files_impl(ctx): output_file = ctx.actions.declare_file(output_name, sibling = src) output_files.append(output_file) - # 复制文件并重命名 - ctx.actions.run( - inputs = [src], - outputs = [output_file], - executable = "cmd", - arguments = ["/c", "copy", src.path.replace("/", "\\"), output_file.path.replace("/", "\\")], - mnemonic = "RenameFile", - progress_message = "Renaming %s to %s" % (src.basename, output_name), - ) + # 跨平台复制文件并重命名 + if is_windows: + # Windows 使用 cmd copy 命令 + ctx.actions.run_shell( + inputs = [src], + outputs = [output_file], + command = "copy \"{}\" \"{}\"".format(src.path.replace("/", "\\"), output_file.path.replace("/", "\\")), + mnemonic = "RenameFile", + progress_message = "Renaming %s to %s" % (src.basename, output_name), + ) + else: + # Unix-like 系统使用 cp 命令 + ctx.actions.run_shell( + inputs = [src], + outputs = [output_file], + command = "cp \"{}\" \"{}\"".format(src.path, output_file.path), + mnemonic = "RenameFile", + progress_message = "Renaming %s to %s" % (src.basename, output_name), + ) return [DefaultInfo(files = depset(output_files))] @@ -46,5 +59,8 @@ rename_files = rule( allow_empty = True, allow_files = [".mcfunction", ".raw.mcfunction"], ), + "_windows_constraint": attr.label( + default = "@platforms//os:windows", + ), }, ) \ No newline at end of file From a02f263f840d5bec5d78a093fa46b31362a374bf Mon Sep 17 00:00:00 2001 From: "opencode-agent[bot]" Date: Sat, 24 Jan 2026 17:33:44 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=90=9B=20fix:=20add=20force=20flags?= =?UTF-8?q?=20to=20cross-platform=20file=20copy=20in=20rename=5Ffiles=20ru?= =?UTF-8?q?le?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Windows: use `copy /y` to suppress overwrite prompts - Unix: use `cp -f` to force overwrite - Ensures robust file copying across platforms --- rule/rename_files.bzl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/rule/rename_files.bzl b/rule/rename_files.bzl index 5b4852d..9aa0cb9 100644 --- a/rule/rename_files.bzl +++ b/rule/rename_files.bzl @@ -32,20 +32,20 @@ def _rename_files_impl(ctx): # 跨平台复制文件并重命名 if is_windows: - # Windows 使用 cmd copy 命令 + # Windows 使用 cmd copy /y 命令,/y 选项避免覆盖提示 ctx.actions.run_shell( inputs = [src], outputs = [output_file], - command = "copy \"{}\" \"{}\"".format(src.path.replace("/", "\\"), output_file.path.replace("/", "\\")), + command = "copy /y \"{}\" \"{}\"".format(src.path.replace("/", "\\"), output_file.path.replace("/", "\\")), mnemonic = "RenameFile", progress_message = "Renaming %s to %s" % (src.basename, output_name), ) else: - # Unix-like 系统使用 cp 命令 + # Unix-like 系统使用 cp -f 命令,-f 选项强制覆盖 ctx.actions.run_shell( inputs = [src], outputs = [output_file], - command = "cp \"{}\" \"{}\"".format(src.path, output_file.path), + command = "cp -f \"{}\" \"{}\"".format(src.path, output_file.path), mnemonic = "RenameFile", progress_message = "Renaming %s to %s" % (src.basename, output_name), )