diff options
Diffstat (limited to 'meson/test cases/common/65 build always')
5 files changed, 56 insertions, 0 deletions
diff --git a/meson/test cases/common/65 build always/main.c b/meson/test cases/common/65 build always/main.c new file mode 100644 index 000000000..a9ee55ea1 --- /dev/null +++ b/meson/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/meson/test cases/common/65 build always/meson.build b/meson/test cases/common/65 build always/meson.build new file mode 100644 index 000000000..f720c8943 --- /dev/null +++ b/meson/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/meson/test cases/common/65 build always/version.c.in b/meson/test cases/common/65 build always/version.c.in new file mode 100644 index 000000000..619e51786 --- /dev/null +++ b/meson/test cases/common/65 build always/version.c.in @@ -0,0 +1,3 @@ +#include"version.h" + +const char *version_string = "@VERSION@"; diff --git a/meson/test cases/common/65 build always/version.h b/meson/test cases/common/65 build always/version.h new file mode 100644 index 000000000..7d433f035 --- /dev/null +++ b/meson/test cases/common/65 build always/version.h @@ -0,0 +1,3 @@ +#pragma once + +extern const char *version_string; diff --git a/meson/test cases/common/65 build always/version_gen.py b/meson/test cases/common/65 build always/version_gen.py new file mode 100755 index 000000000..fbe2df93f --- /dev/null +++ b/meson/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) |