• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# 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
15import("//build_overrides/pigweed.gni")
16
17pw_universal_copy = {
18  if (host_os == "win") {
19    cp_command = "cp -af {{source}} {{output}}"
20
21    # Use python script in absence of cp command.
22    copy_tool_path =
23        rebase_path(dir_pw_toolchain) + "/py/pw_toolchain/copy_with_metadata.py"
24    fallback_command = "python $copy_tool_path {{source}} {{output}}"
25
26    command = "cmd /c \"($cp_command > NUL 2>&1) || ($fallback_command)\""
27  } 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}
60