diff options
author | Nirbheek Chauhan <nirbheek@centricular.com> | 2017-02-15 21:26:31 +0530 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2017-02-17 15:42:12 -0500 |
commit | 15b6915954c7c3d7a06455aeb7995524ac43ff3b (patch) | |
tree | 13d44490c03fe116e5961ec80f82c22f3cf25bd8 /mesonbuild/build.py | |
parent | 16adedf6bc941745d3f10a2ad70fe710dfe1b206 (diff) | |
download | meson-15b6915954c7c3d7a06455aeb7995524ac43ff3b.zip meson-15b6915954c7c3d7a06455aeb7995524ac43ff3b.tar.gz meson-15b6915954c7c3d7a06455aeb7995524ac43ff3b.tar.bz2 |
custom_target: Recursively flatten `command:`
Without this, files() in the arguments give an error because it's a list
of mesonlib.File objects:
Array as argument 1 contains a non-string.
It also breaks in nested lists. Includes a test for this.
Diffstat (limited to 'mesonbuild/build.py')
-rw-r--r-- | mesonbuild/build.py | 50 |
1 files changed, 24 insertions, 26 deletions
diff --git a/mesonbuild/build.py b/mesonbuild/build.py index 5466431..5f2de3b 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -1298,6 +1298,29 @@ class CustomTarget(Target): deps.append(c) return deps + def flatten_command(self, cmd): + if not isinstance(cmd, list): + cmd = [cmd] + final_cmd = [] + for c in cmd: + if hasattr(c, 'held_object'): + c = c.held_object + if isinstance(c, (str, File)): + final_cmd.append(c) + elif isinstance(c, dependencies.ExternalProgram): + if not c.found(): + m = 'Tried to use not-found external program {!r} in "command"' + raise InvalidArguments(m.format(c.name)) + final_cmd += c.get_command() + elif isinstance(c, (BuildTarget, CustomTarget)): + self.dependencies.append(c) + final_cmd.append(c) + elif isinstance(c, list): + final_cmd += self.flatten_command(c) + else: + raise InvalidArguments('Argument {!r} in "command" is invalid'.format(c)) + return final_cmd + def process_kwargs(self, kwargs): super().process_kwargs(kwargs) self.sources = kwargs.get('input', []) @@ -1325,32 +1348,7 @@ class CustomTarget(Target): if os.path.split(depfile)[1] != depfile: raise InvalidArguments('Depfile must be a plain filename without a subdirectory.') self.depfile = depfile - cmd = kwargs['command'] - if not(isinstance(cmd, list)): - cmd = [cmd] - final_cmd = [] - for i, c in enumerate(cmd): - if hasattr(c, 'held_object'): - c = c.held_object - if isinstance(c, (str, File)): - final_cmd.append(c) - elif isinstance(c, dependencies.ExternalProgram): - if not c.found(): - raise InvalidArguments('Tried to use not found external program {!r} in a build rule.'.format(c.name)) - final_cmd += c.get_command() - elif isinstance(c, (BuildTarget, CustomTarget)): - self.dependencies.append(c) - final_cmd.append(c) - 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 + self.command = self.flatten_command(kwargs['command']) if self.capture: for c in self.command: if isinstance(c, str) and '@OUTPUT@' in c: |