makefiles/utils/variables: add functions to help managing variables#11664
makefiles/utils/variables: add functions to help managing variables#11664jcarrano merged 3 commits intoRIOT-OS:masterfrom
Conversation
smlng
left a comment
There was a problem hiding this comment.
First, to me memoized sounds odd, but that's subjective and non-blocking - I would use stored or memorized instead.
Second, I get the following errors when building in docker:
Building application "tests_build_system_utils" for "native" with MCU "native".
"make" -C /data/riotbuild/riotbase/boards/native
"make" -C /data/riotbuild/riotbase/boards/native/drivers
"make" -C /data/riotbuild/riotbase/core
"make" -C /data/riotbuild/riotbase/cpu/native
"make" -C /data/riotbuild/riotbase/cpu/native/periph
"make" -C /data/riotbuild/riotbase/cpu/native/vfs
"make" -C /data/riotbuild/riotbase/drivers
"make" -C /data/riotbuild/riotbase/drivers/periph_common
"make" -C /data/riotbuild/riotbase/sys
"make" -C /data/riotbuild/riotbase/sys/auto_init
text data bss dec hex filename
22770 568 47652 70990 1154e /data/riotbuild/riotbase/tests/build_system_utils/bin/native/tests_build_system_utils.elf
bash: line 0: test: 1560237203N: integer expression expected
ERROR: 1560237203N >= 1560237203N
make[1]: *** [test-exported-variables] Error 1
Command '/Library/Developer/CommandLineTools/usr/bin/make -C /Volumes/devel/github/smlng/RIOT/makefiles/utils -f test-variables.mk test-exported-variables' failed
bash: line 0: test: 1560237203N: integer expression expected
ERROR: 1560237203N >= 1560237203N
make[1]: *** [test-exported-variables] Error 1
make: *** [test-exported-variables] Error 1
Third: see comments.
makefiles/utils/variables.mk
Outdated
| # These functions should help replacing immediate evaluation and global 'export' | ||
|
|
||
|
|
||
| # Evaluate a deferred variable only on once on its first usage |
There was a problem hiding this comment.
typo: double on, remove before once
There was a problem hiding this comment.
I can see that I piggybacked that change from a wip branch a bit too fast :D
makefiles/utils/variables.mk
Outdated
| # variable = $(call memoized,<variable>,<value>) | ||
| # | ||
| # Parameters | ||
| # variable: name on the variable you set |
makefiles/utils/variables.mk
Outdated
|
|
||
|
|
||
| # Evaluate a deferred variable only on once on its first usage | ||
| # Uses after will be as if it was an immediate evaluation |
There was a problem hiding this comment.
wording: better to read: # Uses after [that] will be as ...
|
Damn it does not support Memoized comes from the concept https://en.wikipedia.org/wiki/Memoization but I welcome alternative names. |
I think this name suits perfectly, no need for another one. |
The error is not in docker but in |
|
@smlng I updated to use |
|
yep, python works on macOS ... alternative would be to use |
Here it is just a test, not the all applications workflow, so I did not look for performance optimization. And it gives a solution without asking for |
|
@smlng do you agree with the updated changes ? |
|
yep, pleas squash |
|
please 😄 |
This allows exporting variables only for some target. It will allow not exporting variables when not needed, and so prevent unnecessary evaluation.
This allow deferring a variable evaluation to its usage but still benefit from only evaluating it once on multiple uses.
Import utils functions in Makefile.include to allow using them.
3cbafa3 to
25a1bc4
Compare
|
Squashed. |
|
Thank you for the review. We need to start using it to remove more exports. |
Contribution description
Add functions to set variables and environment for targets
These functions should help replacing immediate evaluation and global 'export'
target-export-variablestarget-export-variables <target> <variables>function that exports a list of variables for some targetsThis should help exporting variables only for the required targets so not evaluate
shellcalls for nothing.Like
make cleandoes not needCFLAGSbut if the variable is exported, it will evaluate which options are supported inCFLAGSanyway.memoizedVARIABLE = $(call memoized,VARIABLE,<value>)function that allows only evaluatingvaluewhen the variable is used like a normal deferred variable, but further evaluations will use an immediate value.This should help not assigning
shellcommands results with:=to call it once only, as it result to evaluating even if not needed. Replacing by a direct=would result in the command be executed on each evaluation which is not wanted.This gives the best of both worlds.
The implementation requires to repeat the variable name in the
call memoizedarguments.Testing procedure
Review and run the test in
tests/build_system_utils.If it executes without error, it is working.
You can also run it with
QUIET=0to see the executed commands.Issues/PRs references
Tracking: remove harmful use of
exportin make and immediate evaluation #10850