Commit bf8cb87f authored by Hans Wennborg's avatar Hans Wennborg

Clang build.py: LLVM no longer has SVN revision numbers

Instead, version the package as e.g. n12345-3bf7fdde-0, where 12345 is the
number of commits since the first commit in the git repo.

Bug: 1015315
Change-Id: I1996a5268a5320276f01b9517ae29219b74892e5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1874165Reviewed-by: default avatarNico Weber <thakis@chromium.org>
Commit-Queue: Hans Wennborg <hans@chromium.org>
Cr-Commit-Position: refs/heads/master@{#708245}
parent 27e5fa6c
...@@ -52,6 +52,9 @@ BUG_REPORT_URL = ('https://crbug.com and run' ...@@ -52,6 +52,9 @@ BUG_REPORT_URL = ('https://crbug.com and run'
' tools/clang/scripts/process_crashreports.py' ' tools/clang/scripts/process_crashreports.py'
' (only works inside Google) which will upload a report') ' (only works inside Google) which will upload a report')
FIRST_LLVM_COMMIT = '97724f18c79c7cc81ced24239eb5e883bf1398ef'
def RunCommand(command, msvc_arch=None, env=None, fail_hard=True): def RunCommand(command, msvc_arch=None, env=None, fail_hard=True):
"""Run command and return success (True) or failure; or if fail_hard is """Run command and return success (True) or failure; or if fail_hard is
...@@ -104,9 +107,11 @@ def CheckoutLLVM(commit, dir): ...@@ -104,9 +107,11 @@ def CheckoutLLVM(commit, dir):
if os.path.isdir(dir): if os.path.isdir(dir):
os.chdir(dir) os.chdir(dir)
# git diff-index --quiet returns success when there is no diff. # git diff-index --quiet returns success when there is no diff.
# Also check that the first commit is reachable.
if (RunCommand(['git', 'diff-index', '--quiet', 'HEAD'], fail_hard=False) if (RunCommand(['git', 'diff-index', '--quiet', 'HEAD'], fail_hard=False)
and RunCommand(['git', 'fetch'], fail_hard=False) and RunCommand(['git', 'fetch'], fail_hard=False)
and RunCommand(['git', 'checkout', commit], fail_hard=False)): and RunCommand(['git', 'checkout', commit], fail_hard=False)
and RunCommand(['git', 'show', FIRST_LLVM_COMMIT], fail_hard=False)):
return return
# If we can't use the current repo, delete it. # If we can't use the current repo, delete it.
...@@ -114,12 +119,7 @@ def CheckoutLLVM(commit, dir): ...@@ -114,12 +119,7 @@ def CheckoutLLVM(commit, dir):
print('Removing %s.' % dir) print('Removing %s.' % dir)
RmTree(dir) RmTree(dir)
# Do a somewhat shallow clone to save on bandwidth for GitHub and for us. clone_cmd = ['git', 'clone', 'https://github.com/llvm/llvm-project/', dir]
# The depth was chosen to be deep enough to contain the version we're
# building, and shallow enough to save significantly on bandwidth compared to
# a full clone.
clone_cmd = ['git', 'clone', '--depth', '10000',
'https://github.com/llvm/llvm-project/', dir]
if RunCommand(clone_cmd, fail_hard=False): if RunCommand(clone_cmd, fail_hard=False):
os.chdir(dir) os.chdir(dir)
...@@ -147,12 +147,10 @@ def GetLatestLLVMCommit(): ...@@ -147,12 +147,10 @@ def GetLatestLLVMCommit():
return ref['object']['sha'] return ref['object']['sha']
def GetSvnRevision(commit): def GetCommitCount(commit):
"""Get the svn revision corresponding to a git commit in the LLVM repo.""" """Get the number of commits from FIRST_LLVM_COMMIT to commit."""
commit = json.loads(UrlOpen(('https://api.github.com/repos/llvm/' return subprocess.check_output(['git', 'rev-list', '--count',
'llvm-project/git/commits/' + commit))) FIRST_LLVM_COMMIT + '..' + commit]).rstrip()
revision = re.search("llvm-svn: ([0-9]+)$", commit['message']).group(1)
return revision
def DeleteChromeToolsShim(): def DeleteChromeToolsShim():
...@@ -371,6 +369,9 @@ def main(): ...@@ -371,6 +369,9 @@ def main():
return 1 return 1
# Don't buffer stdout, so that print statements are immediately flushed.
sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
# The gnuwin package also includes curl, which is needed to interact with the # The gnuwin package also includes curl, which is needed to interact with the
# github API below. # github API below.
# TODO(crbug.com/965937): Use urllib once our Python is recent enough, and # TODO(crbug.com/965937): Use urllib once our Python is recent enough, and
...@@ -384,11 +385,13 @@ def main(): ...@@ -384,11 +385,13 @@ def main():
global CLANG_REVISION, PACKAGE_VERSION global CLANG_REVISION, PACKAGE_VERSION
if args.llvm_force_head_revision: if args.llvm_force_head_revision:
CLANG_REVISION = GetLatestLLVMCommit() CLANG_REVISION = GetLatestLLVMCommit()
PACKAGE_VERSION = '%s-%s-0' % (GetSvnRevision(CLANG_REVISION),
CLANG_REVISION[:8])
# Don't buffer stdout, so that print statements are immediately flushed. if not args.skip_checkout:
sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0) CheckoutLLVM(CLANG_REVISION, LLVM_DIR);
if args.llvm_force_head_revision:
PACKAGE_VERSION = 'n%s-%s-0' % (GetCommitCount(CLANG_REVISION),
CLANG_REVISION[:8])
print('Locally building clang %s...' % PACKAGE_VERSION) print('Locally building clang %s...' % PACKAGE_VERSION)
WriteStampFile('', STAMP_FILE) WriteStampFile('', STAMP_FILE)
...@@ -397,8 +400,6 @@ def main(): ...@@ -397,8 +400,6 @@ def main():
AddCMakeToPath(args) AddCMakeToPath(args)
DeleteChromeToolsShim() DeleteChromeToolsShim()
if not args.skip_checkout:
CheckoutLLVM(CLANG_REVISION, LLVM_DIR);
if args.skip_build: if args.skip_build:
return 0 return 0
......
...@@ -18,7 +18,7 @@ import shutil ...@@ -18,7 +18,7 @@ import shutil
import subprocess import subprocess
import sys import sys
from build import GetSvnRevision from build import GetCommitCount
# Path constants. # Path constants.
THIS_DIR = os.path.dirname(__file__) THIS_DIR = os.path.dirname(__file__)
...@@ -66,14 +66,14 @@ def main(): ...@@ -66,14 +66,14 @@ def main():
args = parser.parse_args() args = parser.parse_args()
clang_git_revision = args.clang_git_revision[0] clang_git_revision = args.clang_git_revision[0]
clang_svn_revision = GetSvnRevision(clang_git_revision) clang_svn_revision = GetCommitCount(clang_git_revision)
clang_sub_revision = args.clang_sub_revision clang_sub_revision = args.clang_sub_revision
# Needs shell=True on Windows due to git.bat in depot_tools. # Needs shell=True on Windows due to git.bat in depot_tools.
git_revision = subprocess.check_output( git_revision = subprocess.check_output(
["git", "rev-parse", "origin/master"], shell=is_win).strip() ["git", "rev-parse", "origin/master"], shell=is_win).strip()
print("Making a patch for Clang {}-{}-{}".format( print("Making a patch for Clang n{}-{}-{}".format(
clang_svn_revision, clang_git_revision[:8], clang_sub_revision)) clang_svn_revision, clang_git_revision[:8], clang_sub_revision))
print("Chrome revision: {}".format(git_revision)) print("Chrome revision: {}".format(git_revision))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment