blob: 701d614f014242b38bbcb173a528d9e2176982e1 [file] [log] [blame]
Blink Reformat4c46d092018-04-07 15:32:37 +00001#!/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"""
8Builds applications in debug mode:
9- Copies the module directories into their destinations.
10- Copies app.html as-is.
11"""
12
13from os import path
14from os.path import join
15import os
16import shutil
17import sys
18
19import modular_build
20
21
22def 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 Reformat4c46d092018-04-07 15:32:37 +000028 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 Lippe118843d2019-07-26 18:38:51 +000032 symlink_dir_or_copy(input_path, output_path)
Blink Reformat4c46d092018-04-07 15:32:37 +000033
34
Tim van der Lippe118843d2019-07-26 18:38:51 +000035def 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
52def copy_file(src, dest, safe=False):
Blink Reformat4c46d092018-04-07 15:32:37 +000053 if safe and path.exists(dest):
54 os.remove(dest)
Tim van der Lippe118843d2019-07-26 18:38:51 +000055 shutil.copy(src, dest)
Blink Reformat4c46d092018-04-07 15:32:37 +000056
57
Tim van der Lippe118843d2019-07-26 18:38:51 +000058def copy_dir(src, dest):
Blink Reformat4c46d092018-04-07 15:32:37 +000059 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 Lippe118843d2019-07-26 18:38:51 +000068 copy_file(src_name, dest_name)
Blink Reformat4c46d092018-04-07 15:32:37 +000069
70
71if __name__ == '__main__':
72 sys.exit(main(sys.argv))