Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overriding find_program on the command line #13096

Open
ryandesign opened this issue Apr 16, 2024 · 9 comments
Open

Overriding find_program on the command line #13096

ryandesign opened this issue Apr 16, 2024 · 9 comments

Comments

@ryandesign
Copy link

I wish to build someone else's software that uses meson. In their meson.build file they have written:

  m4 = find_program('m4', required: true)

I do not want meson to search for a program called m4. Instead, I want to inform meson which program it should use for this purpose (specifically /opt/local/bin/gm4). I don't want to patch the meson.build file. If this were an autoconf-generated configure script, it would be a simple matter of specifying an argument like ac_cv_prog_M4=/opt/local/bin/gm4 on the command line when I run ./configure. What's the meson equivalent?

I have read How do I do X in Meson? and the documentation for find_program() and meson.override_find_program() and I haven't found anything that seems applicable to this.

@thesamesam
Copy link
Contributor

@eli-schwartz I think I wanted this before for Valgrind, maybe.

@thesamesam
Copy link
Contributor

thesamesam commented Apr 16, 2024

@ryandesign You can do what we do in our zstd packaging:

# This replaces the no-find-valgrind patch once bugfix lands in a meson
# release + we can BDEPEND on it (https://github.com/mesonbuild/meson/pull/11372)
cat >> ${native_file} <<-EOF || die
[binaries]
valgrind='valgrind-falseified'
EOF

meson setup ... --native-file "${native_file}"

@eli-schwartz
Copy link
Member

A machine file can easily specify the exact command to use. Specifying this on the command line is not currently possible (but has been discussed).

@tristan957
Copy link
Contributor

Related: #12623. You have to convince @jpakkane

ryandesign added a commit to ryandesign/macports-ports that referenced this issue Apr 17, 2024
Ports can append key=value pairs to meson.native.binaries to override
the results of find_program.

See: https://trac.macports.org/ticket/63356
See: mesonbuild/meson#13096
@ryandesign
Copy link
Author

You can do what we do in our zstd packaging

Thanks. It's less convenient to have to write these options to a separate file than to specify them on the command line directly, but it works—for find_program. I'm seeing meson.build files that find python by using find_installation instead, and this method doesn't seem to work for that. How do I override the results of find_installation? How many more ways are there that meson.build files typically find programs, and how do I override their results from the command line or from a machine file?

@ryandesign
Copy link
Author

this method doesn't seem to work for […] find_installation

Scratch that… the meson.build file said:

python = import('python').find_installation('python3')

so I assumed what I would have to add to the machine file was:

[binaries]
python3='/opt/local/bin/python3.12'

That didn't work. What did work however was:

[binaries]
python='/opt/local/bin/python3.12'

@ryandesign
Copy link
Author

I've now convinced myself by looking through the python module's find_installation function that the python binary key is indeed the correct one to use:

np: T.List[str] = state.environment.lookup_binary_entry(MachineChoice.HOST, 'python') or []

However searching through the meson codebase for other instances of lookup_binary_entry I found the python3 module and it uses the key python3:

command = state.environment.lookup_binary_entry(mesonlib.MachineChoice.HOST, 'python3')

So to override a particular build system's python choice, it sounds like I have to read the meson.build file to discover whether it is using the python or python3 module.

All of this information on how to override a meson.build file's program choices would be useful to have in the documentation.

The "How do I do X in Meson?" document seems to be a mix of information targeted at meson.build authors and users building software that uses a meson.build file. It might be useful to separate it clearly into two sections for those two different audiences. The section aimed at users should not assume any prior knowledge of meson or python—most users just want to build a piece of software, not understand its build system.

@dcbaker
Copy link
Member

dcbaker commented Apr 19, 2024

The python3 module is deprecated, so I wouldn't worry about what it's doing. I'm not sure that there's even anyone using it anymore, or has been for some time.

@eli-schwartz
Copy link
Member

I think in the past couple of years I have seen maybe two projects that used it, and both were only using it because they started using it before the "python" module replaced it.

ryandesign added a commit to macports/macports-ports that referenced this issue Apr 26, 2024
Ports can append key=value pairs to meson.native.binaries to override
the results of find_program.

See: https://trac.macports.org/ticket/63356
See: mesonbuild/meson#13096
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants