From ee9832cdb180aad535a37f973148149df5ef3a1c Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Sat, 16 Dec 2017 14:22:39 +0200 Subject: [PATCH] Added standalone test case for subdir preservation. --- .../common/173 preserve gendir/base.inp | 1 + .../com/mesonbuild/subbie.inp | 1 + .../common/173 preserve gendir/genprog.py | 47 +++++++++++++++++++ .../common/173 preserve gendir/meson.build | 12 +++++ .../common/173 preserve gendir/testprog.c | 6 +++ 5 files changed, 67 insertions(+) create mode 100644 test cases/common/173 preserve gendir/base.inp create mode 100644 test cases/common/173 preserve gendir/com/mesonbuild/subbie.inp create mode 100755 test cases/common/173 preserve gendir/genprog.py create mode 100644 test cases/common/173 preserve gendir/meson.build create mode 100644 test cases/common/173 preserve gendir/testprog.c diff --git a/test cases/common/173 preserve gendir/base.inp b/test cases/common/173 preserve gendir/base.inp new file mode 100644 index 000000000..df967b96a --- /dev/null +++ b/test cases/common/173 preserve gendir/base.inp @@ -0,0 +1 @@ +base diff --git a/test cases/common/173 preserve gendir/com/mesonbuild/subbie.inp b/test cases/common/173 preserve gendir/com/mesonbuild/subbie.inp new file mode 100644 index 000000000..df0f4e9ae --- /dev/null +++ b/test cases/common/173 preserve gendir/com/mesonbuild/subbie.inp @@ -0,0 +1 @@ +subbie diff --git a/test cases/common/173 preserve gendir/genprog.py b/test cases/common/173 preserve gendir/genprog.py new file mode 100755 index 000000000..8bd2b9d82 --- /dev/null +++ b/test cases/common/173 preserve gendir/genprog.py @@ -0,0 +1,47 @@ +#!/usr/bin/env python3 + +import os, sys, argparse +import pathlib + +h_templ = '''#pragma once + +int %s(); +''' + +c_templ = '''#include"%s.h" + +int %s() { + return 0; +} +''' + +parser = argparse.ArgumentParser() +parser.add_argument('--searchdir', required=True) +parser.add_argument('--outdir', required=True) +parser.add_argument('ifiles', nargs='+') + +options = parser.parse_args() + +searchdir = options.searchdir +outdir = options.outdir +ifiles = options.ifiles + +rel_ofiles = [] + +for ifile in ifiles: + if not ifile.startswith(options.searchdir): + sys.exit('Input file %s does not start with search dir %s.' % (ifile, searchdir)) + rel_ofile = ifile[len(searchdir):] + if rel_ofile[0] == '/' or rel_ofile[0] == '\\': + rel_ofile = rel_ofile[1:] + rel_ofiles.append(os.path.splitext(rel_ofile)[0]) + +ofile_bases = [os.path.join(outdir, i) for i in rel_ofiles] + +for i, ifile_name in enumerate(ifiles): + proto_name = open(ifile_name).readline().strip() + h_out = ofile_bases[i] + '.h' + c_out = ofile_bases[i] + '.c' + os.makedirs(os.path.split(ofile_bases[i])[0], exist_ok=True) + open(h_out, 'w').write(h_templ % (proto_name)) + open(c_out, 'w').write(c_templ % (proto_name, proto_name)) diff --git a/test cases/common/173 preserve gendir/meson.build b/test cases/common/173 preserve gendir/meson.build new file mode 100644 index 000000000..b1a63b1f0 --- /dev/null +++ b/test cases/common/173 preserve gendir/meson.build @@ -0,0 +1,12 @@ +project('preserve subdir', 'c') + +gprog = find_program('genprog.py') + +gen = generator(gprog, \ + output : ['@BASENAME@.c', '@BASENAME@.h'], + preserve_path_from : meson.current_source_dir(), + arguments : ['--searchdir=@CURRENT_SOURCE_DIR@', '--outdir=@BUILD_DIR@', '@INPUT@']) + +generated = gen.process('base.inp', 'com/mesonbuild/subbie.inp') +e = executable('testprog', 'testprog.c', generated) +test('testprog', e) diff --git a/test cases/common/173 preserve gendir/testprog.c b/test cases/common/173 preserve gendir/testprog.c new file mode 100644 index 000000000..46b460257 --- /dev/null +++ b/test cases/common/173 preserve gendir/testprog.c @@ -0,0 +1,6 @@ +#include"base.h" +#include"com/mesonbuild/subbie.h" + +int main(int argc, char **argv) { + return base() + subbie(); +}