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 cStringIO | 8 import cStringIO |
9 import codecs | 9 import codecs |
10 import collections | 10 import collections |
(...skipping 1018 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1029 try: | 1029 try: |
1030 call(PATCH_TOOL, '-p0', '--remove-empty-files', '--force', '--forward', | 1030 call(PATCH_TOOL, '-p0', '--remove-empty-files', '--force', '--forward', |
1031 stdin_data=patch, cwd=patch_root, tries=1) | 1031 stdin_data=patch, cwd=patch_root, tries=1) |
1032 for filename, _ in patches: | 1032 for filename, _ in patches: |
1033 full_filename = path.abspath(path.join(patch_root, filename)) | 1033 full_filename = path.abspath(path.join(patch_root, filename)) |
1034 git('add', full_filename, cwd=path.dirname(full_filename)) | 1034 git('add', full_filename, cwd=path.dirname(full_filename)) |
1035 except SubprocessFailed as e: | 1035 except SubprocessFailed as e: |
1036 raise PatchFailed(e.message, e.code, e.output) | 1036 raise PatchFailed(e.message, e.code, e.output) |
1037 | 1037 |
1038 def apply_rietveld_issue(issue, patchset, root, server, _rev_map, _revision, | 1038 def apply_rietveld_issue(issue, patchset, root, server, _rev_map, _revision, |
1039 email_file, key_file, whitelist=None, blacklist=None): | 1039 email_file, key_file, oauth2_file, |
| 1040 whitelist=None, blacklist=None): |
1040 apply_issue_bin = ('apply_issue.bat' if sys.platform.startswith('win') | 1041 apply_issue_bin = ('apply_issue.bat' if sys.platform.startswith('win') |
1041 else 'apply_issue') | 1042 else 'apply_issue') |
1042 cmd = [apply_issue_bin, | 1043 cmd = [apply_issue_bin, |
1043 # The patch will be applied on top of this directory. | 1044 # The patch will be applied on top of this directory. |
1044 '--root_dir', root, | 1045 '--root_dir', root, |
1045 # Tell apply_issue how to fetch the patch. | 1046 # Tell apply_issue how to fetch the patch. |
1046 '--issue', issue, | 1047 '--issue', issue, |
1047 '--server', server, | 1048 '--server', server, |
1048 # Always run apply_issue.py, otherwise it would see update.flag | 1049 # Always run apply_issue.py, otherwise it would see update.flag |
1049 # and then bail out. | 1050 # and then bail out. |
1050 '--force', | 1051 '--force', |
1051 # Don't run gclient sync when it sees a DEPS change. | 1052 # Don't run gclient sync when it sees a DEPS change. |
1052 '--ignore_deps', | 1053 '--ignore_deps', |
1053 ] | 1054 ] |
1054 # Use an oauth key file if specified. | 1055 # Use an oauth key or json file if specified. |
1055 if email_file and key_file: | 1056 if oauth2_file: |
| 1057 cmd.extend(['--auth-refresh-token-json', oauth2_file]) |
| 1058 elif email_file and key_file: |
1056 cmd.extend(['--email-file', email_file, '--private-key-file', key_file]) | 1059 cmd.extend(['--email-file', email_file, '--private-key-file', key_file]) |
1057 else: | 1060 else: |
1058 cmd.append('--no-auth') | 1061 cmd.append('--no-auth') |
1059 | 1062 |
1060 if patchset: | 1063 if patchset: |
1061 cmd.extend(['--patchset', patchset]) | 1064 cmd.extend(['--patchset', patchset]) |
1062 if whitelist: | 1065 if whitelist: |
1063 for item in whitelist: | 1066 for item in whitelist: |
1064 cmd.extend(['--whitelist', item]) | 1067 cmd.extend(['--whitelist', item]) |
1065 elif blacklist: | 1068 elif blacklist: |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1259 continue | 1262 continue |
1260 # TODO(hinoka): Catch SVNRevisionNotFound error maybe? | 1263 # TODO(hinoka): Catch SVNRevisionNotFound error maybe? |
1261 git('fetch', 'origin', cwd=deps_name) | 1264 git('fetch', 'origin', cwd=deps_name) |
1262 force_revision(deps_name, revision) | 1265 force_revision(deps_name, revision) |
1263 | 1266 |
1264 | 1267 |
1265 def ensure_checkout(solutions, revisions, first_sln, target_os, target_os_only, | 1268 def ensure_checkout(solutions, revisions, first_sln, target_os, target_os_only, |
1266 patch_root, issue, patchset, patch_url, rietveld_server, | 1269 patch_root, issue, patchset, patch_url, rietveld_server, |
1267 gerrit_repo, gerrit_ref, gerrit_rebase_patch_ref, | 1270 gerrit_repo, gerrit_ref, gerrit_rebase_patch_ref, |
1268 revision_mapping, apply_issue_email_file, | 1271 revision_mapping, apply_issue_email_file, |
1269 apply_issue_key_file, buildspec, gyp_env, shallow, runhooks, | 1272 apply_issue_key_file, apply_issue_oauth2_file, buildspec, |
1270 refs, git_cache_dir, gerrit_reset): | 1273 gyp_env, shallow, runhooks, refs, git_cache_dir, |
| 1274 gerrit_reset): |
1271 # Get a checkout of each solution, without DEPS or hooks. | 1275 # Get a checkout of each solution, without DEPS or hooks. |
1272 # Calling git directly because there is no way to run Gclient without | 1276 # Calling git directly because there is no way to run Gclient without |
1273 # invoking DEPS. | 1277 # invoking DEPS. |
1274 print 'Fetching Git checkout' | 1278 print 'Fetching Git checkout' |
1275 | 1279 |
1276 git_ref = git_checkout(solutions, revisions, shallow, refs, git_cache_dir) | 1280 git_ref = git_checkout(solutions, revisions, shallow, refs, git_cache_dir) |
1277 | 1281 |
1278 patches = None | 1282 patches = None |
1279 if patch_url: | 1283 if patch_url: |
1280 patches = get_svn_patch(patch_url) | 1284 patches = get_svn_patch(patch_url) |
1281 | 1285 |
1282 print '===Processing patch solutions===' | 1286 print '===Processing patch solutions===' |
1283 already_patched = [] | 1287 already_patched = [] |
1284 patch_root = patch_root or '' | 1288 patch_root = patch_root or '' |
1285 print 'Patch root is %r' % patch_root | 1289 print 'Patch root is %r' % patch_root |
1286 for solution in solutions: | 1290 for solution in solutions: |
1287 print 'Processing solution %r' % solution['name'] | 1291 print 'Processing solution %r' % solution['name'] |
1288 if (patch_root == solution['name'] or | 1292 if (patch_root == solution['name'] or |
1289 solution['name'].startswith(patch_root + '/')): | 1293 solution['name'].startswith(patch_root + '/')): |
1290 relative_root = solution['name'][len(patch_root) + 1:] | 1294 relative_root = solution['name'][len(patch_root) + 1:] |
1291 target = '/'.join([relative_root, 'DEPS']).lstrip('/') | 1295 target = '/'.join([relative_root, 'DEPS']).lstrip('/') |
1292 print ' relative root is %r, target is %r' % (relative_root, target) | 1296 print ' relative root is %r, target is %r' % (relative_root, target) |
1293 if patches: | 1297 if patches: |
1294 apply_svn_patch(patch_root, patches, whitelist=[target]) | 1298 apply_svn_patch(patch_root, patches, whitelist=[target]) |
1295 already_patched.append(target) | 1299 already_patched.append(target) |
1296 elif issue: | 1300 elif issue: |
1297 apply_rietveld_issue(issue, patchset, patch_root, rietveld_server, | 1301 apply_rietveld_issue(issue, patchset, patch_root, rietveld_server, |
1298 revision_mapping, git_ref, apply_issue_email_file, | 1302 revision_mapping, git_ref, apply_issue_email_file, |
1299 apply_issue_key_file, whitelist=[target]) | 1303 apply_issue_key_file, apply_issue_oauth2_file, |
| 1304 whitelist=[target]) |
1300 already_patched.append(target) | 1305 already_patched.append(target) |
1301 elif gerrit_ref and gerrit_rebase_patch_ref: | 1306 elif gerrit_ref and gerrit_rebase_patch_ref: |
1302 apply_gerrit_ref(gerrit_repo, gerrit_ref, patch_root, gerrit_reset, | 1307 apply_gerrit_ref(gerrit_repo, gerrit_ref, patch_root, gerrit_reset, |
1303 True) | 1308 True) |
1304 | 1309 |
1305 # Ensure our build/ directory is set up with the correct .gclient file. | 1310 # Ensure our build/ directory is set up with the correct .gclient file. |
1306 gclient_configure(solutions, target_os, target_os_only, git_cache_dir) | 1311 gclient_configure(solutions, target_os, target_os_only, git_cache_dir) |
1307 | 1312 |
1308 # Let gclient do the DEPS syncing. | 1313 # Let gclient do the DEPS syncing. |
1309 # The branch-head refspec is a special case because its possible Chrome | 1314 # The branch-head refspec is a special case because its possible Chrome |
(...skipping 16 matching lines...) Expand all Loading... |
1326 # Finally, ensure that all DEPS are pinned to the correct revision. | 1331 # Finally, ensure that all DEPS are pinned to the correct revision. |
1327 dir_names = [sln['name'] for sln in solutions] | 1332 dir_names = [sln['name'] for sln in solutions] |
1328 ensure_deps_revisions(gclient_output.get('solutions', {}), | 1333 ensure_deps_revisions(gclient_output.get('solutions', {}), |
1329 dir_names, revisions) | 1334 dir_names, revisions) |
1330 # Apply the rest of the patch here (sans DEPS) | 1335 # Apply the rest of the patch here (sans DEPS) |
1331 if patches: | 1336 if patches: |
1332 apply_svn_patch(patch_root, patches, blacklist=already_patched) | 1337 apply_svn_patch(patch_root, patches, blacklist=already_patched) |
1333 elif issue: | 1338 elif issue: |
1334 apply_rietveld_issue(issue, patchset, patch_root, rietveld_server, | 1339 apply_rietveld_issue(issue, patchset, patch_root, rietveld_server, |
1335 revision_mapping, git_ref, apply_issue_email_file, | 1340 revision_mapping, git_ref, apply_issue_email_file, |
1336 apply_issue_key_file, blacklist=already_patched) | 1341 apply_issue_key_file, apply_issue_oauth2_file, |
| 1342 blacklist=already_patched) |
1337 elif gerrit_ref and not gerrit_rebase_patch_ref: | 1343 elif gerrit_ref and not gerrit_rebase_patch_ref: |
1338 apply_gerrit_ref(gerrit_repo, gerrit_ref, patch_root, gerrit_reset, False) | 1344 apply_gerrit_ref(gerrit_repo, gerrit_ref, patch_root, gerrit_reset, False) |
1339 | 1345 |
1340 # Reset the deps_file point in the solutions so that hooks get run properly. | 1346 # Reset the deps_file point in the solutions so that hooks get run properly. |
1341 for sln in solutions: | 1347 for sln in solutions: |
1342 sln['deps_file'] = sln.get('deps_file', 'DEPS').replace('.DEPS.git', 'DEPS') | 1348 sln['deps_file'] = sln.get('deps_file', 'DEPS').replace('.DEPS.git', 'DEPS') |
1343 gclient_configure(solutions, target_os, target_os_only, git_cache_dir) | 1349 gclient_configure(solutions, target_os, target_os_only, git_cache_dir) |
1344 | 1350 |
1345 return gclient_output | 1351 return gclient_output |
1346 | 1352 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1397 parse = optparse.OptionParser() | 1403 parse = optparse.OptionParser() |
1398 | 1404 |
1399 parse.add_option('--issue', help='Issue number to patch from.') | 1405 parse.add_option('--issue', help='Issue number to patch from.') |
1400 parse.add_option('--patchset', | 1406 parse.add_option('--patchset', |
1401 help='Patchset from issue to patch from, if applicable.') | 1407 help='Patchset from issue to patch from, if applicable.') |
1402 parse.add_option('--apply_issue_email_file', | 1408 parse.add_option('--apply_issue_email_file', |
1403 help='--email-file option passthrough for apply_patch.py.') | 1409 help='--email-file option passthrough for apply_patch.py.') |
1404 parse.add_option('--apply_issue_key_file', | 1410 parse.add_option('--apply_issue_key_file', |
1405 help='--private-key-file option passthrough for ' | 1411 help='--private-key-file option passthrough for ' |
1406 'apply_patch.py.') | 1412 'apply_patch.py.') |
| 1413 parse.add_option('--apply_issue_oauth2_file', |
| 1414 help='--auth-refresh-token-json option passthrough for ' |
| 1415 'apply_patch.py.') |
1407 parse.add_option('--patch_url', help='Optional URL to SVN patch.') | 1416 parse.add_option('--patch_url', help='Optional URL to SVN patch.') |
1408 parse.add_option('--root', dest='patch_root', | 1417 parse.add_option('--root', dest='patch_root', |
1409 help='DEPRECATED: Use --patch_root.') | 1418 help='DEPRECATED: Use --patch_root.') |
1410 parse.add_option('--patch_root', help='Directory to patch on top of.') | 1419 parse.add_option('--patch_root', help='Directory to patch on top of.') |
1411 parse.add_option('--rietveld_server', | 1420 parse.add_option('--rietveld_server', |
1412 default='codereview.chromium.org', | 1421 default='codereview.chromium.org', |
1413 help='Rietveld server.') | 1422 help='Rietveld server.') |
1414 parse.add_option('--gerrit_repo', | 1423 parse.add_option('--gerrit_repo', |
1415 help='Gerrit repository to pull the ref from.') | 1424 help='Gerrit repository to pull the ref from.') |
1416 parse.add_option('--gerrit_ref', help='Gerrit ref to apply.') | 1425 parse.add_option('--gerrit_ref', help='Gerrit ref to apply.') |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1574 issue=options.issue, | 1583 issue=options.issue, |
1575 patchset=options.patchset, | 1584 patchset=options.patchset, |
1576 patch_url=options.patch_url, | 1585 patch_url=options.patch_url, |
1577 rietveld_server=options.rietveld_server, | 1586 rietveld_server=options.rietveld_server, |
1578 gerrit_repo=options.gerrit_repo, | 1587 gerrit_repo=options.gerrit_repo, |
1579 gerrit_ref=options.gerrit_ref, | 1588 gerrit_ref=options.gerrit_ref, |
1580 gerrit_rebase_patch_ref=not options.gerrit_no_rebase_patch_ref, | 1589 gerrit_rebase_patch_ref=not options.gerrit_no_rebase_patch_ref, |
1581 revision_mapping=options.revision_mapping, | 1590 revision_mapping=options.revision_mapping, |
1582 apply_issue_email_file=options.apply_issue_email_file, | 1591 apply_issue_email_file=options.apply_issue_email_file, |
1583 apply_issue_key_file=options.apply_issue_key_file, | 1592 apply_issue_key_file=options.apply_issue_key_file, |
| 1593 apply_issue_oauth2_file=options.apply_issue_oauth2_file, |
1584 | 1594 |
1585 # For official builders. | 1595 # For official builders. |
1586 buildspec=buildspec, | 1596 buildspec=buildspec, |
1587 gyp_env=options.gyp_env, | 1597 gyp_env=options.gyp_env, |
1588 runhooks=not options.no_runhooks, | 1598 runhooks=not options.no_runhooks, |
1589 | 1599 |
1590 # Finally, extra configurations such as shallowness of the clone. | 1600 # Finally, extra configurations such as shallowness of the clone. |
1591 shallow=options.shallow, | 1601 shallow=options.shallow, |
1592 refs=options.refs, | 1602 refs=options.refs, |
1593 git_cache_dir=options.git_cache_dir, | 1603 git_cache_dir=options.git_cache_dir, |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1735 except Exception: | 1745 except Exception: |
1736 # Unexpected failure. | 1746 # Unexpected failure. |
1737 emit_flag(options.flag_file) | 1747 emit_flag(options.flag_file) |
1738 raise | 1748 raise |
1739 else: | 1749 else: |
1740 emit_flag(options.flag_file) | 1750 emit_flag(options.flag_file) |
1741 | 1751 |
1742 | 1752 |
1743 if __name__ == '__main__': | 1753 if __name__ == '__main__': |
1744 sys.exit(main()) | 1754 sys.exit(main()) |
OLD | NEW |