aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEli Schwartz <eschwartz@archlinux.org>2022-03-27 11:46:42 -0400
committerEli Schwartz <eschwartz@archlinux.org>2022-03-31 22:52:31 -0400
commit8ae2bf5a9e652d49027191709cda5353446af487 (patch)
tree930e6765fd6779e515221830d9167649092a7f90
parent3455f21f72fdc66f35479e01cf9d1fff50665c16 (diff)
downloadmeson-8ae2bf5a9e652d49027191709cda5353446af487.zip
meson-8ae2bf5a9e652d49027191709cda5353446af487.tar.gz
meson-8ae2bf5a9e652d49027191709cda5353446af487.tar.bz2
allow RunTarget to skip wrapping due to env
Forcing serialization on when writing out the build rule makes very little sense. It was always "forced" on because we mandated a couple of environment variables due to legacy reasons. Add an attribute to RunTarget to say that a given target doesn't *need* those environment variables, and let ninja optimize them away and run the command directly if set.
-rw-r--r--mesonbuild/backend/backends.py11
-rw-r--r--mesonbuild/backend/ninjabackend.py7
-rw-r--r--mesonbuild/build.py4
3 files changed, 13 insertions, 9 deletions
diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py
index 0f70643..b5b8171 100644
--- a/mesonbuild/backend/backends.py
+++ b/mesonbuild/backend/backends.py
@@ -1445,11 +1445,12 @@ class Backend:
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.set('MESON_SOURCE_ROOT', [self.environment.get_source_dir()])
- env.set('MESON_BUILD_ROOT', [self.environment.get_build_dir()])
- env.set('MESON_SUBDIR', [target.subdir])
- env.set('MESONINTROSPECT', [introspect_cmd])
+ if target.default_env:
+ introspect_cmd = join_args(self.environment.get_build_command() + ['introspect'])
+ env.set('MESON_SOURCE_ROOT', [self.environment.get_source_dir()])
+ env.set('MESON_BUILD_ROOT', [self.environment.get_build_dir()])
+ env.set('MESON_SUBDIR', [target.subdir])
+ env.set('MESONINTROSPECT', [introspect_cmd])
return env
def run_postconf_scripts(self) -> None:
diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py
index 422f6bc..8eb4901 100644
--- a/mesonbuild/backend/ninjabackend.py
+++ b/mesonbuild/backend/ninjabackend.py
@@ -11,6 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
+from __future__ import annotations
from collections import OrderedDict
from enum import Enum, unique
@@ -1034,7 +1035,7 @@ class NinjaBackend(backends.Backend):
subproject_prefix = ''
return f'{subproject_prefix}{target.name}'
- def generate_run_target(self, target):
+ def generate_run_target(self, target: build.RunTarget):
target_name = self.build_run_target_name(target)
if not target.command:
# This is an alias target, it has no command, it just depends on
@@ -1044,9 +1045,9 @@ class NinjaBackend(backends.Backend):
target_env = self.get_run_target_env(target)
_, _, cmd = self.eval_custom_target_command(target)
meson_exe_cmd, reason = self.as_meson_exe_cmdline(target.command[0], cmd[1:],
- force_serialize=True, env=target_env,
+ env=target_env,
verbose=True)
- cmd_type = f' (wrapped by meson {reason})'
+ cmd_type = f' (wrapped by meson {reason})' if reason else ''
internal_target_name = f'meson-{target_name}'
elem = NinjaBuildElement(self.all_outputs, internal_target_name, 'CUSTOM_COMMAND', [])
elem.add_item('COMMAND', meson_exe_cmd)
diff --git a/mesonbuild/build.py b/mesonbuild/build.py
index eaf9433..22927f9 100644
--- a/mesonbuild/build.py
+++ b/mesonbuild/build.py
@@ -2596,7 +2596,8 @@ class RunTarget(Target, CommandBase):
subdir: str,
subproject: str,
environment: environment.Environment,
- env: T.Optional['EnvironmentVariables'] = None):
+ env: T.Optional['EnvironmentVariables'] = None,
+ default_env: bool = True):
self.typename = 'run'
# These don't produce output artifacts
super().__init__(name, subdir, subproject, False, MachineChoice.BUILD, environment)
@@ -2605,6 +2606,7 @@ class RunTarget(Target, CommandBase):
self.command = self.flatten_command(command)
self.absolute_paths = False
self.env = env
+ self.default_env = default_env
def __repr__(self) -> str:
repr_str = "<{0} {1}: {2}>"