From 416a00308f5b0f228af3c93eb597eca8529fdbb0 Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Sun, 8 Jul 2018 20:57:09 +0530 Subject: cross: Use ExternalProgram for cross-file exe_wrapper We already have code to fetch and find binaries specified in a cross file, so use the same code for exe_wrapper. This allows us to handle the same corner-cases that were fixed for other cross binaries. --- mesonbuild/backend/backends.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'mesonbuild/backend/backends.py') diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py index 354d25a..b13aa10 100644 --- a/mesonbuild/backend/backends.py +++ b/mesonbuild/backend/backends.py @@ -72,6 +72,8 @@ class ExecutableSerialisation: self.cmd_args = cmd_args self.env = env self.is_cross = is_cross + if exe_wrapper is not None: + assert(isinstance(exe_wrapper, dependencies.ExternalProgram)) self.exe_runner = exe_wrapper self.workdir = workdir self.extra_paths = extra_paths @@ -85,6 +87,8 @@ class TestSerialisation: self.suite = suite self.fname = fname self.is_cross_built = is_cross_built + if exe_wrapper is not None: + assert(isinstance(exe_wrapper, dependencies.ExternalProgram)) self.exe_runner = exe_wrapper self.is_parallel = is_parallel self.cmd_args = cmd_args @@ -310,7 +314,7 @@ class Backend: self.environment.cross_info.need_cross_compiler() and \ self.environment.cross_info.need_exe_wrapper() if is_cross_built: - exe_wrapper = self.environment.cross_info.config['binaries'].get('exe_wrapper', None) + exe_wrapper = self.environment.get_exe_wrapper() else: exe_wrapper = None es = ExecutableSerialisation(basename, exe_cmd, cmd_args, env, @@ -646,10 +650,10 @@ class Backend: is_cross = is_cross and exe.is_cross if isinstance(exe, dependencies.ExternalProgram): # E.g. an external verifier or simulator program run on a generated executable. - # Can always be run. + # Can always be run without a wrapper. is_cross = False if is_cross: - exe_wrapper = self.environment.cross_info.config['binaries'].get('exe_wrapper', None) + exe_wrapper = self.environment.get_exe_wrapper() else: exe_wrapper = None if mesonlib.for_windows(is_cross, self.environment) or \ @@ -711,9 +715,8 @@ class Backend: def exe_object_to_cmd_array(self, exe): if self.environment.is_cross_build() and \ - self.environment.cross_info.need_exe_wrapper() and \ isinstance(exe, build.BuildTarget) and exe.is_cross: - if 'exe_wrapper' not in self.environment.cross_info.config['binaries']: + if self.environment.exe_wrapper is None: s = 'Can not use target %s as a generator because it is cross-built\n' s += 'and no exe wrapper is defined. You might want to set it to native instead.' s = s % exe.name -- cgit v1.1 From e8dae2b966498207867cb07d58f4404b76c087ce Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Mon, 9 Jul 2018 04:02:02 +0530 Subject: cross: Be more permissive about not-found exe_wrapper We used to immediately try to use whatever exe_wrapper was defined in the cross file, but some people generate the cross file once and use it for several projects, most of which do not even need an exe wrapper to build. Now we're a bit more resilient. We quietly fall back to using non-exe-wrapper paths for compiler checks and skip the sanity check. However, if some code needs the exe wrapper, f.ex., if you run a built executable using custom_target() or run_target(), we will error out during setup. Tests will, of course, continue to error out when you run them if the exe wrapper was not found. We don't want people's tests to silently "pass" (aka skip) because of a bad CI setup. Closes https://github.com/mesonbuild/meson/issues/3562 This commit also adds a test for the behaviour of exe_wrapper in these cases, and refactors the unit tests a bit for it. --- mesonbuild/backend/backends.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'mesonbuild/backend/backends.py') diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py index b13aa10..b55d3e0 100644 --- a/mesonbuild/backend/backends.py +++ b/mesonbuild/backend/backends.py @@ -276,8 +276,11 @@ class Backend: raise MesonException('Unknown data type in object list.') return obj_list - def serialize_executable(self, exe, cmd_args, workdir, env={}, + def serialize_executable(self, tname, exe, cmd_args, workdir, env={}, extra_paths=None, capture=None): + ''' + Serialize an executable for running with a generator or a custom target + ''' import hashlib if extra_paths is None: # The callee didn't check if we needed extra paths, so check it here @@ -302,19 +305,24 @@ class Backend: with open(exe_data, 'wb') as f: if isinstance(exe, dependencies.ExternalProgram): exe_cmd = exe.get_command() - exe_needs_wrapper = False + exe_is_native = True elif isinstance(exe, (build.BuildTarget, build.CustomTarget)): exe_cmd = [self.get_target_filename_abs(exe)] - exe_needs_wrapper = exe.is_cross + exe_is_native = not exe.is_cross else: exe_cmd = [exe] - exe_needs_wrapper = False - is_cross_built = exe_needs_wrapper and \ + exe_is_native = True + is_cross_built = (not exe_is_native) and \ self.environment.is_cross_build() and \ self.environment.cross_info.need_cross_compiler() and \ self.environment.cross_info.need_exe_wrapper() if is_cross_built: exe_wrapper = self.environment.get_exe_wrapper() + if not exe_wrapper.found(): + msg = 'The exe_wrapper {!r} defined in the cross file is ' \ + 'needed by target {!r}, but was not found. Please ' \ + 'check the command and/or add it to PATH.' + raise MesonException(msg.format(exe_wrapper.name, tname)) else: exe_wrapper = None es = ExecutableSerialisation(basename, exe_cmd, cmd_args, env, -- cgit v1.1