summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorCXSforHPU <[email protected]>2026-11-05 13:23:46 +0800
committerGitHub <[email protected]>2026-11-05 13:23:46 +0800
commit1a27d8b098b86b942a989a0ae8c2d09d37c680c8 (patch)
tree1f6b17cbd28e017c3a761097698cf0e7a3a2ca02 /tools
parentbd991539318e1e065cd830a209f15c731e64142d (diff)
[tools][mkdist] Fix repeated RTT_ROOT injection and read-only directory cleanup (#11874)
Make RTT_ROOT injection idempotent and handle read-only files when rebuilding distribution directories.
Diffstat (limited to 'tools')
-rw-r--r--tools/mkdist.py30
1 files changed, 20 insertions, 10 deletions
diff --git a/tools/mkdist.py b/tools/mkdist.py
index 7024d43d7e..4ff76584bb 100644
--- a/tools/mkdist.py
+++ b/tools/mkdist.py
@@ -46,16 +46,21 @@ def do_copy_file(src, dst):
shutil.copy2(src, dst)
def do_copy_folder(src_dir, dst_dir, ignore=None):
- import shutil
+ import shutil, stat
+
+ def _remove_readonly(func, path, excinfo):
+ os.chmod(path, stat.S_IWRITE)
+ func(path)
+
# check source directory
if not os.path.exists(src_dir):
return
try:
if os.path.exists(dst_dir):
- shutil.rmtree(dst_dir)
- except:
- print('Deletes folder: %s failed.' % dst_dir)
+ shutil.rmtree(dst_dir, onerror = _remove_readonly)
+ except Exception as e:
+ print('Deletes folder: %s failed: %s\n' % (dst_dir, e))
return
shutil.copytree(src_dir, dst_dir, ignore = ignore)
@@ -102,14 +107,19 @@ def bsp_copy_files(bsp_root, dist_dir):
ignore_patterns('build', '__pycache__', 'dist', '*.pyc', '*.old', '*.map', 'rtthread.bin', '.sconsign.dblite', '*.elf', '*.axf', 'cconfig.h'))
def bsp_update_sconstruct(dist_dir):
- with open(os.path.join(dist_dir, 'SConstruct'), 'r') as f:
+ sconstruct_path = os.path.join(dist_dir, 'SConstruct')
+ with open(sconstruct_path, 'r') as f:
data = f.readlines()
- with open(os.path.join(dist_dir, 'SConstruct'), 'w') as f:
+ # idempotency: skip when the injection is already effective. Match only the uncommented
+ # form, because some BSPs ship a commented-out copy of this block as source residue, and
+ # treating it as injected would leave the dist project RTT_ROOT pointing at the BSP dir.
+ if any(line.lstrip().startswith('if not os.getenv("RTT_ROOT"):') for line in data):
+ return
+ with open(sconstruct_path, 'w') as f:
for line in data:
- if line.find('RTT_ROOT') != -1:
- if line.find('sys.path') != -1:
- f.write('# set RTT_ROOT\n')
- f.write('if not os.getenv("RTT_ROOT"): \n RTT_ROOT="rt-thread"\n\n')
+ if line.find('RTT_ROOT') != -1 and line.find('sys.path') != -1:
+ f.write('# set RTT_ROOT\n')
+ f.write('if not os.getenv("RTT_ROOT"): \n RTT_ROOT="rt-thread"\n\n')
f.write(line)
def bsp_update_kconfig_testcases(dist_dir):