diff options
author | Dylan Baker <dylan@pnwbakers.com> | 2021-02-25 14:56:35 -0800 |
---|---|---|
committer | Dylan Baker <dylan@pnwbakers.com> | 2021-02-26 09:05:30 -0800 |
commit | e0795539598c8dd21756158d0687b461712f0a21 (patch) | |
tree | 1f93a5ffa2688f2696c20d96a71b971e1b7ce68d | |
parent | ec5fe58e6dd0f42f126b48d1ebd191deeea38541 (diff) | |
download | meson-e0795539598c8dd21756158d0687b461712f0a21.zip meson-e0795539598c8dd21756158d0687b461712f0a21.tar.gz meson-e0795539598c8dd21756158d0687b461712f0a21.tar.bz2 |
interpreter: correctly track whether a subproject is initialized
The way the tracking is currently done it works if no new subprojects
are added to a configured build directory. For cases where we want to
add a new subproject, it fails because we don't initialize builtins for
that subproject. This corrects that by checking to see if the subproject
already exists, and if it doesn't initializes the bultins for it.
Fixes: #8421
6 files changed, 35 insertions, 1 deletions
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index 98c5713..ea65bc6 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -3185,7 +3185,11 @@ external dependencies (including libraries) must go to "dependencies".''') # have any effect. self.project_default_options = mesonlib.stringlistify(kwargs.get('default_options', [])) self.project_default_options = coredata.create_options_dict(self.project_default_options, self.subproject) - if self.environment.first_invocation: + + # If this is the first invocation we alway sneed to initialize + # builtins, if this is a subproject that is new in a re-invocation we + # need to initialize builtins for that + if self.environment.first_invocation or (self.subproject != '' and self.subproject not in self.subprojects): default_options = self.project_default_options.copy() default_options.update(self.default_project_options) self.coredata.init_builtins(self.subproject) diff --git a/run_unittests.py b/run_unittests.py index f7f9fd5..acd775c 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -5544,6 +5544,13 @@ class AllPlatformTests(BasePlatformTests): check_installed_files(['--skip-subprojects', 'bar'], main_expected) check_installed_files(['--skip-subprojects', 'another'], all_expected) + def test_adding_subproject_to_configure_project(self) -> None: + srcdir = os.path.join(self.unit_test_dir, '92 new subproject in configured project') + self.init(srcdir) + self.build() + self.setconf('-Duse-sub=true') + self.build() + class FailureTests(BasePlatformTests): ''' diff --git a/test cases/unit/92 new subproject in configured project/meson.build b/test cases/unit/92 new subproject in configured project/meson.build new file mode 100644 index 0000000..b82aa41 --- /dev/null +++ b/test cases/unit/92 new subproject in configured project/meson.build @@ -0,0 +1,7 @@ +# SPDX-license-identifier: Apache-2.0 +# Copyright © 2021 Intel Corporation +project('existing project with new subproject', 'c') + +if get_option('use-sub') + dep = subproject('sub') +endif diff --git a/test cases/unit/92 new subproject in configured project/meson_options.txt b/test cases/unit/92 new subproject in configured project/meson_options.txt new file mode 100644 index 0000000..12d8395 --- /dev/null +++ b/test cases/unit/92 new subproject in configured project/meson_options.txt @@ -0,0 +1,3 @@ +# SPDX-license-identifier: Apache-2.0 +# Copyright © 2021 Intel Corporation +option('use-sub', type : 'boolean', value : false) diff --git a/test cases/unit/92 new subproject in configured project/subprojects/sub/foo.c b/test cases/unit/92 new subproject in configured project/subprojects/sub/foo.c new file mode 100644 index 0000000..9713d9f --- /dev/null +++ b/test cases/unit/92 new subproject in configured project/subprojects/sub/foo.c @@ -0,0 +1,6 @@ +/* SPDX-license-identifier: Apache-2.0 */ +/* Copyright © 2021 Intel Corporation */ + +int func(void) { + return 1; +} diff --git a/test cases/unit/92 new subproject in configured project/subprojects/sub/meson.build b/test cases/unit/92 new subproject in configured project/subprojects/sub/meson.build new file mode 100644 index 0000000..a833b0c --- /dev/null +++ b/test cases/unit/92 new subproject in configured project/subprojects/sub/meson.build @@ -0,0 +1,7 @@ +# SPDX-license-identifier: Apache-2.0 +# Copyright © 2021 Intel Corporation +project('new subproject', 'c') + +l = library('foo', 'foo.c') + +dep = declare_dependency(link_with : l) |