| 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 = [ '-O %s=%s' % (k, norm(v)) |
| 234 for k,v in args.project_override.iteritems() ] |
| 235 |
| 236 print json.dumps({ |
| 237 'variables': { |
| 238 'files': [norm(f) for f in package_deps.root_package.all_files(context)], |
| 239 'command': [ |
| 240 'python', |
| 241 recipes_tool, |
| 242 '--package', norm( |
| 243 package_deps.root_package.repo_spec.proto_file(context).path), |
| 244 '--no-fetch', |
| 245 ] + overrides, |
| 246 }, |
| 247 }, indent=2, separators=(',', ': ')) |
| 248 |
| 221 def main(): | 249 def main(): |
| 222 from recipe_engine import package | 250 from recipe_engine import package |
| 223 | 251 |
| 224 # Super-annoyingly, we need to manually parse for simulation_test since | 252 # 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. | 253 # argparse is bonkers and doesn't allow us to forward --help to subcommands. |
| 226 if 'simulation_test' in sys.argv: | 254 if 'simulation_test' in sys.argv: |
| 227 index = sys.argv.index('simulation_test') | 255 index = sys.argv.index('simulation_test') |
| 228 sys.argv = sys.argv[:index+1] + [json.dumps(sys.argv[index+1:])] | 256 sys.argv = sys.argv[:index+1] + [json.dumps(sys.argv[index+1:])] |
| 229 | 257 |
| 230 parser = argparse.ArgumentParser(description='Do things with recipes.') | 258 parser = argparse.ArgumentParser(description='Do things with recipes.') |
| 231 | 259 |
| 232 parser.add_argument( | 260 parser.add_argument( |
| 233 '--package', | 261 '--package', |
| 234 help='Package to operate on (directory containing ' | 262 help='Package to operate on (directory containing ' |
| 235 'infra/config/recipes.cfg)') | 263 'infra/config/recipes.cfg)') |
| 236 parser.add_argument( | 264 parser.add_argument( |
| 237 '--verbose', '-v', action='store_true', | 265 '--verbose', '-v', action='store_true', |
| 238 help='Increase logging verboisty') | 266 help='Increase logging verboisty') |
| 239 parser.add_argument( | 267 parser.add_argument( |
| 240 '--no-fetch', action='store_true', | 268 '--no-fetch', action='store_true', |
| 241 help='Disable automatic fetching') | 269 help='Disable automatic fetching') |
| 242 parser.add_argument( | 270 parser.add_argument( |
| 243 '--bootstrap-script', | 271 '--bootstrap-script', |
| 244 help='Path to the script used to bootstrap this tool (internal use only)') | 272 help='Path to the script used to bootstrap this tool (internal use only)') |
| 245 parser.add_argument('-O', '--project-override', metavar='ID=PATH', | 273 parser.add_argument('-O', '--project-override', metavar='ID=PATH', |
| 246 action=ProjectOverrideAction, | 274 action=ProjectOverrideAction, |
| 275 default={}, |
| 247 help='Override a project repository path with a local one.') | 276 help='Override a project repository path with a local one.') |
| 248 | 277 |
| 249 subp = parser.add_subparsers() | 278 subp = parser.add_subparsers() |
| 250 | 279 |
| 251 fetch_p = subp.add_parser( | 280 fetch_p = subp.add_parser( |
| 252 'fetch', | 281 'fetch', |
| 253 help='Fetch and update dependencies.') | 282 help='Fetch and update dependencies.') |
| 254 fetch_p.set_defaults(command='fetch') | 283 fetch_p.set_defaults(command='fetch') |
| 255 | 284 |
| 256 simulation_test_p = subp.add_parser('simulation_test', | 285 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') | 337 doc_p.set_defaults(command='doc') |
| 309 | 338 |
| 310 info_p = subp.add_parser( | 339 info_p = subp.add_parser( |
| 311 'info', | 340 'info', |
| 312 help='Query information about the current recipe package') | 341 help='Query information about the current recipe package') |
| 313 info_p.set_defaults(command='info') | 342 info_p.set_defaults(command='info') |
| 314 info_p.add_argument( | 343 info_p.add_argument( |
| 315 '--recipes-dir', action='store_true', | 344 '--recipes-dir', action='store_true', |
| 316 help='Get the subpath where the recipes live relative to repository root') | 345 help='Get the subpath where the recipes live relative to repository root') |
| 317 | 346 |
| 347 isolate_p = subp.add_parser( |
| 348 'isolate', |
| 349 help='Write an isolate file to stdout for the recipe toolchain of the ' |
| 350 'current project') |
| 351 isolate_p.set_defaults(command='isolate') |
| 352 |
| 318 args = parser.parse_args() | 353 args = parser.parse_args() |
| 319 | 354 |
| 320 if args.verbose: | 355 if args.verbose: |
| 321 logging.getLogger().setLevel(logging.INFO) | 356 logging.getLogger().setLevel(logging.INFO) |
| 322 | 357 |
| 323 repo_root, config_file = get_package_config(args) | 358 repo_root, config_file = get_package_config(args) |
| 324 package_deps = package.PackageDeps.create( | 359 package_deps = package.PackageDeps.create( |
| 325 repo_root, config_file, allow_fetch=not args.no_fetch, | 360 repo_root, config_file, allow_fetch=not args.no_fetch, |
| 326 overrides=args.project_override) | 361 overrides=args.project_override) |
| 327 | 362 |
| 328 if args.command == 'fetch': | 363 if args.command == 'fetch': |
| 329 # We already did everything in the create() call above. | 364 # We already did everything in the create() call above. |
| 330 assert not args.no_fetch, 'Fetch? No-fetch? Make up your mind!' | 365 assert not args.no_fetch, 'Fetch? No-fetch? Make up your mind!' |
| 331 return 0 | 366 return 0 |
| 332 if args.command == 'simulation_test': | 367 if args.command == 'simulation_test': |
| 333 return simulation_test(package_deps, args) | 368 return simulation_test(package_deps, args) |
| 334 elif args.command == 'lint': | 369 elif args.command == 'lint': |
| 335 return lint(package_deps, args) | 370 return lint(package_deps, args) |
| 336 elif args.command == 'run': | 371 elif args.command == 'run': |
| 337 return run(package_deps, args) | 372 return run(package_deps, args) |
| 338 elif args.command == 'roll': | 373 elif args.command == 'roll': |
| 339 assert not args.no_fetch, ( | 374 assert not args.no_fetch, ( |
| 340 'Rolling without fetching is not supported yet.') | 375 'Rolling without fetching is not supported yet.') |
| 341 return roll(args) | 376 return roll(args) |
| 342 elif args.command == 'doc': | 377 elif args.command == 'doc': |
| 343 return doc(package_deps, args) | 378 return doc(package_deps, args) |
| 344 elif args.command == 'info': | 379 elif args.command == 'info': |
| 345 return info(args) | 380 return info(args) |
| 381 elif args.command == 'isolate': |
| 382 return isolate(package_deps, args) |
| 346 else: | 383 else: |
| 347 print """Dear sir or madam, | 384 print """Dear sir or madam, |
| 348 It has come to my attention that a quite impossible condition has come | 385 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. | 386 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, | 387 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 | 388 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 | 389 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 | 390 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 | 391 unfortunate circumstance, and wish you the best in deciding the next action |
| 355 in your venture and larger life. | 392 in your venture and larger life. |
| 356 | 393 |
| 357 Warmly, | 394 Warmly, |
| 358 recipes.py | 395 recipes.py |
| 359 """ | 396 """ |
| 360 return 1 | 397 return 1 |
| 361 | 398 |
| 362 return 0 | 399 return 0 |
| 363 | 400 |
| 364 if __name__ == '__main__': | 401 if __name__ == '__main__': |
| 365 sys.exit(main()) | 402 sys.exit(main()) |
| OLD | NEW |