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 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 'client.v8.branches', | 344 'client.v8.branches', |
345 'client.v8.ports', | 345 'client.v8.ports', |
346 'tryserver.v8', | 346 'tryserver.v8', |
347 ] | 347 ] |
348 GIT_MASTERS += internal_data.get('GIT_MASTERS', []) | 348 GIT_MASTERS += internal_data.get('GIT_MASTERS', []) |
349 | 349 |
350 | 350 |
351 # How many times to try before giving up. | 351 # How many times to try before giving up. |
352 ATTEMPTS = 5 | 352 ATTEMPTS = 5 |
353 | 353 |
354 # Find deps2git | |
355 DEPS2GIT_DIR_PATH = path.join(SCRIPTS_DIR, 'tools', 'deps2git') | |
356 DEPS2GIT_PATH = path.join(DEPS2GIT_DIR_PATH, 'deps2git.py') | |
357 S2G_INTERNAL_PATH = path.join(SCRIPTS_DIR, 'tools', 'deps2git_internal', | |
358 'svn_to_git_internal.py') | |
359 GIT_CACHE_PATH = path.join(DEPOT_TOOLS_DIR, 'git_cache.py') | 354 GIT_CACHE_PATH = path.join(DEPOT_TOOLS_DIR, 'git_cache.py') |
360 | 355 |
361 # Find the patch tool. | 356 # Find the patch tool. |
362 if sys.platform.startswith('win'): | 357 if sys.platform.startswith('win'): |
363 if not BUILD_INTERNAL_DIR: | 358 if not BUILD_INTERNAL_DIR: |
364 print 'Warning: could not find patch tool because there is no ' | 359 print 'Warning: could not find patch tool because there is no ' |
365 print 'build_internal present.' | 360 print 'build_internal present.' |
366 PATCH_TOOL = None | 361 PATCH_TOOL = None |
367 else: | 362 else: |
368 PATCH_TOOL = path.join(BUILD_INTERNAL_DIR, 'tools', 'patch.EXE') | 363 PATCH_TOOL = path.join(BUILD_INTERNAL_DIR, 'tools', 'patch.EXE') |
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
804 match = "^%s: [^ ]*@%s " % (GIT_SVN_ID_FOOTER_KEY, revision) | 799 match = "^%s: [^ ]*@%s " % (GIT_SVN_ID_FOOTER_KEY, revision) |
805 ref = branch if branch.startswith('refs/') else 'origin/%s' % branch | 800 ref = branch if branch.startswith('refs/') else 'origin/%s' % branch |
806 cmd = ['log', '-E', '--grep', match, '--format=%H', '--max-count=1', ref] | 801 cmd = ['log', '-E', '--grep', match, '--format=%H', '--max-count=1', ref] |
807 result = git(*cmd, cwd=sln_dir).strip() | 802 result = git(*cmd, cwd=sln_dir).strip() |
808 if result: | 803 if result: |
809 return result | 804 return result |
810 raise SVNRevisionNotFound('We can\'t resolve svn r%s into a git hash in %s' % | 805 raise SVNRevisionNotFound('We can\'t resolve svn r%s into a git hash in %s' % |
811 (revision, sln_dir)) | 806 (revision, sln_dir)) |
812 | 807 |
813 | 808 |
814 def _last_commit_for_file(filename, repo_base): | |
815 cmd = ['log', '--format=%H', '--max-count=1', '--', filename] | |
816 return git(*cmd, cwd=repo_base).strip() | |
817 | |
818 | |
819 def need_to_run_deps2git(repo_base, deps_file, deps_git_file): | |
820 """Checks to see if we need to run deps2git. | |
821 | |
822 Returns True if there was a DEPS change after the last .DEPS.git update | |
823 or if DEPS has local modifications. | |
824 """ | |
825 # See if DEPS is dirty | |
826 deps_file_status = git( | |
827 'status', '--porcelain', deps_file, cwd=repo_base).strip() | |
828 if deps_file_status and deps_file_status.startswith('M '): | |
829 return True | |
830 | |
831 last_known_deps_ref = _last_commit_for_file(deps_file, repo_base) | |
832 last_known_deps_git_ref = _last_commit_for_file(deps_git_file, repo_base) | |
833 merge_base_ref = git('merge-base', last_known_deps_ref, | |
834 last_known_deps_git_ref, cwd=repo_base).strip() | |
835 | |
836 # If the merge base of the last DEPS and last .DEPS.git file is not | |
837 # equivilent to the hash of the last DEPS file, that means the DEPS file | |
838 # was committed after the last .DEPS.git file. | |
839 return last_known_deps_ref != merge_base_ref | |
840 | |
841 | |
842 def ensure_deps2git(solution, shallow, git_cache_dir): | |
843 repo_base = path.join(os.getcwd(), solution['name']) | |
844 deps_file = path.join(repo_base, 'DEPS') | |
845 deps_git_file = path.join(repo_base, '.DEPS.git') | |
846 if (not git('ls-files', 'DEPS', cwd=repo_base).strip() or | |
847 not git('ls-files', '.DEPS.git', cwd=repo_base).strip()): | |
848 return | |
849 | |
850 print 'Checking if %s is newer than %s' % (deps_file, deps_git_file) | |
851 if not need_to_run_deps2git(repo_base, deps_file, deps_git_file): | |
852 return | |
853 | |
854 print '===DEPS file modified, need to run deps2git===' | |
855 cmd = [sys.executable, DEPS2GIT_PATH, | |
856 '--workspace', os.getcwd(), | |
857 '--cache_dir', git_cache_dir, | |
858 '--deps', deps_file, | |
859 '--out', deps_git_file] | |
860 if 'chrome-internal.googlesource' in solution['url']: | |
861 cmd.extend(['--extra-rules', S2G_INTERNAL_PATH]) | |
862 if shallow: | |
863 cmd.append('--shallow') | |
864 call(*cmd) | |
865 | |
866 | |
867 def emit_log_lines(name, lines): | 809 def emit_log_lines(name, lines): |
868 for line in lines.splitlines(): | 810 for line in lines.splitlines(): |
869 print '@@@STEP_LOG_LINE@%s@%s@@@' % (name, line) | 811 print '@@@STEP_LOG_LINE@%s@%s@@@' % (name, line) |
870 print '@@@STEP_LOG_END@%s@@@' % name | 812 print '@@@STEP_LOG_END@%s@@@' % name |
871 | 813 |
872 | 814 |
873 def emit_properties(properties): | 815 def emit_properties(properties): |
874 for property_name, property_value in sorted(properties.items()): | 816 for property_name, property_value in sorted(properties.items()): |
875 print '@@@SET_BUILD_PROPERTY@%s@"%s"@@@' % (property_name, property_value) | 817 print '@@@SET_BUILD_PROPERTY@%s@"%s"@@@' % (property_name, property_value) |
876 | 818 |
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1353 already_patched.append(target) | 1295 already_patched.append(target) |
1354 elif issue: | 1296 elif issue: |
1355 apply_rietveld_issue(issue, patchset, patch_root, rietveld_server, | 1297 apply_rietveld_issue(issue, patchset, patch_root, rietveld_server, |
1356 revision_mapping, git_ref, apply_issue_email_file, | 1298 revision_mapping, git_ref, apply_issue_email_file, |
1357 apply_issue_key_file, whitelist=[target]) | 1299 apply_issue_key_file, whitelist=[target]) |
1358 already_patched.append(target) | 1300 already_patched.append(target) |
1359 elif gerrit_ref and gerrit_rebase_patch_ref: | 1301 elif gerrit_ref and gerrit_rebase_patch_ref: |
1360 apply_gerrit_ref(gerrit_repo, gerrit_ref, patch_root, gerrit_reset, | 1302 apply_gerrit_ref(gerrit_repo, gerrit_ref, patch_root, gerrit_reset, |
1361 True) | 1303 True) |
1362 | 1304 |
1363 if not buildspec: | |
1364 # Run deps2git if there is a DEPS change after the last .DEPS.git commit. | |
1365 for solution in solutions: | |
1366 ensure_deps2git(solution, shallow, git_cache_dir) | |
1367 | |
1368 # Ensure our build/ directory is set up with the correct .gclient file. | 1305 # Ensure our build/ directory is set up with the correct .gclient file. |
1369 gclient_configure(solutions, target_os, target_os_only, git_cache_dir) | 1306 gclient_configure(solutions, target_os, target_os_only, git_cache_dir) |
1370 | 1307 |
1371 # Let gclient do the DEPS syncing. | 1308 # Let gclient do the DEPS syncing. |
1372 # The branch-head refspec is a special case because its possible Chrome | 1309 # The branch-head refspec is a special case because its possible Chrome |
1373 # src, which contains the branch-head refspecs, is DEPSed in. | 1310 # src, which contains the branch-head refspecs, is DEPSed in. |
1374 gclient_output = gclient_sync(buildspec or BRANCH_HEADS_REFSPEC in refs, | 1311 gclient_output = gclient_sync(buildspec or BRANCH_HEADS_REFSPEC in refs, |
1375 shallow) | 1312 shallow) |
1376 | 1313 |
1377 # Now that gclient_sync has finished, we should revert any .DEPS.git so that | 1314 # Now that gclient_sync has finished, we should revert any .DEPS.git so that |
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1798 except Exception: | 1735 except Exception: |
1799 # Unexpected failure. | 1736 # Unexpected failure. |
1800 emit_flag(options.flag_file) | 1737 emit_flag(options.flag_file) |
1801 raise | 1738 raise |
1802 else: | 1739 else: |
1803 emit_flag(options.flag_file) | 1740 emit_flag(options.flag_file) |
1804 | 1741 |
1805 | 1742 |
1806 if __name__ == '__main__': | 1743 if __name__ == '__main__': |
1807 sys.exit(main()) | 1744 sys.exit(main()) |
OLD | NEW |