Skip to content

Commit

Permalink
programs: Store the project version when overriding find_program
Browse files Browse the repository at this point in the history
When we're using the output of configure_file() with
override_find_program(), we weren't storing the version anywhere, so
get_version() was trying to run the script during setup.

This is usually fine, except in cases where the configure_file()
script actually has to import a library built as part of the project,
and fails to run.

For built executables, we simply use the project version, and we
now do the same here too.
  • Loading branch information
nirbheek committed Sep 26, 2024
1 parent 1aac6cc commit abdba2b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion mesonbuild/interpreter/mesonmain.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ def override_find_program_method(self, args: T.Tuple[str, T.Union[mesonlib.File,
self.interpreter.environment.build_dir)
if not os.path.exists(abspath):
raise InterpreterException(f'Tried to override {name} with a file that does not exist.')
exe = OverrideProgram(name, [abspath])
exe = OverrideProgram(name, [abspath], version=self.interpreter.project_version)
self.interpreter.add_find_program_override(name, exe)

@typed_kwargs(
Expand Down
6 changes: 6 additions & 0 deletions mesonbuild/programs.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,12 @@ class OverrideProgram(ExternalProgram):

"""A script overriding a program."""

def __init__(self, *args, version: str, **kwargs: T.Any) -> None:
self.version = version
super().__init__(*args, **kwargs)

def get_version(self, interpreter: T.Optional['Interpreter'] = None) -> str:
return self.version

def find_external_program(env: 'Environment', for_machine: MachineChoice, name: str,
display_name: str, default_names: T.List[str],
Expand Down

0 comments on commit abdba2b

Please sign in to comment.