summaryrefslogtreecommitdiffstats
path: root/test cases/common/65 build always
diff options
context:
space:
mode:
Diffstat (limited to 'test cases/common/65 build always')
-rw-r--r--test cases/common/65 build always/main.c7
-rw-r--r--test cases/common/65 build always/meson.build14
-rw-r--r--test cases/common/65 build always/version.c.in3
-rw-r--r--test cases/common/65 build always/version.h3
-rwxr-xr-xtest cases/common/65 build always/version_gen.py29
5 files changed, 56 insertions, 0 deletions
diff --git a/test cases/common/65 build always/main.c b/test cases/common/65 build always/main.c
new file mode 100644
index 0000000..a9ee55e
--- /dev/null
+++ b/test cases/common/65 build always/main.c
@@ -0,0 +1,7 @@
+#include<stdio.h>
+#include"version.h"
+
+int main(void) {
+ printf("Version is %s.\n", version_string);
+ return 0;
+}
diff --git a/test cases/common/65 build always/meson.build b/test cases/common/65 build always/meson.build
new file mode 100644
index 0000000..f720c89
--- /dev/null
+++ b/test cases/common/65 build always/meson.build
@@ -0,0 +1,14 @@
+project('run always', 'c')
+
+version = '1.0.0'
+
+vgen = find_program('version_gen.py')
+
+version_src = custom_target('Version string',
+input : 'version.c.in',
+output : 'version.c',
+command : [vgen, '@INPUT@', '@OUTPUT@', version],
+build_always : true,
+)
+
+executable('versionprinter', 'main.c', version_src)
diff --git a/test cases/common/65 build always/version.c.in b/test cases/common/65 build always/version.c.in
new file mode 100644
index 0000000..619e517
--- /dev/null
+++ b/test cases/common/65 build always/version.c.in
@@ -0,0 +1,3 @@
+#include"version.h"
+
+const char *version_string = "@VERSION@";
diff --git a/test cases/common/65 build always/version.h b/test cases/common/65 build always/version.h
new file mode 100644
index 0000000..7d433f0
--- /dev/null
+++ b/test cases/common/65 build always/version.h
@@ -0,0 +1,3 @@
+#pragma once
+
+extern const char *version_string;
diff --git a/test cases/common/65 build always/version_gen.py b/test cases/common/65 build always/version_gen.py
new file mode 100755
index 0000000..fbe2df9
--- /dev/null
+++ b/test cases/common/65 build always/version_gen.py
@@ -0,0 +1,29 @@
+#!/usr/bin/env python3
+
+import sys, os, subprocess
+
+def generate(infile, outfile, fallback):
+ workdir = os.path.split(infile)[0]
+ if workdir == '':
+ workdir = '.'
+ try:
+ version = subprocess.check_output(['git', 'describe'], cwd=workdir).decode().strip()
+ except (subprocess.CalledProcessError, OSError, UnicodeDecodeError):
+ version = fallback
+ with open(infile) as f:
+ newdata = f.read().replace('@VERSION@', version)
+ try:
+ with open(outfile) as f:
+ olddata = f.read()
+ if olddata == newdata:
+ return
+ except OSError:
+ pass
+ with open(outfile, 'w') as f:
+ f.write(newdata)
+
+if __name__ == '__main__':
+ infile = sys.argv[1]
+ outfile = sys.argv[2]
+ fallback = sys.argv[3]
+ generate(infile, outfile, fallback)