diff --git a/mesonbuild/compilers.py b/mesonbuild/compilers.py index 9ddaa560d..5c1dcb194 100644 --- a/mesonbuild/compilers.py +++ b/mesonbuild/compilers.py @@ -441,7 +441,7 @@ class Compiler(): return extra_flags @contextlib.contextmanager - def compile(self, code, extra_args=None): + def compile(self, code, extra_args=None, compile_only=False): if extra_args is None: extra_args = [] @@ -457,20 +457,25 @@ class Compiler(): # Extension only matters if running results; '.exe' is # guaranteed to be executable on every platform. - output = os.path.join(tmpdirname, 'output.exe') + if compile_only: + suffix = 'obj' + else: + suffix = 'exe' + output = os.path.join(tmpdirname, 'output.' + suffix) commands = self.get_exelist() commands.append(srcname) commands += extra_args commands += self.get_output_args(output) + if compile_only: + commands += self.get_compile_only_args() mlog.debug('Running compile:') mlog.debug('Working directory: ', tmpdirname) mlog.debug('Command line: ', ' '.join(commands), '\n') mlog.debug('Code:\n', code) - p, stdo, stde = Popen_safe(commands, cwd=tmpdirname) - mlog.debug('Compiler stdout:\n', stdo) - mlog.debug('Compiler stderr:\n', stde) - + p, p.stdo, p.stde = Popen_safe(commands, cwd=tmpdirname) + mlog.debug('Compiler stdout:\n', p.stdo) + mlog.debug('Compiler stderr:\n', p.stde) p.input_name = srcname p.output_name = output yield p @@ -748,14 +753,13 @@ int main () {{ # Add CFLAGS/CXXFLAGS/OBJCFLAGS/OBJCXXFLAGS from the env # We assume that the user has ensured these are compiler-specific args += env.coredata.external_args[self.language] - # We only want to compile; not link - args += self.get_compile_only_args() # Append extra_args to the compiler check args such that it overrides extra_args = self._override_args(self.get_compiler_check_args(), extra_args) extra_args = self.unix_link_flags_to_native(extra_args) # Append both to the compiler args such that they override them args = self._override_args(args, extra_args) - with self.compile(code, args) as p: + # We only want to compile; not link + with self.compile(code, args, compile_only=True) as p: return p.returncode == 0 def _links_wrapper(self, code, env, extra_args, dependencies): @@ -1408,14 +1412,16 @@ class ValaCompiler(Compiler): def get_output_args(self, target): return ['-o', target] + def get_compile_only_args(self): + return ['-C'] + def get_werror_args(self): return ['--fatal-warnings'] def sanity_check(self, work_dir, environment): code = 'class MesonSanityCheck : Object { }' args = self.get_cross_extra_flags(environment, compile=True, link=False) - args += ['-C'] - with self.compile(code, args) as p: + with self.compile(code, args, compile_only=True) as p: if p.returncode != 0: msg = 'Vala compiler {!r} can not compile programs' \ ''.format(self.name_string()) @@ -1435,8 +1441,8 @@ class ValaCompiler(Compiler): code = 'class MesonFindLibrary : Object { }' vapi_args = ['--pkg', libname] args = self.get_cross_extra_flags(env, compile=True, link=False) - args += ['-C'] + vapi_args - with self.compile(code, args) as p: + args += vapi_args + with self.compile(code, args, compile_only=True) as p: if p.returncode == 0: return vapi_args # Not found? Try to find the vapi file itself.