From c71601077699df8464fce4cf9dc11bea598c071e Mon Sep 17 00:00:00 2001 From: Marvin W Date: Sat, 22 Aug 2026 16:21:13 +0200 Subject: Use meson native project version --- build-aux/version.py | 80 ++++++++++++++++++++++++++++++++++++++++++++ libdino/meson.build | 17 ++-------- libdino/src/application.vala | 8 +++-- libdino/src/version.c.in | 4 +++ libdino/src/version.vala.in | 5 --- libdino/version.py | 65 ----------------------------------- main/src/ui/main_window.vala | 3 ++ meson.build | 45 +++++++++++++++++-------- 8 files changed, 125 insertions(+), 102 deletions(-) create mode 100644 build-aux/version.py create mode 100644 libdino/src/version.c.in delete mode 100644 libdino/src/version.vala.in delete mode 100644 libdino/version.py diff --git a/build-aux/version.py b/build-aux/version.py new file mode 100644 index 00000000..45fdfcd3 --- /dev/null +++ b/build-aux/version.py @@ -0,0 +1,80 @@ +import argparse +import subprocess +import re + + +def compute_version_from_file(file): + try: + with open(file) as f: + version_from_file = f.read().strip() + if version_from_file != "": + if version_from_file.startswith("RELEASE "): + return version_from_file[8:].strip() + if version_from_file.startswith("PRERELEASE "): + return version_from_file[11:].strip() + return version_from_file + except FileNotFoundError: + pass + return None + + +def compute_version_from_git(git_repo, git): + try: + git_release_tag = subprocess.check_output([git, "describe", "--tags", "--abbrev=0"], + cwd=git_repo, text=True).strip() + if re.match("^v?([0-9]+[.]?[0-9]*[.]?[0-9]*)(-[.0-9A-Za-z-]+)?([+][.0-9A-Za-z-]+)?$", git_release_tag) is None: + return None + git_describe = subprocess.check_output([git, "describe", "--tags"], cwd=git_repo, text=True).strip() + if git_release_tag == git_describe: + return git_release_tag[1:] + matches = re.match("^.*-([0-9]+)-g([0-9a-f]+)$", git_describe) + if matches is None: + return None + git_tag_offset = matches.groups()[0] + git_commit_hash = matches.groups()[1] + git_commit_time = subprocess.check_output([git, "show", "--format=%cd", "--date=format:%Y%m%d", "-s"], + cwd=git_repo, text=True).strip() + return "%s~git%s.%s.%s" % (git_release_tag[1:], git_tag_offset, git_commit_time, git_commit_hash) + except subprocess.CalledProcessError: + pass + return None + + +def compute_version(file, git_repo, git): + version_from_file = compute_version_from_file(file) + if version_from_file is not None: + return version_from_file + version_from_git = compute_version_from_git(git_repo, git) + if version_from_git is not None: + return version_from_git + return "" + + +def main(): + p = argparse.ArgumentParser(description="Compute the Dino version") + p.add_argument("--git-repo", help="Path to checked out git repository") + p.add_argument("--git", help="Path to git executable", default="git") + p.add_argument("--depfile", help="Create depfile") + p.add_argument("--deptarget", help="Target in depfile") + p.add_argument("version_file", metavar="VERSION_FILE", + help="Use this file's contents as version if the file exists") + args, unknown = p.parse_known_args() + if args.depfile: + with open(args.depfile, mode='w') as f: + f.write("version.stamp: ") + f.write(args.git_repo + "/VERSION ") + f.write(args.git_repo + "/.git/HEAD ") + try: + with open(args.git_repo + "/.git/HEAD") as f2: + head = f2.read().strip() + if head.startswith("ref:"): + f.write(args.git_repo + "/.git/" + head[4:].strip()) + except FileNotFoundError: + pass + else: + version = compute_version(args.version_file, args.git_repo, args.git) + print(version) + + +if __name__ == "__main__": + main() diff --git a/libdino/meson.build b/libdino/meson.build index 12665b18..d0bb2cef 100644 --- a/libdino/meson.build +++ b/libdino/meson.build @@ -1,17 +1,4 @@ -# version_vala -version_py = files('version.py')[0] -if meson.version().version_compare('>=1.4.0') - version_py_path = version_py.full_path() -else - version_py_path = meson.current_source_dir() / 'version.py' -endif -command = [prog_python, version_py_path, version_file_path, '--git-repo', meson.current_source_dir()] -if prog_git.found() - command += ['--git', prog_git] -endif -# We add those dummy args to ensure meson sees the dependency -command += [version_py, version_file] -version_vala = vcs_tag(command: command, input: 'src/version.vala.in', output: 'version.vala', replace_string: '%VERSION%') +version_c = configure_file(input: 'src/version.c.in', output: 'version.c', configuration: {'VERSION': meson.project_version()}) # libdino dependencies = [ @@ -86,7 +73,7 @@ sources = files( 'src/util/util.vala', 'src/util/weak_timeout.vala', ) -sources += [version_vala] +sources += [version_c] c_args = [ '-DDINO_SYSTEM_LIBDIR_NAME="@0@"'.format(get_option('prefix') / get_option('libdir')), '-DDINO_SYSTEM_PLUGIN_DIR="@0@"'.format(get_option('prefix') / get_option('libdir') / get_option('plugindir')), diff --git a/libdino/src/application.vala b/libdino/src/application.vala index 35b706a4..f2e3cc9b 100644 --- a/libdino/src/application.vala +++ b/libdino/src/application.vala @@ -2,10 +2,12 @@ using Dino.Entities; namespace Dino { -public string get_version() { return VERSION; } +public extern unowned string get_version(); + public string get_short_version() { - if (!VERSION.contains("~")) return VERSION; - return VERSION.split("~")[0] + "+"; + string version = get_version(); + if (!version.contains("~")) return version; + return version.split("~")[0] + "+"; } public interface Application : GLib.Application { diff --git a/libdino/src/version.c.in b/libdino/src/version.c.in new file mode 100644 index 00000000..44603c04 --- /dev/null +++ b/libdino/src/version.c.in @@ -0,0 +1,4 @@ +const char* dino_get_version () +{ + return "@VERSION@"; +} \ No newline at end of file diff --git a/libdino/src/version.vala.in b/libdino/src/version.vala.in deleted file mode 100644 index 2711d4a6..00000000 --- a/libdino/src/version.vala.in +++ /dev/null @@ -1,5 +0,0 @@ -namespace Dino { - -public const string VERSION = "%VERSION%"; - -} diff --git a/libdino/version.py b/libdino/version.py deleted file mode 100644 index 87490d18..00000000 --- a/libdino/version.py +++ /dev/null @@ -1,65 +0,0 @@ -import argparse -import subprocess -import re - - -def compute_version_from_file(file): - try: - with open(file) as f: - version_from_file = f.read().strip() - if version_from_file != "": - if version_from_file.startswith("RELEASE "): - return version_from_file[8:].strip() - if version_from_file.startswith("PRERELEASE "): - return version_from_file[11:].strip() - return version_from_file - except FileNotFoundError: - pass - return None - - -def compute_version_from_git(git_repo, git): - try: - git_release_tag = subprocess.check_output([git, "describe", "--tags", "--abbrev=0"], - cwd=git_repo, text=True).strip() - if re.match("^v?([0-9]+[.]?[0-9]*[.]?[0-9]*)(-[.0-9A-Za-z-]+)?([+][.0-9A-Za-z-]+)?$", git_release_tag) is None: - return None - git_describe = subprocess.check_output([git, "describe", "--tags"], cwd=git_repo, text=True).strip() - if git_release_tag == git_describe: - return git_release_tag[1:] - matches = re.match("^.*-([0-9]+)-g([0-9a-f]+)$", git_describe) - if matches is None: - return None - git_tag_offset = matches.groups()[0] - git_commit_hash = matches.groups()[1] - git_commit_time = subprocess.check_output([git, "show", "--format=%cd", "--date=format:%Y%m%d", "-s"], - cwd=git_repo, text=True).strip() - return "%s~git%s.%s.%s" % (git_release_tag[1:], git_tag_offset, git_commit_time, git_commit_hash) - except subprocess.CalledProcessError: - pass - return None - - -def compute_version(file, git_repo, git): - version_from_file = compute_version_from_file(file) - if version_from_file is not None: - return version_from_file - version_from_git = compute_version_from_git(git_repo, git) - if version_from_git is not None: - return version_from_git - return "" - - -def main(): - p = argparse.ArgumentParser(description="Compute the Dino version") - p.add_argument("--git-repo", help="Path to checked out git repository") - p.add_argument("--git", help="Path to git executable", default="git") - p.add_argument("version_file", metavar="VERSION_FILE", - help="Use this file's contents as version if the file exists") - args, unknown = p.parse_known_args() - version = compute_version(args.version_file, args.git_repo, args.git) - print(version) - - -if __name__ == "__main__": - main() diff --git a/main/src/ui/main_window.vala b/main/src/ui/main_window.vala index 6cabfea7..d2a23954 100644 --- a/main/src/ui/main_window.vala +++ b/main/src/ui/main_window.vala @@ -52,6 +52,9 @@ public class MainWindow : Adw.ApplicationWindow { this.title = "Dino"; this.add_css_class("dino-main"); + if (Dino.get_version().contains("~git")) { + this.add_css_class("devel"); + } ((Widget)this).realize.connect(restore_window_size); diff --git a/meson.build b/meson.build index eb372b6a..0fbe797d 100644 --- a/meson.build +++ b/meson.build @@ -1,9 +1,37 @@ -project('Dino', 'c', 'cpp', 'vala', license: 'GPL-3.0', meson_version: '>=1.3.0') +project( + 'Dino', + 'c', 'cpp', 'vala', + license: 'GPL-3.0', + meson_version: '>=1.3.0', + version: run_command( + find_program('python3', required: true), # Can't use import('python').find_installation() here + meson.current_source_dir() / 'build-aux' / 'version.py', + meson.current_source_dir() / 'VERSION', + '--git-repo', meson.current_source_dir(), + '--git', find_program('git', required: false), + check: true + ).stdout().strip() +) -fs = import('fs') gnome = import('gnome') i18n = import('i18n') -python = import('python') + +# Trigger recomnfiguration on version change +version_stamp = configure_file( + command: [ + # Keep in sync with above + find_program('python3', required: true), + meson.current_source_dir() / 'build-aux' / 'version.py', + meson.current_source_dir() / 'VERSION', + '--git-repo', meson.current_source_dir(), + '--git', find_program('git', required: false), + # Trigger depfile generation + '--depfile', '@DEPFILE@' + ], + input: 'build-aux' / 'version.py', + output: 'version.stamp', + depfile: 'version.d' +) # plugin_crypto is enabled if any of the crypto plugins is enabled, auto if # none of them are explicitly enabled but at least one is set to auto, or @@ -53,17 +81,6 @@ if not dep_webrtc_audio_processing.found() dep_webrtc_audio_processing = disabler() endif -prog_git = find_program('git', required: false) -prog_python = python.find_installation() - -if import('fs').is_file('VERSION') and meson.version().version_compare('>=1.4.0') - version_file = files('VERSION')[0] - version_file_path = version_file.full_path() -else - version_file = 'invalid' - version_file_path = meson.current_source_dir() / 'VERSION' -endif - default_install_rpath = '' if get_option('set-install-rpath') default_install_rpath = get_option('prefix') / get_option('libdir') -- cgit v1.3