mirror of
https://github.com/electron/electron.git
synced 2026-05-02 03:00:22 -04:00
BUILD.gn previously hard-coded read_file(".git/packed-refs", ...) and
".git/HEAD" to derive electron_version. In a `git worktree` checkout
.git is a file containing a gitdir: pointer, not a directory, so GN's
read_file() fails and gn gen aborts unless override_electron_version is
set manually.
Ask git itself for the real locations via `git rev-parse --git-dir` /
`--git-common-dir` in a small helper script, and feed those resolved
paths to read_file() and the exec_script dependency list. Behaviour in
a plain clone is unchanged (both resolve to electron/.git/...), and the
tarball case still fails loudly with a pointer to
override_electron_version.
36 lines
1.3 KiB
Python
36 lines
1.3 KiB
Python
#!/usr/bin/env python3
|
|
|
|
import os
|
|
import subprocess
|
|
import sys
|
|
|
|
# Resolve the on-disk locations of HEAD and packed-refs for this checkout so
|
|
# that BUILD.gn can register them as build graph inputs. In a plain clone both
|
|
# live under electron/.git/, but in a `git worktree` checkout .git is a file
|
|
# pointing at <common>/.git/worktrees/<name>; HEAD lives there while
|
|
# packed-refs is shared in the common dir. GN's read_file() does not follow
|
|
# that indirection, so we ask git to do it for us.
|
|
|
|
ELECTRON_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
|
|
|
|
|
|
def rev_parse(flag):
|
|
out = subprocess.check_output(['git', 'rev-parse', flag],
|
|
cwd=ELECTRON_DIR,
|
|
stderr=subprocess.PIPE,
|
|
universal_newlines=True).strip()
|
|
return out if os.path.isabs(out) else os.path.join(ELECTRON_DIR, out)
|
|
|
|
|
|
try:
|
|
git_dir = rev_parse('--git-dir')
|
|
common_dir = rev_parse('--git-common-dir')
|
|
except (subprocess.CalledProcessError, OSError) as e:
|
|
sys.stderr.write(f'get-git-ref-paths.py: not a git checkout '
|
|
f'(set override_electron_version): {e}\n')
|
|
sys.exit(1)
|
|
|
|
for p in (os.path.join(common_dir, 'packed-refs'),
|
|
os.path.join(git_dir, 'HEAD')):
|
|
print(os.path.normpath(p).replace('\\', '/'))
|