Chromium Code Reviews| 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 import codecs | 6 import codecs |
| 7 import copy | 7 import copy |
| 8 import cStringIO | 8 import cStringIO |
| 9 import ctypes | 9 import ctypes |
| 10 import json | 10 import json |
| (...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 596 def get_git_hash(revision, dir_name): | 596 def get_git_hash(revision, dir_name): |
| 597 match = "^git-svn-id: [^ ]*@%s " % create_less_than_or_equal_regex(revision) | 597 match = "^git-svn-id: [^ ]*@%s " % create_less_than_or_equal_regex(revision) |
| 598 cmd = ['log', '-E', '--grep', match, '--format=%H', '--max-count=1'] | 598 cmd = ['log', '-E', '--grep', match, '--format=%H', '--max-count=1'] |
| 599 results = git(*cmd, cwd=dir_name).strip().splitlines() | 599 results = git(*cmd, cwd=dir_name).strip().splitlines() |
| 600 if results: | 600 if results: |
| 601 return results[0] | 601 return results[0] |
| 602 raise Exception('We can\'t resolve svn revision %s into a git hash' % | 602 raise Exception('We can\'t resolve svn revision %s into a git hash' % |
| 603 revision) | 603 revision) |
| 604 | 604 |
| 605 | 605 |
| 606 def get_revision_mapping(root, addl_rev_map): | |
| 607 result = {} | |
| 608 if root in GOT_REVISION_MAPPINGS: | |
| 609 result.update(GOT_REVISION_MAPPINGS[root]) | |
| 610 if addl_rev_map: | |
| 611 result.update(json.loads(addl_rev_map)) | |
| 612 return result | |
| 613 | |
| 614 | |
| 615 def _last_commit_for_file(filename, repo_base): | 606 def _last_commit_for_file(filename, repo_base): |
| 616 cmd = ['log', '--format=%H', '--max-count=1', '--', filename] | 607 cmd = ['log', '--format=%H', '--max-count=1', '--', filename] |
| 617 return git(*cmd, cwd=repo_base).strip() | 608 return git(*cmd, cwd=repo_base).strip() |
| 618 | 609 |
| 619 | 610 |
| 620 def need_to_run_deps2git(repo_base, deps_file, deps_git_file): | 611 def need_to_run_deps2git(repo_base, deps_file, deps_git_file): |
| 621 """Checks to see if we need to run deps2git. | 612 """Checks to see if we need to run deps2git. |
| 622 | 613 |
| 623 Returns True if there was a DEPS change after the last .DEPS.git update. | 614 Returns True if there was a DEPS change after the last .DEPS.git update. |
| 624 """ | 615 """ |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 843 if attempt == RETRIES - 1: | 834 if attempt == RETRIES - 1: |
| 844 raise | 835 raise |
| 845 | 836 |
| 846 | 837 |
| 847 def apply_issue_svn(root, patch_url): | 838 def apply_issue_svn(root, patch_url): |
| 848 patch_data = call('svn', 'cat', patch_url) | 839 patch_data = call('svn', 'cat', patch_url) |
| 849 call(PATCH_TOOL, '-p0', '--remove-empty-files', '--force', '--forward', | 840 call(PATCH_TOOL, '-p0', '--remove-empty-files', '--force', '--forward', |
| 850 stdin_data=patch_data, cwd=root) | 841 stdin_data=patch_data, cwd=root) |
| 851 | 842 |
| 852 | 843 |
| 853 def apply_issue_rietveld(issue, patchset, root, server, rev_map, revision): | 844 def apply_issue_rietveld(issue, patchset, root, server, _rev_map, revision): |
| 854 apply_issue_bin = ('apply_issue.bat' if sys.platform.startswith('win') | 845 apply_issue_bin = ('apply_issue.bat' if sys.platform.startswith('win') |
| 855 else 'apply_issue') | 846 else 'apply_issue') |
| 856 call(apply_issue_bin, | 847 call(apply_issue_bin, |
| 857 '--root_dir', root, | 848 '--root_dir', root, |
| 858 '--issue', issue, | 849 '--issue', issue, |
| 859 '--patchset', patchset, | 850 '--patchset', patchset, |
| 860 '--no-auth', | 851 '--no-auth', |
| 861 '--server', server, | 852 '--server', server, |
| 862 '--base_ref', revision, | 853 '--base_ref', revision, |
| 863 '--force', | 854 '--force', |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1031 parse.add_option('--patch_url', help='Optional URL to SVN patch.') | 1022 parse.add_option('--patch_url', help='Optional URL to SVN patch.') |
| 1032 parse.add_option('--root', help='Repository root.') | 1023 parse.add_option('--root', help='Repository root.') |
| 1033 parse.add_option('--rietveld_server', | 1024 parse.add_option('--rietveld_server', |
| 1034 default='codereview.chromium.org', | 1025 default='codereview.chromium.org', |
| 1035 help='Rietveld server.') | 1026 help='Rietveld server.') |
| 1036 parse.add_option('--specs', help='Gcilent spec.') | 1027 parse.add_option('--specs', help='Gcilent spec.') |
| 1037 parse.add_option('--master', help='Master name.') | 1028 parse.add_option('--master', help='Master name.') |
| 1038 parse.add_option('-f', '--force', action='store_true', | 1029 parse.add_option('-f', '--force', action='store_true', |
| 1039 help='Bypass check to see if we want to be run. ' | 1030 help='Bypass check to see if we want to be run. ' |
| 1040 'Should ONLY be used locally.') | 1031 'Should ONLY be used locally.') |
| 1041 parse.add_option('--revision_mapping') | 1032 parse.add_option('--revision_mapping', |
| 1042 parse.add_option('--revision-mapping') # Backwards compatability. | 1033 help='{"path/to/repo/": "property_name"}') |
| 1034 parse.add_option('--revision_mapping_file', | |
| 1035 help=('Same as revision_mapping, except its a path to a json' | |
| 1036 ' file containing that format.')) | |
| 1037 parse.add_option('--revision-mapping', # Backwards compatability. | |
| 1038 help='DEPRECATED, use "revision_mapping" instead') | |
| 1043 # TODO(hinoka): Support root@revision format. | 1039 # TODO(hinoka): Support root@revision format. |
| 1044 parse.add_option('--revision', | 1040 parse.add_option('--revision', |
| 1045 help='Revision to check out. Can be an SVN revision number, ' | 1041 help='Revision to check out. Can be an SVN revision number, ' |
| 1046 'git hash, or any form of git ref.') | 1042 'git hash, or any form of git ref.') |
| 1047 parse.add_option('--slave_name', default=socket.getfqdn().split('.')[0], | 1043 parse.add_option('--slave_name', default=socket.getfqdn().split('.')[0], |
| 1048 help='Hostname of the current machine, ' | 1044 help='Hostname of the current machine, ' |
| 1049 'used for determining whether or not to activate.') | 1045 'used for determining whether or not to activate.') |
| 1050 parse.add_option('--builder_name', help='Name of the builder, ' | 1046 parse.add_option('--builder_name', help='Name of the builder, ' |
| 1051 'used for determining whether or not to activate.') | 1047 'used for determining whether or not to activate.') |
| 1052 parse.add_option('--build_dir', default=os.getcwd()) | 1048 parse.add_option('--build_dir', default=os.getcwd()) |
| 1053 parse.add_option('--flag_file', default=path.join(os.getcwd(), | 1049 parse.add_option('--flag_file', default=path.join(os.getcwd(), |
| 1054 'update.flag')) | 1050 'update.flag')) |
| 1055 parse.add_option('--shallow', action='store_true', | 1051 parse.add_option('--shallow', action='store_true', |
| 1056 help='Use shallow clones for cache repositories.') | 1052 help='Use shallow clones for cache repositories.') |
| 1057 parse.add_option('--gyp_env', action='append', default=[], | 1053 parse.add_option('--gyp_env', action='append', default=[], |
| 1058 help='Environment variables to pass into gclient runhooks.') | 1054 help='Environment variables to pass into gclient runhooks.') |
| 1059 parse.add_option('--clobber', action='store_true', | 1055 parse.add_option('--clobber', action='store_true', |
| 1060 help='Delete checkout first, always') | 1056 help='Delete checkout first, always') |
| 1061 parse.add_option('-o', '--output_json', | 1057 parse.add_option('-o', '--output_json', |
| 1062 help='Output JSON information into a specified file') | 1058 help='Output JSON information into a specified file') |
| 1063 | 1059 |
| 1064 | 1060 |
| 1065 return parse.parse_args() | 1061 options, args = parse.parse_args() |
| 1062 | |
| 1063 try: | |
| 1064 if options.revision_mapping_file is not None: | |
|
hinoka
2014/05/09 23:08:13
"if options.revision_mapping_file" should be suffi
iannucci
2014/05/11 03:48:45
Done.
| |
| 1065 if options.revision_mapping is not None: | |
| 1066 print ('WARNING: revision_mapping_file was set at the same ' | |
| 1067 'time as revision_mapping?') | |
|
hinoka
2014/05/09 23:08:13
nit: Add "Ignoring revision_mapping" to warning.
iannucci
2014/05/11 03:48:45
Done.
| |
| 1068 with open(options.revision_mapping_file, 'r') as f: | |
| 1069 options.revision_mapping = json.load(f) | |
| 1070 elif options.revision_mapping is not None: | |
| 1071 options.revision_mapping = json.loads(options.revision_mapping) | |
| 1072 except Exception as e: | |
| 1073 print ( | |
| 1074 'WARNING: Caught execption while parsing revision_mapping*: %s' | |
| 1075 % (str(e),) | |
| 1076 ) | |
| 1077 | |
| 1078 return options, args | |
| 1066 | 1079 |
| 1067 | 1080 |
| 1068 def main(): | 1081 def main(): |
| 1069 # Get inputs. | 1082 # Get inputs. |
| 1070 options, _ = parse_args() | 1083 options, _ = parse_args() |
| 1071 builder = options.builder_name | 1084 builder = options.builder_name |
| 1072 slave = options.slave_name | 1085 slave = options.slave_name |
| 1073 master = options.master | 1086 master = options.master |
| 1074 | 1087 |
| 1075 # Check if this script should activate or not. | 1088 # Check if this script should activate or not. |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1176 shallow=options.shallow) | 1189 shallow=options.shallow) |
| 1177 gclient_output = ensure_checkout(**checkout_parameters) | 1190 gclient_output = ensure_checkout(**checkout_parameters) |
| 1178 except GclientSyncFailed: | 1191 except GclientSyncFailed: |
| 1179 print 'We failed gclient sync, lets delete the checkout and retry.' | 1192 print 'We failed gclient sync, lets delete the checkout and retry.' |
| 1180 ensure_no_checkout(dir_names, '*') | 1193 ensure_no_checkout(dir_names, '*') |
| 1181 gclient_output = ensure_checkout(**checkout_parameters) | 1194 gclient_output = ensure_checkout(**checkout_parameters) |
| 1182 | 1195 |
| 1183 # Revision is an svn revision, unless its a git master or past flag day. | 1196 # Revision is an svn revision, unless its a git master or past flag day. |
| 1184 use_svn_rev = master not in GIT_MASTERS and not FLAG_DAY | 1197 use_svn_rev = master not in GIT_MASTERS and not FLAG_DAY |
| 1185 # Take care of got_revisions outputs. | 1198 # Take care of got_revisions outputs. |
| 1186 revision_mapping = get_revision_mapping(svn_root, options.revision_mapping) | 1199 revision_mapping = GOT_REVISION_MAPPINGS.get(svn_root, {}) |
| 1200 if options.revision_mapping: | |
| 1201 revision_mapping.update(options.revision_mapping) | |
| 1202 | |
| 1187 got_revisions = parse_got_revision(gclient_output, revision_mapping, | 1203 got_revisions = parse_got_revision(gclient_output, revision_mapping, |
| 1188 use_svn_rev) | 1204 use_svn_rev) |
| 1189 | 1205 |
| 1190 if options.output_json: | 1206 if options.output_json: |
| 1191 # Tell recipes information such as root, got_revision, etc. | 1207 # Tell recipes information such as root, got_revision, etc. |
| 1192 emit_json(options.output_json, | 1208 emit_json(options.output_json, |
| 1193 did_run=True, | 1209 did_run=True, |
| 1194 root=first_sln, | 1210 root=first_sln, |
| 1195 patch_root=options.root, | 1211 patch_root=options.root, |
| 1196 step_text=step_text, | 1212 step_text=step_text, |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 1212 specs=options.specs) | 1228 specs=options.specs) |
| 1213 all_threads.append(thr) | 1229 all_threads.append(thr) |
| 1214 | 1230 |
| 1215 # Sort of wait for all telemetry threads to finish. | 1231 # Sort of wait for all telemetry threads to finish. |
| 1216 for thr in all_threads: | 1232 for thr in all_threads: |
| 1217 thr.join(5) | 1233 thr.join(5) |
| 1218 | 1234 |
| 1219 | 1235 |
| 1220 if __name__ == '__main__': | 1236 if __name__ == '__main__': |
| 1221 sys.exit(main()) | 1237 sys.exit(main()) |
| OLD | NEW |