From 51827d4484845432588f850b24245d22b1d9c9f0 Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Wed, 12 Feb 2014 22:37:25 +0200 Subject: [PATCH] Can override install directory on a target-by-target basis. --- backends.py | 14 +++++++++----- build.py | 7 +++++++ interpreter.py | 11 +++++++++-- .../52 custom install dirs/installed_files.txt | 2 ++ .../common/52 custom install dirs/meson.build | 4 ++++ test cases/common/52 custom install dirs/prog.c | 3 +++ test cases/common/52 custom install dirs/sample.h | 6 ++++++ 7 files changed, 40 insertions(+), 7 deletions(-) create mode 100644 test cases/common/52 custom install dirs/installed_files.txt create mode 100644 test cases/common/52 custom install dirs/meson.build create mode 100644 test cases/common/52 custom install dirs/prog.c create mode 100644 test cases/common/52 custom install dirs/sample.h diff --git a/backends.py b/backends.py index 6e710f4b0..6a1109b3c 100644 --- a/backends.py +++ b/backends.py @@ -547,10 +547,12 @@ class NinjaBackend(Backend): should_strip = self.environment.coredata.strip for t in self.build.get_targets().values(): if t.should_install(): - if isinstance(t, build.Executable): - outdir = bindir - else: - outdir = libdir + outdir = t.get_custom_install_dir() + if outdir is None: + if isinstance(t, build.Executable): + outdir = bindir + else: + outdir = libdir i = [self.get_target_filename(t), outdir, t.get_aliaslist(), should_strip] d.targets.append(i) @@ -571,7 +573,9 @@ class NinjaBackend(Backend): headers = self.build.get_headers() for h in headers: - outdir = os.path.join(incroot, h.get_subdir()) + outdir = h.get_custom_install_dir() + if outdir is None: + outdir = os.path.join(incroot, h.get_subdir()) for f in h.get_sources(): abspath = os.path.join(self.environment.get_source_dir(), f) # FIXME i = [abspath, outdir] diff --git a/build.py b/build.py index af0768e34..3a2cd1e05 100644 --- a/build.py +++ b/build.py @@ -194,6 +194,9 @@ class BuildTarget(): for i in self.link_targets: result += i.get_rpaths() return result + + def get_custom_install_dir(self): + return self.custom_install_dir def process_kwargs(self, kwargs): self.copy_kwargs(kwargs) @@ -236,6 +239,10 @@ class BuildTarget(): if not isinstance(deplist, list): deplist = [deplist] self.add_external_deps(deplist) + self.custom_install_dir = kwargs.get('install_dir', None) + if self.custom_install_dir is not None: + if not isinstance(self.custom_install_dir, str): + raise InvalidArguments('Custom_install_dir must be a string') def get_subdir(self): return self.subdir diff --git a/interpreter.py b/interpreter.py index 9f84816e6..1e74f4091 100644 --- a/interpreter.py +++ b/interpreter.py @@ -52,13 +52,13 @@ class TryRunResultHolder(InterpreterObject): def returncode_method(self, args, kwargs): return self.res.returncode - + def compiled_method(self, args, kwargs): return self.res.compiled def stdout_method(self, args, kwargs): return self.res.stdout - + def stderr_method(self, args, kwargs): return self.res.stderr @@ -267,6 +267,10 @@ class Headers(InterpreterObject): InterpreterObject.__init__(self) self.sources = sources self.subdir = kwargs.get('subdir', '') + self.custom_install_dir = kwargs.get('install_dir', None) + if self.custom_install_dir is not None: + if not isinstance(self.custom_install_dir, str): + raise InterpreterException('Custom_install_dir must be a string.') def set_subdir(self, subdir): self.subdir = subdir @@ -277,6 +281,9 @@ class Headers(InterpreterObject): def get_sources(self): return self.sources + def get_custom_install_dir(self): + return self.custom_install_dir + class Data(InterpreterObject): def __init__(self, subdir, sources, kwargs): InterpreterObject.__init__(self) diff --git a/test cases/common/52 custom install dirs/installed_files.txt b/test cases/common/52 custom install dirs/installed_files.txt new file mode 100644 index 000000000..a8a496c82 --- /dev/null +++ b/test cases/common/52 custom install dirs/installed_files.txt @@ -0,0 +1,2 @@ +dib/dab/dub/prog +some/dir/sample.h diff --git a/test cases/common/52 custom install dirs/meson.build b/test cases/common/52 custom install dirs/meson.build new file mode 100644 index 000000000..5f1919a0c --- /dev/null +++ b/test cases/common/52 custom install dirs/meson.build @@ -0,0 +1,4 @@ +project('custom install dirs', 'c') + +executable('prog', 'prog.c', install : true, install_dir : 'dib/dab/dub') +headers('sample.h', install_dir : 'some/dir') diff --git a/test cases/common/52 custom install dirs/prog.c b/test cases/common/52 custom install dirs/prog.c new file mode 100644 index 000000000..0f0061d2a --- /dev/null +++ b/test cases/common/52 custom install dirs/prog.c @@ -0,0 +1,3 @@ +int main(int argc, char **arv) { + return 0; +} diff --git a/test cases/common/52 custom install dirs/sample.h b/test cases/common/52 custom install dirs/sample.h new file mode 100644 index 000000000..dc030dac1 --- /dev/null +++ b/test cases/common/52 custom install dirs/sample.h @@ -0,0 +1,6 @@ +#ifndef SAMPLE_H +#define SAMPLE_H + +int wackiness(); + +#endif