vaeth / portage-bashrc-mv

Provide support for /etc/portage/bashrc.d and /etc/portage/package.cflags for the portage package manager (Gentoo Linux)
http://www.mathematik.uni-wuerzburg.de/~vaeth/gentoo/index.html#portage-bashrc
30 stars 9 forks source link

[package.cflags]: Is it posible somhow to set flags depend on USE-flag(s) enabled/disabled? #8

Closed pchome closed 7 years ago

pchome commented 7 years ago

This should be useful for lto-overlay users when LTO disabled for whole package but problem caused by USE-flag. Example (https://github.com/InBetweenNames/gentooLTO/blob/ce11e856b832274930d7fca10895f0533a14e891/sys-config/ltoize/files/package.cflags/ltoworkarounds.conf):

app-editors/vim *FLAGS+=-ffat-lto-objects # required for perl USE flag
net-misc/dhcp *FLAGS-=-flto* # Cannot be built with LTO by default, but can if "server" USE is disabled
...

Maybe something like app-editors/vim[perl] *FLAGS+=-ffat-lto-objects or app-editors/vim FOR_USE=perl *FLAGS+=-ffat-lto-objects ?

vaeth commented 7 years ago

Adding even more functions is probably not sane. You can use arbitrary bash code anyway. Although it is not documented, you can just call the internal implementation of *FLAGS+= as long you do not use wildcards: "use perl && FlagAddAllFlags -ffat-lto-objects"

pchome commented 7 years ago

Thanks, it seems net-misc/dhcp *FLAGS-="$(use server && echo -n '-flto*')" works fine.

edit: No it's don't work :)

vaeth commented 7 years ago

Quoting must be done rather tricky. There are two eval's executed: One for the whole line, and one for the part after FLAGS-= The following should work: ```net-misc/dhcp 'FLAGS-="$(use server && echo "-flto")"' Since eix -vle dhcp shows that all dhcp ebuilds are at least EAPI 5 you should also be able to use net-misc/dhcp 'FLAGS-="$(usex server "-flto*")"'```

pchome commented 7 years ago

The following should work

Yes, but

  1. I noticed all $(...) executed at once if there is more than one in config (this is obvious but I messed)
  2. use server dies if package have no server use flag (accidentally detected while all commands w/ different flags started executing during emerge process :) )

So final try for now is net-misc/dhcp "has server ${IUSE//+} && use server && FlagSubAllFlags -flto*".

vaeth commented 7 years ago

noticed all $(...) executed at once

This happened in your example because of the missing outer quote: The outer eval (for the whole line) is executed unconditionally for every line, because it is used for splitting the line. The inner eval, however, applies only if the package matches.

use server dies if package have no server use flag

Of course; so does usex. But if you quote as in my example, the "use" or "usex" will be executed only for the corresponding package.

Note: When writing this reply, I realize that it might be more efficient if the outer eval is not executed unconditionally. Maybe in a future release I will change this behavior. No matter whether I will make this change or not: Quoting twice is necessary, because in the "matching" case there are 2 eval's.

vaeth commented 7 years ago

The change announced in the previous note is now in the new release. This could make your previous code work by accident. However, I would strongly recommend to use the correct (two-level) quoting.

pchome commented 7 years ago

Tanks, noted.

But to prevent breakage in case use flag removed for package (this happens sometimes) I still need to check IUSE. So between this two variants: net-misc/dhcp '*FLAGS-="$(has server ${IUSE//+} && use server && echo "-flto*")"' and net-misc/dhcp "has server ${IUSE//+} && use server && FlagSubAllFlags -flto*" I prefer last one.

vaeth commented 7 years ago

The last one only works, because the curent implementation makes "set -f" active during the eval: Otherwise, -flto* might be extended if it matches a file in the current directory. If some of "has" or "use" should mess with the -f flag, it will break.

IIRC, checking IUSE is against pms: It was intentionally removed from pms to avoid that global functions like eclasses (or /etc/portage/bashrc) do tests like this. Some pms fanatics might suggest a patch to portage which will unset IUSE (I am surprised that it still works...).

Edit: In EAPI 6 in_iuse was provided as a substitute which, however, can be used only in certain phases. So, you can probably do (untested!): >=net-misc/dhcp-4.3.6 'in_iuse server && use server && FlagSubAllFlags "-flto*"'

pchome commented 7 years ago

untested

Tested while playing with first variant a while ago ;) along with use_if_iuse (or so) and they not initialized/available.

vaeth commented 7 years ago

not initialized/available

They are available only since EAPI=6. That's why i have put the minimum version requirement on dhcp.