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

Side by Side Diff: chrome/browser/resources/vulcanize.py

Issue 2670723002: [MD History] Vulcanize as part of GN build. (Closed)
Patch Set: address nits Created 3 years, 10 months 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
« no previous file with comments | « chrome/browser/resources/vulcanize.gni ('k') | chrome/browser/resources/vulcanize_gn.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
dpapad 2017/02/10 18:31:18 FYI, this file is still referenced by https://cs.c
2 # Copyright 2016 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 import os
7 import subprocess
8 import sys
9 import tempfile
10
11
12 # See //docs/vulcanize.md for instructions on installing prerequistes and
13 # running the vulcanize build.
14
15 _HERE_PATH = os.path.join(os.path.dirname(__file__))
16 _SRC_PATH = os.path.normpath(os.path.join(_HERE_PATH, '..', '..', '..'))
17
18 sys.path.append(os.path.join(_SRC_PATH, 'third_party', 'node'))
19 import node
20 import node_modules
21
22
23 _RESOURCES_PATH = os.path.join(_SRC_PATH, 'ui', 'webui', 'resources')
24
25 _CR_ELEMENTS_PATH = os.path.join(_RESOURCES_PATH, 'cr_elements')
26 _CSS_RESOURCES_PATH = os.path.join(_RESOURCES_PATH, 'css')
27 _HTML_RESOURCES_PATH = os.path.join(_RESOURCES_PATH, 'html')
28 _JS_RESOURCES_PATH = os.path.join(_RESOURCES_PATH, 'js')
29 _POLYMER_PATH = os.path.join(
30 _SRC_PATH, 'third_party', 'polymer', 'v1_0', 'components-chromium')
31
32 _VULCANIZE_BASE_ARGS = [
33 '--exclude', 'crisper.js',
34
35 # These files are already combined and minified.
36 '--exclude', 'chrome://resources/html/polymer.html',
37 '--exclude', 'web-animations-next-lite.min.js',
38
39 # These files are dynamically created by C++.
40 '--exclude', 'load_time_data.js',
41 '--exclude', 'strings.js',
42 '--exclude', 'text_defaults.css',
43 '--exclude', 'text_defaults_md.css',
44
45 '--inline-css',
46 '--inline-scripts',
47
48 '--redirect', '"chrome://resources/cr_elements/|%s"' % _CR_ELEMENTS_PATH,
49 '--redirect', '"chrome://resources/css/|%s"' % _CSS_RESOURCES_PATH,
50 '--redirect', '"chrome://resources/html/|%s"' % _HTML_RESOURCES_PATH,
51 '--redirect', '"chrome://resources/js/|%s"' % _JS_RESOURCES_PATH,
52 '--redirect', '"chrome://resources/polymer/v1_0/|%s"' % _POLYMER_PATH,
53
54 '--strip-comments',
55 ]
56
57
58 def _run_node(cmd_parts, stdout=None):
59 cmd = " ".join([node.GetBinaryPath()] + cmd_parts)
60 process = subprocess.Popen(
61 cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
62 stdout, stderr = process.communicate()
63
64 if stderr:
65 print >> sys.stderr, '%s failed: %s' % (cmd, stderr)
66 raise
67
68 return stdout
69
70
71 def _vulcanize(directory, host, html_in_file, html_out_file='vulcanized.html',
72 js_out_file='crisper.js', extra_args=None):
73 print 'Vulcanizing %s/%s' % (directory, html_in_file)
74
75 target_path = os.path.join(_HERE_PATH, directory)
76 html_in_path = os.path.join(target_path, html_in_file)
77 html_out_path = os.path.join(target_path, html_out_file)
78 js_out_path = os.path.join(target_path, js_out_file)
79 extra_args = extra_args or []
80
81 output = _run_node(
82 [node_modules.PathToVulcanize()] + _VULCANIZE_BASE_ARGS + extra_args +
83 ['--redirect', '"chrome://%s/|%s"' % (host, target_path), html_in_path])
84
85 with tempfile.NamedTemporaryFile(mode='wt+', delete=False) as tmp:
86 # Grit includes are not supported, use HTML imports instead.
87 tmp.write(output.replace(
88 '<include src="', '<include src-disabled="'))
89
90 try:
91 _run_node([node_modules.PathToCrisper(), '--source', tmp.name,
92 '--script-in-head', 'false', '--html', html_out_path,
93 '--js', js_out_path])
94
95 # TODO(tsergeant): Remove when JS resources are minified by default:
96 # crbug.com/619091.
97 _run_node([node_modules.PathToUglifyJs(), js_out_path,
98 '--comments', '"/Copyright|license|LICENSE|\<\/?if/"',
99 '--output', js_out_path])
100 finally:
101 os.remove(tmp.name)
102
103
104 def _css_build(directory, files):
105 target_path = os.path.join(_HERE_PATH, directory)
106 paths = map(lambda f: os.path.join(target_path, f), files)
107
108 _run_node([node_modules.PathToPolymerCssBuild()] + paths)
109
110
111 def main():
112 # Already loaded by history.html:
113 history_extra_args = ['--exclude', 'chrome://resources/html/util.html',
114 '--exclude', 'chrome://history/constants.html']
115 _vulcanize(directory='md_history', host='history', html_in_file='app.html',
116 html_out_file='app.vulcanized.html', js_out_file='app.crisper.js',
117 extra_args=history_extra_args)
118
119 # Ensures that no file transitively imported by app.vulcanized.html is
120 # imported by lazy_load.vulcanized.html.
121 lazy_load_extra_args = ['--exclude', 'chrome://history/app.html']
122 _vulcanize(directory='md_history', host='history',
123 html_in_file='lazy_load.html',
124 html_out_file='lazy_load.vulcanized.html',
125 js_out_file='lazy_load.crisper.js',
126 extra_args=history_extra_args + lazy_load_extra_args)
127 _css_build(directory='md_history', files=['app.vulcanized.html',
128 'lazy_load.vulcanized.html'])
129
130
131 if __name__ == '__main__':
132 main()
OLDNEW
« no previous file with comments | « chrome/browser/resources/vulcanize.gni ('k') | chrome/browser/resources/vulcanize_gn.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698