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

Implicit dependency fallback when a subproject wrap or dir exists #6902

Merged
merged 12 commits into from
Jul 1, 2020

Conversation

xclaesse
Copy link
Member

@xclaesse xclaesse commented Apr 4, 2020

No description provided.

@xclaesse xclaesse requested a review from jpakkane as a code owner April 4, 2020 22:16
@xclaesse xclaesse force-pushed the auto-fallback branch 3 times, most recently from a818473 to 783b779 Compare April 5, 2020 04:15
@xclaesse
Copy link
Member Author

xclaesse commented Apr 5, 2020

For the record, I filed this MR for glib to override every dependency it provides: https://gitlab.gnome.org/GNOME/glib/-/merge_requests/1441.

@xclaesse xclaesse force-pushed the auto-fallback branch 2 times, most recently from fb8f31e to 84bd6eb Compare April 5, 2020 16:17
Copy link
Contributor

@textshell textshell left a comment

Choose a reason for hiding this comment

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

I think provide should not be in the wrap-* section in the wrap file. Although it needs to be in the wrap file to discover the needed subproject to download, i think it's not itself related to the way to download the subproject.
Also having this in a different section would allow having a file in the actual sub project that contains this information without conflating that information with wrap download information.

mesonbuild/wrap/wrap.py Outdated Show resolved Hide resolved
mesonbuild/interpreter.py Show resolved Hide resolved
docs/markdown/Reference-manual.md Outdated Show resolved Hide resolved
@xclaesse xclaesse force-pushed the auto-fallback branch 2 times, most recently from bdd5623 to 6e05017 Compare April 5, 2020 22:21
@xclaesse xclaesse force-pushed the auto-fallback branch 3 times, most recently from 1ea6a0a to 73b7044 Compare April 5, 2020 22:47
@xclaesse
Copy link
Member Author

xclaesse commented Apr 5, 2020

I think provide should not be in the wrap-* section in the wrap file. Although it needs to be in the wrap file to discover the needed subproject to download, i think it's not itself related to the way to download the subproject.
Also having this in a different section would allow having a file in the actual sub project that contains this information without conflating that information with wrap download information.

Agreed, I changed to have its own [provide] section in the form:

[provide]
foo-1.0 = foo_dep
bar-1.0 = 

That means that dependency('foo-1.0') will return foo_dep variable from the subproject, and dependency('bar-1.0') assumes that subproject does meson.override_dependency('bar-1.0', bar_dep) so it's not needed to give the variable name in the wrap file.

@xclaesse
Copy link
Member Author

@textshell @jpakkane CI failure is unrelated, this is ready for review/merge.

@xclaesse
Copy link
Member Author

@textshell following our IRC discussion, I added 2 commits to this PR.

The 1st adds dependency_names entry in [provide] section to avoid empty foo-1.0 = entries when the variable name is not needed.

The 2nd patch ensures that every dependencies provided by a wrap file are overriden when we used the fallback for one of them.

@xclaesse xclaesse force-pushed the auto-fallback branch 2 times, most recently from 47ce698 to cf9d9a3 Compare April 20, 2020 23:45
@xclaesse
Copy link
Member Author

While at it, I also added fallback for find_program() now that we have a mechanism for wrap files to tell which program it provides.

@xclaesse
Copy link
Member Author

CI fails because it requires #7002 I think.

@lgtm-com
Copy link

lgtm-com bot commented Jun 12, 2020

This pull request introduces 1 alert when merging 984dd2f into 49a9742 - view on LGTM.com

new alerts:

  • 1 for Unused local variable

@xclaesse
Copy link
Member Author

@textshell check the last 2 commits I added in this PR, I think it should be enough to replace override_dependencies_from_wrap() function I had in previous iteration.

@jpakkane
Copy link
Member

One thing that comes to mind is that if both override and the variable name in the wrap file is defined then they should point to the same object. If they don't it should be a hard error. IIRC there is some code for this but does it work in this case also? Maybe there should be a failing test for this here.

@xclaesse
Copy link
Member Author

If the subproject does:

foo_dep = declare_dependency(...)
meson.override_dependency('foo', foo_dep)

bar_dep = declare_dependency(...)

And your wrap has:

...
[provide]
foo = bar_dep

It will be catched in verify_fallback_consistency() method and raise exception.

Would make sense to add a failing test for that indeed.

@xclaesse xclaesse force-pushed the auto-fallback branch 2 times, most recently from 9f6afe2 to b72255c Compare June 29, 2020 19:25
@xclaesse
Copy link
Member Author

@jpakkane failing unit test added.

@jpakkane
Copy link
Member

⚔️ conflicts in docs.

But apart from that looks good. I was never happy with the way fallbacks were defined but could not come up with a proper solution. Looking at this now just makes me want to slap my forehead and go "yes, of course this is how it should have been done".

Once this is in we might even consider deprecating the fallback kwargs after a few releases.

The value for that key must be a coma separated list of dependecy names
provided by that subproject, when no variable name is needed because the
subproject uses override_dependency().
This fix the following common pattern, we don't want to implicitly
fallback on the first line:

foo_dep = dependency('foo', required: false)
if not foo_dep.found()
  foo_dep = cc.find_library('foo', required : false)
  if not foo_dep.found()
    foo_dep = dependency('foo', fallback: 'foo')
  endif
endif
We don't need the legacy variable name system as for dependency()
fallbacks because meson.override_find_program() is largely used already,
so we can just rely on it.
It makes the code cleaner to have 3 separate dictionaries for
packagename, dependency and programs.
Dependency 'foo' is overriden with 'foo_dep' so using fallback variable
name 'bar_dep' should abort.
@jpakkane jpakkane merged commit 026e386 into mesonbuild:master Jul 1, 2020
@xclaesse xclaesse deleted the auto-fallback branch July 1, 2020 20:51
@xclaesse
Copy link
Member Author

xclaesse commented Jul 2, 2020

@textshell thanks a lot for your time spent on the review. I'm glad we made it for the release, but if you still had something to add we can always do a follow-up PR.

Now that this is merged, I rebased #6968 for 0.56 release.

@textshell
Copy link
Contributor

My main worry is that auto fallback might trigger fallback behavior which might be stricter than i initially expected and might block some usage as subproject possibly. But i can't really say without looking some time at the code again specially with this as focus.

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.

3 participants