Skip to content

Commit

Permalink
compilers: Pass all options to links/compiles
Browse files Browse the repository at this point in the history
The `compiler.links()` and `compiler.compiles()` functions did
not take into account all arguments which might be added to a real link or
real compile job, specifically it was failing to add many of the options
which are added as a result of language level options such as `b_coverage`
or `b_sanitize`.

This commit fixes that by constructing the args list for these functions
using the same methods as a real compile/link job.

A new unittest has been added to check that this is functioning correctly.

Fixes: mesonbuild#13610
  • Loading branch information
amcn committed Sep 17, 2024
1 parent 9cb9ad8 commit 1288812
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
6 changes: 4 additions & 2 deletions mesonbuild/interpreter/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from .. import mesonlib
from .. import mlog
from ..compilers import SUFFIX_TO_LANG, RunResult
from ..compilers.compilers import CompileCheckMode
from ..compilers.compilers import CompileCheckMode, get_base_compile_args, get_base_link_args
from ..interpreterbase import (ObjectHolder, noPosargs, noKwargs,
FeatureNew, FeatureNewKwargs, disablerIfNotFound,
InterpreterException)
Expand Down Expand Up @@ -271,9 +271,11 @@ def _determine_args(self, kwargs: BaseCompileKW,
args.extend(self.compiler.get_include_args(idir, False))
if not kwargs['no_builtin_args']:
opts = coredata.OptionsView(self.environment.coredata.optstore, self.subproject)
args += self.compiler.get_option_compile_args(opts)
args.extend(self.compiler.get_option_compile_args(opts))
args.extend(get_base_compile_args(opts, self.compiler, self.environment))
if mode is CompileCheckMode.LINK:
args.extend(self.compiler.get_option_link_args(opts))
args.extend(get_base_link_args(opts, self.compiler, False, self.environment.get_build_dir()))
if kwargs.get('werror', False):
args.extend(self.compiler.get_werror_args())
args.extend(kwargs['args'])
Expand Down
18 changes: 18 additions & 0 deletions test cases/common/279 compiler.links args/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# https://github.com/mesonbuild/meson/issues/13610

project('279 compiler.links args', 'c')
cc = meson.get_compiler('c')

gcov_str = '''
#include <gcov.h>
int main(void) {
__gcov_dump();
return 0;
}
'''

if cc.links(gcov_str)
message('successful link')
else
error('does not link')
endif
9 changes: 9 additions & 0 deletions unittests/allplatformstests.py
Original file line number Diff line number Diff line change
Expand Up @@ -5040,3 +5040,12 @@ def test_rsp_support(self):
'link', 'lld-link', 'mwldarm', 'mwldeppc', 'optlink', 'xilink',
}
self.assertEqual(cc.linker.get_accepts_rsp(), has_rsp)

def test_compiler_link_args(self):
testdir = os.path.join(self.common_test_dir, '279 compiler.links args')

with self.assertRaises(subprocess.CalledProcessError):
self.init(testdir)

# This should succeed without raising due to '-Db_coverage=true'
self.init(testdir, extra_args=['-Db_coverage=true'])

0 comments on commit 1288812

Please sign in to comment.