aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build.py11
-rw-r--r--ninjabackend.py13
-rw-r--r--test cases/common/56 custom target/meson.build7
-rw-r--r--test cases/frameworks/7 gir/installed_files.txt1
-rw-r--r--test cases/frameworks/7 gir/meson.build26
-rw-r--r--test cases/frameworks/7 gir/prog.c17
6 files changed, 65 insertions, 10 deletions
diff --git a/build.py b/build.py
index 9d02740..d1a4de0 100644
--- a/build.py
+++ b/build.py
@@ -569,10 +569,12 @@ class CustomTarget:
self.subdir = subdir
self.dependencies = []
self.process_kwargs(kwargs)
- self.sources = []
self.extra_files = []
def process_kwargs(self, kwargs):
+ self.sources = kwargs.get('input', [])
+ if not isinstance(self.sources, list):
+ self.sources = [self.sources]
if 'output' not in kwargs:
raise InvalidArguments('Missing keyword argument "output".')
self.output = kwargs['output']
@@ -598,6 +600,13 @@ class CustomTarget:
elif isinstance(c, BuildTarget) or isinstance(c, CustomTarget):
self.dependencies.append(c)
final_cmd.append(os.path.join(c.get_subdir(), c.get_filename()))
+ elif isinstance(c, list):
+ # Hackety hack, only supports one level of flattening. Should really
+ # work to arbtrary depth.
+ for s in c:
+ if not isinstance(s, str):
+ raise InvalidArguments('Array as argument %d contains a non-string.' % i)
+ final_cmd.append(s)
else:
raise InvalidArguments('Argument %s in "command" is invalid.' % i)
self.command = final_cmd
diff --git a/ninjabackend.py b/ninjabackend.py
index 45e19dd..ad06486 100644
--- a/ninjabackend.py
+++ b/ninjabackend.py
@@ -137,8 +137,19 @@ class NinjaBackend(backends.Backend):
def generate_custom_target(self, target, outfile):
ofilename = os.path.join(target.subdir, target.output)
deps = [os.path.join(i.get_subdir(), i.get_filename()) for i in target.get_dependencies()]
+ srcs = [os.path.join(self.build_to_src, i) for i in target.sources]
+ deps += srcs
elem = NinjaBuildElement(ofilename, 'CUSTOM_COMMAND', deps)
- elem.add_item('COMMAND', target.command)
+ cmd = []
+ for i in target.command:
+ if i == '@INPUT@':
+ cmd += srcs
+ elif i == '@OUTPUT@':
+ cmd.append(ofilename)
+ else:
+ cmd.append(i)
+ elem.add_item('COMMAND', cmd)
+ elem.add_item('description', 'Generating %s with a custom command.' % ofilename)
elem.write(outfile)
self.processed_targets[target.name] = True
diff --git a/test cases/common/56 custom target/meson.build b/test cases/common/56 custom target/meson.build
index c53dda2..ef51da8 100644
--- a/test cases/common/56 custom target/meson.build
+++ b/test cases/common/56 custom target/meson.build
@@ -2,13 +2,14 @@ project('custom target', 'c')
python = find_program('python3')
+# Note that this will not add a depencency to the compiler executable.
+# Code will not be rebuilt if it changes.
comp = '@0@/@1@'.format(meson.current_source_dir(), 'my_compiler.py')
-infile = '@0@/@1@'.format(meson.current_source_dir(), 'data_source.txt')
-outfile = '@0@/@1@'.format(meson.current_build_dir(), 'data.dat')
mytarget = custom_target('bindat',
output : 'data.dat',
-command : [python, comp, infile, outfile],
+input : 'data_source.txt',
+command : [python, comp, '@INPUT@', '@OUTPUT@'],
install : true,
install_dir : 'subdir'
)
diff --git a/test cases/frameworks/7 gir/installed_files.txt b/test cases/frameworks/7 gir/installed_files.txt
new file mode 100644
index 0000000..568324a
--- /dev/null
+++ b/test cases/frameworks/7 gir/installed_files.txt
@@ -0,0 +1 @@
+typelibdir/Meson-1.0.typelib \ No newline at end of file
diff --git a/test cases/frameworks/7 gir/meson.build b/test cases/frameworks/7 gir/meson.build
index af85c8b..2f02b8f 100644
--- a/test cases/frameworks/7 gir/meson.build
+++ b/test cases/frameworks/7 gir/meson.build
@@ -2,10 +2,34 @@ project('gobject-introspection', 'c')
glib = dependency('glib-2.0')
gobj = dependency('gobject-2.0')
+gir = dependency('gobject-introspection-1.0')
+gmod = dependency('gmodule-2.0')
+
+girscan = find_program('g-ir-scanner')
+girc = find_program('g-ir-compiler')
libsources = ['golib.c', 'golib.h']
exe = executable('goprog', libsources, 'prog.c',
-deps : [glib, gobj])
+deps : [glib, gobj, gir, gmod])
test('gobjtest', exe)
+
+# Let's create Gir data with custom targets to prove that
+# Meson's syntax is expressive enough.
+r = run_command('pkg-config', '--cflags', 'gobject-introspection-1.0')
+custom_gir_args = r.stdout().strip().split()
+
+golibgir = custom_target('golibgir',
+ output : 'Meson-1.0.gir',
+ input : libsources,
+ command : [girscan, '@INPUT@', '--program', exe, custom_gir_args, '--include=GObject-2.0',
+ '--namespace=Meson', '--nsversion=1.0', '--output', '@OUTPUT@'],
+)
+
+custom_target('golibtypelib',
+ output : 'Meson-1.0.typelib',
+ command : [girc, golibgir,'--output', '@OUTPUT@'],
+ install : true,
+ install_dir : 'typelibdir'
+)
diff --git a/test cases/frameworks/7 gir/prog.c b/test cases/frameworks/7 gir/prog.c
index 137737e..71584d6 100644
--- a/test cases/frameworks/7 gir/prog.c
+++ b/test cases/frameworks/7 gir/prog.c
@@ -1,11 +1,20 @@
-#include<glib.h>
-#include<glib-object.h>
#include"golib.h"
-int main (int argc, char *argv[])
-{
+#include<girepository.h>
+
+int main(int argc, char *argv[]) {
+ GOptionContext *ctx;
+ GError *error = NULL;
MesonSample *i;
+ ctx = g_option_context_new(NULL);
+ g_option_context_add_group(ctx, g_irepository_get_option_group ());
+
+ if (!g_option_context_parse(ctx, &argc, &argv, &error)) {
+ g_print("sample: %s\n", error->message);
+ return 1;
+ }
+
i = meson_sample_new();
meson_sample_func(i);
g_object_unref(G_OBJECT(i));