| OLD | NEW |
| 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 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 parser.add_argument('--mojom-sources', | 180 parser.add_argument('--mojom-sources', |
| 181 metavar='mojom_sources', | 181 metavar='mojom_sources', |
| 182 help='.mojom and .mojom.dart sources', | 182 help='.mojom and .mojom.dart sources', |
| 183 nargs='*', | 183 nargs='*', |
| 184 default=[]) | 184 default=[]) |
| 185 parser.add_argument('--sdk-ext-directories', | 185 parser.add_argument('--sdk-ext-directories', |
| 186 metavar='sdk_ext_directories', | 186 metavar='sdk_ext_directories', |
| 187 help='Directory containing .dart sources', | 187 help='Directory containing .dart sources', |
| 188 nargs='*', | 188 nargs='*', |
| 189 default=[]) | 189 default=[]) |
| 190 parser.add_argument('--sdk-ext-files', |
| 191 metavar='sdk_ext_files', |
| 192 help='List of .dart files that are part of of sdk_ext.', |
| 193 nargs='*', |
| 194 default=[]) |
| 190 args = parser.parse_args() | 195 args = parser.parse_args() |
| 191 | 196 |
| 192 # We must have a pubspec.yaml. | 197 # We must have a pubspec.yaml. |
| 193 assert has_pubspec_yaml(args.package_sources) | 198 assert has_pubspec_yaml(args.package_sources) |
| 194 | 199 |
| 195 # Copy or symlink package sources into pkg directory. | 200 # Copy or symlink package sources into pkg directory. |
| 196 target_dir = os.path.join(args.pkg_directory, args.package_name) | 201 target_dir = os.path.join(args.pkg_directory, args.package_name) |
| 197 common_source_prefix = os.path.commonprefix(args.package_sources) | 202 common_source_prefix = os.path.commonprefix(args.package_sources) |
| 198 for source in args.package_sources: | 203 for source in args.package_sources: |
| 199 relative_source = os.path.relpath(source, common_source_prefix) | 204 relative_source = os.path.relpath(source, common_source_prefix) |
| 200 target = os.path.join(target_dir, relative_source) | 205 target = os.path.join(target_dir, relative_source) |
| 201 copy_or_link(source, target) | 206 copy_or_link(source, target) |
| 202 | 207 |
| 203 # Copy sdk-ext sources into pkg directory | 208 # Copy sdk-ext sources into pkg directory |
| 204 sdk_ext_dir = os.path.join(target_dir, 'sdk_ext') | 209 sdk_ext_dir = os.path.join(target_dir, 'sdk_ext') |
| 205 for directory in args.sdk_ext_directories: | 210 for directory in args.sdk_ext_directories: |
| 206 sdk_ext_sources = list_files(directory, dart_filter) | 211 sdk_ext_sources = list_files(directory, dart_filter) |
| 207 common_prefix = os.path.commonprefix(sdk_ext_sources) | 212 common_prefix = os.path.commonprefix(sdk_ext_sources) |
| 208 for source in sdk_ext_sources: | 213 for source in sdk_ext_sources: |
| 209 relative_source = os.path.relpath(source, common_prefix) | 214 relative_source = os.path.relpath(source, common_prefix) |
| 210 target = os.path.join(sdk_ext_dir, relative_source) | 215 target = os.path.join(sdk_ext_dir, relative_source) |
| 211 copy_or_link(source, target) | 216 copy_or_link(source, target) |
| 217 for source in args.sdk_ext_files: |
| 218 common_prefix = os.path.commonprefix(args.sdk_ext_files) |
| 219 relative_source = os.path.relpath(source, common_prefix) |
| 220 target = os.path.join(sdk_ext_dir, relative_source) |
| 221 copy_or_link(source, target) |
| 212 | 222 |
| 213 lib_path = os.path.join(target_dir, "lib") | 223 lib_path = os.path.join(target_dir, "lib") |
| 214 lib_mojom_path = os.path.join(lib_path, "mojom") | 224 lib_mojom_path = os.path.join(lib_path, "mojom") |
| 215 | 225 |
| 216 # Copy generated mojom.dart files. | 226 # Copy generated mojom.dart files. |
| 217 generated_mojom_lib_path = os.path.join(args.gen_directory, "mojom/lib") | 227 generated_mojom_lib_path = os.path.join(args.gen_directory, "mojom/lib") |
| 218 for mojom_source_path in args.mojom_sources: | 228 for mojom_source_path in args.mojom_sources: |
| 219 path = mojom_path(mojom_source_path) | 229 path = mojom_path(mojom_source_path) |
| 220 source_path = '%s.dart' % os.path.join(generated_mojom_lib_path, path) | 230 source_path = '%s.dart' % os.path.join(generated_mojom_lib_path, path) |
| 221 target_path = '%s.dart' % os.path.join(lib_mojom_path, path) | 231 target_path = '%s.dart' % os.path.join(lib_mojom_path, path) |
| 222 copy(source_path, target_path) | 232 copy(source_path, target_path) |
| 223 | 233 |
| 224 # Symlink packages/ | 234 # Symlink packages/ |
| 225 package_path = os.path.join(args.package_root, args.package_name) | 235 package_path = os.path.join(args.package_root, args.package_name) |
| 226 link(lib_path, package_path) | 236 link(lib_path, package_path) |
| 227 | 237 |
| 228 # Remove any broken symlinks in target_dir and package root. | 238 # Remove any broken symlinks in target_dir and package root. |
| 229 remove_broken_symlinks(target_dir) | 239 remove_broken_symlinks(target_dir) |
| 230 remove_broken_symlinks(args.package_root) | 240 remove_broken_symlinks(args.package_root) |
| 231 | 241 |
| 232 # Write stamp file. | 242 # Write stamp file. |
| 233 with open(args.stamp_file, 'w'): | 243 with open(args.stamp_file, 'w'): |
| 234 pass | 244 pass |
| 235 | 245 |
| 236 if __name__ == '__main__': | 246 if __name__ == '__main__': |
| 237 sys.exit(main()) | 247 sys.exit(main()) |
| OLD | NEW |