diff options
-rw-r--r-- | docs/markdown/Commands.md | 7 | ||||
-rw-r--r-- | docs/markdown/snippets/devenv.md | 8 | ||||
-rw-r--r-- | mesonbuild/backend/backends.py | 21 | ||||
-rw-r--r-- | mesonbuild/compilers/mixins/visualstudio.py | 3 | ||||
-rw-r--r-- | mesonbuild/modules/gnome.py | 19 | ||||
-rw-r--r-- | mesonbuild/scripts/depfixer.py | 41 | ||||
-rw-r--r-- | test cases/common/128 generated assembly/empty.c | 0 | ||||
-rw-r--r-- | test cases/common/128 generated assembly/meson.build | 28 | ||||
-rw-r--r-- | test cases/common/128 generated assembly/square-x86.S.in | 2 | ||||
-rw-r--r-- | test cases/common/128 generated assembly/square-x86_64.S.in | 2 | ||||
-rw-r--r-- | test cases/common/128 generated assembly/square.def | 2 |
11 files changed, 111 insertions, 22 deletions
diff --git a/docs/markdown/Commands.md b/docs/markdown/Commands.md index 0751aed..fc8cdd2 100644 --- a/docs/markdown/Commands.md +++ b/docs/markdown/Commands.md @@ -295,5 +295,12 @@ These variables are set in environment in addition to those set using `meson.add - `PATH` includes every directory where there is an executable that would be installed into `bindir`. On windows it also includes every directory where there is a DLL needed to run those executables. +- `LD_LIBRARY_PATH` includes every directory where there is a shared library that + would be installed into `libdir`. This allows to run system application using + custom build of some libraries. For example running system GEdit when building + GTK from git. On OSX the environment variable is `DYLD_LIBRARY_PATH` and + `PATH` on Windows. +- `GI_TYPELIB_PATH` includes every directory where a GObject Introspection + typelib is built. This is automatically set when using `gnome.generate_gir()`. {{ devenv_arguments.inc }} diff --git a/docs/markdown/snippets/devenv.md b/docs/markdown/snippets/devenv.md index c3bac10..1160945 100644 --- a/docs/markdown/snippets/devenv.md +++ b/docs/markdown/snippets/devenv.md @@ -26,4 +26,10 @@ These variables are set in environment in addition to those set using `meson.add - `PATH` includes every directory where there is an executable that would be installed into `bindir`. On windows it also includes every directory where there is a DLL needed to run those executables. - +- `LD_LIBRARY_PATH` includes every directory where there is a shared library that + would be installed into `libdir`. This allows to run system application using + custom build of some libraries. For example running system GEdit when building + GTK from git. On OSX the environment variable is `DYLD_LIBRARY_PATH` and + `PATH` on Windows. +- `GI_TYPELIB_PATH` includes every directory where a GObject Introspection + typelib is built. This is automatically set when using `gnome.generate_gir()`. diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py index 9624ed6..5ce27c3 100644 --- a/mesonbuild/backend/backends.py +++ b/mesonbuild/backend/backends.py @@ -1496,18 +1496,33 @@ class Backend: def get_devenv(self) -> build.EnvironmentVariables: env = build.EnvironmentVariables() extra_paths = set() + library_paths = set() for t in self.build.get_targets().values(): cross_built = not self.environment.machines.matches_build_machine(t.for_machine) can_run = not cross_built or not self.environment.need_exe_wrapper() - in_bindir = t.should_install() and not t.get_install_dir(self.environment)[1] - if isinstance(t, build.Executable) and can_run and in_bindir: + in_default_dir = t.should_install() and not t.get_install_dir(self.environment)[1] + if not can_run or not in_default_dir: + continue + tdir = os.path.join(self.environment.get_build_dir(), self.get_target_dir(t)) + if isinstance(t, build.Executable): # Add binaries that are going to be installed in bindir into PATH # so they get used by default instead of searching on system when # in developer environment. - extra_paths.add(os.path.join(self.environment.get_build_dir(), self.get_target_dir(t))) + extra_paths.add(tdir) if mesonlib.is_windows() or mesonlib.is_cygwin(): # On windows we cannot rely on rpath to run executables from build # directory. We have to add in PATH the location of every DLL needed. extra_paths.update(self.determine_windows_extra_paths(t, [])) + elif isinstance(t, build.SharedLibrary): + # Add libraries that are going to be installed in libdir into + # LD_LIBRARY_PATH. This allows running system applications using + # that library. + library_paths.add(tdir) + if mesonlib.is_windows() or mesonlib.is_cygwin(): + extra_paths.update(library_paths) + elif mesonlib.is_osx(): + env.prepend('DYLD_LIBRARY_PATH', list(library_paths)) + else: + env.prepend('LD_LIBRARY_PATH', list(library_paths)) env.prepend('PATH', list(extra_paths)) return env diff --git a/mesonbuild/compilers/mixins/visualstudio.py b/mesonbuild/compilers/mixins/visualstudio.py index 2b173eb..763d030 100644 --- a/mesonbuild/compilers/mixins/visualstudio.py +++ b/mesonbuild/compilers/mixins/visualstudio.py @@ -412,6 +412,9 @@ class ClangClCompiler(VisualStudioLikeCompiler): super().__init__(target) self.id = 'clang-cl' + # Assembly + self.can_compile_suffixes.add('s') + def has_arguments(self, args: T.List[str], env: 'Environment', code: str, mode: str) -> T.Tuple[bool, bool]: if mode != 'link': args = args + ['-Werror=unknown-argument'] diff --git a/mesonbuild/modules/gnome.py b/mesonbuild/modules/gnome.py index 8a48ca8..dc2979e 100644 --- a/mesonbuild/modules/gnome.py +++ b/mesonbuild/modules/gnome.py @@ -50,11 +50,13 @@ gresource_dep_needed_version = '>= 2.51.1' native_glib_version = None class GnomeModule(ExtensionModule): - gir_dep = None - - install_glib_compile_schemas = False - install_gio_querymodules = [] - install_gtk_update_icon_cache = False + def __init__(self, interpreter: 'Interpreter') -> None: + super().__init__(interpreter) + self.gir_dep = None + self.install_glib_compile_schemas = False + self.install_gio_querymodules = [] + self.install_gtk_update_icon_cache = False + self.devenv = None @staticmethod def _get_native_glib_version(state): @@ -480,6 +482,12 @@ class GnomeModule(ExtensionModule): return girtarget + def _devenv_append(self, varname: str, value: str) -> None: + if self.devenv is None: + self.devenv = build.EnvironmentVariables() + self.interpreter.build.devenv.append(self.devenv) + self.devenv.append(varname, [value]) + def _get_gir_dep(self, state): if not self.gir_dep: self.gir_dep = self._get_native_dep(state, 'gobject-introspection-1.0') @@ -884,6 +892,7 @@ class GnomeModule(ExtensionModule): typelib_cmd += ["--includedir=" + incdir] typelib_target = self._make_typelib_target(state, typelib_output, typelib_cmd, kwargs) + self._devenv_append('GI_TYPELIB_PATH', os.path.join(state.environment.get_build_dir(), state.subdir)) rv = [scan_target, typelib_target] diff --git a/mesonbuild/scripts/depfixer.py b/mesonbuild/scripts/depfixer.py index 8ce74ee..c215749 100644 --- a/mesonbuild/scripts/depfixer.py +++ b/mesonbuild/scripts/depfixer.py @@ -13,8 +13,12 @@ # limitations under the License. -import sys, struct -import shutil, subprocess +import sys +import os +import stat +import struct +import shutil +import subprocess import typing as T from ..mesonlib import OrderedSet @@ -120,9 +124,9 @@ class Elf(DataSizes): def __init__(self, bfile: str, verbose: bool = True) -> None: self.bfile = bfile self.verbose = verbose - self.bf = open(bfile, 'r+b') self.sections = [] # type: T.List[SectionHeader] self.dynamic = [] # type: T.List[DynamicEntry] + self.open_bf(bfile) try: (self.ptrsize, self.is_le) = self.detect_elf_type() super().__init__(self.ptrsize, self.is_le) @@ -130,19 +134,40 @@ class Elf(DataSizes): self.parse_sections() self.parse_dynamic() except (struct.error, RuntimeError): - self.bf.close() + self.close_bf() raise + def open_bf(self, bfile: str) -> None: + self.bf = None + self.bf_perms = None + try: + self.bf = open(bfile, 'r+b') + except PermissionError as e: + self.bf_perms = stat.S_IMODE(os.lstat(bfile).st_mode) + os.chmod(bfile, stat.S_IREAD | stat.S_IWRITE | stat.S_IEXEC) + try: + self.bf = open(bfile, 'r+b') + except Exception: + os.chmod(bfile, self.bf_perms) + self.bf_perms = None + raise e + + def close_bf(self) -> None: + if self.bf is not None: + if self.bf_perms is not None: + os.fchmod(self.bf.fileno(), self.bf_perms) + self.bf_perms = None + self.bf.close() + self.bf = None + def __enter__(self) -> 'Elf': return self def __del__(self) -> None: - if self.bf: - self.bf.close() + self.close_bf() def __exit__(self, exc_type: T.Any, exc_value: T.Any, traceback: T.Any) -> None: - self.bf.close() - self.bf = None + self.close_bf() def detect_elf_type(self) -> T.Tuple[int, bool]: data = self.bf.read(6) diff --git a/test cases/common/128 generated assembly/empty.c b/test cases/common/128 generated assembly/empty.c new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/test cases/common/128 generated assembly/empty.c diff --git a/test cases/common/128 generated assembly/meson.build b/test cases/common/128 generated assembly/meson.build index 89b680d..b256630 100644 --- a/test cases/common/128 generated assembly/meson.build +++ b/test cases/common/128 generated assembly/meson.build @@ -6,10 +6,25 @@ if build_machine.system() == 'cygwin' error('MESON_SKIP_TEST: Cygwin is broken and nobody knows how to fix it. Patches welcome.') endif -if ['msvc', 'clang-cl', 'intel-cl'].contains(cc.get_id()) +if ['msvc', 'intel-cl'].contains(cc.get_id()) error('MESON_SKIP_TEST: assembly files cannot be compiled directly by the compiler') endif +crt_workaround = [] +if cc.get_linker_id() == 'lld-link' + # It seems that when building without a .c file, lld-link.exe + # misses the fact that it needs to include the c runtime to + # make a working .dll. So here we add an empty .c file to easily + # pull in crt. + crt_workaround += 'empty.c' + if host_machine.cpu_family() == 'x86' + # x86 assembly needs manual annotation to be compatible with + # Safe Exception Handlers (?) This assembly doesn't have such + # annotation, so just disable the feature. + add_project_link_arguments('/SAFESEH:NO', language : 'c') + endif +endif + cpu = host_machine.cpu_family() supported_cpus = ['arm', 'x86', 'x86_64'] @@ -17,6 +32,11 @@ if not supported_cpus.contains(cpu) error('MESON_SKIP_TEST: unsupported cpu family: ' + cpu) endif +if cc.get_id() == 'clang-cl' and cc.version().version_compare('< 12.0.0') and cpu == 'arm' + # https://reviews.llvm.org/D89622 + error('MESON_SKIP_TEST: arm debug symbols not supported in clang-cl < 12.0.0') +endif + if cc.symbols_have_underscore_prefix() add_project_arguments('-DMESON_TEST__UNDERSCORE_SYMBOL', language : 'c') endif @@ -29,7 +49,8 @@ copygen = generator(copy, arguments : ['@INPUT@', '@OUTPUT@'], output : '@BASENAME@') -l = shared_library('square-gen', copygen.process(input)) +l = shared_library('square-gen', crt_workaround + [copygen.process(input)], + vs_module_defs: 'square.def') test('square-gen-test', executable('square-gen-test', 'main.c', link_with : l)) @@ -38,6 +59,7 @@ copyct = custom_target('square', output : output, command : [copy, '@INPUT@', '@OUTPUT@']) -l = shared_library('square-ct', copyct) +l = shared_library('square-ct', crt_workaround + [copyct], + vs_module_defs: 'square.def') test('square-ct-test', executable('square-ct-test', 'main.c', link_with : l)) diff --git a/test cases/common/128 generated assembly/square-x86.S.in b/test cases/common/128 generated assembly/square-x86.S.in index ee77b81..1a48fc4 100644 --- a/test cases/common/128 generated assembly/square-x86.S.in +++ b/test cases/common/128 generated assembly/square-x86.S.in @@ -1,6 +1,6 @@ #include "symbol-underscore.h" -#ifdef _MSC_VER +#if defined(_MSC_VER) && !defined(__clang__) .386 .MODEL FLAT, C diff --git a/test cases/common/128 generated assembly/square-x86_64.S.in b/test cases/common/128 generated assembly/square-x86_64.S.in index b2cf3eb..d504341 100644 --- a/test cases/common/128 generated assembly/square-x86_64.S.in +++ b/test cases/common/128 generated assembly/square-x86_64.S.in @@ -1,6 +1,6 @@ #include "symbol-underscore.h" -#ifdef _MSC_VER /* MSVC on Windows */ +#if defined(_MSC_VER) && !defined(__clang__) /* MSVC on Windows */ PUBLIC SYMBOL_NAME(square_unsigned) _TEXT SEGMENT diff --git a/test cases/common/128 generated assembly/square.def b/test cases/common/128 generated assembly/square.def new file mode 100644 index 0000000..79f3d65 --- /dev/null +++ b/test cases/common/128 generated assembly/square.def @@ -0,0 +1,2 @@ +EXPORTS + square_unsigned |