pw_toolchain: Fix cp command for Windows
The `cp` executable is not always present on the Windows machine.
This commit adds the fallback mechanism based on the python script
to simulate the desired behaviour of `cp -af` command. The original
behaviour has been kept untouched.
Change-Id: I423542abfdf960ab29ba719f889bf143b462411b
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/29780
Reviewed-by: Michael Spang <spang@google.com>
Commit-Queue: Michael Spang <spang@google.com>
diff --git a/pw_toolchain/universal_tools.gni b/pw_toolchain/universal_tools.gni
index 8fcc062..820276d 100644
--- a/pw_toolchain/universal_tools.gni
+++ b/pw_toolchain/universal_tools.gni
@@ -12,9 +12,18 @@
# License for the specific language governing permissions and limitations under
# the License.
+import("//build_overrides/pigweed.gni")
+
pw_universal_copy = {
if (host_os == "win") {
- command = "cp -af {{source}} {{output}}"
+ cp_command = "cp -af {{source}} {{output}}"
+
+ # Use python script in absence of cp command.
+ copy_tool_path =
+ rebase_path(dir_pw_toolchain) + "/py/pw_toolchain/copy_with_metadata.py"
+ fallback_command = "python $copy_tool_path {{source}} {{output}}"
+
+ command = "cmd /c \"($cp_command > NUL 2>&1) || ($fallback_command)\""
} else {
# Use a hard link if possible as this is faster. Also, Mac doesn't
# preserve timestamps properly with cp -af.