binman: Do not pollute source tree when build with `make O=...`
PATCH 1/1 binman: Do not pollute source tree when build with `make O=...`
Importing libraries in Python caches the bytecode by default. Since we run scripts in source tree it ignores the current directory settings, which is $(srctree), and creates cache just in the middle of the source tree. Move cache to the current directory.
--- tools/binman/main.py | 7 +++++++ 1 file changed, 7 insertions(+)
tools/binman/main.py +7 -0
@@ -16,6 +16,13 @@ import sys import traceback import unittest +# +# Do not pollute source tree with cache files: +# https://stackoverflow.com/a/60024195/2511795 +# https://bugs.python.org/issue33499 +# +sys.pycache_prefix = os.path.relpath(os.path.dirname(sys.argv[0]), os.environ['srctree']) + # Bring in the patman and dtoc libraries (but don't override the first path # in PYTHONPATH) our_path = os.path.dirname(os.path.realpath(__file__))
Signature · 1 line
2.33.0
Quoted 18 lines · Andy Shevchenko
Importing libraries in Python caches the bytecode by default. Since we run scripts in source tree it ignores the current directory settings, which is $(srctree), and creates cache just in the middle of the source tree. Move cache to the current directory.
Signed-off-by Andy Shevchenko <[email protected]>--- tools/binman/main.py | 7 +++++++ 1 file changed, 7 insertions(+)tools/binman/main.py +0
-0@@ -16,6 +16,13 @@ import sys import traceback import unittest
tools/binman/main.py import sys · line 28
Quoted 10 lines
tools/binman/main.py +7
-0+# +# Do not pollute source tree with cache files: +# https://stackoverflow.com/a/60024195/2511795 +# https://bugs.python.org/issue33499 +# +sys.pycache_prefix = os.path.relpath(os.path.dirname(sys.argv[0]), os.environ['srctree']) + # Bring in the patman and dtoc libraries (but don't override the first path # in PYTHONPATH) our_path = os.path.dirname(os.path.realpath(__file__))
Do we need some wrapper around this so it doesn't blow up on older than Python 3.8? Looking over the logs, we force 3.8 to be the minimum version, I think it's 3.6. Which means that we aren't documenting the minimum version well, and should. But, 3.8 is only 2 years old and I always get a little itchy around saying we need tools that feel to me to be super recent still.
Signature · 1 line
Tom
Quoted 15 lines · Tom Rini
tools/binman/main.py import sys · line 28
Quoted 10 lines · Andy Shevchenko
tools/binman/main.py +7
-0+# +# Do not pollute source tree with cache files: +# https://stackoverflow.com/a/60024195/2511795 +# https://bugs.python.org/issue33499 +# +sys.pycache_prefix = os.path.relpath(os.path.dirname(sys.argv[0]), os.environ['srctree']) + # Bring in the patman and dtoc libraries (but don't override the first path # in PYTHONPATH) our_path = os.path.dirname(os.path.realpath(__file__))Do we need some wrapper around this so it doesn't blow up on older than Python 3.8?
Why does it blow? Some global variables which won't be used by older versions.
Quoted 5 lines
Looking over the logs, we force 3.8 to be the minimum
version, I think it's 3.6. Which means that we aren't documenting the minimum version well, and should. But, 3.8 is only 2 years old and I always get a little itchy around saying we need tools that feel to me to be super recent still.
P.S. scratch above, I have a v2
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 17 lines · Andy Shevchenko
Quoted 15 lines · Tom Rini
tools/binman/main.py import sys · line 28
Quoted 10 lines · Andy Shevchenko
tools/binman/main.py +7
-0+# +# Do not pollute source tree with cache files: +# https://stackoverflow.com/a/60024195/2511795 +# https://bugs.python.org/issue33499 +# +sys.pycache_prefix = os.path.relpath(os.path.dirname(sys.argv[0]), os.environ['srctree']) + # Bring in the patman and dtoc libraries (but don't override the first path # in PYTHONPATH) our_path = os.path.dirname(os.path.realpath(__file__))Do we need some wrapper around this so it doesn't blow up on older than Python 3.8?
Quoted 1 line
Why does it blow? Some global variables which won't be used by older versions.
Does it? I don't know, I wasn't clear enough, sorry. What happens on an older python here? Silent ignore is fine.
Signature · 1 line
Tom
Quoted 17 lines · Tom Rini
Quoted 16 lines · Andy Shevchenko
Quoted 14 lines · Tom Rini
tools/binman/main.py import sys · line 28
Quoted 10 lines · Andy Shevchenko
tools/binman/main.py +7
-0+# +# Do not pollute source tree with cache files: +# https://stackoverflow.com/a/60024195/2511795 +# https://bugs.python.org/issue33499 +# +sys.pycache_prefix = os.path.relpath(os.path.dirname(sys.argv[0]), os.environ['srctree']) + # Bring in the patman and dtoc libraries (but don't override the first path # in PYTHONPATH) our_path = os.path.dirname(os.path.realpath(__file__))Do we need some wrapper around this so it doesn't blow up on older than Python 3.8?
Quoted 4 lines
Quoted 1 line
Why does it blow? Some global variables which won't be used by older versions.
Does it? I don't know, I wasn't clear enough, sorry. What happens on an older python here? Silent ignore is fine.
Usually that's the idea that new features are hardly tried to be backward compatible (yes, I know that the history of Python had a lot of counter examples, but still). In any case, that one was never used before.
You may try yourself, btw:
sys.foobar = "blablabla"
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 23 lines · Andy Shevchenko
Quoted 17 lines · Tom Rini
Quoted 16 lines · Andy Shevchenko
Quoted 14 lines · Tom Rini
tools/binman/main.py import sys · line 28
Quoted 10 lines · Andy Shevchenko
tools/binman/main.py +7
-0+# +# Do not pollute source tree with cache files: +# https://stackoverflow.com/a/60024195/2511795 +# https://bugs.python.org/issue33499 +# +sys.pycache_prefix = os.path.relpath(os.path.dirname(sys.argv[0]), os.environ['srctree']) + # Bring in the patman and dtoc libraries (but don't override the first path # in PYTHONPATH) our_path = os.path.dirname(os.path.realpath(__file__))Do we need some wrapper around this so it doesn't blow up on older than Python 3.8?
Quoted 4 lines
Quoted 1 line
Why does it blow? Some global variables which won't be used by older versions.
Does it? I don't know, I wasn't clear enough, sorry. What happens on an older python here? Silent ignore is fine.
Quoted 8 lines
Usually that's the idea that new features are hardly tried to be backward compatible (yes, I know that the history of Python had a lot of counter examples, but still). In any case, that one was never used before.
You may try yourself, btw:
sys.foobar = "blablabla"
Ah ok, thanks!
Signature · 1 line
Tom