diff options
author | Rafael Ăvila de EspĂndola <rafael@espindo.la> | 2018-08-19 08:19:11 -0700 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2018-09-03 21:24:01 +0300 |
commit | 07d2d88fa9bd4f3598f9212b7209f98443b636d9 (patch) | |
tree | d8abbc85c1206530cd152bdeacf2a25758e6d211 /mesonbuild | |
parent | 862019e6de9c896e6e876c272db3e5c95393ac3c (diff) | |
download | meson-07d2d88fa9bd4f3598f9212b7209f98443b636d9.zip meson-07d2d88fa9bd4f3598f9212b7209f98443b636d9.tar.gz meson-07d2d88fa9bd4f3598f9212b7209f98443b636d9.tar.bz2 |
Allow override_find_program to use an executable.
With this it is now possible to do
foobar = executable('foobar', ...)
meson.override_find_program('foobar', foobar)
Which is convenient for a project like protobuf which produces both a
dependency and a tool. If protobuf is updated to use
override_find_program, it can be used as
protobuf_dep = dependency('protobuf', version : '>=3.3.1',
fallback : ['protobuf', 'protobuf_dep'])
protoc_prog = find_program('protoc')
Diffstat (limited to 'mesonbuild')
-rw-r--r-- | mesonbuild/build.py | 4 | ||||
-rw-r--r-- | mesonbuild/dependencies/base.py | 4 | ||||
-rw-r--r-- | mesonbuild/interpreter.py | 14 |
3 files changed, 17 insertions, 5 deletions
diff --git a/mesonbuild/build.py b/mesonbuild/build.py index efe58f8..585a8d3 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -1314,6 +1314,10 @@ class Executable(BuildTarget): # Only linkwithable if using export_dynamic self.is_linkwithable = self.export_dynamic + def description(self): + '''Human friendly description of the executable''' + return self.name + def type_suffix(self): return "@exe" diff --git a/mesonbuild/dependencies/base.py b/mesonbuild/dependencies/base.py index e375f10..b369780 100644 --- a/mesonbuild/dependencies/base.py +++ b/mesonbuild/dependencies/base.py @@ -1057,6 +1057,10 @@ class ExternalProgram: r = '<{} {!r} -> {!r}>' return r.format(self.__class__.__name__, self.name, self.command) + def description(self): + '''Human friendly description of the command''' + return ' '.join(self.command) + @staticmethod def from_cross_info(cross_info, name): if name not in cross_info.config['binaries']: diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index dba3fc0..9bd21e3 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -480,7 +480,7 @@ class ExternalProgramHolder(InterpreterObject, ObjectHolder): return self.held_object.get_path() def found(self): - return self.held_object.found() + return isinstance(self.held_object, build.Executable) or self.held_object.found() def get_command(self): return self.held_object.get_command() @@ -1780,9 +1780,8 @@ class MesonMain(InterpreterObject): if not os.path.exists(abspath): raise InterpreterException('Tried to override %s with a file that does not exist.' % name) exe = dependencies.ExternalProgram(abspath) - if not isinstance(exe, dependencies.ExternalProgram): - # FIXME, make this work if the exe is an Executable target. - raise InterpreterException('Second argument must be an external program.') + if not isinstance(exe, (dependencies.ExternalProgram, build.Executable)): + raise InterpreterException('Second argument must be an external program or executable.') self.interpreter.add_find_program_override(name, exe) @noPosargs @@ -2184,6 +2183,11 @@ external dependencies (including libraries) must go to "dependencies".''') 'or configure_file(), or a compiler object; not {!r}' if isinstance(cmd, ExternalProgramHolder): cmd = cmd.held_object + if isinstance(cmd, build.Executable): + progname = node.args.arguments[0].value + msg = 'Program {!r} was overridden with the compiled executable {!r}'\ + ' and therefore cannot be used during configuration' + raise InterpreterException(msg.format(progname, cmd.description())) elif isinstance(cmd, CompilerHolder): cmd = cmd.compiler.get_exelist()[0] prog = ExternalProgram(cmd, silent=True) @@ -2758,7 +2762,7 @@ external dependencies (including libraries) must go to "dependencies".''') exe = self.build.find_overrides[name] if not silent: mlog.log('Program', mlog.bold(name), 'found:', mlog.green('YES'), - '(overridden: %s)' % ' '.join(exe.command)) + '(overridden: %s)' % exe.description()) return ExternalProgramHolder(exe) return None |