Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | # -*- coding: UTF-8 -*- |
| 3 | # |
| 4 | # Copyright 2016 The Chromium Authors. All rights reserved. |
| 5 | # Use of this source code is governed by a BSD-style license that can be |
| 6 | # found in the LICENSE file. |
| 7 | """ |
| 8 | Builds applications in debug mode: |
| 9 | - Copies the module directories into their destinations. |
| 10 | - Copies app.html as-is. |
| 11 | """ |
| 12 | |
| 13 | from os import path |
| 14 | from os.path import join |
| 15 | import os |
| 16 | import shutil |
| 17 | import sys |
| 18 | |
| 19 | import modular_build |
| 20 | |
| 21 | |
| 22 | def main(argv): |
| 23 | try: |
| 24 | input_path_flag_index = argv.index('--input_path') |
| 25 | input_path = argv[input_path_flag_index + 1] |
| 26 | output_path_flag_index = argv.index('--output_path') |
| 27 | output_path = argv[output_path_flag_index + 1] |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 28 | except: |
| 29 | print('Usage: %s app_1 app_2 ... app_N --input_path <input_path> --output_path <output_path>' % argv[0]) |
| 30 | raise |
| 31 | |
Tim van der Lippe | 118843d | 2019-07-26 18:38:51 +0000 | [diff] [blame] | 32 | symlink_dir_or_copy(input_path, output_path) |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 33 | |
| 34 | |
Tim van der Lippe | 118843d | 2019-07-26 18:38:51 +0000 | [diff] [blame] | 35 | def symlink_dir_or_copy(src, dest): |
| 36 | if hasattr(os, 'symlink'): |
| 37 | if path.exists(dest): |
| 38 | if os.path.islink(dest): |
| 39 | os.unlink(dest) |
| 40 | else: |
| 41 | shutil.rmtree(dest) |
| 42 | os.symlink(join(os.getcwd(), src), dest) |
| 43 | else: |
| 44 | for filename in os.listdir(src): |
| 45 | new_src = join(os.getcwd(), src, filename) |
| 46 | if os.path.isdir(new_src): |
| 47 | copy_dir(new_src, join(dest, filename)) |
| 48 | else: |
| 49 | copy_file(new_src, join(dest, filename), safe=True) |
| 50 | |
| 51 | |
| 52 | def copy_file(src, dest, safe=False): |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 53 | if safe and path.exists(dest): |
| 54 | os.remove(dest) |
Tim van der Lippe | 118843d | 2019-07-26 18:38:51 +0000 | [diff] [blame] | 55 | shutil.copy(src, dest) |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 56 | |
| 57 | |
Tim van der Lippe | 118843d | 2019-07-26 18:38:51 +0000 | [diff] [blame] | 58 | def copy_dir(src, dest): |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 59 | if path.exists(dest): |
| 60 | shutil.rmtree(dest) |
| 61 | for src_dir, dirs, files in os.walk(src): |
| 62 | subpath = path.relpath(src_dir, src) |
| 63 | dest_dir = path.normpath(join(dest, subpath)) |
| 64 | os.mkdir(dest_dir) |
| 65 | for name in files: |
| 66 | src_name = join(os.getcwd(), src_dir, name) |
| 67 | dest_name = join(dest_dir, name) |
Tim van der Lippe | 118843d | 2019-07-26 18:38:51 +0000 | [diff] [blame] | 68 | copy_file(src_name, dest_name) |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 69 | |
| 70 | |
| 71 | if __name__ == '__main__': |
| 72 | sys.exit(main(sys.argv)) |