OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # | 2 # |
3 # Copyright 2014 The Chromium Authors. All rights reserved. | 3 # Copyright 2014 The Chromium Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 """Copies files to a directory.""" | 7 """Copies files to a directory.""" |
8 | 8 |
9 import optparse | 9 import optparse |
| 10 import os |
10 import shutil | 11 import shutil |
11 import sys | 12 import sys |
12 | 13 |
13 from util import build_utils | 14 from util import build_utils |
14 | 15 |
15 | 16 |
| 17 def _get_all_files(base): |
| 18 """Returns a list of all the files in |base|. Each entry is relative to the |
| 19 last path entry of |base|.""" |
| 20 result = [] |
| 21 dirname = os.path.dirname(base) |
| 22 for root, _, files in os.walk(base): |
| 23 result.extend([os.path.join(root[len(dirname):], f) for f in files]) |
| 24 return result |
| 25 |
| 26 |
16 def main(args): | 27 def main(args): |
17 args = build_utils.ExpandFileArgs(args) | 28 args = build_utils.ExpandFileArgs(args) |
18 | 29 |
19 parser = optparse.OptionParser() | 30 parser = optparse.OptionParser() |
20 build_utils.AddDepfileOption(parser) | 31 build_utils.AddDepfileOption(parser) |
21 | 32 |
22 parser.add_option('--dest', help='Directory to copy files to.') | 33 parser.add_option('--dest', help='Directory to copy files to.') |
23 parser.add_option('--files', action='append', | 34 parser.add_option('--files', action='append', |
24 help='List of files to copy.') | 35 help='List of files to copy.') |
25 parser.add_option('--clear', action='store_true', | 36 parser.add_option('--clear', action='store_true', |
26 help='If set, the destination directory will be deleted ' | 37 help='If set, the destination directory will be deleted ' |
27 'before copying files to it. This is highly recommended to ' | 38 'before copying files to it. This is highly recommended to ' |
28 'ensure that no stale files are left in the directory.') | 39 'ensure that no stale files are left in the directory.') |
29 parser.add_option('--stamp', help='Path to touch on success.') | 40 parser.add_option('--stamp', help='Path to touch on success.') |
30 | 41 |
31 options, _ = parser.parse_args(args) | 42 options, _ = parser.parse_args(args) |
32 | 43 |
33 if options.clear: | 44 if options.clear: |
34 build_utils.DeleteDirectory(options.dest) | 45 build_utils.DeleteDirectory(options.dest) |
35 build_utils.MakeDirectory(options.dest) | 46 build_utils.MakeDirectory(options.dest) |
36 | 47 |
37 files = [] | 48 files = [] |
38 for file_arg in options.files: | 49 for file_arg in options.files: |
39 files += build_utils.ParseGypList(file_arg) | 50 files += build_utils.ParseGypList(file_arg) |
40 | 51 |
| 52 deps = [] |
| 53 |
41 for f in files: | 54 for f in files: |
42 shutil.copy(f, options.dest) | 55 if os.path.isdir(f): |
| 56 if not options.clear: |
| 57 print ('To avoid stale files you must use --clear when copying ' |
| 58 'directories') |
| 59 sys.exit(-1) |
| 60 shutil.copytree(f, os.path.join(options.dest, os.path.basename(f))) |
| 61 deps.extend(_get_all_files(f)) |
| 62 else: |
| 63 shutil.copy(f, options.dest) |
| 64 deps.append(f) |
43 | 65 |
44 if options.depfile: | 66 if options.depfile: |
45 build_utils.WriteDepfile( | 67 build_utils.WriteDepfile( |
46 options.depfile, | 68 options.depfile, |
47 files + build_utils.GetPythonDependencies()) | 69 deps + build_utils.GetPythonDependencies()) |
48 | 70 |
49 if options.stamp: | 71 if options.stamp: |
50 build_utils.Touch(options.stamp) | 72 build_utils.Touch(options.stamp) |
51 | 73 |
52 | 74 |
53 if __name__ == '__main__': | 75 if __name__ == '__main__': |
54 sys.exit(main(sys.argv[1:])) | 76 sys.exit(main(sys.argv[1:])) |
55 | 77 |
OLD | NEW |