2016-08-04 06:51:47 +00:00
|
|
|
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
|
|
|
|
# vim: set filetype=python:
|
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
|
|
|
@template
|
|
|
|
@imports('textwrap')
|
|
|
|
@imports(_from='mozbuild.configure', _import='DependsFunction')
|
|
|
|
def compiler_class(compiler):
|
|
|
|
class Compiler(DependsFunction):
|
|
|
|
# Generates a test program and attempts to compile it. In case of
|
|
|
|
# failure, the resulting check will return None. If the test program
|
|
|
|
# succeeds, it will return the output of the test program.
|
|
|
|
# - `includes` are the includes (as file names) 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, 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,
|
2016-08-05 08:13:48 +00:00
|
|
|
check_msg=None, when=None, onerror=lambda: None):
|
2016-08-04 06:51:47 +00:00
|
|
|
includes = includes or []
|
|
|
|
source_lines = ['#include <%s>' % f for f in includes]
|
|
|
|
source = '\n'.join(source_lines) + '\n'
|
|
|
|
source += textwrap.dedent('''\
|
|
|
|
int
|
|
|
|
main(void)
|
|
|
|
{
|
|
|
|
%s
|
|
|
|
;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
''' % body)
|
|
|
|
|
|
|
|
if check_msg:
|
|
|
|
def checking_fn(fn):
|
2016-08-10 01:00:43 +00:00
|
|
|
return checking(check_msg)(fn)
|
2016-08-04 06:51:47 +00:00
|
|
|
else:
|
|
|
|
def checking_fn(fn):
|
|
|
|
return fn
|
|
|
|
|
2016-08-31 21:23:20 +00:00
|
|
|
@depends_when(self, dependable(flags), extra_toolchain_flags, when=when)
|
2016-08-04 06:51:47 +00:00
|
|
|
@checking_fn
|
2016-08-31 21:23:20 +00:00
|
|
|
def func(compiler, flags, extra_flags):
|
|
|
|
flags = flags or []
|
2016-08-04 06:51:47 +00:00
|
|
|
flags += extra_flags
|
|
|
|
flags.append('-c')
|
|
|
|
|
2016-08-10 01:00:43 +00:00
|
|
|
if try_invoke_compiler(
|
2016-08-04 06:51:47 +00:00
|
|
|
compiler.wrapper + [compiler.compiler] + compiler.flags,
|
2016-08-10 01:00:43 +00:00
|
|
|
compiler.language, source, flags,
|
|
|
|
onerror=onerror) is not None:
|
|
|
|
return True
|
2016-08-04 06:51:47 +00:00
|
|
|
|
|
|
|
return func
|
|
|
|
|
|
|
|
compiler.__class__ = Compiler
|
|
|
|
return compiler
|