Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(62)

Side by Side Diff: third_party/WebKit/Source/devtools/scripts/build/build_debug_applications.py

Issue 2464463002: Revert of DevTools: clean up scripts folder (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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 """
9 Builds applications in debug mode:
10 - Copies the module directories into their destinations.
11 - Copies app.html as-is.
12 """
13
14 from os import path
15 from os.path import join
16 import os
17 import shutil
18 import sys
19
20 import modular_build
21
22
23 def main(argv):
24 try:
25 input_path_flag_index = argv.index('--input_path')
26 input_path = argv[input_path_flag_index + 1]
27 output_path_flag_index = argv.index('--output_path')
28 output_path = argv[output_path_flag_index + 1]
29 application_names = argv[1:input_path_flag_index]
30 except:
31 print('Usage: %s app_1 app_2 ... app_N --input_path <input_path> --outpu t_path <output_path>' % argv[0])
32 raise
33
34 loader = modular_build.DescriptorLoader(input_path)
35 for app in application_names:
36 descriptors = loader.load_application(app + '.json')
37 builder = DebugBuilder(app, descriptors, input_path, output_path)
38 builder.build_app()
39
40
41 def symlink_or_copy_file(src, dest, safe=False):
42 if safe and path.exists(dest):
43 os.remove(dest)
44 if hasattr(os, 'symlink'):
45 os.symlink(src, dest)
46 else:
47 shutil.copy(src, dest)
48
49
50 def symlink_or_copy_dir(src, dest):
51 if path.exists(dest):
52 shutil.rmtree(dest)
53 for src_dir, dirs, files in os.walk(src):
54 subpath = path.relpath(src_dir, src)
55 dest_dir = path.normpath(join(dest, subpath))
56 os.mkdir(dest_dir)
57 for name in files:
58 src_name = join(os.getcwd(), src_dir, name)
59 dest_name = join(dest_dir, name)
60 symlink_or_copy_file(src_name, dest_name)
61
62
63 # Outputs:
64 # <app_name>.html as-is
65 # <app_name>.js as-is
66 # <module_name>/<all_files>
67 class DebugBuilder(object):
68 def __init__(self, application_name, descriptors, application_dir, output_di r):
69 self.application_name = application_name
70 self.descriptors = descriptors
71 self.application_dir = application_dir
72 self.output_dir = output_dir
73
74 def app_file(self, extension):
75 return self.application_name + '.' + extension
76
77 def build_app(self):
78 if self.descriptors.has_html:
79 self._build_html()
80 for filename in os.listdir(self.application_dir):
81 src = join(os.getcwd(), self.application_dir, filename)
82 if os.path.isdir(src):
83 symlink_or_copy_dir(src, join(self.output_dir, filename))
84 else:
85 symlink_or_copy_file(src, join(self.output_dir, filename), safe= True)
86
87 def _build_html(self):
88 html_name = self.app_file('html')
89 symlink_or_copy_file(join(os.getcwd(), self.application_dir, html_name), join(self.output_dir, html_name), True)
90
91
92 if __name__ == '__main__':
93 sys.exit(main(sys.argv))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698