diff options
author | Jussi Pakkanen <jpakkane@gmail.com> | 2020-09-29 19:24:25 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-29 19:24:25 +0300 |
commit | 5f70984403e48e72e22991882ac6ffa03d6ce18e (patch) | |
tree | f6a290c0afb15e572193b1e05a1268c20a1c89fb | |
parent | ff186b05261210602490ea4764e5ccfa2ec494fc (diff) | |
parent | 7176b74fd60fb4726826c46c545c2ed25c26cd20 (diff) | |
download | meson-5f70984403e48e72e22991882ac6ffa03d6ce18e.zip meson-5f70984403e48e72e22991882ac6ffa03d6ce18e.tar.gz meson-5f70984403e48e72e22991882ac6ffa03d6ce18e.tar.bz2 |
Merge pull request #7772 from xclaesse/deprecate-source-root
Deprecate meson.build_root() and meson.source_root()
-rw-r--r-- | docs/markdown/Reference-manual.md | 20 | ||||
-rw-r--r-- | docs/markdown/snippets/deprecate_source_build_root.md | 10 | ||||
-rw-r--r-- | mesonbuild/interpreter.py | 24 | ||||
-rw-r--r-- | mesonbuild/interpreterbase.py | 1 | ||||
-rw-r--r-- | test cases/common/227 fs module/meson.build | 5 | ||||
-rw-r--r-- | test cases/common/227 fs module/subdir/meson.build | 2 | ||||
-rw-r--r-- | test cases/common/227 fs module/subprojects/subbie/meson.build | 4 | ||||
-rw-r--r-- | test cases/common/227 fs module/subprojects/subbie/subsub/meson.build | 2 |
8 files changed, 59 insertions, 9 deletions
diff --git a/docs/markdown/Reference-manual.md b/docs/markdown/Reference-manual.md index 1d0bb92..d315b53 100644 --- a/docs/markdown/Reference-manual.md +++ b/docs/markdown/Reference-manual.md @@ -1808,17 +1808,23 @@ the following methods. or `xcode`. - `build_root()`: returns a string with the absolute path to the build - root directory. Note: this function will return the build root of - the parent project if called from a subproject, which is usually - not what you want. Try using `current_build_dir()`. + root directory. *(deprecated since 0.56.0)*: this function will return the + build root of the parent project if called from a subproject, which is usually + not what you want. Try using `current_build_dir()` or `project_build_root()`. - `source_root()`: returns a string with the absolute path to the source root directory. Note: you should use the `files()` function to refer to files in the root source directory instead of - constructing paths manually with `meson.source_root()`. This - function will return the source root of the parent project if called - from a subproject, which is usually not what you want. Try using - `current_source_dir()`. + constructing paths manually with `meson.source_root()`. + *(deprecated since 0.56.0)*: This function will return the source root of the + parent project if called from a subproject, which is usually not what you want. + Try using `current_source_dir()` or `project_source_root()`. + +- `project_build_root()` *(since 0.56.0)*: returns a string with the absolute path + to the build root directory of the current (sub)project. + +- `project_source_root()` *(since 0.56.0)*: returns a string with the absolute path + to the source root directory of the current (sub)project. - `current_build_dir()`: returns a string with the absolute path to the current build directory. diff --git a/docs/markdown/snippets/deprecate_source_build_root.md b/docs/markdown/snippets/deprecate_source_build_root.md new file mode 100644 index 0000000..1cebef4 --- /dev/null +++ b/docs/markdown/snippets/deprecate_source_build_root.md @@ -0,0 +1,10 @@ +## `meson.build_root()` and `meson.source_root()` are deprecated + +Those function are common source of issue when used in a subproject because they +point to the parent project root which is rarely what is expected and is a +violation of subproject isolation. + +`meson.current_source_dir()` and `meson.current_build_dir()` should be used instead +and have been available in all Meson versions. New functions `meson.project_source_root()` +and `meson.project_build_root()` have been added in Meson 0.56.0 to get the root +of the current (sub)project. diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index 3af5b51..0e5e0f8 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -1924,6 +1924,8 @@ class MesonMain(InterpreterObject): 'current_build_dir': self.current_build_dir_method, 'source_root': self.source_root_method, 'build_root': self.build_root_method, + 'project_source_root': self.project_source_root_method, + 'project_build_root': self.project_build_root_method, 'add_install_script': self.add_install_script_method, 'add_postconf_script': self.add_postconf_script_method, 'add_dist_script': self.add_dist_script_method, @@ -2061,16 +2063,38 @@ class MesonMain(InterpreterObject): @noPosargs @permittedKwargs({}) + @FeatureDeprecated('meson.source_root', '0.56.0', 'use meson.current_source_dir instead.') def source_root_method(self, args, kwargs): return self.interpreter.environment.source_dir @noPosargs @permittedKwargs({}) + @FeatureDeprecated('meson.build_root', '0.56.0', 'use meson.current_build_dir instead.') def build_root_method(self, args, kwargs): return self.interpreter.environment.build_dir @noPosargs @permittedKwargs({}) + @FeatureNew('meson.project_source_root', '0.56.0') + def project_source_root_method(self, args, kwargs): + src = self.interpreter.environment.source_dir + sub = self.interpreter.root_subdir + if sub == '': + return src + return os.path.join(src, sub) + + @noPosargs + @permittedKwargs({}) + @FeatureNew('meson.project_build_root', '0.56.0') + def project_build_root_method(self, args, kwargs): + src = self.interpreter.environment.build_dir + sub = self.interpreter.root_subdir + if sub == '': + return src + return os.path.join(src, sub) + + @noPosargs + @permittedKwargs({}) @FeatureDeprecated('meson.has_exe_wrapper', '0.55.0', 'use meson.can_run_host_binaries instead.') def has_exe_wrapper_method(self, args: T.Tuple[object, ...], kwargs: T.Dict[str, object]) -> bool: return self.can_run_host_binaries_impl(args, kwargs) diff --git a/mesonbuild/interpreterbase.py b/mesonbuild/interpreterbase.py index 1524409..d3f8181 100644 --- a/mesonbuild/interpreterbase.py +++ b/mesonbuild/interpreterbase.py @@ -464,6 +464,7 @@ class InterpreterBase: self.funcs = {} # type: T.Dict[str, T.Callable[[mparser.BaseNode, T.List[TYPE_nvar], T.Dict[str, TYPE_nvar]], TYPE_var]] self.builtin = {} # type: T.Dict[str, InterpreterObject] self.subdir = subdir + self.root_subdir = subdir self.subproject = subproject self.variables = {} # type: T.Dict[str, TYPE_var] self.argument_depth = 0 diff --git a/test cases/common/227 fs module/meson.build b/test cases/common/227 fs module/meson.build index cff0987..f090d35 100644 --- a/test cases/common/227 fs module/meson.build +++ b/test cases/common/227 fs module/meson.build @@ -96,6 +96,9 @@ f1 = 'meson.build' f2 = 'subdir/../meson.build' assert(fs.is_samepath(f1, f2), 'is_samepath not detercting same files') assert(fs.is_samepath(meson.source_root(), 'subdir/..'), 'is_samepath not detecting same directory') +assert(fs.is_samepath(meson.project_source_root(), 'subdir/..'), 'is_samepath not detecting same directory') +# This fails with python3.5. It can be uncommented when we depend on python >= 3.6 +#assert(fs.is_samepath(meson.project_build_root(), meson.current_build_dir() / 'subdir/..'), 'is_samepath not detecting same directory') assert(not fs.is_samepath(f1, 'subdir/subdirfile.txt'), 'is_samepath known bad comparison') assert(not fs.is_samepath('not-a-path', f2), 'is_samepath should not error if path(s) do not exist') @@ -111,3 +114,5 @@ assert(fs.stem('foo/bar/baz.dll') == 'baz', 'failed to get stem with suffix') assert(fs.stem('foo/bar/baz.dll.a') == 'baz.dll', 'failed to get stem with compound suffix') subdir('subdir') + +subproject('subbie') diff --git a/test cases/common/227 fs module/subdir/meson.build b/test cases/common/227 fs module/subdir/meson.build index ec6f102..dc04b41 100644 --- a/test cases/common/227 fs module/subdir/meson.build +++ b/test cases/common/227 fs module/subdir/meson.build @@ -1 +1,3 @@ assert(fs.exists('subdirfile.txt'), 'Subdir file lookup is broken.') +assert(fs.is_samepath(meson.project_source_root(), '..'), 'is_samepath not detecting same directory') +assert(fs.is_samepath(meson.project_build_root(), meson.current_build_dir() / '..'), 'is_samepath not detecting same directory') diff --git a/test cases/common/227 fs module/subprojects/subbie/meson.build b/test cases/common/227 fs module/subprojects/subbie/meson.build index 55fc286..ca6d36b 100644 --- a/test cases/common/227 fs module/subprojects/subbie/meson.build +++ b/test cases/common/227 fs module/subprojects/subbie/meson.build @@ -3,7 +3,7 @@ project('subbie') fs = import('fs') assert(fs.exists('subprojectfile.txt'), 'Subproject root file not found.') +assert(fs.is_samepath(meson.project_source_root(), meson.current_source_dir()), 'is_samepath not detecting same directory') +assert(fs.is_samepath(meson.project_build_root(), meson.current_build_dir()), 'is_samepath not detecting same directory') subdir('subsub') - -subproject('subbie') diff --git a/test cases/common/227 fs module/subprojects/subbie/subsub/meson.build b/test cases/common/227 fs module/subprojects/subbie/subsub/meson.build index cf9a271..4ac68ae 100644 --- a/test cases/common/227 fs module/subprojects/subbie/subsub/meson.build +++ b/test cases/common/227 fs module/subprojects/subbie/subsub/meson.build @@ -1 +1,3 @@ assert(fs.exists('subsubfile.txt'), 'Subproject subdir lookup failed.') +assert(fs.is_samepath(meson.project_source_root(), meson.current_source_dir() / '..'), 'is_samepath not detecting same directory') +assert(fs.is_samepath(meson.project_build_root(), meson.current_build_dir() / '..'), 'is_samepath not detecting same directory') |