1 # -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
2 # vim: set filetype=python:
3 # This Source Code Form is subject to the terms of the Mozilla Public
4 # License, v. 2.0. If a copy of the MPL was not distributed with this
5 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 @imports(_from='mozbuild.configure', _import='SandboxDependsFunction')
11 def compiler_class(compiler, host_or_target):
12 is_target = host_or_target is target
14 class Compiler(SandboxDependsFunction):
15 # Generates a test program and attempts to compile it. In case of
16 # failure, the resulting check will return None. If the test program
17 # succeeds, it will return the output of the test program.
18 # - `includes` are the includes (as file names) that will appear at the
19 # top of the generated test program.
20 # - `body` is the code that will appear in the main function of the
21 # generated test program. `return 0;` is appended to the function
23 # - `flags` are the flags to be passed to the compiler, in addition to
25 # - `check_msg` is the message to be printed to accompany compiling the
27 def try_compile(self, includes=None, body='', flags=None,
28 check_msg=None, when=None, onerror=lambda: None):
29 includes = includes or []
30 source_lines = ['#include <%s>' % f for f in includes]
31 source = '\n'.join(source_lines) + '\n'
32 source += textwrap.dedent('''\
44 return checking(check_msg)(fn)
49 @depends(self, dependable(flags), extra_toolchain_flags, when=when)
51 def func(compiler, flags, extra_flags):
54 flags += extra_flags or []
57 if try_invoke_compiler(
59 [compiler.compiler] + compiler.flags,
60 compiler.language, source, flags,
61 onerror=onerror) is not None:
66 compiler.__class__ = Compiler