| 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') | |
| 79 known_args, extra_args = parser.parse_known_args(args) | 78 known_args, extra_args = parser.parse_known_args(args) |
| 80 | 79 |
| 81 if known_args.properties_file: | 80 if known_args.properties_file: |
| 82 properties = get_properties_from_file(known_args.properties_file) | 81 properties = get_properties_from_file(known_args.properties_file) |
| 83 else: | 82 else: |
| 84 # If properties were given as command line arguments, make sure that | 83 # If properties were given as command line arguments, make sure that |
| 85 # they are all prop=value pairs. | 84 # they are all prop=value pairs. |
| 86 bad_params = [x for x in extra_args if '=' not in x] | 85 bad_params = [x for x in extra_args if '=' not in x] |
| 87 if bad_params: | 86 if bad_params: |
| 88 parser.error('Error: Got bad arguments: %s' % bad_params) | 87 parser.error('Error: Got bad arguments: %s' % bad_params) |
| 89 properties = get_properties_from_args(extra_args) | 88 properties = get_properties_from_args(extra_args) |
| 90 | 89 |
| 91 assert type(properties) is dict | 90 assert type(properties) is dict |
| 92 properties['recipe'] = known_args.recipe | 91 properties['recipe'] = known_args.recipe |
| 93 return properties, known_args.master_overrides_slave | 92 return properties |
| 94 | 93 |
| 95 | 94 |
| 96 def get_properties_from_args(args): | 95 def get_properties_from_args(args): |
| 97 properties = dict(x.split('=', 1) for x in args) | 96 properties = dict(x.split('=', 1) for x in args) |
| 98 for key, val in properties.iteritems(): | 97 for key, val in properties.iteritems(): |
| 99 try: | 98 try: |
| 100 properties[key] = ast.literal_eval(val) | 99 properties[key] = ast.literal_eval(val) |
| 101 except (ValueError, SyntaxError): | 100 except (ValueError, SyntaxError): |
| 102 pass # If a value couldn't be evaluated, silently ignore it. | 101 pass # If a value couldn't be evaluated, silently ignore it. |
| 103 return properties | 102 return properties |
| 104 | 103 |
| 105 | 104 |
| 106 def get_properties_from_file(filename): | 105 def get_properties_from_file(filename): |
| 107 properties_file = sys.stdin if filename == '-' else open(filename) | 106 properties_file = sys.stdin if filename == '-' else open(filename) |
| 108 return ast.literal_eval(properties_file.read()) | 107 return ast.literal_eval(properties_file.read()) |
| 109 | 108 |
| 110 | 109 |
| 111 def main(args): | 110 def main(args): |
| 112 """Gets the recipe name and properties and runs an annotated run.""" | 111 """Gets the recipe name and properties and runs an annotated run.""" |
| 113 properties, master_overrides_slave = parse_args(args) | 112 properties = parse_args(args) |
| 114 properties.setdefault('use_mirror', False) | 113 properties.setdefault('use_mirror', False) |
| 115 | 114 |
| 116 if not os.path.exists(SLAVE_DIR): | 115 if not os.path.exists(SLAVE_DIR): |
| 117 os.makedirs(SLAVE_DIR) | 116 os.makedirs(SLAVE_DIR) |
| 118 | 117 |
| 119 # Remove any GYP environment variables for the run. | 118 # Remove any GYP environment variables for the run. |
| 120 env = os.environ.copy() | 119 env = os.environ.copy() |
| 121 for k in env.keys(): | 120 for k in env.keys(): |
| 122 if k.startswith('GYP'): | 121 if k.startswith('GYP'): |
| 123 del env[k] | 122 del env[k] |
| 124 | 123 |
| 125 env['RUN_SLAVE_UPDATED_SCRIPTS'] = '1' | 124 env['RUN_SLAVE_UPDATED_SCRIPTS'] = '1' |
| 126 env['PYTHONUNBUFFERED'] = '1' | 125 env['PYTHONUNBUFFERED'] = '1' |
| 127 env['PYTHONIOENCODING'] = 'UTF-8' | 126 env['PYTHONIOENCODING'] = 'UTF-8' |
| 128 | 127 |
| 129 cmd = ['python', '-u', RUNIT, 'python', '-u', ANNOTATED_RUN, | 128 return subprocess.call( |
| 130 '--keep-stdin', # so that pdb works for local execution | 129 ['python', '-u', RUNIT, 'python', '-u', ANNOTATED_RUN, |
| 131 '--factory-properties', json.dumps(properties), | 130 '--keep-stdin', # so that pdb works for local execution |
| 132 '--build-properties', json.dumps(properties)] | 131 '--factory-properties', json.dumps(properties), |
| 133 | 132 '--build-properties', json.dumps(properties)], |
| 134 if master_overrides_slave: | 133 cwd=SLAVE_DIR, |
| 135 cmd.append('--master-overrides-slave') | 134 env=env) |
| 136 | |
| 137 return subprocess.call(cmd, cwd=SLAVE_DIR, env=env) | |
| 138 | 135 |
| 139 | 136 |
| 140 if __name__ == '__main__': | 137 if __name__ == '__main__': |
| 141 sys.exit(main(sys.argv[1:])) | 138 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |