OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 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 # TODO(hinoka): Use logging. | 6 # TODO(hinoka): Use logging. |
7 | 7 |
8 import codecs | 8 import codecs |
9 import copy | 9 import copy |
10 import cStringIO | 10 import cStringIO |
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
531 match = "^git-svn-id: [^ ]*@%s " % revision | 531 match = "^git-svn-id: [^ ]*@%s " % revision |
532 cmd = ['log', '-E', '--grep', match, '--format=%H', '--max-count=1', | 532 cmd = ['log', '-E', '--grep', match, '--format=%H', '--max-count=1', |
533 'origin/master'] | 533 'origin/master'] |
534 result = git(*cmd, cwd=sln_dir).strip() | 534 result = git(*cmd, cwd=sln_dir).strip() |
535 if result: | 535 if result: |
536 return result | 536 return result |
537 raise SVNRevisionNotFound('We can\'t resolve svn r%s into a git hash in %s' % | 537 raise SVNRevisionNotFound('We can\'t resolve svn r%s into a git hash in %s' % |
538 (revision, sln_dir)) | 538 (revision, sln_dir)) |
539 | 539 |
540 | 540 |
541 def get_revision_mapping(root, addl_rev_map): | |
542 result = {} | |
543 if root in GOT_REVISION_MAPPINGS: | |
544 result.update(GOT_REVISION_MAPPINGS[root]) | |
545 if addl_rev_map: | |
546 result.update(json.loads(addl_rev_map)) | |
547 return result | |
548 | |
549 | |
550 def _last_commit_for_file(filename, repo_base): | 541 def _last_commit_for_file(filename, repo_base): |
551 cmd = ['log', '--format=%H', '--max-count=1', '--', filename] | 542 cmd = ['log', '--format=%H', '--max-count=1', '--', filename] |
552 return git(*cmd, cwd=repo_base).strip() | 543 return git(*cmd, cwd=repo_base).strip() |
553 | 544 |
554 | 545 |
555 def need_to_run_deps2git(repo_base, deps_file, deps_git_file): | 546 def need_to_run_deps2git(repo_base, deps_file, deps_git_file): |
556 """Checks to see if we need to run deps2git. | 547 """Checks to see if we need to run deps2git. |
557 | 548 |
558 Returns True if there was a DEPS change after the last .DEPS.git update | 549 Returns True if there was a DEPS change after the last .DEPS.git update |
559 or if DEPS has local modifications. | 550 or if DEPS has local modifications. |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
858 patch = ''.join(diffs) | 849 patch = ''.join(diffs) |
859 | 850 |
860 if patch: | 851 if patch: |
861 print '===Patching files===' | 852 print '===Patching files===' |
862 for filename, _ in patches: | 853 for filename, _ in patches: |
863 print 'Patching %s' % filename | 854 print 'Patching %s' % filename |
864 call(PATCH_TOOL, '-p0', '--remove-empty-files', '--force', '--forward', | 855 call(PATCH_TOOL, '-p0', '--remove-empty-files', '--force', '--forward', |
865 stdin_data=patch, cwd=patch_root, tries=1) | 856 stdin_data=patch, cwd=patch_root, tries=1) |
866 | 857 |
867 | 858 |
868 def apply_rietveld_issue(issue, patchset, root, server, rev_map, revision, | 859 def apply_rietveld_issue(issue, patchset, root, server, _rev_map, _revision, |
869 whitelist=None, blacklist=None): | 860 whitelist=None, blacklist=None): |
870 apply_issue_bin = ('apply_issue.bat' if sys.platform.startswith('win') | 861 apply_issue_bin = ('apply_issue.bat' if sys.platform.startswith('win') |
871 else 'apply_issue') | 862 else 'apply_issue') |
872 cmd = [apply_issue_bin, | 863 cmd = [apply_issue_bin, |
873 # The patch will be applied on top of this directory. | 864 # The patch will be applied on top of this directory. |
874 '--root_dir', root, | 865 '--root_dir', root, |
875 # Tell apply_issue how to fetch the patch. | 866 # Tell apply_issue how to fetch the patch. |
876 '--issue', issue, | 867 '--issue', issue, |
877 '--patchset', patchset, | 868 '--patchset', patchset, |
878 '--no-auth', | 869 '--no-auth', |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1123 parse.add_option('--patch_url', help='Optional URL to SVN patch.') | 1114 parse.add_option('--patch_url', help='Optional URL to SVN patch.') |
1124 parse.add_option('--root', help='Repository root.') | 1115 parse.add_option('--root', help='Repository root.') |
1125 parse.add_option('--rietveld_server', | 1116 parse.add_option('--rietveld_server', |
1126 default='codereview.chromium.org', | 1117 default='codereview.chromium.org', |
1127 help='Rietveld server.') | 1118 help='Rietveld server.') |
1128 parse.add_option('--specs', help='Gcilent spec.') | 1119 parse.add_option('--specs', help='Gcilent spec.') |
1129 parse.add_option('--master', help='Master name.') | 1120 parse.add_option('--master', help='Master name.') |
1130 parse.add_option('-f', '--force', action='store_true', | 1121 parse.add_option('-f', '--force', action='store_true', |
1131 help='Bypass check to see if we want to be run. ' | 1122 help='Bypass check to see if we want to be run. ' |
1132 'Should ONLY be used locally.') | 1123 'Should ONLY be used locally.') |
1133 parse.add_option('--revision_mapping') | 1124 parse.add_option('--revision_mapping', |
1134 parse.add_option('--revision-mapping') # Backwards compatability. | 1125 help='{"path/to/repo/": "property_name"}') |
| 1126 parse.add_option('--revision_mapping_file', |
| 1127 help=('Same as revision_mapping, except its a path to a json' |
| 1128 ' file containing that format.')) |
| 1129 parse.add_option('--revision-mapping', # Backwards compatability. |
| 1130 help='DEPRECATED, use "revision_mapping" instead') |
1135 parse.add_option('--revision', action='append', default=[], | 1131 parse.add_option('--revision', action='append', default=[], |
1136 help='Revision to check out. Can be an SVN revision number, ' | 1132 help='Revision to check out. Can be an SVN revision number, ' |
1137 'git hash, or any form of git ref. Can prepend ' | 1133 'git hash, or any form of git ref. Can prepend ' |
1138 'root@<rev> to specify which repository, where root ' | 1134 'root@<rev> to specify which repository, where root ' |
1139 'is either a filesystem path, git https url, or ' | 1135 'is either a filesystem path, git https url, or ' |
1140 'svn url. To specify Tip of Tree, set rev to HEAD.') | 1136 'svn url. To specify Tip of Tree, set rev to HEAD.') |
1141 parse.add_option('--slave_name', default=socket.getfqdn().split('.')[0], | 1137 parse.add_option('--slave_name', default=socket.getfqdn().split('.')[0], |
1142 help='Hostname of the current machine, ' | 1138 help='Hostname of the current machine, ' |
1143 'used for determining whether or not to activate.') | 1139 'used for determining whether or not to activate.') |
1144 parse.add_option('--builder_name', help='Name of the builder, ' | 1140 parse.add_option('--builder_name', help='Name of the builder, ' |
1145 'used for determining whether or not to activate.') | 1141 'used for determining whether or not to activate.') |
1146 parse.add_option('--build_dir', default=os.getcwd()) | 1142 parse.add_option('--build_dir', default=os.getcwd()) |
1147 parse.add_option('--flag_file', default=path.join(os.getcwd(), | 1143 parse.add_option('--flag_file', default=path.join(os.getcwd(), |
1148 'update.flag')) | 1144 'update.flag')) |
1149 parse.add_option('--shallow', action='store_true', | 1145 parse.add_option('--shallow', action='store_true', |
1150 help='Use shallow clones for cache repositories.') | 1146 help='Use shallow clones for cache repositories.') |
1151 parse.add_option('--gyp_env', action='append', default=[], | 1147 parse.add_option('--gyp_env', action='append', default=[], |
1152 help='Environment variables to pass into gclient runhooks.') | 1148 help='Environment variables to pass into gclient runhooks.') |
1153 parse.add_option('--clobber', action='store_true', | 1149 parse.add_option('--clobber', action='store_true', |
1154 help='Delete checkout first, always') | 1150 help='Delete checkout first, always') |
1155 parse.add_option('-o', '--output_json', | 1151 parse.add_option('-o', '--output_json', |
1156 help='Output JSON information into a specified file') | 1152 help='Output JSON information into a specified file') |
1157 | 1153 |
1158 | 1154 |
1159 return parse.parse_args() | 1155 options, args = parse.parse_args() |
| 1156 |
| 1157 try: |
| 1158 if options.revision_mapping_file: |
| 1159 if options.revision_mapping: |
| 1160 print ('WARNING: Ignoring --revision_mapping: --revision_mapping_file ' |
| 1161 'was set at the same time as --revision_mapping?') |
| 1162 with open(options.revision_mapping_file, 'r') as f: |
| 1163 options.revision_mapping = json.load(f) |
| 1164 elif options.revision_mapping: |
| 1165 options.revision_mapping = json.loads(options.revision_mapping) |
| 1166 except Exception as e: |
| 1167 print ( |
| 1168 'WARNING: Caught execption while parsing revision_mapping*: %s' |
| 1169 % (str(e),) |
| 1170 ) |
| 1171 |
| 1172 return options, args |
1160 | 1173 |
1161 | 1174 |
1162 def main(): | 1175 def main(): |
1163 # Get inputs. | 1176 # Get inputs. |
1164 options, _ = parse_args() | 1177 options, _ = parse_args() |
1165 builder = options.builder_name | 1178 builder = options.builder_name |
1166 slave = options.slave_name | 1179 slave = options.slave_name |
1167 master = options.master | 1180 master = options.master |
1168 | 1181 |
1169 # Check if this script should activate or not. | 1182 # Check if this script should activate or not. |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1277 shallow=options.shallow) | 1290 shallow=options.shallow) |
1278 gclient_output = ensure_checkout(**checkout_parameters) | 1291 gclient_output = ensure_checkout(**checkout_parameters) |
1279 except GclientSyncFailed: | 1292 except GclientSyncFailed: |
1280 print 'We failed gclient sync, lets delete the checkout and retry.' | 1293 print 'We failed gclient sync, lets delete the checkout and retry.' |
1281 ensure_no_checkout(dir_names, '*') | 1294 ensure_no_checkout(dir_names, '*') |
1282 gclient_output = ensure_checkout(**checkout_parameters) | 1295 gclient_output = ensure_checkout(**checkout_parameters) |
1283 | 1296 |
1284 # Revision is an svn revision, unless its a git master or past flag day. | 1297 # Revision is an svn revision, unless its a git master or past flag day. |
1285 use_svn_rev = master not in GIT_MASTERS and not FLAG_DAY | 1298 use_svn_rev = master not in GIT_MASTERS and not FLAG_DAY |
1286 # Take care of got_revisions outputs. | 1299 # Take care of got_revisions outputs. |
1287 revision_mapping = get_revision_mapping(svn_root, options.revision_mapping) | 1300 revision_mapping = dict(GOT_REVISION_MAPPINGS.get(svn_root, {})) |
| 1301 if options.revision_mapping: |
| 1302 revision_mapping.update(options.revision_mapping) |
| 1303 |
1288 got_revisions = parse_got_revision(gclient_output, revision_mapping, | 1304 got_revisions = parse_got_revision(gclient_output, revision_mapping, |
1289 use_svn_rev) | 1305 use_svn_rev) |
1290 | 1306 |
1291 if options.output_json: | 1307 if options.output_json: |
1292 # Tell recipes information such as root, got_revision, etc. | 1308 # Tell recipes information such as root, got_revision, etc. |
1293 emit_json(options.output_json, | 1309 emit_json(options.output_json, |
1294 did_run=True, | 1310 did_run=True, |
1295 root=first_sln, | 1311 root=first_sln, |
1296 patch_root=options.root, | 1312 patch_root=options.root, |
1297 step_text=step_text, | 1313 step_text=step_text, |
(...skipping 15 matching lines...) Expand all Loading... |
1313 specs=options.specs) | 1329 specs=options.specs) |
1314 all_threads.append(thr) | 1330 all_threads.append(thr) |
1315 | 1331 |
1316 # Sort of wait for all telemetry threads to finish. | 1332 # Sort of wait for all telemetry threads to finish. |
1317 for thr in all_threads: | 1333 for thr in all_threads: |
1318 thr.join(5) | 1334 thr.join(5) |
1319 | 1335 |
1320 | 1336 |
1321 if __name__ == '__main__': | 1337 if __name__ == '__main__': |
1322 sys.exit(main()) | 1338 sys.exit(main()) |
OLD | NEW |