# HG changeset patch # User Mike Hommey # Date 1545259238 0 # Wed Dec 19 22:40:38 2018 +0000 # Node ID f9f9a274668228b922c21866353bce5c7dec955b # Parent e07c2ce50e93ebb3f73ce651335c243567f17dac Bug 1515257 - Add a try_run method more generic than try_compile. r=firefox-build-system-reviewers,ted It will be useful to run tests like try_compile, with different flags and different kinds of sources. Depends on D14949 Differential Revision: https://phabricator.services.mozilla.com/D14950 diff --git a/build/moz.configure/compilers-util.configure b/build/moz.configure/compilers-util.configure --- a/build/moz.configure/compilers-util.configure +++ b/build/moz.configure/compilers-util.configure @@ -21,47 +21,76 @@ def compiler_class(compiler, host_or_tar # generated test program. `return 0;` is appended to the function # body automatically. # - `flags` are the flags to be passed to the compiler, in addition to # `-c`. # - `check_msg` is the message to be printed to accompany compiling the # test program. def try_compile(self, includes=None, body='', flags=None, check_msg=None, when=None, onerror=lambda: None): - includes = includes or [] - source_lines = ['#include <%s>' % f for f in includes] - source = '\n'.join(source_lines) + '\n' - source += textwrap.dedent('''\ + @depends(dependable(flags)) + def flags(flags): + flags = list(flags or []) + flags.append('-c') + return flags + + @depends(dependable(includes)) + def header(includes): + includes = includes or [] + return ['#include <%s>' % f for f in includes] + + return self.try_run( + header=header, body=body, flags=flags, check_msg=check_msg, + when=when, onerror=onerror) + + # Generates a test program and run the compiler against it. In case of + # failure, the resulting check will return None. + # - `header` is code that will appear at the top of the generated test + # program. + # - `body` is the code that will appear in the main function of the + # generated test program. `return 0;` is appended to the function + # body automatically. + # - `flags` are the flags to be passed to the compiler. + # - `check_msg` is the message to be printed to accompany compiling the + # test program. + # - `onerror` is a function called when the check fails. + def try_run(self, header=None, body='', flags=None, + check_msg=None, when=None, onerror=lambda: None): + source = textwrap.dedent('''\ int main(void) { %s ; return 0; } ''' % body) if check_msg: def checking_fn(fn): return checking(check_msg)(fn) else: def checking_fn(fn): return fn - @depends(self, dependable(flags), extra_toolchain_flags, when=when) + @depends(self, dependable(flags), extra_toolchain_flags, dependable(header), when=when) @checking_fn - def func(compiler, flags, extra_flags): - flags = flags or [] + def func(compiler, flags, extra_flags, header): + flags = list(flags or []) if is_target: flags += extra_flags or [] - flags.append('-c') + header = header or '' + if isinstance(header, (list, tuple)): + header = '\n'.join(header) + if header: + header += '\n' if try_invoke_compiler( compiler.wrapper + [compiler.compiler] + compiler.flags, - compiler.language, source, flags, + compiler.language, header + source, flags, onerror=onerror) is not None: return True return func compiler.__class__ = Compiler return compiler