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.
pull/10194/head
Eli Schwartz 3 years ago
parent 3455f21f72
commit 8ae2bf5a9e
No known key found for this signature in database
GPG Key ID: CEB167EFB5722BD6
  1. 11
      mesonbuild/backend/backends.py
  2. 7
      mesonbuild/backend/ninjabackend.py
  3. 4
      mesonbuild/build.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:

@ -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)

@ -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}>"

Loading…
Cancel
Save