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."""
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|."""
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
])
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
)
45 build_utils
.DeleteDirectory(options
.dest
)
46 build_utils
.MakeDirectory(options
.dest
)
49 for file_arg
in options
.files
:
50 files
+= build_utils
.ParseGypList(file_arg
)
57 print ('To avoid stale files you must use --clear when copying '
60 shutil
.copytree(f
, os
.path
.join(options
.dest
, os
.path
.basename(f
)))
61 deps
.extend(_get_all_files(f
))
63 shutil
.copy(f
, options
.dest
)
67 build_utils
.WriteDepfile(
69 deps
+ build_utils
.GetPythonDependencies())
72 build_utils
.Touch(options
.stamp
)
75 if __name__
== '__main__':
76 sys
.exit(main(sys
.argv
[1:]))