Skip to content

Commit 1e31eb8

Browse files
committed
fixes repl for unix and macOS build
There was a change I had made that would not allow more advanced things like history to be available when using the repl. I have fixed this issue. I also started working on adding a roll back to restore all micropython code back to it's originals upon build failure and also when a build completes sucessfully. This allows for keeping micropython scrubbed of any changes in the event a user wants to compile for a different port. While I am not modifying anything outside of the the port directories at the moment the need might arrise at some point in time.
1 parent 93815a3 commit 1e31eb8

File tree

5 files changed

+434
-463
lines changed

5 files changed

+434
-463
lines changed

builder/__init__.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,85 @@
88
_windows_env = None
99

1010

11+
def scrub_build_folder():
12+
for f in os.listdir('build'):
13+
f = os.path.join('build', f)
14+
for pattern in ('.h', 'manifest.py', '.board'):
15+
if f.endswith(pattern):
16+
os.remove(f)
17+
18+
19+
def revert_files(port):
20+
if port in ('macOS', 'raspberry_pi'):
21+
revert_files('unix')
22+
23+
src_path = f'micropy_updates/originals/{port}'
24+
25+
if port in ('raspberry_pi', 'macOS'):
26+
port = 'unix'
27+
28+
dst_path = f'lib/micropython/ports/{port}'
29+
30+
if not os.path.exists(src_path) or not os.listdir(src_path):
31+
return
32+
33+
def iter_path(src_p, dst_p):
34+
for file in os.listdir(src_p):
35+
src_file = os.path.join(src_p, file)
36+
dst_file = os.path.join(dst_p, file)
37+
38+
if os.path.isdir(src_file):
39+
iter_path(src_file, dst_file)
40+
os.rmdir(src_file)
41+
else:
42+
read_file(src_file, dst_file)
43+
os.remove(src_file)
44+
45+
iter_path(src_path, dst_path)
46+
47+
48+
def copy_updated_files(port):
49+
50+
src_path = f'micropy_updates/{port}'
51+
originals_path = f'micropy_updates/originals/{port}'
52+
53+
if port in ('raspberry_pi', 'macOS'):
54+
port = 'unix'
55+
56+
dst_path = f'lib/micropython/ports/{port}'
57+
58+
for file in os.listdir(src_path):
59+
60+
src_file = os.path.join(dst_path, file)
61+
dst_file = os.path.join(originals_path, file)
62+
63+
read_file(src_file, dst_file)
64+
65+
src_file = os.path.join(src_path, file)
66+
dst_file = os.path.join(dst_path, file)
67+
68+
read_file(src_file, dst_file)
69+
70+
71+
def write_file(file, data):
72+
with open(file, 'wb') as f:
73+
f.write(data.encode('utf-8'))
74+
75+
76+
def read_file(file, save_file):
77+
with open(file, 'rb') as f1:
78+
data = f1.read()
79+
80+
save_path = os.path.split(save_file)[0]
81+
if not os.path.exists(save_path):
82+
os.makedirs(save_path)
83+
84+
with open(save_file, 'wb') as f2:
85+
f2.write(data)
86+
87+
return data.decode('utf-8')
88+
89+
1190
def setup_windows_build():
1291

1392
global _windows_env

0 commit comments

Comments
 (0)