| 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 '''Produces various output formats from a set of JavaScript files with | 7 '''Produces various output formats from a set of JavaScript files with |
| 8 closure style require/provide calls. | 8 closure style require/provide calls. |
| 9 | 9 |
| 10 Scans one or more directory trees for JavaScript files. Then, from a | 10 Scans one or more directory trees for JavaScript files. Then, from a |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 - bundle: a concatenation of all the files, separated by newlines is output. | 23 - bundle: a concatenation of all the files, separated by newlines is output. |
| 24 | 24 |
| 25 - compressed_bundle: A bundle where non-significant whitespace, including | 25 - compressed_bundle: A bundle where non-significant whitespace, including |
| 26 comments, has been stripped is output. | 26 comments, has been stripped is output. |
| 27 | 27 |
| 28 - copy: the files are copied, or hard linked if possible, to the destination | 28 - copy: the files are copied, or hard linked if possible, to the destination |
| 29 directory. In this case, no output is generated. | 29 directory. In this case, no output is generated. |
| 30 ''' | 30 ''' |
| 31 | 31 |
| 32 | 32 |
| 33 import errno |
| 33 import optparse | 34 import optparse |
| 34 import os | 35 import os |
| 35 import re | 36 import re |
| 36 import shutil | 37 import shutil |
| 37 import sys | 38 import sys |
| 38 | 39 |
| 39 _SCRIPT_DIR = os.path.realpath(os.path.dirname(__file__)) | 40 _SCRIPT_DIR = os.path.realpath(os.path.dirname(__file__)) |
| 40 _CHROME_SOURCE = os.path.realpath( | 41 _CHROME_SOURCE = os.path.realpath( |
| 41 os.path.join(_SCRIPT_DIR, *[os.path.pardir] * 6)) | 42 os.path.join(_SCRIPT_DIR, *[os.path.pardir] * 6)) |
| 42 sys.path.insert(0, os.path.join( | 43 sys.path.insert(0, os.path.join( |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 Die('COMPILED var assignment not found in %s' % base.GetInPath()) | 227 Die('COMPILED var assignment not found in %s' % base.GetInPath()) |
| 227 sources[base.GetInPath()] = SourceWithPaths( | 228 sources[base.GetInPath()] = SourceWithPaths( |
| 228 new_content, | 229 new_content, |
| 229 base.GetInPath(), | 230 base.GetInPath(), |
| 230 base.GetOutPath()) | 231 base.GetOutPath()) |
| 231 | 232 |
| 232 def LinkOrCopyFiles(sources, dest_dir): | 233 def LinkOrCopyFiles(sources, dest_dir): |
| 233 '''Copies a list of sources to a destination directory.''' | 234 '''Copies a list of sources to a destination directory.''' |
| 234 | 235 |
| 235 def LinkOrCopyOneFile(src, dst): | 236 def LinkOrCopyOneFile(src, dst): |
| 236 if not os.path.exists(os.path.dirname(dst)): | 237 try: |
| 237 os.makedirs(os.path.dirname(dst)) | 238 os.makedirs(os.path.dirname(dst)) |
| 239 except OSError as err: |
| 240 if err.errno != errno.EEXIST: |
| 241 raise |
| 238 if os.path.exists(dst): | 242 if os.path.exists(dst): |
| 239 os.unlink(dst) | 243 os.unlink(dst) |
| 240 try: | 244 try: |
| 241 os.link(src, dst) | 245 os.link(src, dst) |
| 242 except: | 246 except: |
| 243 shutil.copy(src, dst) | 247 shutil.copy(src, dst) |
| 244 | 248 |
| 245 for source in sources: | 249 for source in sources: |
| 246 LinkOrCopyOneFile(source.GetInPath(), | 250 LinkOrCopyOneFile(source.GetInPath(), |
| 247 os.path.join(dest_dir, source.GetOutPath())) | 251 os.path.join(dest_dir, source.GetOutPath())) |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 finally: | 373 finally: |
| 370 if options.output_file: | 374 if options.output_file: |
| 371 out_file.close() | 375 out_file.close() |
| 372 if options.stampfile: | 376 if options.stampfile: |
| 373 WriteStampfile(options.stampfile) | 377 WriteStampfile(options.stampfile) |
| 374 if options.depfile: | 378 if options.depfile: |
| 375 WriteDepfile(options.depfile, options.output_file, bundle.GetInPaths()) | 379 WriteDepfile(options.depfile, options.output_file, bundle.GetInPaths()) |
| 376 | 380 |
| 377 if __name__ == '__main__': | 381 if __name__ == '__main__': |
| 378 main() | 382 main() |
| OLD | NEW |