diff options
-rw-r--r-- | mesonbuild/compilers.py | 14 | ||||
-rw-r--r-- | mesonbuild/coredata.py | 7 | ||||
-rw-r--r-- | mesonbuild/environment.py | 6 | ||||
-rw-r--r-- | mesonbuild/interpreter.py | 7 | ||||
-rwxr-xr-x | run_unittests.py | 15 | ||||
-rw-r--r-- | test cases/common/140 get define/meson.build | 9 | ||||
-rw-r--r-- | test cases/common/140 get define/meson_options.txt | 1 |
7 files changed, 44 insertions, 15 deletions
diff --git a/mesonbuild/compilers.py b/mesonbuild/compilers.py index ce3f09a..6f08d98 100644 --- a/mesonbuild/compilers.py +++ b/mesonbuild/compilers.py @@ -953,12 +953,14 @@ class CCompiler(Compiler): # Read c_args/cpp_args/etc from the cross-info file (if needed) args += self.get_cross_extra_flags(env, compile=(mode != 'preprocess'), link=(mode == 'link')) - # 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] - # Add LDFLAGS from the env. We assume that the user has ensured these - # are compiler-specific - if mode == 'link': + if mode == 'preprocess': + # Add CPPFLAGS from the env. + args += env.coredata.external_preprocess_args[self.language] + elif mode == 'compile': + # Add CFLAGS/CXXFLAGS/OBJCFLAGS/OBJCXXFLAGS from the env + args += env.coredata.external_args[self.language] + elif mode == 'link': + # Add LDFLAGS from the env args += env.coredata.external_link_args[self.language] args += self.get_compiler_check_args() # extra_args must override all other arguments, so we add them last diff --git a/mesonbuild/coredata.py b/mesonbuild/coredata.py index 67516e7..27f1dd7 100644 --- a/mesonbuild/coredata.py +++ b/mesonbuild/coredata.py @@ -148,10 +148,11 @@ class CoreData: self.user_options = {} self.compiler_options = {} self.base_options = {} - # These two, external_*args, are set via env vars CFLAGS, LDFLAGS, etc + # These external_*args, are set via env vars CFLAGS, LDFLAGS, etc # but only when not cross-compiling. - self.external_args = {} - self.external_link_args = {} + self.external_preprocess_args = {} # CPPFLAGS only + self.external_args = {} # CPPFLAGS + CFLAGS + self.external_link_args = {} # CFLAGS + LDFLAGS (with MSVC: only LDFLAGS) if options.cross_file is not None: self.cross_file = os.path.join(os.getcwd(), options.cross_file) else: diff --git a/mesonbuild/environment.py b/mesonbuild/environment.py index f2de31a..cb62506 100644 --- a/mesonbuild/environment.py +++ b/mesonbuild/environment.py @@ -770,7 +770,7 @@ def get_args_from_envvars(compiler): compiler_is_linker = (compiler.get_exelist() == compiler.get_linker_exelist()) if lang not in ('c', 'cpp', 'objc', 'objcpp', 'fortran', 'd'): - return [], [] + return [], [], [] # Compile flags cflags_mapping = {'c': 'CFLAGS', @@ -794,7 +794,7 @@ def get_args_from_envvars(compiler): # this when the linker is stand-alone such as with MSVC C/C++, etc. link_flags = compile_flags + link_flags - # Pre-processof rlags (not for fortran) + # Pre-processor flags (not for fortran or D) preproc_flags = '' if lang in ('c', 'cpp', 'objc', 'objcpp'): preproc_flags = os.environ.get('CPPFLAGS', '') @@ -802,7 +802,7 @@ def get_args_from_envvars(compiler): preproc_flags = shlex.split(preproc_flags) compile_flags += preproc_flags - return compile_flags, link_flags + return preproc_flags, compile_flags, link_flags class CrossBuildInfo: def __init__(self, filename): diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index 959ce6a..85e2b9a 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -1787,9 +1787,10 @@ class Interpreter(InterpreterBase): raise mlog.log('Native %s compiler: ' % lang, mlog.bold(' '.join(comp.get_exelist())), ' (%s %s)' % (comp.id, comp.version), sep='') if not comp.get_language() in self.coredata.external_args: - (ext_compile_args, ext_link_args) = environment.get_args_from_envvars(comp) - self.coredata.external_args[comp.get_language()] = ext_compile_args - self.coredata.external_link_args[comp.get_language()] = ext_link_args + (preproc_args, compile_args, link_args) = environment.get_args_from_envvars(comp) + self.coredata.external_preprocess_args[comp.get_language()] = preproc_args + self.coredata.external_args[comp.get_language()] = compile_args + self.coredata.external_link_args[comp.get_language()] = link_args self.build.add_compiler(comp) if need_cross_compiler: mlog.log('Cross %s compiler: ' % lang, mlog.bold(' '.join(cross_comp.get_exelist())), ' (%s %s)' % (cross_comp.id, cross_comp.version), sep='') diff --git a/run_unittests.py b/run_unittests.py index 0656f88..53abef7 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -947,6 +947,21 @@ class AllPlatformTests(BasePlatformTests): m = re.search('build c-asm.*: c_LINKER', contents) self.assertIsNotNone(m, msg=contents) + def test_preprocessor_checks_CPPFLAGS(self): + ''' + Test that preprocessor compiler checks read CPPFLAGS but not CFLAGS + ''' + testdir = os.path.join(self.common_test_dir, '140 get define') + define = 'MESON_TEST_DEFINE_VALUE' + # NOTE: this list can't have \n, ' or " + # \n is never substituted by the GNU pre-processor via a -D define + # ' and " confuse shlex.split() even when they are escaped + # % and # confuse the MSVC preprocessor + value = 'spaces and fun!@$^&*()-=_+{}[]:;<>?,./~`' + os.environ['CPPFLAGS'] = '-D{}="{}"'.format(define, value) + os.environ['CFLAGS'] = '-DMESON_FAIL_VALUE=cflags-read'.format(define) + self.init(testdir, ['-D{}={}'.format(define, value)]) + class WindowsTests(BasePlatformTests): ''' diff --git a/test cases/common/140 get define/meson.build b/test cases/common/140 get define/meson.build index 0d83b8d..7a0969f 100644 --- a/test cases/common/140 get define/meson.build +++ b/test cases/common/140 get define/meson.build @@ -16,4 +16,13 @@ foreach lang : ['c', 'cpp'] else error('Please report a bug and help us improve support for this platform') endif + + # Check that an undefined value is empty. + have = cc.get_define('MESON_FAIL_VALUE') + assert(have == '', 'MESON_FAIL_VALUE value is "@0@" instead of ""'.format(have)) + + # This is used in the test_preprocessor_checks_CPPFLAGS() unit test. + have = cc.get_define('MESON_TEST_DEFINE_VALUE') + expect = get_option('MESON_TEST_DEFINE_VALUE') + assert(have == expect, 'MESON_TEST_DEFINE_VALUE value is "@0@" instead of "@1@"'.format(have, expect)) endforeach diff --git a/test cases/common/140 get define/meson_options.txt b/test cases/common/140 get define/meson_options.txt new file mode 100644 index 0000000..a88cecd --- /dev/null +++ b/test cases/common/140 get define/meson_options.txt @@ -0,0 +1 @@ +option('MESON_TEST_DEFINE_VALUE', type : 'string', default : '') |