diff options
author | Nirbheek Chauhan <nirbheek@centricular.com> | 2018-04-15 07:41:12 +0530 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2018-04-15 22:29:49 +0300 |
commit | ef81a013a5fd5f2e962a9c7f37beea0156711dbc (patch) | |
tree | af745308bd09b2f90525056f4bb1fbed0850b14d | |
parent | 86f725c1e523088c691432c608b3228499ca3c7b (diff) | |
download | meson-ef81a013a5fd5f2e962a9c7f37beea0156711dbc.zip meson-ef81a013a5fd5f2e962a9c7f37beea0156711dbc.tar.gz meson-ef81a013a5fd5f2e962a9c7f37beea0156711dbc.tar.bz2 |
cross: Add compiler cross_args after normal args
This way they override all other arguments. This matches the order of
link arguments too.
Note that this means -I flags will come in afterwards and not override
anything else, but this is correct since that's how toolchain paths
work normally too -- they are searched last.
Closes https://github.com/mesonbuild/meson/issues/3089
5 files changed, 56 insertions, 7 deletions
diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index c941319..41f840d 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -1660,9 +1660,9 @@ rule FORTRAN_DEP_HACK if mesonlib.is_windows(): command_template = ' command = {executable} @$out.rsp\n' \ ' rspfile = $out.rsp\n' \ - ' rspfile_content = {cross_args} $ARGS {output_args} {compile_only_args} $in\n' + ' rspfile_content = $ARGS{cross_args} {output_args} {compile_only_args} $in\n' else: - command_template = ' command = {executable} {cross_args} $ARGS {output_args} {compile_only_args} $in\n' + command_template = ' command = {executable} $ARGS {cross_args} {output_args} {compile_only_args} $in\n' command = command_template.format( executable=' '.join([ninja_quote(i) for i in compiler.get_exelist()]), cross_args=' '.join(self.get_cross_info_lang_args(compiler.language, is_cross)), @@ -1721,10 +1721,10 @@ rule FORTRAN_DEP_HACK if mesonlib.is_windows(): command_template = ''' command = {executable} @$out.rsp rspfile = $out.rsp - rspfile_content = {cross_args} $ARGS {dep_args} {output_args} {compile_only_args} $in + rspfile_content = $ARGS {cross_args} {dep_args} {output_args} {compile_only_args} $in ''' else: - command_template = ' command = {executable} {cross_args} $ARGS {dep_args} {output_args} {compile_only_args} $in\n' + command_template = ' command = {executable} $ARGS {cross_args} {dep_args} {output_args} {compile_only_args} $in\n' command = command_template.format( executable=' '.join([ninja_quote(i) for i in compiler.get_exelist()]), cross_args=' '.join(cross_args), @@ -1769,7 +1769,7 @@ rule FORTRAN_DEP_HACK output = '' else: output = ' '.join(compiler.get_output_args('$out')) - command = " command = {executable} {cross_args} $ARGS {dep_args} {output_args} {compile_only_args} $in\n".format( + command = " command = {executable} $ARGS {cross_args} {dep_args} {output_args} {compile_only_args} $in\n".format( executable=' '.join(compiler.get_exelist()), cross_args=' '.join(cross_args), dep_args=' '.join(quoted_depargs), diff --git a/run_unittests.py b/run_unittests.py index 8bd5ae8..19a8c87 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -482,6 +482,7 @@ class BasePlatformTests(unittest.TestCase): self.backend = getattr(Backend, os.environ.get('MESON_UNIT_TEST_BACKEND', 'ninja')) self.meson_mainfile = os.path.join(src_root, 'meson.py') self.meson_args = ['--backend=' + self.backend.name] + self.meson_cross_file = None self.meson_command = meson_command + self.meson_args self.mconf_command = meson_command + ['configure'] self.mintro_command = meson_command + ['introspect'] @@ -567,6 +568,8 @@ class BasePlatformTests(unittest.TestCase): if default_args: args += ['--prefix', self.prefix, '--libdir', self.libdir] + if self.meson_cross_file: + args += ['--cross-file', self.meson_cross_file] self.privatedir = os.path.join(self.builddir, 'meson-private') if inprocess: try: @@ -2814,7 +2817,8 @@ cpu = 'armv7' # Not sure if correct. endian = 'little' ''' % os.path.join(testdir, 'some_cross_tool.py')) crossfile.flush() - self.init(testdir, ['--cross-file=' + crossfile.name]) + self.meson_cross_file = crossfile.name + self.init(testdir) def test_reconfigure(self): testdir = os.path.join(self.unit_test_dir, '13 reconfigure') @@ -2920,7 +2924,7 @@ class LinuxArmCrossCompileTests(BasePlatformTests): def setUp(self): super().setUp() src_root = os.path.dirname(__file__) - self.meson_command += ['--cross=' + os.path.join(src_root, 'cross', 'ubuntu-armhf.txt')] + self.meson_cross_file = os.path.join(src_root, 'cross', 'ubuntu-armhf.txt') def test_cflags_cross_environment_pollution(self): ''' @@ -2934,6 +2938,21 @@ class LinuxArmCrossCompileTests(BasePlatformTests): compdb = self.get_compdb() self.assertNotIn('-DBUILD_ENVIRONMENT_ONLY', compdb[0]['command']) + def test_cross_file_overrides_always_args(self): + ''' + Test that $lang_args in cross files always override get_always_args(). + Needed for overriding the default -D_FILE_OFFSET_BITS=64 on some + architectures such as some Android versions and Raspbian. + https://github.com/mesonbuild/meson/issues/3049 + https://github.com/mesonbuild/meson/issues/3089 + ''' + testdir = os.path.join(self.unit_test_dir, '29 cross file overrides always args') + self.meson_cross_file = os.path.join(self.unit_test_dir, 'ubuntu-armhf-overrides.txt') + self.init(testdir) + compdb = self.get_compdb() + self.assertRegex(compdb[0]['command'], '-D_FILE_OFFSET_BITS=64.*-U_FILE_OFFSET_BITS') + self.build() + class RewriterTests(unittest.TestCase): diff --git a/test cases/unit/29 cross file overrides always args/meson.build b/test cases/unit/29 cross file overrides always args/meson.build new file mode 100644 index 0000000..ef6556e --- /dev/null +++ b/test cases/unit/29 cross file overrides always args/meson.build @@ -0,0 +1,3 @@ +project('cross compile args override always args', 'c') + +executable('no-file-offset-bits', 'test.c') diff --git a/test cases/unit/29 cross file overrides always args/test.c b/test cases/unit/29 cross file overrides always args/test.c new file mode 100644 index 0000000..315f92e --- /dev/null +++ b/test cases/unit/29 cross file overrides always args/test.c @@ -0,0 +1,8 @@ +#ifdef _FILE_OFFSET_BITS + #error "_FILE_OFFSET_BITS should not be set" +#endif + +int main(int argc, char *argv[]) +{ + return 0; +} diff --git a/test cases/unit/29 cross file overrides always args/ubuntu-armhf-overrides.txt b/test cases/unit/29 cross file overrides always args/ubuntu-armhf-overrides.txt new file mode 100644 index 0000000..a00a7d1 --- /dev/null +++ b/test cases/unit/29 cross file overrides always args/ubuntu-armhf-overrides.txt @@ -0,0 +1,19 @@ +[binaries] +# we could set exe_wrapper = qemu-arm-static but to test the case +# when cross compiled binaries can't be run we don't do that +c = '/usr/bin/arm-linux-gnueabihf-gcc' +cpp = '/usr/bin/arm-linux-gnueabihf-g++' +rust = ['rustc', '--target', 'arm-unknown-linux-gnueabihf', '-C', 'linker=/usr/bin/arm-linux-gnueabihf-gcc-7'] +ar = '/usr/arm-linux-gnueabihf/bin/ar' +strip = '/usr/arm-linux-gnueabihf/bin/strip' +pkgconfig = '/usr/bin/arm-linux-gnueabihf-pkg-config' + +[properties] +root = '/usr/arm-linux-gnueabihf' +c_args = ['-U_FILE_OFFSET_BITS'] + +[host_machine] +system = 'linux' +cpu_family = 'arm' +cpu = 'armv7' # Not sure if correct. +endian = 'little' |