diff options
author | Jussi Pakkanen <jpakkane@gmail.com> | 2021-02-07 11:46:41 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-07 11:46:41 +0000 |
commit | 8b82ffa9e423558d7644c7135db4114f59537829 (patch) | |
tree | 90a326f8e796d4a81e98e0639fe67b6a0459ed08 /mesonbuild/backend/backends.py | |
parent | 8e73e5fe1c4fcd5a875cb4777c7938f9069e0102 (diff) | |
parent | f63e168685c22a749502161355a7ea98a6c5344a (diff) | |
download | meson-8b82ffa9e423558d7644c7135db4114f59537829.zip meson-8b82ffa9e423558d7644c7135db4114f59537829.tar.gz meson-8b82ffa9e423558d7644c7135db4114f59537829.tar.bz2 |
Merge pull request #8305 from xclaesse/run-target-env
run_target: Add env kwarg
Diffstat (limited to 'mesonbuild/backend/backends.py')
-rw-r--r-- | mesonbuild/backend/backends.py | 45 |
1 files changed, 22 insertions, 23 deletions
diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py index 233173f..e19afca 100644 --- a/mesonbuild/backend/backends.py +++ b/mesonbuild/backend/backends.py @@ -21,8 +21,6 @@ import json import os import pickle import re -import shlex -import textwrap import typing as T import hashlib import copy @@ -34,7 +32,7 @@ from .. import mlog from ..compilers import LANGUAGES_USING_LDFLAGS from ..mesonlib import ( File, MachineChoice, MesonException, OptionType, OrderedSet, OptionOverrideProxy, - classify_unity_sources, unholder, OptionKey + classify_unity_sources, unholder, OptionKey, join_args ) if T.TYPE_CHECKING: @@ -138,6 +136,7 @@ class ExecutableSerialisation: self.capture = capture self.pickled = False self.skip_if_destdir = False + self.verbose = False class TestSerialisation: def __init__(self, name: str, project: str, suite: str, fname: T.List[str], @@ -432,12 +431,14 @@ class Backend: def as_meson_exe_cmdline(self, tname, exe, cmd_args, workdir=None, extra_bdeps=None, capture=None, force_serialize=False, - env: T.Optional[build.EnvironmentVariables] = None): + env: T.Optional[build.EnvironmentVariables] = None, + verbose: bool = False): ''' Serialize an executable for running with a generator or a custom target ''' cmd = [exe] + cmd_args es = self.get_executable_serialisation(cmd, workdir, extra_bdeps, capture, env) + es.verbose = verbose reasons = [] if es.extra_paths: reasons.append('to set PATH') @@ -987,18 +988,8 @@ class Backend: if delta > 0.001: raise MesonException('Clock skew detected. File {} has a time stamp {:.4f}s in the future.'.format(absf, delta)) - def build_target_to_cmd_array(self, bt, check_cross): + def build_target_to_cmd_array(self, bt): if isinstance(bt, build.BuildTarget): - if check_cross and isinstance(bt, build.Executable) and bt.for_machine is not MachineChoice.BUILD: - if (self.environment.is_cross_build() and - self.environment.exe_wrapper is None and - self.environment.need_exe_wrapper()): - s = textwrap.dedent(''' - Cannot use target {} as a generator because it is built for the - host machine and no exe wrapper is defined or needs_exe_wrapper is - true. You might want to set `native: true` instead to build it for - the build machine.'''.format(bt.name)) - raise MesonException(s) arr = [os.path.join(self.environment.get_build_dir(), self.get_target_filename(bt))] else: arr = bt.get_command() @@ -1129,11 +1120,9 @@ class Backend: inputs = self.get_custom_target_sources(target) # Evaluate the command list cmd = [] - index = -1 for i in target.command: - index += 1 if isinstance(i, build.BuildTarget): - cmd += self.build_target_to_cmd_array(i, (index == 0)) + cmd += self.build_target_to_cmd_array(i) continue elif isinstance(i, build.CustomTarget): # GIR scanner will attempt to execute this binary but @@ -1146,10 +1135,7 @@ class Backend: i = os.path.join(self.environment.get_build_dir(), i) # FIXME: str types are blindly added ignoring 'target.absolute_paths' # because we can't know if they refer to a file or just a string - elif not isinstance(i, str): - err_msg = 'Argument {0} is of unknown type {1}' - raise RuntimeError(err_msg.format(str(i), str(type(i)))) - else: + elif isinstance(i, str): if '@SOURCE_ROOT@' in i: i = i.replace('@SOURCE_ROOT@', source_root) if '@BUILD_ROOT@' in i: @@ -1179,6 +1165,9 @@ class Backend: else: lead_dir = self.environment.get_build_dir() i = i.replace(source, os.path.join(lead_dir, outdir)) + else: + err_msg = 'Argument {0} is of unknown type {1}' + raise RuntimeError(err_msg.format(str(i), str(type(i)))) cmd.append(i) # Substitute the rest of the template strings values = mesonlib.get_filenames_templates_dict(inputs, outputs) @@ -1204,11 +1193,21 @@ class Backend: cmd = [i.replace('\\', '/') for i in cmd] return inputs, outputs, cmd + def get_run_target_env(self, target: build.RunTarget) -> build.EnvironmentVariables: + env = target.env if target.env else build.EnvironmentVariables() + introspect_cmd = join_args(self.environment.get_build_command() + ['introspect']) + env.add_var(env.set, 'MESON_SOURCE_ROOT', [self.environment.get_source_dir()], {}) + env.add_var(env.set, 'MESON_BUILD_ROOT', [self.environment.get_build_dir()], {}) + env.add_var(env.set, 'MESON_SUBDIR', [target.subdir], {}) + env.add_var(env.set, 'MESONINTROSPECT', [introspect_cmd], {}) + return env + def run_postconf_scripts(self) -> None: from ..scripts.meson_exe import run_exe + introspect_cmd = join_args(self.environment.get_build_command() + ['introspect']) env = {'MESON_SOURCE_ROOT': self.environment.get_source_dir(), 'MESON_BUILD_ROOT': self.environment.get_build_dir(), - 'MESONINTROSPECT': ' '.join([shlex.quote(x) for x in self.environment.get_build_command() + ['introspect']]), + 'MESONINTROSPECT': introspect_cmd, } for s in self.build.postconf_scripts: |