Skip to content

Commit 1645f5e

Browse files
committed
[gn build] replace llvm_allow_tardy_revision with llvm_append_vc_rev
Previously, the gn build would create VCSRevision.h / VCSVersion.h files with some LLD_REVISION / LLVM_REVISION / CLANG_REVISION but by default wouldn't add a dependency on .git/logs/HEAD so that the step doesn't rerun after every branch switch or every pull. That's bad for deterministic builds, and having --version print some arbitrarily old revision isn't great either. Instead, move to the model that the cmake build (now) uses fairly consistently: If llvm_append_vc_rev is set, include the revision, else don't. Since the GN build is focused on developers, set llvm_append_vc_rev to false instead of true by default (different from the cmake build), so that things don't rebuild after every branch switch and every pull. While here, also remove some pre-monorepo code. Differential Revision: https://reviews.llvm.org/D72859
1 parent fb5fafb commit 1645f5e

File tree

2 files changed

+31
-32
lines changed

2 files changed

+31
-32
lines changed

llvm/utils/gn/build/write_vcsrevision.gni

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@
99
# Defaults to [ "LLVM" ]
1010

1111
declare_args() {
12-
# If this set to false, VCSRevision.h is updated after every git commit.
12+
# If this is set to true, VCSRevision.h is updated after every git commit.
1313
# That's technically correct, but results in rebuilds after every commit.
14-
# If it's true (default), VCSRevision.h will usually be somewhat
15-
# out-of-date, but builds will be faster.
16-
llvm_allow_tardy_revision = true
14+
# If it's false (default), VCSRevision.h will not contain a revision.
15+
llvm_append_vc_rev = false
1716
}
1817

1918
template("write_vcsrevision") {
@@ -29,9 +28,10 @@ template("write_vcsrevision") {
2928
}
3029

3130
args = [ rebase_path(header, root_build_dir) ]
32-
if (!llvm_allow_tardy_revision) {
31+
if (llvm_append_vc_rev) {
3332
depfile = "$header.d"
3433
args += [
34+
"--write-git-rev",
3535
"-d",
3636
rebase_path(depfile, root_build_dir),
3737
]

llvm/utils/gn/build/write_vcsrevision.py

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -29,40 +29,39 @@ def main():
2929
parser.add_argument('-d', '--depfile',
3030
help='if set, writes a depfile that causes this script '
3131
'to re-run each time the current revision changes')
32+
parser.add_argument('--write-git-rev', action='store_true',
33+
help='if set, writes git revision, else writes #undef')
3234
parser.add_argument('--name', action='append',
3335
help='if set, writes a depfile that causes this script '
3436
'to re-run each time the current revision changes')
3537
parser.add_argument('vcs_header', help='path to the output file to write')
3638
args = parser.parse_args()
3739

38-
if os.path.isdir(os.path.join(LLVM_DIR, '.svn')):
39-
print('SVN support not implemented', file=sys.stderr)
40-
return 1
41-
if os.path.exists(os.path.join(LLVM_DIR, '.git')):
42-
print('non-mono-repo git support not implemented', file=sys.stderr)
43-
return 1
44-
45-
git, use_shell = which('git'), False
46-
if not git:
47-
git = which('git.exe')
48-
if not git:
49-
git = which('git.bat')
50-
use_shell = True
51-
52-
git_dir = subprocess.check_output([git, 'rev-parse', '--git-dir'],
53-
cwd=LLVM_DIR, shell=use_shell).decode().strip()
54-
if not os.path.isdir(git_dir):
55-
print('.git dir not found at "%s"' % git_dir, file=sys.stderr)
56-
return 1
57-
58-
rev = subprocess.check_output([git, 'rev-parse', '--short', 'HEAD'],
59-
cwd=git_dir, shell=use_shell).decode().strip()
60-
url = subprocess.check_output([git, 'remote', 'get-url', 'origin'],
61-
cwd=git_dir, shell=use_shell).decode().strip()
6240
vcsrevision_contents = ''
63-
for name in args.name:
64-
vcsrevision_contents += '#define %s_REVISION "%s"\n' % (name, rev)
65-
vcsrevision_contents += '#define %s_REPOSITORY "%s"\n' % (name, url)
41+
if args.write_git_rev:
42+
git, use_shell = which('git'), False
43+
if not git: git = which('git.exe')
44+
if not git: git, use_shell = which('git.bat'), True
45+
git_dir = subprocess.check_output(
46+
[git, 'rev-parse', '--git-dir'],
47+
cwd=LLVM_DIR, shell=use_shell).decode().strip()
48+
if not os.path.isdir(git_dir):
49+
print('.git dir not found at "%s"' % git_dir, file=sys.stderr)
50+
return 1
51+
52+
rev = subprocess.check_output(
53+
[git, 'rev-parse', '--short', 'HEAD'],
54+
cwd=git_dir, shell=use_shell).decode().strip()
55+
url = subprocess.check_output(
56+
[git, 'remote', 'get-url', 'origin'],
57+
cwd=git_dir, shell=use_shell).decode().strip()
58+
for name in args.name:
59+
vcsrevision_contents += '#define %s_REVISION "%s"\n' % (name, rev)
60+
vcsrevision_contents += '#define %s_REPOSITORY "%s"\n' % (name, url)
61+
else:
62+
for name in args.name:
63+
vcsrevision_contents += '#undef %s_REVISION\n' % name
64+
vcsrevision_contents += '#undef %s_REPOSITORY\n' % name
6665

6766
# If the output already exists and is identical to what we'd write,
6867
# return to not perturb the existing file's timestamp.

0 commit comments

Comments
 (0)