diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index c2c4fe304..4bd7d7f3a 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -33,6 +33,7 @@ from .modules import ModuleReturnValue import os, sys, shutil, uuid import re, shlex from collections import namedtuple +from pathlib import PurePath import importlib @@ -1981,7 +1982,7 @@ to directly access options of other subprojects.''') @noKwargs def func_error(self, node, args, kwargs): self.validate_arguments(args, 1, [str]) - raise InterpreterException('Error encountered: ' + args[0]) + raise InterpreterException('Problem encountered: ' + args[0]) def detect_compilers(self, lang, need_cross_compiler): cross_comp = None @@ -2358,10 +2359,10 @@ root and issuing %s. raise # If the subproject execution failed in a non-fatal way, don't raise an # exception; let the caller handle things. - except: + except Exception as e: mlog.log('Also couldn\'t find a fallback subproject in', mlog.bold(os.path.join(self.subproject_dir, dirname)), - 'for the dependency', mlog.bold(name)) + 'for the dependency', mlog.bold(name), '\nReason:', str(e)) return None dep = self.get_subproject_dep(name, dirname, varname, kwargs.get('required', True)) if not dep: @@ -2982,11 +2983,16 @@ different subdirectory. def evaluate_subproject_info(self, path_from_source_root, subproject_dirname): depth = 0 subproj_name = '' - segs = path_from_source_root.split(os.path.sep) - while segs and segs[0] == subproject_dirname: - depth += 1 - subproj_name = segs[1] - segs = segs[2:] + segs = PurePath(path_from_source_root).parts + segs_spd = PurePath(subproject_dirname).parts + while segs and segs[0] == segs_spd[0]: + if len(segs_spd) == 1: + subproj_name = segs[1] + segs = segs[2:] + depth += 1 + else: + segs_spd = segs_spd[1:] + segs = segs[1:] return (depth, subproj_name) # Check that the indicated file is within the same subproject diff --git a/test cases/common/177 subproject nested subproject dirs/contrib/subprojects/alpha/a.c b/test cases/common/177 subproject nested subproject dirs/contrib/subprojects/alpha/a.c new file mode 100644 index 000000000..7ac3e5e57 --- /dev/null +++ b/test cases/common/177 subproject nested subproject dirs/contrib/subprojects/alpha/a.c @@ -0,0 +1,15 @@ +int func2(); + +#if defined _WIN32 || defined __CYGWIN__ + #define DLL_PUBLIC __declspec(dllexport) +#else + #if defined __GNUC__ + #define DLL_PUBLIC __attribute__ ((visibility("default"))) + #else + #pragma message ("Compiler does not support symbol visibility.") + #define DLL_PUBLIC + #endif +#endif + +int DLL_PUBLIC func() { return func2(); } + diff --git a/test cases/common/177 subproject nested subproject dirs/contrib/subprojects/alpha/meson.build b/test cases/common/177 subproject nested subproject dirs/contrib/subprojects/alpha/meson.build new file mode 100644 index 000000000..12f656427 --- /dev/null +++ b/test cases/common/177 subproject nested subproject dirs/contrib/subprojects/alpha/meson.build @@ -0,0 +1,4 @@ +project('alpha project', 'c', subproject_dir: 'var/subprojects') + +b = subproject('beta') +l = shared_library('a', 'a.c', link_with : b.get_variable('lb')) diff --git a/test cases/common/177 subproject nested subproject dirs/contrib/subprojects/alpha/var/subprojects/wrap_files_might_be_here b/test cases/common/177 subproject nested subproject dirs/contrib/subprojects/alpha/var/subprojects/wrap_files_might_be_here new file mode 100644 index 000000000..8d1c8b69c --- /dev/null +++ b/test cases/common/177 subproject nested subproject dirs/contrib/subprojects/alpha/var/subprojects/wrap_files_might_be_here @@ -0,0 +1 @@ + diff --git a/test cases/common/177 subproject nested subproject dirs/contrib/subprojects/beta/b.c b/test cases/common/177 subproject nested subproject dirs/contrib/subprojects/beta/b.c new file mode 100644 index 000000000..a95651bc0 --- /dev/null +++ b/test cases/common/177 subproject nested subproject dirs/contrib/subprojects/beta/b.c @@ -0,0 +1,14 @@ +#if defined _WIN32 || defined __CYGWIN__ + #define DLL_PUBLIC __declspec(dllexport) +#else + #if defined __GNUC__ + #define DLL_PUBLIC __attribute__ ((visibility("default"))) + #else + #pragma message ("Compiler does not support symbol visibility.") + #define DLL_PUBLIC + #endif +#endif + +int DLL_PUBLIC func2() { + return 42; +} diff --git a/test cases/common/177 subproject nested subproject dirs/contrib/subprojects/beta/meson.build b/test cases/common/177 subproject nested subproject dirs/contrib/subprojects/beta/meson.build new file mode 100644 index 000000000..ea4cc9bdf --- /dev/null +++ b/test cases/common/177 subproject nested subproject dirs/contrib/subprojects/beta/meson.build @@ -0,0 +1,3 @@ +project('beta project', 'c') + +lb = shared_library('b', 'b.c') diff --git a/test cases/common/177 subproject nested subproject dirs/meson.build b/test cases/common/177 subproject nested subproject dirs/meson.build new file mode 100644 index 000000000..a4d0a9716 --- /dev/null +++ b/test cases/common/177 subproject nested subproject dirs/meson.build @@ -0,0 +1,7 @@ +project('gamma project', 'c', subproject_dir: 'contrib/subprojects') + +a = subproject('alpha') +lib = a.get_variable('l') + +exe = executable('prog', 'prog.c', link_with : lib) +test('basic', exe) diff --git a/test cases/common/177 subproject nested subproject dirs/prog.c b/test cases/common/177 subproject nested subproject dirs/prog.c new file mode 100644 index 000000000..394f139eb --- /dev/null +++ b/test cases/common/177 subproject nested subproject dirs/prog.c @@ -0,0 +1,5 @@ +int func(); + +int main(int argc, char **argv) { + return func() == 42 ? 0 : 1; +}