Skip to content

Commit 8b723bf

Browse files
committed
sets the windows build environment globally
1 parent 2e86c94 commit 8b723bf

File tree

3 files changed

+46
-19
lines changed

3 files changed

+46
-19
lines changed

builder/__init__.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,43 @@
44
import threading
55
import random
66

7+
_windows_env = None
8+
9+
def setup_windows_build():
10+
11+
global _windows_env
12+
13+
if _windows_env is None:
14+
import pyMSVC
15+
16+
env = pyMSVC.setup_environment()
17+
print(env)
18+
19+
for key in os.environ.keys():
20+
if 'COMNTOOLS' in key:
21+
version = key.replace('COMNTOOLS', '').replace('VS', '')
22+
break
23+
else:
24+
print(os.environ)
25+
raise RuntimeError('unable to locate common tools version')
26+
27+
version = 'v' + version
28+
29+
msbuild_path = env.visual_c.msbuild_path.lower()
30+
msbuild_path = msbuild_path.split('msbuild', 1)[0][:-1]
31+
32+
VCTargetsPath = os.path.join(
33+
msbuild_path,
34+
'Msbuild',
35+
'Microsoft',
36+
'VC',
37+
version
38+
)
39+
os.environ['VCTargetsPath'] = VCTargetsPath + '\\'
40+
41+
_windows_env = env
42+
43+
return _windows_env
744

845
def update_mphalport(target):
946
if target == 'esp8266':

builder/windows.py

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from . import spawn
55
from . import generate_manifest
66
from . import update_mphalport
7+
from . import setup_windows_build
78

89

910
mpy_cross_cmd = []
@@ -53,26 +54,8 @@ def build_commands(_, extra_args, script_dir, lv_cflags, board):
5354
LV_CFLAGS = lv_cflags
5455

5556
if sys.platform.startswith('win'):
56-
import pyMSVC
57+
env = setup_windows_build()
5758

58-
env = pyMSVC.setup_environment()
59-
print(env)
60-
61-
for key in os.environ.keys():
62-
if 'COMNTOOLS' in key:
63-
version = key.replace('COMNTOOLS', '').replace('VS', '')
64-
break
65-
else:
66-
print(os.environ)
67-
raise RuntimeError('unable to locate common tools version')
68-
69-
version = 'v' + version
70-
71-
msbuild_path = env.visual_c.msbuild_path.lower()
72-
msbuild_path = msbuild_path.split('msbuild', 1)[0][:-1]
73-
74-
VCTargetsPath = os.path.join(msbuild_path, 'Msbuild', 'Microsoft', 'VC', version)
75-
os.environ['VCTargetsPath'] = VCTargetsPath + '\\'
7659
mpy_cross_cmd.extend([
7760
f'"{env.visual_c.msbuild_path}"',
7861
'lib/micropython/mpy-cross/mpy-cross.vcxproj'

make.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,14 @@ def create_lvgl_header():
170170
f'#include "{SCRIPT_DIR}/ext_mod/lvgl_addons/include/color_addons.h"\n'
171171
)
172172

173+
173174
if __name__ == '__main__':
175+
176+
if sys.platform.startswith('win'):
177+
from builder import setup_windows_build
178+
179+
setup_windows_build()
180+
174181
if target.lower() == 'esp32':
175182
from builder import esp32 as mod
176183
elif target.lower() == 'unix':

0 commit comments

Comments
 (0)