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

Allow overriding programs from the command line #12623

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

tristan957
Copy link
Contributor

People coming from autotools are used to having easy access for overriding programs. This should ease that transition.

@tristan957
Copy link
Contributor Author

cc @anarazel. This could help us to remove the options in the Postgres build.

@tristan957
Copy link
Contributor Author

I plan on adding a test in the future if people seem to think that this is a good approach. @jpakkane had previously said he was open to such a feature, but people have different opinions as time change.

@tristan957
Copy link
Contributor Author

Hmm not sure how to fix the CI at the moment. I must be missing something with Coredata. Any help is appreciated!

@vtorri
Copy link
Contributor

vtorri commented Dec 12, 2023

@tristan957 what about instead writing a web page in the site which do a comparison of usages between meson and autotools ? I don't think it's a good idea to add several ways to do the same things

I've been using the autotools during more than 10 years. When I've heard about meson, i've used it quite easily. There are examples, community is responsive. It should be sufficient

@eli-schwartz
Copy link
Member

I don't think it's a good idea to add several ways to do the same things

But we already have several ways to do everything else. Every command-line -D option to meson can be specified in a machine file, for example. I don't really have a problem adding "several" ways to do the opposite by taking a machine file setting and allowing it to be specified on the command line.

Furthermore, it's a frequent pain point of users, to have to create a whole new file just to pass one tiny little tweak to meson.

@tristan957
Copy link
Contributor Author

@tristan957 what about instead writing a web page in the site which do a comparison of usages between meson and autotools ? I don't think it's a good idea to add several ways to do the same things

I've been using the autotools during more than 10 years. When I've heard about meson, i've used it quite easily. There are examples, community is responsive. It should be sufficient

I've tried advocating for machine files in Postgres for this purpose, but it was said it was a worse solution than this, so here we are, me proposing a solution which makes the transition from autotools to meson a little bit easier.

@@ -59,6 +61,14 @@ def add_arguments(parser: argparse.ArgumentParser) -> None:
'newer version of meson.')
parser.add_argument('--clearcache', action='store_true', default=False,
help='Clear cached state (e.g. found dependencies). Since 1.3.0.')
parser.add_argument('--native-program',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I not tied to these argument names

mesonbuild/coredata.py Outdated Show resolved Hide resolved
mesonbuild/interpreter/interpreter.py Outdated Show resolved Hide resolved
Comment on lines 610 to 615
for a in aliases:
parts = a.split('=', 1)
if len(parts) == 1:
pass

alias_map[parts[0]] = parts[1]
Copy link
Member

@bruchar1 bruchar1 Feb 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about

Suggested change
for a in aliases:
parts = a.split('=', 1)
if len(parts) == 1:
pass
alias_map[parts[0]] = parts[1]
alias_map.update(p.split('=', maxsplit=1) for p in aliases if '=' in p)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this call update needlessly?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh? What do you mean? It iterates through aliases, test for the presence of =, split it, and add it to the dict, just like your for loop...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The difference is that when aliases is empty, a for loop doesn't enter the block body, while alias_map.update(generator_expression) calls the .update() method with no values.

That being said, it's a good point to do:

for a in aliases:
    if '=' in a:
        parts = a.split('=', 1)
        alias_map[parts[0]] = parts[1]

This was changed in 751f03c, but the
type annotation was not correct when it was added.
@tristan957
Copy link
Contributor Author

The codeql error is rather interesting.

mesonbuild/msetup.py Outdated Show resolved Hide resolved
Comment on lines 269 to 270
self.options.cross_program = [f'{k[0]}={v[1]}' for k, v in env.coredata.get_program_overrides(MachineChoice.HOST).items()]
self.options.native_program = [f'{k[0]}={v[1]}' for k, v in env.coredata.get_program_overrides(MachineChoice.BUILD).items()]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In terms of readability this feels somehow inscrutable.

It also unfortunately doesn't actually get dumped to cmd_line.txt at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was a bug. These shouldn't have been indexed. Let me know what you think

Comment on lines +273 to +274
native-program
cross-program
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eli-schwartz do we allow passing machine files in mconfigure? Seems like not. Should these options match what the other options do?

People coming from autotools are used to having easy access for
overriding programs. This should ease that transition.
@jpakkane
Copy link
Member

I have conflicting feelings about this MR, since we already have machine files for exactly this use case. On one hand I can see how it might be nice under some circumtances but OTOH having more than one way of doing something has a tendency to come back and bite you in the ass.

@tristan957
Copy link
Contributor Author

Well that is unfortunate since you initially expressed interest in it. All I can tell you is that machine files are not satisfactory for the powers that be in Postgres.

Copy link
Member

@dcbaker dcbaker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm with @jpakkane that I'm torn on this, since now we have three ways to override programs, env vars, machine files, and now command line.

I'd really like to see the order of env, machine file, and command line specified (with the same precedence we have for CFLAGS, -Dc_args and c_args in the machine file, along with tests for that.

def __parse_program_overrides(options: SharedCMDOptions, for_machine: MachineChoice) -> OrderedDict[str, str]:
overrides_map: OrderedDict[str, str] = OrderedDict()
overrides: T.List[str]
if for_machine == MachineChoice.BUILD:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if for_machine == MachineChoice.BUILD:
if for_machine is MachineChoice.BUILD:

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

Successfully merging this pull request may close these issues.

None yet

6 participants