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
buildsystem: unset all PKG_* variables before sourcing a new package #2072
Conversation
As it doesn't hurt to have some standard for variable naming at package.mk and of the benefit of one less thing to care about this is good to go I think. |
I think for loop in reset_pkg_vars function could be optimized by grepping all package.mk files and extracting PKG_ variables only once? On first grep one flag variable would be set to prevent grepping again. |
@vpeter4 grepping all packages sounds far more complicated/error prone, and also slower - there are over 770 packages that would need to be grepped/parsed (at least half of which wouldn't even be needed for any particular build - a Generic build uses only about 360 packages, a create_addon build might only need one package). Also, this current implementation unsets only those |
I've pushed a change which simplifies the
|
Well, I don't know what is faster but 10 seconds is a lot. That's why I decided to see how much does it take. But I'm not sure how you even got 10 sec. For me making tar is only few seconds difference (Odroid_C2 project). Which is fine. For Generic it would take few more. And just for reference
Better having code nicer :) |
That is 10 seconds added to a build that might take up to 4 hours. The 10 seconds I calculated by performing The problem with parsing package.mk is that you also need to take into consideration those
or that might be indented:
which is why parsing package.mk is inherently more complex. |
Agree, issues can escalates quickly out of control with my approach. And when considered all corner cases the question would be if final result would be much better. Probably not that much. |
config/functions
Outdated
reset_pkg_vars() { | ||
local vars var | ||
|
||
for var in $(set | awk -F= '/^PKG_.*=/ { print $1 }'); do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bash allows for var in ${!PKG_*}; do
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh... very nice, thanks! :)
Is this likely to be compatible with all versions of bash?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added an extra commit using your solution which I will squash if there are not likely to be any compatibility issues.
Some stats, using the latest I'm using this test script, which can be run in the root of the LE repo:
It sources each package three times as this is a fairly representative test of what happens during a build (build > unpack > install). That said, the script does processes far more packages than any build, eg. Generic processes only 309 packages. Timings are in seconds, for 557 packages, average of 3 runs (row #1 is the current "traditional" method):
Based on a Generic build with 309 packages, the new method #2 should add about 2.8 (309 * 0.009) seconds to the total build time. |
This looks pretty good to me. The only thing I would maybe add is a default Otherwise I am happy to get this in. |
What would you suggest as a default PKG_VERSION? |
Doesn't really matter to me :)
|
I've changed |
Back to My guess is that We should change the default PKG_VERSION in a separate PR when cleaning up those packages that don't have/need a version. |
This follows on from a discussion on Slack arising out of #2067, which is adding a new package variable
PKG_ADDON_BROKEN
.Adding new variables in a package leads to the risk of those variables leaking over into a subsequent package unless they are unset before the new package is sourced. To prevent leakage we currently maintain a list of variables that must be unset in config/path, which is almost always going to be missing one or more variables.
This PR attempts to address this issue by automatically unsetting ALL
PKG_*
variables before sourcing a new package.I've tested this with clean builds of RPi, RPi2 and Generic, and no problems.
This change does add some overhead - about 10 seconds extra to a Generic build on AMD FX-8350 which isn't excessive in the scheme of things - but does mean we don't have to worry about critical package variables being accidentally leaked and causing unpredictable behaviour.
Potentially all variables set within a package could/should include the
PKG_
prefix, for example whereTVH_TRANSCODING
becomesPKG_TVH_TRANSCODING
. however the decision really is whether the variable being set is ever likely to be used by another package - if it is then it should definitely use thePKG_
prefix, and if not then... meh.