diff options
| author | Paolo Bonzini <pbonzini@redhat.com> | 2025-10-04 12:47:50 +0200 |
|---|---|---|
| committer | Dylan Baker <dylan@pnwbakers.com> | 2025-10-16 08:51:11 -0700 |
| commit | 41a8d31b8a25884501b8ab071915e6b24a648add (patch) | |
| tree | 03f9d489ade167d687055437808f47e60f62034b | |
| parent | df9e801cc11344a6b865fbd961a23ca4d311aa2e (diff) | |
| download | meson-41a8d31b8a25884501b8ab071915e6b24a648add.tar.gz | |
build: store Environment in Generator
Objects like targets already store the environment in which they
were created, do the same for Generator: pass it to the constructor
and use it in process_files.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
| -rw-r--r-- | mesonbuild/backend/backends.py | 3 | ||||
| -rw-r--r-- | mesonbuild/build.py | 10 | ||||
| -rw-r--r-- | mesonbuild/interpreter/interpreter.py | 2 | ||||
| -rw-r--r-- | mesonbuild/modules/_qt.py | 4 |
4 files changed, 13 insertions, 6 deletions
diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py index a5995e6b1..b2d4e5a00 100644 --- a/mesonbuild/backend/backends.py +++ b/mesonbuild/backend/backends.py @@ -2034,7 +2034,8 @@ class Backend: exe = programs.ExternalProgram(compiler.get_exe()) args = compiler.get_exe_args() commands = self.compiler_to_generator_args(target, compiler) - generator = build.Generator(exe, args + commands.to_native(), + generator = build.Generator(self.environment, + exe, args + commands.to_native(), [output_templ], depfile='@PLAINNAME@.d', depends=depends) return generator.process_files(sources, self.interpreter) diff --git a/mesonbuild/build.py b/mesonbuild/build.py index 1cba2f6b4..c1a92e2ba 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -1988,7 +1988,8 @@ class FileMaybeInTargetPrivateDir: return self.fname class Generator(HoldableObject): - def __init__(self, exe: T.Union['Executable', programs.ExternalProgram], + def __init__(self, env: Environment, + exe: T.Union['Executable', programs.ExternalProgram], arguments: T.List[str], output: T.List[str], # how2dataclass @@ -1997,6 +1998,7 @@ class Generator(HoldableObject): capture: bool = False, depends: T.Optional[T.List[BuildTargetTypes]] = None, name: str = 'Generator'): + self.environment = env self.exe = exe self.depfile = depfile self.capture = capture @@ -2052,17 +2054,17 @@ class Generator(HoldableObject): output.depends.add(e) fs = [FileInTargetPrivateDir(f) for f in e.get_outputs()] elif isinstance(e, str): - fs = [File.from_source_file(state.environment.source_dir, state.subdir, e)] + fs = [File.from_source_file(self.environment.source_dir, state.subdir, e)] else: fs = [e] for f in fs: if preserve_path_from: - abs_f = f.absolute_path(state.environment.source_dir, state.environment.build_dir) + abs_f = f.absolute_path(self.environment.source_dir, self.environment.build_dir) if not is_parent_path(preserve_path_from, abs_f): raise InvalidArguments('generator.process: When using preserve_path_from, all input files must be in a subdirectory of the given dir.') f = FileMaybeInTargetPrivateDir(f) - output.add_file(f, state.environment) + output.add_file(f, self.environment) return output diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py index 8481f36bd..537f2768a 100644 --- a/mesonbuild/interpreter/interpreter.py +++ b/mesonbuild/interpreter/interpreter.py @@ -2228,7 +2228,7 @@ class Interpreter(InterpreterBase, HoldableObject): if '@OUTPUT@' in o: raise InvalidArguments('Tried to use @OUTPUT@ in a rule with more than one output.') - return build.Generator(args[0], **kwargs) + return build.Generator(self.environment, args[0], **kwargs) @typed_pos_args('benchmark', str, (build.Executable, build.Jar, ExternalProgram, mesonlib.File, build.CustomTarget, build.CustomTargetIndex)) @typed_kwargs('benchmark', *TEST_KWS) diff --git a/mesonbuild/modules/_qt.py b/mesonbuild/modules/_qt.py index a02dd3b7a..650523904 100644 --- a/mesonbuild/modules/_qt.py +++ b/mesonbuild/modules/_qt.py @@ -514,6 +514,7 @@ class QtBaseModule(ExtensionModule): preserve_path_from = os.path.join(state.source_root, state.subdir) if kwargs['preserve_paths'] else None gen = build.Generator( + state.environment, self.tools['uic'], kwargs['extra_args'] + ['-o', '@OUTPUT@', '@INPUT@'], ['ui_@BASENAME@.h'], @@ -589,6 +590,7 @@ class QtBaseModule(ExtensionModule): if do_output_json: header_gen_output.append('moc_@BASENAME@.cpp.json') moc_gen = build.Generator( + state.environment, self.tools['moc'], arguments, header_gen_output, depfile='moc_@BASENAME@.cpp.d', name=f'Qt{self.qt_version} moc header') @@ -598,6 +600,7 @@ class QtBaseModule(ExtensionModule): if do_output_json: source_gen_output.append('@BASENAME@.moc.json') moc_gen = build.Generator( + state.environment, self.tools['moc'], arguments, source_gen_output, depfile='@BASENAME@.moc.d', name=f'Qt{self.qt_version} moc source') @@ -892,6 +895,7 @@ class QtBaseModule(ExtensionModule): command_args.append('@INPUT@') cache_gen = build.Generator( + state.environment, self.tools['qmlcachegen'], command_args, [f'{target_name}_@BASENAME@.cpp'], |
