From 24484412b570f53e447b81017a15ec23b6417106 Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Sat, 7 Feb 2015 14:33:43 +0200 Subject: [PATCH] Start proper approach to determining how build_always targets should work by writing a proper test case illustrating how it should behave. --- test cases/common/72 build always/main.c | 7 +++++ test cases/common/72 build always/meson.build | 15 ++++++++++ .../common/72 build always/version.c.in | 3 ++ test cases/common/72 build always/version.h | 3 ++ .../common/72 build always/version_gen.py | 29 +++++++++++++++++++ 5 files changed, 57 insertions(+) create mode 100644 test cases/common/72 build always/main.c create mode 100644 test cases/common/72 build always/meson.build create mode 100644 test cases/common/72 build always/version.c.in create mode 100644 test cases/common/72 build always/version.h create mode 100755 test cases/common/72 build always/version_gen.py diff --git a/test cases/common/72 build always/main.c b/test cases/common/72 build always/main.c new file mode 100644 index 000000000..f8d9ac971 --- /dev/null +++ b/test cases/common/72 build always/main.c @@ -0,0 +1,7 @@ +#include +#include"version.h" + +int main(int argc, char **argv) { + printf("Version is %s.\n", version_string); + return 0; +} diff --git a/test cases/common/72 build always/meson.build b/test cases/common/72 build always/meson.build new file mode 100644 index 000000000..7cb2e4b0a --- /dev/null +++ b/test cases/common/72 build always/meson.build @@ -0,0 +1,15 @@ +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, +include_directories : include_directories('.')) diff --git a/test cases/common/72 build always/version.c.in b/test cases/common/72 build always/version.c.in new file mode 100644 index 000000000..619e51786 --- /dev/null +++ b/test cases/common/72 build always/version.c.in @@ -0,0 +1,3 @@ +#include"version.h" + +const char *version_string = "@VERSION@"; diff --git a/test cases/common/72 build always/version.h b/test cases/common/72 build always/version.h new file mode 100644 index 000000000..d3fe5c695 --- /dev/null +++ b/test cases/common/72 build always/version.h @@ -0,0 +1,3 @@ +#pragma once + +const char *version_string; diff --git a/test cases/common/72 build always/version_gen.py b/test cases/common/72 build always/version_gen.py new file mode 100755 index 000000000..34e8da3c0 --- /dev/null +++ b/test cases/common/72 build always/version_gen.py @@ -0,0 +1,29 @@ +#!/usr/bin/python3 + +import sys, os, subprocess + +def generate(infile, outfile, fallback): + workdir = os.path.split(infile)[0] + if workdir == '': + workdir = '.' + p = subprocess.Popen(['git', 'describe'], cwd=workdir, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + (stdo, _) = p.communicate() + # If we are working off an extracted tarball, git version number is not available. + if p.returncode == 0: + version = stdo.decode().strip() + else: + version = fallback + newdata = open(infile).read().replace('@VERSION@', version) + try: + olddata = open(outfile).read() + if olddata == newdata: + return + except Exception: + pass + open(outfile, 'w').write(newdata) + +if __name__ == '__main__': + infile = sys.argv[1] + outfile = sys.argv[2] + fallback = sys.argv[3] + generate(infile, outfile, fallback)