Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / build / android / gyp / copy_ex.py
bloba474e770654f8eebfa13392e9086b4ed96b7a996
1 #!/usr/bin/env python
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
5 # found in the LICENSE file.
7 """Copies files to a directory."""
9 import optparse
10 import os
11 import shutil
12 import sys
14 from util import build_utils
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
27 def main(args):
28 args = build_utils.ExpandFileArgs(args)
30 parser = optparse.OptionParser()
31 build_utils.AddDepfileOption(parser)
33 parser.add_option('--dest', help='Directory to copy files to.')
34 parser.add_option('--files', action='append',
35 help='List of files to copy.')
36 parser.add_option('--clear', action='store_true',
37 help='If set, the destination directory will be deleted '
38 'before copying files to it. This is highly recommended to '
39 'ensure that no stale files are left in the directory.')
40 parser.add_option('--stamp', help='Path to touch on success.')
42 options, _ = parser.parse_args(args)
44 if options.clear:
45 build_utils.DeleteDirectory(options.dest)
46 build_utils.MakeDirectory(options.dest)
48 files = []
49 for file_arg in options.files:
50 files += build_utils.ParseGypList(file_arg)
52 deps = []
54 for f in files:
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)
66 if options.depfile:
67 build_utils.WriteDepfile(
68 options.depfile,
69 deps + build_utils.GetPythonDependencies())
71 if options.stamp:
72 build_utils.Touch(options.stamp)
75 if __name__ == '__main__':
76 sys.exit(main(sys.argv[1:]))