aboutsummaryrefslogtreecommitdiff
path: root/libdino/version.py
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi.dcr@tutanota.com>2023-09-11 23:03:51 +0200
committerXavier Del Campo Romero <xavi.dcr@tutanota.com>2023-10-09 14:08:59 +0200
commitbe7e0c2d5689d962fd2424e60ed21062d0674e95 (patch)
treef3b5fc213f7cb832e31f4877db0abf9e2c908930 /libdino/version.py
parent1cc99a640fe694c1545eb2ecc01311f7bad26aed (diff)
downloaddino-be7e0c2d5689d962fd2424e60ed21062d0674e95.tar.gz
Backport Meson build support
Meson builds have better integration with Vala. For example, Meson handles incremental compilation of Vala source files better than CMake. Limitations: As done with CMake builds, gresource.xml should be compiled. Now, it has been generated from a CMake build and manually copied into the source tree.
Diffstat (limited to 'libdino/version.py')
-rw-r--r--libdino/version.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/libdino/version.py b/libdino/version.py
new file mode 100644
index 00000000..d34db6a8
--- /dev/null
+++ b/libdino/version.py
@@ -0,0 +1,36 @@
+import argparse
+import subprocess
+VERSION_VALA = """\
+namespace Dino {{
+
+public const string VERSION = "{}";
+
+}}
+"""
+
+def compute_version(file, git_repo, git):
+ try:
+ with open(file) as f:
+ return f.read().strip()
+ except FileNotFoundError:
+ pass
+ return subprocess.check_output([git, "describe", "--tags"], cwd=git_repo, text=True).strip()
+
+def generate_version_vala(version):
+ if "\\" in version or "\"" in version:
+ raise ValueError(f"invalid version {version!r}")
+ return VERSION_VALA.format(version)
+
+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")
+ p.add_argument("output", metavar="OUTPUT", help="Vala file to output to")
+ args = p.parse_args()
+ out = generate_version_vala(compute_version(args.version_file, args.git_repo, args.git))
+ with open(args.output, "w") as f:
+ f.write(out)
+
+if __name__ == "__main__":
+ main()