Bug 1507844 - Push the devtools.inspector.flexboxHighlighter.enabled pref in browser_...
[gecko.git] / build / moz.configure / compilers-util.configure
blob621a2afd8f5bcaa548313104774a06aad3de3333
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/.
8 @template
9 @imports('textwrap')
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
22         #   body automatically.
23         # - `flags` are the flags to be passed to the compiler, in addition to
24         #   `-c`.
25         # - `check_msg` is the message to be printed to accompany compiling the
26         #   test program.
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('''\
33                 int
34                 main(void)
35                 {
36                 %s
37                   ;
38                   return 0;
39                 }
40             ''' % body)
42             if check_msg:
43                 def checking_fn(fn):
44                     return checking(check_msg)(fn)
45             else:
46                 def checking_fn(fn):
47                     return fn
49             @depends(self, dependable(flags), extra_toolchain_flags, when=when)
50             @checking_fn
51             def func(compiler, flags, extra_flags):
52                 flags = flags or []
53                 if is_target:
54                     flags += extra_flags or []
55                 flags.append('-c')
57                 if try_invoke_compiler(
58                         compiler.wrapper +
59                         [compiler.compiler] + compiler.flags,
60                         compiler.language, source, flags,
61                         onerror=onerror) is not None:
62                     return True
64             return func
66     compiler.__class__ = Compiler
67     return compiler