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

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

Issue 1147293003: Start including sdk_ext sources in sky dart-pkg (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 7 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/BUILD.gn » ('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
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 dirs[:] = filter(wrapped_filter, dirs) 98 dirs[:] = filter(wrapped_filter, dirs)
99 99
100 100
101 def copy_or_link(from_root, to_root, filter_func=None): 101 def copy_or_link(from_root, to_root, filter_func=None):
102 if USE_LINKS: 102 if USE_LINKS:
103 link(from_root, to_root) 103 link(from_root, to_root)
104 else: 104 else:
105 copy(from_root, to_root, filter_func) 105 copy(from_root, to_root, filter_func)
106 106
107 107
108 def list_files(from_root, filter_func=None):
109 file_list = []
110 for root, dirs, files in os.walk(from_root):
111 # filter_func expects paths not names, so wrap it to make them absolute.
112 wrapped_filter = None
113 if filter_func:
114 wrapped_filter = lambda name: filter_func(os.path.join(root, name))
115 for name in filter(wrapped_filter, files):
116 path = os.path.join(root, name)
117 file_list.append(path)
118 dirs[:] = filter(wrapped_filter, dirs)
119 return file_list
120
121
108 def remove_broken_symlink(path): 122 def remove_broken_symlink(path):
109 try: 123 try:
110 link_path = os.readlink(path) 124 link_path = os.readlink(path)
111 except OSError as e: 125 except OSError as e:
112 # Path was not a symlink. 126 # Path was not a symlink.
113 if e.errno == errno.EINVAL: 127 if e.errno == errno.EINVAL:
114 pass 128 pass
115 else: 129 else:
116 if not os.path.exists(link_path): 130 if not os.path.exists(link_path):
117 os.unlink(path) 131 os.unlink(path)
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 required=True) 175 required=True)
162 parser.add_argument('--package-sources', 176 parser.add_argument('--package-sources',
163 metavar='package_sources', 177 metavar='package_sources',
164 help='Package sources', 178 help='Package sources',
165 nargs='+') 179 nargs='+')
166 parser.add_argument('--mojom-sources', 180 parser.add_argument('--mojom-sources',
167 metavar='mojom_sources', 181 metavar='mojom_sources',
168 help='.mojom and .mojom.dart sources', 182 help='.mojom and .mojom.dart sources',
169 nargs='*', 183 nargs='*',
170 default=[]) 184 default=[])
185 parser.add_argument('--sdk-ext-directories',
186 metavar='sdk_ext_directories',
187 help='Directory containing .dart sources',
188 nargs='*',
189 default=[])
171 args = parser.parse_args() 190 args = parser.parse_args()
172 191
173 # We must have a pubspec.yaml. 192 # We must have a pubspec.yaml.
174 assert has_pubspec_yaml(args.package_sources) 193 assert has_pubspec_yaml(args.package_sources)
175 194
176 # Copy or symlink package sources into pkg directory. 195 # Copy or symlink package sources into pkg directory.
177 target_dir = os.path.join(args.pkg_directory, args.package_name) 196 target_dir = os.path.join(args.pkg_directory, args.package_name)
178 common_source_prefix = os.path.commonprefix(args.package_sources) 197 common_source_prefix = os.path.commonprefix(args.package_sources)
179 for source in args.package_sources: 198 for source in args.package_sources:
180 relative_source = os.path.relpath(source, common_source_prefix) 199 relative_source = os.path.relpath(source, common_source_prefix)
181 target = os.path.join(target_dir, relative_source) 200 target = os.path.join(target_dir, relative_source)
182 copy_or_link(source, target) 201 copy_or_link(source, target)
183 202
203 # Copy sdk-ext sources into pkg directory
204 sdk_ext_dir = os.path.join(target_dir, 'sdk_ext')
205 for directory in args.sdk_ext_directories:
206 sdk_ext_sources = list_files(directory, dart_filter)
207 common_prefix = os.path.commonprefix(sdk_ext_sources)
208 for source in sdk_ext_sources:
209 relative_source = os.path.relpath(source, common_prefix)
210 target = os.path.join(sdk_ext_dir, relative_source)
211 copy_or_link(source, target)
212
184 lib_path = os.path.join(target_dir, "lib") 213 lib_path = os.path.join(target_dir, "lib")
185 lib_mojom_path = os.path.join(lib_path, "mojom") 214 lib_mojom_path = os.path.join(lib_path, "mojom")
186 215
187 # Copy mojom sources 216 # Copy mojom sources
188 for mojom_source_path in args.mojom_sources: 217 for mojom_source_path in args.mojom_sources:
189 path = mojom_path(mojom_source_path) 218 path = mojom_path(mojom_source_path)
190 copy(mojom_source_path, os.path.join(lib_mojom_path, path)) 219 copy(mojom_source_path, os.path.join(lib_mojom_path, path))
191 220
192 # Copy generated mojom.dart files. 221 # Copy generated mojom.dart files.
193 generated_mojom_lib_path = os.path.join(args.gen_directory, "mojom/lib") 222 generated_mojom_lib_path = os.path.join(args.gen_directory, "mojom/lib")
(...skipping 10 matching lines...) Expand all
204 # Remove any broken symlinks in target_dir and package root. 233 # Remove any broken symlinks in target_dir and package root.
205 remove_broken_symlinks(target_dir) 234 remove_broken_symlinks(target_dir)
206 remove_broken_symlinks(args.package_root) 235 remove_broken_symlinks(args.package_root)
207 236
208 # Write stamp file. 237 # Write stamp file.
209 with open(args.stamp_file, 'w'): 238 with open(args.stamp_file, 'w'):
210 pass 239 pass
211 240
212 if __name__ == '__main__': 241 if __name__ == '__main__':
213 sys.exit(main()) 242 sys.exit(main())
OLDNEW
« no previous file with comments | « mojo/public/dart/rules.gni ('k') | sky/sdk/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698