| OLD | NEW |
| 1 #!/usr/bin/python -u | 1 #!/usr/bin/python -u |
| 2 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2013 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 """This allows easy execution of a recipe (scripts/slave/recipes, etc.) | 6 """This allows easy execution of a recipe (scripts/slave/recipes, etc.) |
| 7 without buildbot. | 7 without buildbot. |
| 8 | 8 |
| 9 This is currently useful for testing recipes locally while developing them. | 9 This is currently useful for testing recipes locally while developing them. |
| 10 | 10 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 | 68 |
| 69 %(prog)s <recipe_name> property1=value1 property2=value2 | 69 %(prog)s <recipe_name> property1=value1 property2=value2 |
| 70 """ | 70 """ |
| 71 | 71 |
| 72 | 72 |
| 73 def parse_args(args): | 73 def parse_args(args): |
| 74 """Parses the command line arguments and returns type-scrubbed properties.""" | 74 """Parses the command line arguments and returns type-scrubbed properties.""" |
| 75 parser = argparse.ArgumentParser(usage=USAGE) | 75 parser = argparse.ArgumentParser(usage=USAGE) |
| 76 parser.add_argument('recipe') | 76 parser.add_argument('recipe') |
| 77 parser.add_argument('--properties-file') | 77 parser.add_argument('--properties-file') |
| 78 parser.add_argument('--master-overrides-slave', action='store_true') |
| 78 known_args, extra_args = parser.parse_known_args(args) | 79 known_args, extra_args = parser.parse_known_args(args) |
| 79 | 80 |
| 80 if known_args.properties_file: | 81 if known_args.properties_file: |
| 81 properties = get_properties_from_file(known_args.properties_file) | 82 properties = get_properties_from_file(known_args.properties_file) |
| 82 else: | 83 else: |
| 83 # If properties were given as command line arguments, make sure that | 84 # If properties were given as command line arguments, make sure that |
| 84 # they are all prop=value pairs. | 85 # they are all prop=value pairs. |
| 85 bad_params = [x for x in extra_args if '=' not in x] | 86 bad_params = [x for x in extra_args if '=' not in x] |
| 86 if bad_params: | 87 if bad_params: |
| 87 parser.error('Error: Got bad arguments: %s' % bad_params) | 88 parser.error('Error: Got bad arguments: %s' % bad_params) |
| 88 properties = get_properties_from_args(extra_args) | 89 properties = get_properties_from_args(extra_args) |
| 89 | 90 |
| 90 assert type(properties) is dict | 91 assert type(properties) is dict |
| 91 properties['recipe'] = known_args.recipe | 92 properties['recipe'] = known_args.recipe |
| 92 return properties | 93 return properties, known_args.master_overrides_slave |
| 93 | 94 |
| 94 | 95 |
| 95 def get_properties_from_args(args): | 96 def get_properties_from_args(args): |
| 96 properties = dict(x.split('=', 1) for x in args) | 97 properties = dict(x.split('=', 1) for x in args) |
| 97 for key, val in properties.iteritems(): | 98 for key, val in properties.iteritems(): |
| 98 try: | 99 try: |
| 99 properties[key] = ast.literal_eval(val) | 100 properties[key] = ast.literal_eval(val) |
| 100 except (ValueError, SyntaxError): | 101 except (ValueError, SyntaxError): |
| 101 pass # If a value couldn't be evaluated, silently ignore it. | 102 pass # If a value couldn't be evaluated, silently ignore it. |
| 102 return properties | 103 return properties |
| 103 | 104 |
| 104 | 105 |
| 105 def get_properties_from_file(filename): | 106 def get_properties_from_file(filename): |
| 106 properties_file = sys.stdin if filename == '-' else open(filename) | 107 properties_file = sys.stdin if filename == '-' else open(filename) |
| 107 return ast.literal_eval(properties_file.read()) | 108 return ast.literal_eval(properties_file.read()) |
| 108 | 109 |
| 109 | 110 |
| 110 def main(args): | 111 def main(args): |
| 111 """Gets the recipe name and properties and runs an annotated run.""" | 112 """Gets the recipe name and properties and runs an annotated run.""" |
| 112 properties = parse_args(args) | 113 properties, master_overrides_slave = parse_args(args) |
| 113 properties.setdefault('use_mirror', False) | 114 properties.setdefault('use_mirror', False) |
| 114 | 115 |
| 115 if not os.path.exists(SLAVE_DIR): | 116 if not os.path.exists(SLAVE_DIR): |
| 116 os.makedirs(SLAVE_DIR) | 117 os.makedirs(SLAVE_DIR) |
| 117 | 118 |
| 118 # Remove any GYP environment variables for the run. | 119 # Remove any GYP environment variables for the run. |
| 119 env = os.environ.copy() | 120 env = os.environ.copy() |
| 120 for k in env.keys(): | 121 for k in env.keys(): |
| 121 if k.startswith('GYP'): | 122 if k.startswith('GYP'): |
| 122 del env[k] | 123 del env[k] |
| 123 | 124 |
| 124 env['RUN_SLAVE_UPDATED_SCRIPTS'] = '1' | 125 env['RUN_SLAVE_UPDATED_SCRIPTS'] = '1' |
| 125 env['PYTHONUNBUFFERED'] = '1' | 126 env['PYTHONUNBUFFERED'] = '1' |
| 126 env['PYTHONIOENCODING'] = 'UTF-8' | 127 env['PYTHONIOENCODING'] = 'UTF-8' |
| 127 | 128 |
| 128 return subprocess.call( | 129 cmd = ['python', '-u', RUNIT, 'python', '-u', ANNOTATED_RUN, |
| 129 ['python', '-u', RUNIT, 'python', '-u', ANNOTATED_RUN, | 130 '--keep-stdin', # so that pdb works for local execution |
| 130 '--keep-stdin', # so that pdb works for local execution | 131 '--factory-properties', json.dumps(properties), |
| 131 '--factory-properties', json.dumps(properties), | 132 '--build-properties', json.dumps(properties)] |
| 132 '--build-properties', json.dumps(properties)], | 133 |
| 133 cwd=SLAVE_DIR, | 134 if master_overrides_slave: |
| 134 env=env) | 135 cmd.append('--master-overrides-slave') |
| 136 |
| 137 return subprocess.call(cmd, cwd=SLAVE_DIR, env=env) |
| 135 | 138 |
| 136 | 139 |
| 137 if __name__ == '__main__': | 140 if __name__ == '__main__': |
| 138 sys.exit(main(sys.argv[1:])) | 141 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |