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

Side by Side Diff: mojo/public/tools/dart_pkg.py

Issue 1233493008: Generate Sky's _sdkext file using the build system (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 5 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 | « mojo/public/dart/rules.gni ('k') | sky/sdk/.gitignore » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # 2 #
3 # Copyright 2015 The Chromium Authors. All rights reserved. 3 # Copyright 2015 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 """Utility for dart_pkg and dart_pkg_app rules""" 7 """Utility for dart_pkg and dart_pkg_app rules"""
8 8
9 import argparse 9 import argparse
10 import errno 10 import errno
11 import json
11 import os 12 import os
12 import shutil 13 import shutil
13 import sys 14 import sys
14 15
15 # Disable lint check for finding modules: 16 # Disable lint check for finding modules:
16 # pylint: disable=F0401 17 # pylint: disable=F0401
17 18
18 sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), 19 sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)),
19 "bindings/pylib")) 20 "bindings/pylib"))
20 21
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 dirs[:] = filter(wrapped_filter, dirs) 99 dirs[:] = filter(wrapped_filter, dirs)
99 100
100 101
101 def copy_or_link(from_root, to_root, filter_func=None): 102 def copy_or_link(from_root, to_root, filter_func=None):
102 if USE_LINKS: 103 if USE_LINKS:
103 link(from_root, to_root) 104 link(from_root, to_root)
104 else: 105 else:
105 copy(from_root, to_root, filter_func) 106 copy(from_root, to_root, filter_func)
106 107
107 108
109 def remove_if_exists(path):
110 try:
111 os.remove(path)
112 except OSError as e:
113 if e.errno != errno.ENOENT:
114 raise
115
108 def list_files(from_root, filter_func=None): 116 def list_files(from_root, filter_func=None):
109 file_list = [] 117 file_list = []
110 for root, dirs, files in os.walk(from_root): 118 for root, dirs, files in os.walk(from_root):
111 # filter_func expects paths not names, so wrap it to make them absolute. 119 # filter_func expects paths not names, so wrap it to make them absolute.
112 wrapped_filter = None 120 wrapped_filter = None
113 if filter_func: 121 if filter_func:
114 wrapped_filter = lambda name: filter_func(os.path.join(root, name)) 122 wrapped_filter = lambda name: filter_func(os.path.join(root, name))
115 for name in filter(wrapped_filter, files): 123 for name in filter(wrapped_filter, files):
116 path = os.path.join(root, name) 124 path = os.path.join(root, name)
117 file_list.append(path) 125 file_list.append(path)
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 parser.add_argument('--sdk-ext-directories', 193 parser.add_argument('--sdk-ext-directories',
186 metavar='sdk_ext_directories', 194 metavar='sdk_ext_directories',
187 help='Directory containing .dart sources', 195 help='Directory containing .dart sources',
188 nargs='*', 196 nargs='*',
189 default=[]) 197 default=[])
190 parser.add_argument('--sdk-ext-files', 198 parser.add_argument('--sdk-ext-files',
191 metavar='sdk_ext_files', 199 metavar='sdk_ext_files',
192 help='List of .dart files that are part of of sdk_ext.', 200 help='List of .dart files that are part of of sdk_ext.',
193 nargs='*', 201 nargs='*',
194 default=[]) 202 default=[])
203 parser.add_argument('--sdk-ext-mappings',
204 metavar='sdk_ext_mappings',
205 help='Mappings for SDK extension libraries.',
206 nargs='*',
207 default=[])
195 args = parser.parse_args() 208 args = parser.parse_args()
196 209
197 # We must have a pubspec.yaml. 210 # We must have a pubspec.yaml.
198 assert has_pubspec_yaml(args.package_sources) 211 assert has_pubspec_yaml(args.package_sources)
199 212
213 target_dir = os.path.join(args.pkg_directory, args.package_name)
214 lib_path = os.path.join(target_dir, "lib")
215
216 mappings = {}
217 for mapping in args.sdk_ext_mappings:
218 library, path = mapping.split(',', 1)
219 mappings[library] = '../sdk_ext/%s' % path
220
221 sdkext_path = os.path.join(lib_path, '_sdkext')
222 if mappings:
223 with open(sdkext_path, 'w') as stream:
224 json.dump(mappings, stream, sort_keys=True,
225 indent=2, separators=(',', ': '))
226 else:
227 remove_if_exists(sdkext_path)
228
200 # Copy or symlink package sources into pkg directory. 229 # Copy or symlink package sources into pkg directory.
201 target_dir = os.path.join(args.pkg_directory, args.package_name)
202 common_source_prefix = os.path.commonprefix(args.package_sources) 230 common_source_prefix = os.path.commonprefix(args.package_sources)
203 for source in args.package_sources: 231 for source in args.package_sources:
204 relative_source = os.path.relpath(source, common_source_prefix) 232 relative_source = os.path.relpath(source, common_source_prefix)
205 target = os.path.join(target_dir, relative_source) 233 target = os.path.join(target_dir, relative_source)
206 copy_or_link(source, target) 234 copy_or_link(source, target)
207 235
208 # Copy sdk-ext sources into pkg directory 236 # Copy sdk-ext sources into pkg directory
209 sdk_ext_dir = os.path.join(target_dir, 'sdk_ext') 237 sdk_ext_dir = os.path.join(target_dir, 'sdk_ext')
210 for directory in args.sdk_ext_directories: 238 for directory in args.sdk_ext_directories:
211 sdk_ext_sources = list_files(directory, dart_filter) 239 sdk_ext_sources = list_files(directory, dart_filter)
212 common_prefix = os.path.commonprefix(sdk_ext_sources) 240 common_prefix = os.path.commonprefix(sdk_ext_sources)
213 for source in sdk_ext_sources: 241 for source in sdk_ext_sources:
214 relative_source = os.path.relpath(source, common_prefix) 242 relative_source = os.path.relpath(source, common_prefix)
215 target = os.path.join(sdk_ext_dir, relative_source) 243 target = os.path.join(sdk_ext_dir, relative_source)
216 copy_or_link(source, target) 244 copy_or_link(source, target)
217 for source in args.sdk_ext_files: 245 for source in args.sdk_ext_files:
218 common_prefix = os.path.commonprefix(args.sdk_ext_files) 246 common_prefix = os.path.commonprefix(args.sdk_ext_files)
219 relative_source = os.path.relpath(source, common_prefix) 247 relative_source = os.path.relpath(source, common_prefix)
220 target = os.path.join(sdk_ext_dir, relative_source) 248 target = os.path.join(sdk_ext_dir, relative_source)
221 copy_or_link(source, target) 249 copy_or_link(source, target)
222 250
223 lib_path = os.path.join(target_dir, "lib")
224 lib_mojom_path = os.path.join(lib_path, "mojom") 251 lib_mojom_path = os.path.join(lib_path, "mojom")
225 252
226 # Copy generated mojom.dart files. 253 # Copy generated mojom.dart files.
227 generated_mojom_lib_path = os.path.join(args.gen_directory, "mojom/lib") 254 generated_mojom_lib_path = os.path.join(args.gen_directory, "mojom/lib")
228 for mojom_source_path in args.mojom_sources: 255 for mojom_source_path in args.mojom_sources:
229 path = mojom_path(mojom_source_path) 256 path = mojom_path(mojom_source_path)
230 source_path = '%s.dart' % os.path.join(generated_mojom_lib_path, path) 257 source_path = '%s.dart' % os.path.join(generated_mojom_lib_path, path)
231 target_path = '%s.dart' % os.path.join(lib_mojom_path, path) 258 target_path = '%s.dart' % os.path.join(lib_mojom_path, path)
232 copy(source_path, target_path) 259 copy(source_path, target_path)
233 260
234 # Symlink packages/ 261 # Symlink packages/
235 package_path = os.path.join(args.package_root, args.package_name) 262 package_path = os.path.join(args.package_root, args.package_name)
236 link(lib_path, package_path) 263 link(lib_path, package_path)
237 264
238 # Remove any broken symlinks in target_dir and package root. 265 # Remove any broken symlinks in target_dir and package root.
239 remove_broken_symlinks(target_dir) 266 remove_broken_symlinks(target_dir)
240 remove_broken_symlinks(args.package_root) 267 remove_broken_symlinks(args.package_root)
241 268
242 # Write stamp file. 269 # Write stamp file.
243 with open(args.stamp_file, 'w'): 270 with open(args.stamp_file, 'w'):
244 pass 271 pass
245 272
246 if __name__ == '__main__': 273 if __name__ == '__main__':
247 sys.exit(main()) 274 sys.exit(main())
OLDNEW
« no previous file with comments | « mojo/public/dart/rules.gni ('k') | sky/sdk/.gitignore » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698