aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>2021-12-06 14:44:12 +0300
committerSimon Glass <sjg@chromium.org>2021-12-17 09:44:59 -0700
commit022f6b0643ee7cf6f9474b768ba2aa802762980b (patch)
treea7111ff9c51c9d2d17db5bf06d677fc15711ff8a
parent6405ab7ad5898966136cf9044fef1bc0c4fe0ea9 (diff)
downloadu-boot-022f6b0643ee7cf6f9474b768ba2aa802762980b.zip
u-boot-022f6b0643ee7cf6f9474b768ba2aa802762980b.tar.gz
u-boot-022f6b0643ee7cf6f9474b768ba2aa802762980b.tar.bz2
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. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
-rwxr-xr-xtools/binman/main.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/tools/binman/main.py b/tools/binman/main.py
index 1a639f4..2fa55ff 100755
--- a/tools/binman/main.py
+++ b/tools/binman/main.py
@@ -16,9 +16,20 @@ import sys
import traceback
import unittest
+# Get the absolute path to this file at run-time
+our_path = os.path.dirname(os.path.realpath(__file__))
+our1_path = os.path.dirname(our_path)
+our2_path = os.path.dirname(our1_path)
+
+#
+# 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(our_path, os.environ.get('srctree', our2_path))
+
# 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__))
sys.path.insert(2, os.path.join(our_path, '..'))
from patman import test_util