Skip to content

Commit 4fe5593

Browse files
bonzinieli-schwartz
authored andcommitted
unittests: add test case for setting and retrieving build options
Check that build options fall back to host options, and that they can be retrieved with get_option. Signed-off-by: Paolo Bonzini <[email protected]> (cherry picked from commit 1537a13)
1 parent c0dade7 commit 4fe5593

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

test cases/unit/69 cross/crossfile.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ system = '@system@'
33
cpu_family = '@cpu_family@'
44
cpu = '@cpu@'
55
endian = '@endian@'
6+
7+
[built-in options]
8+
c_args = ['-funroll-loops']
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
project('crosstest')
22

3+
add_languages('c', native: true)
34
if get_option('generate')
45
conf_data = configuration_data()
56
conf_data.set('system', build_machine.system())
67
conf_data.set('cpu', build_machine.cpu())
78
conf_data.set('cpu_family', build_machine.cpu_family())
89
conf_data.set('endian', build_machine.endian())
10+
conf_data.set('c_args', '-pedantic')
911

1012
configure_file(input: 'crossfile.in',
1113
output: 'crossfile',
1214
configuration: conf_data)
13-
message('Written cross file')
15+
configure_file(input: 'nativefile.in',
16+
output: 'nativefile',
17+
configuration: conf_data)
18+
message('Written native and cross file')
19+
20+
add_languages('c', native: false)
21+
assert(get_option('build.c_args') == get_option('c_args'))
1422
else
1523
assert(meson.is_cross_build(), 'not setup as cross build')
24+
assert(get_option('build.c_args') == ['-pedantic'])
1625
endif
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[built-in options]
2+
c_args = ['@c_args@']

unittests/allplatformstests.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3276,10 +3276,15 @@ def test_clang_tidy_fix(self):
32763276
def test_identity_cross(self):
32773277
testdir = os.path.join(self.unit_test_dir, '69 cross')
32783278
# Do a build to generate a cross file where the host is this target
3279-
self.init(testdir, extra_args=['-Dgenerate=true'])
3279+
# build.c_args is ignored here.
3280+
self.init(testdir, extra_args=['-Dgenerate=true', '-Dc_args=-funroll-loops',
3281+
'-Dbuild.c_args=-pedantic'])
3282+
self.meson_native_files = [os.path.join(self.builddir, "nativefile")]
3283+
self.assertTrue(os.path.exists(self.meson_native_files[0]))
32803284
self.meson_cross_files = [os.path.join(self.builddir, "crossfile")]
32813285
self.assertTrue(os.path.exists(self.meson_cross_files[0]))
3282-
# Now verify that this is detected as cross
3286+
# Now verify that this is detected as cross and build options are
3287+
# processed correctly
32833288
self.new_builddir()
32843289
self.init(testdir)
32853290

0 commit comments

Comments
 (0)