pw_toolchain: Add copy to GN dummy toolchain

Adds a .gni to share the stamp and copy tools between the dummy
toolchain and generated toolchains.

Change-Id: I04e044c293854b60ad8117b1a603aa1993891d92
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/24441
Commit-Queue: Armando Montanez <amontanez@google.com>
Reviewed-by: Keir Mierle <keir@google.com>
Reviewed-by: Wyatt Hepler <hepler@google.com>
diff --git a/pw_toolchain/universal_tools.gni b/pw_toolchain/universal_tools.gni
new file mode 100644
index 0000000..8fcc062
--- /dev/null
+++ b/pw_toolchain/universal_tools.gni
@@ -0,0 +1,50 @@
+# Copyright 2020 The Pigweed Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy of
+# the License at
+#
+#     https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+pw_universal_copy = {
+  if (host_os == "win") {
+    command = "cp -af {{source}} {{output}}"
+  } else {
+    # Use a hard link if possible as this is faster. Also, Mac doesn't
+    # preserve timestamps properly with cp -af.
+    fallback_command = string_join(" ",
+                                   [
+                                     "rm -rf",
+                                     "{{output}}",
+                                     "&&",
+                                     "cp -af",
+                                     "{{source}}",
+                                     "{{output}}",
+                                   ])
+    command = string_join(" ",
+                          [
+                            "ln -f",
+                            "{{source}}",
+                            "{{output}}",
+                            "2>/dev/null",
+                            "||",
+                            "($fallback_command)",
+                          ])
+  }
+  description = "cp {{source}} {{output}}"
+}
+
+pw_universal_stamp = {
+  if (host_os == "win") {
+    command = "cmd /c type nul > \"{{output}}\""
+  } else {
+    command = "touch {{output}}"
+  }
+  description = "stamp {{output}}"
+}