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

ebuild-writing/using-eclasses: mention sorting inherit arguments #202

Closed
wants to merge 1 commit into from

Conversation

thesamesam
Copy link
Member

Signed-off-by: Sam James sam@gentoo.org

ebuild-writing/using-eclasses/text.xml Outdated Show resolved Hide resolved
ebuild-writing/using-eclasses/text.xml Outdated Show resolved Hide resolved
Signed-off-by: Sam James <sam@gentoo.org>
Comment on lines +30 to +34
alphabetically. An exception is where the phases exported by an eclass are
affected by subsequent arguments. For example, <c>multilib-minimal.eclass</c>
mentions in its
<uri link="::eclass-reference/multilib-minimal.eclass/">documentation</uri>
that it should be inherited last because it overrides most phases.
Copy link
Member

Choose a reason for hiding this comment

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

Thinking about it, an ebuild shouldn't rely on inherit order.

Instead, in the (relatively rare?) case that there's more than one eclass exporting a phase function, the ebuild should define that phase function and call the eclass functions in a well-defined order.

Copy link
Member

Choose a reason for hiding this comment

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

are you going to rewrite all the multilib-minimal using ebuilds? I doubt it. Having the last eclass be the canonical one has been standard practice for a long time

Comment on lines +28 to +35
<p>
When using <c>inherit</c>, it is best practice to sort the arguments (eclasses)
alphabetically. An exception is where the phases exported by an eclass are
affected by subsequent arguments. For example, <c>multilib-minimal.eclass</c>
mentions in its
<uri link="::eclass-reference/multilib-minimal.eclass/">documentation</uri>
that it should be inherited last because it overrides most phases.
</p>
Copy link
Member

Choose a reason for hiding this comment

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

How about something similar to the following instead?

Suggested change
<p>
When using <c>inherit</c>, it is best practice to sort the arguments (eclasses)
alphabetically. An exception is where the phases exported by an eclass are
affected by subsequent arguments. For example, <c>multilib-minimal.eclass</c>
mentions in its
<uri link="::eclass-reference/multilib-minimal.eclass/">documentation</uri>
that it should be inherited last because it overrides most phases.
</p>
<p>
When using <c>inherit</c>, it is best practice to sort the arguments (eclasses)
alphabetically.
</p>
<important>
Don't rely on inherit order. It can be different from what it appears to be
because eclasses can indirectly inherit each other. If several eclasses export
the same phase functions, the ebuild should therefore define that function
and explicitly call the eclass functions in a well defined order.
</important>

Copy link
Member

Choose a reason for hiding this comment

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

Again, disagree, noone is going to clutter multilib ebuilds like this.

Copy link
Member

Choose a reason for hiding this comment

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

"This eclass must always go last" is strange advice. What if more than one eclass says that?

Copy link
Member

Choose a reason for hiding this comment

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

The eclass won't say it, it's the use that implies where it does (even though anything overriding multilib-minimal would seem strange)

Copy link
Member

Choose a reason for hiding this comment

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

But it does:

# multilib-minimal should _always_ go last in inherit order!

@ulm
Copy link
Member

ulm commented Mar 13, 2021

For reference, the old Devrel Handbook had some wisdom about this:

Oh, and you can inherit several eclasses at the same time by saying:

inherit eclass1 eclass2 [...]

...but watch their order! Remember, eclasses can inherit one another and override each other's settings, so you should be careful when dealing with multiple eclasses that might influence one another.

[...]

Let's look at another problem for a moment. Suppose that foo.eclass and bar.eclass both define src_compile(). If you inherit both foo and bar you'll get a different src_compile() depending on the order in which you inherit them. That's ok; you're supposed to keep track of your inheritance order. But you may want to call either of the two src_compile()s explicitly.

This is still up to date, so maybe some of it could be reused?

(I also think that the last sentence from above is what I remembered as a policy, but looks like it was never an absolute requirement.)

@thesamesam thesamesam deleted the inherit-sort branch July 3, 2021 16:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants