blob: eafc0e88f431907d985c761ba0eb2307d8b0d2d9 [file] [log] [blame]
Armando Montanez7cd6f082020-11-11 18:36:15 -08001# Copyright 2020 The Pigweed Authors
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may not
4# use this file except in compliance with the License. You may obtain a copy of
5# the License at
6#
7# https://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations under
13# the License.
14
Duda, Lukasz70c630d2021-01-15 22:53:23 +010015import("//build_overrides/pigweed.gni")
16
Armando Montanez7cd6f082020-11-11 18:36:15 -080017pw_universal_copy = {
18 if (host_os == "win") {
Duda, Lukasz70c630d2021-01-15 22:53:23 +010019 cp_command = "cp -af {{source}} {{output}}"
20
21 # Use python script in absence of cp command.
Michael Spangc8b93902021-05-30 15:53:56 -040022 copy_tool_path = rebase_path(dir_pw_toolchain, root_build_dir) +
23 "/py/pw_toolchain/copy_with_metadata.py"
Duda, Lukasz70c630d2021-01-15 22:53:23 +010024 fallback_command = "python $copy_tool_path {{source}} {{output}}"
25
26 command = "cmd /c \"($cp_command > NUL 2>&1) || ($fallback_command)\""
Armando Montanez7cd6f082020-11-11 18:36:15 -080027 } else {
28 # Use a hard link if possible as this is faster. Also, Mac doesn't
29 # preserve timestamps properly with cp -af.
30 fallback_command = string_join(" ",
31 [
32 "rm -rf",
33 "{{output}}",
34 "&&",
35 "cp -af",
36 "{{source}}",
37 "{{output}}",
38 ])
39 command = string_join(" ",
40 [
41 "ln -f",
42 "{{source}}",
43 "{{output}}",
44 "2>/dev/null",
45 "||",
46 "($fallback_command)",
47 ])
48 }
49 description = "cp {{source}} {{output}}"
50}
51
52pw_universal_stamp = {
53 if (host_os == "win") {
54 command = "cmd /c type nul > \"{{output}}\""
55 } else {
56 command = "touch {{output}}"
57 }
58 description = "stamp {{output}}"
59}