Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions tools/mkdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -102,14 +107,17 @@ 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: if the marker is already present, do nothing on re-runs
if any(line.find('# set RTT_ROOT') != -1 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):
Expand Down
Loading