| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 import argparse | 6 import argparse |
| 7 import itertools | 7 import itertools |
| 8 import os | 8 import os |
| 9 import platform | 9 import platform |
| 10 import re | 10 import re |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 ('chrome://resources/html/', _HTML_RESOURCES_PATH), | 63 ('chrome://resources/html/', _HTML_RESOURCES_PATH), |
| 64 ('chrome://resources/js/', _JS_RESOURCES_PATH), | 64 ('chrome://resources/js/', _JS_RESOURCES_PATH), |
| 65 ('chrome://resources/polymer/v1_0/', _POLYMER_PATH) | 65 ('chrome://resources/polymer/v1_0/', _POLYMER_PATH) |
| 66 ] | 66 ] |
| 67 | 67 |
| 68 | 68 |
| 69 _VULCANIZE_REDIRECT_ARGS = list(itertools.chain.from_iterable(map( | 69 _VULCANIZE_REDIRECT_ARGS = list(itertools.chain.from_iterable(map( |
| 70 lambda m: ['--redirect', '"%s|%s"' % (m[0], m[1])], _URL_MAPPINGS))) | 70 lambda m: ['--redirect', '"%s|%s"' % (m[0], m[1])], _URL_MAPPINGS))) |
| 71 | 71 |
| 72 | 72 |
| 73 _PAK_UNPACK_FOLDER = 'flattened' | |
| 74 | |
| 75 | |
| 76 def _undo_mapping(mappings, url): | 73 def _undo_mapping(mappings, url): |
| 77 for (redirect_url, file_path) in mappings: | 74 for (redirect_url, file_path) in mappings: |
| 78 if url.startswith(redirect_url): | 75 if url.startswith(redirect_url): |
| 79 return url.replace(redirect_url, file_path + os.sep) | 76 return url.replace(redirect_url, file_path + os.sep) |
| 80 # TODO(dbeam): can we make this stricter? | 77 # TODO(dbeam): can we make this stricter? |
| 81 return url | 78 return url |
| 82 | 79 |
| 83 def _request_list_path(out_path, html_out_file): | 80 def _request_list_path(out_path, html_out_file): |
| 84 return os.path.join(out_path, html_out_file + '_requestlist.txt') | 81 return os.path.join(out_path, html_out_file + '_requestlist.txt') |
| 85 | 82 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 110 # Undo the URL mappings applied by vulcanize to get file paths relative to | 107 # Undo the URL mappings applied by vulcanize to get file paths relative to |
| 111 # current working directory. | 108 # current working directory. |
| 112 url_mappings = _URL_MAPPINGS + [ | 109 url_mappings = _URL_MAPPINGS + [ |
| 113 ('/', os.path.relpath(in_path, _CWD)), | 110 ('/', os.path.relpath(in_path, _CWD)), |
| 114 ('chrome://%s/' % args.host, os.path.relpath(in_path, _CWD)), | 111 ('chrome://%s/' % args.host, os.path.relpath(in_path, _CWD)), |
| 115 ] | 112 ] |
| 116 | 113 |
| 117 deps = [_undo_mapping(url_mappings, u) for u in request_list] | 114 deps = [_undo_mapping(url_mappings, u) for u in request_list] |
| 118 deps = map(os.path.normpath, deps) | 115 deps = map(os.path.normpath, deps) |
| 119 | 116 |
| 120 # If the input was a .pak file, the generated depfile should not list files | 117 # If the input was a folder holding an unpacked .pak file, the generated |
| 121 # already in the .pak file. | 118 # depfile should not list files already in the .pak file. |
| 122 if args.input.endswith('.pak'): | 119 if args.input.endswith('.unpak'): |
| 123 filter_url = os.path.join(args.out_folder, _PAK_UNPACK_FOLDER) | 120 filter_url = args.input |
| 124 deps = [d for d in deps if not d.startswith(filter_url)] | 121 deps = [d for d in deps if not d.startswith(filter_url)] |
| 125 | 122 |
| 126 with open(os.path.join(_CWD, args.depfile), 'w') as f: | 123 with open(os.path.join(_CWD, args.depfile), 'w') as f: |
| 127 deps_file_header = os.path.join(args.out_folder, args.html_out_file) | 124 deps_file_header = os.path.join(args.out_folder, args.html_out_file) |
| 128 f.write(deps_file_header + ': ' + ' '.join(deps)) | 125 f.write(deps_file_header + ': ' + ' '.join(deps)) |
| 129 | 126 |
| 130 | 127 |
| 131 def _vulcanize(in_folder, args): | 128 def _vulcanize(in_folder, args): |
| 132 in_path = os.path.normpath(os.path.join(_CWD, in_folder)) | 129 in_path = os.path.normpath(os.path.join(_CWD, in_folder)) |
| 133 out_path = os.path.join(_CWD, args.out_folder) | 130 out_path = os.path.join(_CWD, args.out_folder) |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 parser.add_argument('--out_folder', required=True) | 188 parser.add_argument('--out_folder', required=True) |
| 192 args = parser.parse_args(argv) | 189 args = parser.parse_args(argv) |
| 193 | 190 |
| 194 # NOTE(dbeam): on Windows, GN can send dirs/like/this. When joined, you might | 191 # NOTE(dbeam): on Windows, GN can send dirs/like/this. When joined, you might |
| 195 # get dirs/like/this\file.txt. This looks odd to windows. Normalize to right | 192 # get dirs/like/this\file.txt. This looks odd to windows. Normalize to right |
| 196 # the slashes. | 193 # the slashes. |
| 197 args.depfile = os.path.normpath(args.depfile) | 194 args.depfile = os.path.normpath(args.depfile) |
| 198 args.input = os.path.normpath(args.input) | 195 args.input = os.path.normpath(args.input) |
| 199 args.out_folder = os.path.normpath(args.out_folder) | 196 args.out_folder = os.path.normpath(args.out_folder) |
| 200 | 197 |
| 201 vulcanize_input_folder = args.input | 198 _vulcanize(args.input, args) |
| 202 | 199 _update_dep_file(args.input, args) |
| 203 # If a .pak file was specified, unpack that file first and pass the output to | |
| 204 # vulcanize. | |
| 205 if args.input.endswith('.pak'): | |
| 206 import unpack_pak | |
| 207 output_folder = os.path.join(args.out_folder, _PAK_UNPACK_FOLDER) | |
| 208 unpack_pak.unpack(args.input, output_folder) | |
| 209 vulcanize_input_folder = output_folder | |
| 210 | |
| 211 _vulcanize(vulcanize_input_folder, args) | |
| 212 | |
| 213 _update_dep_file(vulcanize_input_folder, args) | |
| 214 | 200 |
| 215 | 201 |
| 216 if __name__ == '__main__': | 202 if __name__ == '__main__': |
| 217 main(sys.argv[1:]) | 203 main(sys.argv[1:]) |
| OLD | NEW |