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

Side by Side Diff: recipes.py

Issue 1570333002: 'recipes.py isolate' command to build an isolate of the current package's toolchain (Closed) Base URL: git@github.com:luci/recipes-py.git@master
Patch Set: Created 4 years, 11 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
OLDNEW
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
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):
M-A Ruel 2016/01/09 00:51:59 I would have written it as: norm = lambda *p: os.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 print json.dumps({
233 'variables': {
234 'files': [norm(f) for f in package_deps.root_package.all_files(context)],
M-A Ruel 2016/01/09 00:51:59 sorted()
luqui 2016/01/15 23:11:27 Done.
235 'command': [
236 'python',
237 recipes_tool,
238 '--package', norm(
M-A Ruel 2016/01/09 00:51:59 put the norm()'ed item in a separate line.
luqui 2016/01/15 23:11:27 Done.
239 package_deps.root_package.repo_spec.proto_file(context).path),
240 '--no-fetch',
241 ],
242 },
243 }, indent=2, separators=(',', ': '))
M-A Ruel 2016/01/09 00:51:59 return 0 2 empty lines
luqui 2016/01/15 23:11:27 Done.
244
221 def main(): 245 def main():
222 from recipe_engine import package 246 from recipe_engine import package
223 247
224 # Super-annoyingly, we need to manually parse for simulation_test since 248 # 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. 249 # argparse is bonkers and doesn't allow us to forward --help to subcommands.
226 if 'simulation_test' in sys.argv: 250 if 'simulation_test' in sys.argv:
227 index = sys.argv.index('simulation_test') 251 index = sys.argv.index('simulation_test')
228 sys.argv = sys.argv[:index+1] + [json.dumps(sys.argv[index+1:])] 252 sys.argv = sys.argv[:index+1] + [json.dumps(sys.argv[index+1:])]
229 253
230 parser = argparse.ArgumentParser(description='Do things with recipes.') 254 parser = argparse.ArgumentParser(description='Do things with recipes.')
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 doc_p.set_defaults(command='doc') 332 doc_p.set_defaults(command='doc')
309 333
310 info_p = subp.add_parser( 334 info_p = subp.add_parser(
311 'info', 335 'info',
312 help='Query information about the current recipe package') 336 help='Query information about the current recipe package')
313 info_p.set_defaults(command='info') 337 info_p.set_defaults(command='info')
314 info_p.add_argument( 338 info_p.add_argument(
315 '--recipes-dir', action='store_true', 339 '--recipes-dir', action='store_true',
316 help='Get the subpath where the recipes live relative to repository root') 340 help='Get the subpath where the recipes live relative to repository root')
317 341
342 isolate_p = subp.add_parser(
343 'isolate',
344 help='Write an isolate file to stdout for the recipe toolchain of the '
345 'current project')
346 isolate_p.set_defaults(command='isolate')
347
318 args = parser.parse_args() 348 args = parser.parse_args()
319 349
320 if args.verbose: 350 if args.verbose:
321 logging.getLogger().setLevel(logging.INFO) 351 logging.getLogger().setLevel(logging.INFO)
322 352
323 repo_root, config_file = get_package_config(args) 353 repo_root, config_file = get_package_config(args)
324 package_deps = package.PackageDeps.create( 354 package_deps = package.PackageDeps.create(
325 repo_root, config_file, allow_fetch=not args.no_fetch, 355 repo_root, config_file, allow_fetch=not args.no_fetch,
326 overrides=args.project_override) 356 overrides=args.project_override)
327 357
328 if args.command == 'fetch': 358 if args.command == 'fetch':
329 # We already did everything in the create() call above. 359 # We already did everything in the create() call above.
330 assert not args.no_fetch, 'Fetch? No-fetch? Make up your mind!' 360 assert not args.no_fetch, 'Fetch? No-fetch? Make up your mind!'
331 return 0 361 return 0
332 if args.command == 'simulation_test': 362 if args.command == 'simulation_test':
333 return simulation_test(package_deps, args) 363 return simulation_test(package_deps, args)
334 elif args.command == 'lint': 364 elif args.command == 'lint':
335 return lint(package_deps, args) 365 return lint(package_deps, args)
336 elif args.command == 'run': 366 elif args.command == 'run':
337 return run(package_deps, args) 367 return run(package_deps, args)
338 elif args.command == 'roll': 368 elif args.command == 'roll':
339 assert not args.no_fetch, ( 369 assert not args.no_fetch, (
340 'Rolling without fetching is not supported yet.') 370 'Rolling without fetching is not supported yet.')
341 return roll(args) 371 return roll(args)
342 elif args.command == 'doc': 372 elif args.command == 'doc':
343 return doc(package_deps, args) 373 return doc(package_deps, args)
344 elif args.command == 'info': 374 elif args.command == 'info':
345 return info(args) 375 return info(args)
376 elif args.command == 'isolate':
377 return isolate(package_deps, args)
346 else: 378 else:
347 print """Dear sir or madam, 379 print """Dear sir or madam,
348 It has come to my attention that a quite impossible condition has come 380 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. 381 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, 382 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 383 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 384 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 385 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 386 unfortunate circumstance, and wish you the best in deciding the next action
355 in your venture and larger life. 387 in your venture and larger life.
356 388
357 Warmly, 389 Warmly,
358 recipes.py 390 recipes.py
359 """ 391 """
360 return 1 392 return 1
361 393
362 return 0 394 return 0
363 395
364 if __name__ == '__main__': 396 if __name__ == '__main__':
365 sys.exit(main()) 397 sys.exit(main())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698