aboutsummaryrefslogtreecommitdiffstats
path: root/meson/test cases/common/195 generator in subdir/com/mesonbuild
diff options
context:
space:
mode:
authorAngelos Mouzakitis <a.mouzakitis@virtualopensystems.com>2023-10-10 14:33:42 +0000
committerAngelos Mouzakitis <a.mouzakitis@virtualopensystems.com>2023-10-10 14:33:42 +0000
commitaf1a266670d040d2f4083ff309d732d648afba2a (patch)
tree2fc46203448ddcc6f81546d379abfaeb323575e9 /meson/test cases/common/195 generator in subdir/com/mesonbuild
parente02cda008591317b1625707ff8e115a4841aa889 (diff)
Add submodule dependency filesHEADmaster
Change-Id: Iaf8d18082d3991dec7c0ebbea540f092188eb4ec
Diffstat (limited to 'meson/test cases/common/195 generator in subdir/com/mesonbuild')
-rw-r--r--meson/test cases/common/195 generator in subdir/com/mesonbuild/genprog.py46
-rw-r--r--meson/test cases/common/195 generator in subdir/com/mesonbuild/meson.build10
-rw-r--r--meson/test cases/common/195 generator in subdir/com/mesonbuild/subbie.inp1
-rw-r--r--meson/test cases/common/195 generator in subdir/com/mesonbuild/testprog.c5
4 files changed, 62 insertions, 0 deletions
diff --git a/meson/test cases/common/195 generator in subdir/com/mesonbuild/genprog.py b/meson/test cases/common/195 generator in subdir/com/mesonbuild/genprog.py
new file mode 100644
index 000000000..681c43a84
--- /dev/null
+++ b/meson/test cases/common/195 generator in subdir/com/mesonbuild/genprog.py
@@ -0,0 +1,46 @@
+#!/usr/bin/env python3
+
+import os, sys, argparse
+
+h_templ = '''#pragma once
+
+int %s(void);
+'''
+
+c_templ = '''#include"%s.h"
+
+int %s(void) {
+ 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(f'Input file {ifile} does not start with search dir {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/meson/test cases/common/195 generator in subdir/com/mesonbuild/meson.build b/meson/test cases/common/195 generator in subdir/com/mesonbuild/meson.build
new file mode 100644
index 000000000..4808743fe
--- /dev/null
+++ b/meson/test cases/common/195 generator in subdir/com/mesonbuild/meson.build
@@ -0,0 +1,10 @@
+gprog = find_program('genprog.py')
+
+gen = generator(gprog, \
+ output : ['@BASENAME@.c', '@BASENAME@.h'],
+ arguments : ['--searchdir=@CURRENT_SOURCE_DIR@', '--outdir=@BUILD_DIR@', '@INPUT@'])
+
+generated = gen.process('subbie.inp')
+
+e = executable('testprog', 'testprog.c', generated)
+test('testprog', e)
diff --git a/meson/test cases/common/195 generator in subdir/com/mesonbuild/subbie.inp b/meson/test cases/common/195 generator in subdir/com/mesonbuild/subbie.inp
new file mode 100644
index 000000000..df0f4e9ae
--- /dev/null
+++ b/meson/test cases/common/195 generator in subdir/com/mesonbuild/subbie.inp
@@ -0,0 +1 @@
+subbie
diff --git a/meson/test cases/common/195 generator in subdir/com/mesonbuild/testprog.c b/meson/test cases/common/195 generator in subdir/com/mesonbuild/testprog.c
new file mode 100644
index 000000000..7a7cdf7aa
--- /dev/null
+++ b/meson/test cases/common/195 generator in subdir/com/mesonbuild/testprog.c
@@ -0,0 +1,5 @@
+#include"subbie.h"
+
+int main(void) {
+ return subbie();
+}