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: #13610
  • Loading branch information
amcn committed Sep 17, 2024
1 parent 9cb9ad8 commit 819f063
Show file tree
Hide file tree
Showing 3 changed files with 32 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/unit/123 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('gcov links successfully')
else
error('gcov does not link')
endif
10 changes: 10 additions & 0 deletions unittests/allplatformstests.py
Original file line number Diff line number Diff line change
Expand Up @@ -5040,3 +5040,13 @@ 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.unit_test_dir, '279 compiler.links args')

with self.assertRaises(subprocess.CalledProcessError) as cm:
self.init(testdir)
self.assertIn('gcov does not link', cm.exception.stdout)

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

0 comments on commit 819f063

Please sign in to comment.