From 733c266dfd0f533d8f97b93737cf628c02d66ff4 Mon Sep 17 00:00:00 2001 From: Arthur Skowronek <0x5a17ed@tuta.io> Date: Fri, 31 May 2024 23:09:09 +0200 Subject: [PATCH] meson.build: ensure the project git directory is used Signed-off-by: Arthur Skowronek <0x5a17ed@tuta.io> --- ci/isdir.py | 4 ---- meson.build | 19 +++++++++---------- 2 files changed, 9 insertions(+), 14 deletions(-) delete mode 100755 ci/isdir.py diff --git a/ci/isdir.py b/ci/isdir.py deleted file mode 100755 index 30166f7a..00000000 --- a/ci/isdir.py +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env python3 -import os, sys -os.chdir(os.environ['MESON_SOURCE_ROOT']) -sys.exit(0 if os.path.isdir(sys.argv[1]) else 1) diff --git a/meson.build b/meson.build index ef3ac903..d77f9327 100644 --- a/meson.build +++ b/meson.build @@ -11,27 +11,26 @@ prefix = get_option('prefix') localedir = get_option('localedir') # Helper scripts -auxdir = join_paths(meson.current_source_dir(), 'ci') -isdir = join_paths(auxdir, 'isdir.py') - -python3 = find_program('python3') -git = find_program('git', required: false) +git = find_program('git', required: false) # Get the right version +fs = import('fs') -is_git_repo = run_command([isdir, '.git'], check: false).returncode() == 0 +git_dir = join_paths(meson.current_source_dir(), '.git') +is_git_repo = fs.exists(git_dir) version = 'v' + meson.project_version() if git.found() and is_git_repo - git_version = run_command([git.full_path(), 'describe', '--dirty', '--tags'], check: false).stdout().strip() - branch = run_command([git.full_path(), 'rev-parse', '--abbrev-ref', 'HEAD'], check: false).stdout().strip() + git_version = run_command([git.full_path(), '--git-dir', git_dir, 'describe', '--dirty', '--tags'], check: false).stdout().strip() + branch = run_command([git.full_path(), '--git-dir', git_dir, 'rev-parse', '--abbrev-ref', 'HEAD'], check: false).stdout().strip() if branch == 'HEAD' - branch = run_command([git.full_path(), 'rev-parse', 'HEAD'], check: false).stdout().strip() + branch = run_command([git.full_path(), '--git-dir', git_dir, 'rev-parse', 'HEAD'], check: false).stdout().strip() endif if git_version != '' version = git_version endif - if branch != 'master' + default_branch = run_command([git.full_path(), '--git-dir', git_dir, 'config', '--default', 'master', '--get', 'init.defaultBranch']).stdout().strip() + if branch != default_branch version = '@0@ (@1@)'.format(version, branch) endif endif