Skip to content

Commit 36c26f5

Browse files
committed
meson.build: Detect if we build from a git subtree
See https://gitlab.gnome.org/GNOME/gtkmm/-/merge_requests/72
1 parent 716475f commit 36c26f5

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

meson.build

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,15 @@ if not python_version.version_compare(python_version_req)
5454
endif
5555

5656
# Do we build from a git repository?
57-
# Suppose we do if and only if a '.git' directory or file exists.
57+
# Suppose we do if and only if the meson.build file is tracked by git.
5858
cmd_py = '''
59-
import os
60-
import sys
61-
sys.exit(os.path.isdir("@0@") or os.path.isfile("@0@"))
62-
'''.format(project_source_root / '.git')
63-
is_git_build = run_command(python3, '-c', cmd_py, check: false).returncode() != 0
59+
import shutil, subprocess, sys
60+
if not shutil.which('git'):
61+
sys.exit(1)
62+
cmd = [ 'git', 'ls-files', '--error-unmatch', 'meson.build' ]
63+
sys.exit(subprocess.run(cmd, cwd="@0@", stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL).returncode)
64+
'''.format(project_source_root)
65+
is_git_build = run_command(python3, '-c', cmd_py, check: false).returncode() == 0
6466

6567
# Are we testing a dist tarball while it's being built?
6668
# There ought to be a better way. https://github.com/mesonbuild/meson/issues/6866

0 commit comments

Comments
 (0)