Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2015 The Chromium Authors. All rights reserved. | 2 # Copyright 2015 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 """Tool to interact with recipe repositories. | 6 """Tool to interact with recipe repositories. |
| 7 | 7 |
| 8 This tool operates on the nearest ancestor directory containing an | 8 This tool operates on the nearest ancestor directory containing an |
| 9 infra/config/recipes.cfg. | 9 infra/config/recipes.cfg. |
| 10 """ | 10 """ |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 211 | 211 |
| 212 def info(args): | 212 def info(args): |
| 213 from recipe_engine import package | 213 from recipe_engine import package |
| 214 repo_root, config_file = get_package_config(args) | 214 repo_root, config_file = get_package_config(args) |
| 215 package_spec = package.PackageSpec.load_proto(config_file) | 215 package_spec = package.PackageSpec.load_proto(config_file) |
| 216 | 216 |
| 217 if args.recipes_dir: | 217 if args.recipes_dir: |
| 218 print package_spec.recipes_path | 218 print package_spec.recipes_path |
| 219 | 219 |
| 220 | 220 |
| 221 def isolate(package_deps, args): | |
| 222 from recipe_engine import package | |
| 223 | |
| 224 repo_root, config_file = get_package_config(args) | |
| 225 context = package.PackageContext.from_proto_file(repo_root, config_file) | |
| 226 base_path = package_deps.root_package.recipes_dir | |
| 227 def norm(p): | |
| 228 return os.path.relpath(p, base_path) | |
| 229 recipes_tool = norm(os.path.join( | |
| 230 package_deps.get_package('recipe_engine').recipes_dir, | |
| 231 'recipes.py')) | |
| 232 | |
| 233 overrides = sorted( | |
| 234 '-O %s=%s' % (k, norm(v)) for k, v in args.project_override.iteritems()) | |
|
M-A Ruel
2016/01/16 23:30:48
Actually, you want ['-O', '%s=%s'] otherwise this
| |
| 235 | |
| 236 print json.dumps({ | |
| 237 'variables': { | |
| 238 'files': sorted( | |
| 239 norm(f) for f in package_deps.root_package.all_files(context)), | |
| 240 'command': [ | |
| 241 'python', | |
| 242 recipes_tool, | |
| 243 '--package', | |
| 244 norm(package_deps.root_package.repo_spec.proto_file(context).path), | |
| 245 '--no-fetch', | |
| 246 ] + overrides, | |
| 247 }, | |
| 248 }, indent=2, separators=(',', ': '), sort_keys=True) | |
| 249 | |
| 250 | |
| 221 def main(): | 251 def main(): |
| 222 from recipe_engine import package | 252 from recipe_engine import package |
| 223 | 253 |
| 224 # Super-annoyingly, we need to manually parse for simulation_test since | 254 # Super-annoyingly, we need to manually parse for simulation_test since |
| 225 # argparse is bonkers and doesn't allow us to forward --help to subcommands. | 255 # argparse is bonkers and doesn't allow us to forward --help to subcommands. |
| 226 if 'simulation_test' in sys.argv: | 256 if 'simulation_test' in sys.argv: |
| 227 index = sys.argv.index('simulation_test') | 257 index = sys.argv.index('simulation_test') |
| 228 sys.argv = sys.argv[:index+1] + [json.dumps(sys.argv[index+1:])] | 258 sys.argv = sys.argv[:index+1] + [json.dumps(sys.argv[index+1:])] |
| 229 | 259 |
| 230 parser = argparse.ArgumentParser(description='Do things with recipes.') | 260 parser = argparse.ArgumentParser(description='Do things with recipes.') |
| 231 | 261 |
| 232 parser.add_argument( | 262 parser.add_argument( |
| 233 '--package', | 263 '--package', |
| 234 help='Package to operate on (directory containing ' | 264 help='Package to operate on (directory containing ' |
| 235 'infra/config/recipes.cfg)') | 265 'infra/config/recipes.cfg)') |
| 236 parser.add_argument( | 266 parser.add_argument( |
| 237 '--verbose', '-v', action='store_true', | 267 '--verbose', '-v', action='store_true', |
| 238 help='Increase logging verboisty') | 268 help='Increase logging verboisty') |
| 239 parser.add_argument( | 269 parser.add_argument( |
| 240 '--no-fetch', action='store_true', | 270 '--no-fetch', action='store_true', |
| 241 help='Disable automatic fetching') | 271 help='Disable automatic fetching') |
| 242 parser.add_argument( | 272 parser.add_argument( |
| 243 '--bootstrap-script', | 273 '--bootstrap-script', |
| 244 help='Path to the script used to bootstrap this tool (internal use only)') | 274 help='Path to the script used to bootstrap this tool (internal use only)') |
| 245 parser.add_argument('-O', '--project-override', metavar='ID=PATH', | 275 parser.add_argument('-O', '--project-override', metavar='ID=PATH', |
| 246 action=ProjectOverrideAction, | 276 action=ProjectOverrideAction, |
| 277 default={}, | |
| 247 help='Override a project repository path with a local one.') | 278 help='Override a project repository path with a local one.') |
| 248 | 279 |
| 249 subp = parser.add_subparsers() | 280 subp = parser.add_subparsers() |
| 250 | 281 |
| 251 fetch_p = subp.add_parser( | 282 fetch_p = subp.add_parser( |
| 252 'fetch', | 283 'fetch', |
| 253 help='Fetch and update dependencies.') | 284 help='Fetch and update dependencies.') |
| 254 fetch_p.set_defaults(command='fetch') | 285 fetch_p.set_defaults(command='fetch') |
| 255 | 286 |
| 256 simulation_test_p = subp.add_parser('simulation_test', | 287 simulation_test_p = subp.add_parser('simulation_test', |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 308 doc_p.set_defaults(command='doc') | 339 doc_p.set_defaults(command='doc') |
| 309 | 340 |
| 310 info_p = subp.add_parser( | 341 info_p = subp.add_parser( |
| 311 'info', | 342 'info', |
| 312 help='Query information about the current recipe package') | 343 help='Query information about the current recipe package') |
| 313 info_p.set_defaults(command='info') | 344 info_p.set_defaults(command='info') |
| 314 info_p.add_argument( | 345 info_p.add_argument( |
| 315 '--recipes-dir', action='store_true', | 346 '--recipes-dir', action='store_true', |
| 316 help='Get the subpath where the recipes live relative to repository root') | 347 help='Get the subpath where the recipes live relative to repository root') |
| 317 | 348 |
| 349 isolate_p = subp.add_parser( | |
| 350 'isolate', | |
| 351 help='Write an isolate file to stdout for the recipe toolchain of the ' | |
| 352 'current project') | |
| 353 isolate_p.set_defaults(command='isolate') | |
| 354 | |
| 318 args = parser.parse_args() | 355 args = parser.parse_args() |
| 319 | 356 |
| 320 if args.verbose: | 357 if args.verbose: |
| 321 logging.getLogger().setLevel(logging.INFO) | 358 logging.getLogger().setLevel(logging.INFO) |
| 322 | 359 |
| 323 repo_root, config_file = get_package_config(args) | 360 repo_root, config_file = get_package_config(args) |
| 324 package_deps = package.PackageDeps.create( | 361 package_deps = package.PackageDeps.create( |
| 325 repo_root, config_file, allow_fetch=not args.no_fetch, | 362 repo_root, config_file, allow_fetch=not args.no_fetch, |
| 326 overrides=args.project_override) | 363 overrides=args.project_override) |
| 327 | 364 |
| 328 if args.command == 'fetch': | 365 if args.command == 'fetch': |
| 329 # We already did everything in the create() call above. | 366 # We already did everything in the create() call above. |
| 330 assert not args.no_fetch, 'Fetch? No-fetch? Make up your mind!' | 367 assert not args.no_fetch, 'Fetch? No-fetch? Make up your mind!' |
| 331 return 0 | 368 return 0 |
| 332 if args.command == 'simulation_test': | 369 if args.command == 'simulation_test': |
| 333 return simulation_test(package_deps, args) | 370 return simulation_test(package_deps, args) |
| 334 elif args.command == 'lint': | 371 elif args.command == 'lint': |
| 335 return lint(package_deps, args) | 372 return lint(package_deps, args) |
| 336 elif args.command == 'run': | 373 elif args.command == 'run': |
| 337 return run(package_deps, args) | 374 return run(package_deps, args) |
| 338 elif args.command == 'roll': | 375 elif args.command == 'roll': |
| 339 assert not args.no_fetch, ( | 376 assert not args.no_fetch, ( |
| 340 'Rolling without fetching is not supported yet.') | 377 'Rolling without fetching is not supported yet.') |
| 341 return roll(args) | 378 return roll(args) |
| 342 elif args.command == 'doc': | 379 elif args.command == 'doc': |
| 343 return doc(package_deps, args) | 380 return doc(package_deps, args) |
| 344 elif args.command == 'info': | 381 elif args.command == 'info': |
| 345 return info(args) | 382 return info(args) |
| 383 elif args.command == 'isolate': | |
| 384 return isolate(package_deps, args) | |
| 346 else: | 385 else: |
| 347 print """Dear sir or madam, | 386 print """Dear sir or madam, |
| 348 It has come to my attention that a quite impossible condition has come | 387 It has come to my attention that a quite impossible condition has come |
| 349 to pass in the specification you have issued a request for us to fulfill. | 388 to pass in the specification you have issued a request for us to fulfill. |
| 350 It is with a heavy heart that I inform you that, at the present juncture, | 389 It is with a heavy heart that I inform you that, at the present juncture, |
| 351 there is no conceivable next action to be taken upon your request, and as | 390 there is no conceivable next action to be taken upon your request, and as |
| 352 such, we have decided to abort the request with a nonzero status code. We | 391 such, we have decided to abort the request with a nonzero status code. We |
| 353 hope that your larger goals have not been put at risk due to this | 392 hope that your larger goals have not been put at risk due to this |
| 354 unfortunate circumstance, and wish you the best in deciding the next action | 393 unfortunate circumstance, and wish you the best in deciding the next action |
| 355 in your venture and larger life. | 394 in your venture and larger life. |
| 356 | 395 |
| 357 Warmly, | 396 Warmly, |
| 358 recipes.py | 397 recipes.py |
| 359 """ | 398 """ |
| 360 return 1 | 399 return 1 |
| 361 | 400 |
| 362 return 0 | 401 return 0 |
| 363 | 402 |
| 364 if __name__ == '__main__': | 403 if __name__ == '__main__': |
| 365 sys.exit(main()) | 404 sys.exit(main()) |
| OLD | NEW |