1
1
import os
2
2
import sys
3
3
from argparse import ArgumentParser
4
- from . import spawn as _spawn
4
+ from . import spawn
5
5
from . import generate_manifest
6
6
from . import update_mphalport
7
7
8
8
9
- spawn = _spawn
10
-
11
-
12
- install_ps_script = '''\
13
- build\\ esp-idf-tools-setup-offline-5.0.4.exe /VERYSILENT /SUPPRESSMSGBOXES /SP- /NOCANCEL /IDFVERSION=5.0.4 /IDFDIR=C:\\ esp-idf
14
- $InstallerProcess = Get-Process esp-idf-tools-setup
15
- Wait-Process -Id $InstallerProcess.id
16
- '''
17
-
18
- idf_env_bat_script = '''
19
- @echo off
20
-
21
- set "IDF_PATH=C:\\ esp-idf\\ frameworks\\ esp-idf-v5.0.4"
22
- set "IDF_TOOLS_PATH=C:\\ esp-idf\\ frameworks\\ esp-idf-v5.0.4\\ tools"
23
- set "PATH=%IDF_TOOLS_PATH%;%PATH%"
24
- idf-env config get --property python --idf-path %IDF_PATH%\\ > build\\ idf-python-path.txt
25
- set /P "IDF_PYTHON=< build\\ idf-python-path.txt"
26
- idf-env config get --property gitPath > build\\ idf-git-path.txt
27
- set /P "IDF_GIT=< build\\ idf-git-path.txt"
28
- set "PREFIX=%IDF_PYTHON% %IDF_PATH%"
29
- DOSKEY idf.py=%PREFIX%\\ tools\\ idf.py $*
30
- DOSKEY esptool.py=%PREFIX%\\ components\\ esptool_py\\ esptool\\ esptool.py $*
31
- DOSKEY espefuse.py=%PREFIX%\\ components\\ esptool_py\\ esptool\\ espefuse.py $*
32
- DOSKEY espsecure.py=%PREFIX%\\ components\\ esptool_py\\ esptool\\ espsecure.py $*
33
- DOSKEY otatool.py=%PREFIX%\\ components\\ app_update\\ otatool.py $*
34
- DOSKEY parttool.py=%PREFIX%\\ components\\ partition_table\\ parttool.py $*
35
- set PYTHONPATH=
36
- set PYTHONHOME=
37
- set PYTHONNOUSERSITE=True
38
- set "IDF_PYTHON_DIR=%IDF_PYTHON%"
39
- set "IDF_GIT_DIR=%IDF_GIT%"
40
- set "PATH=%IDF_PYTHON_DIR%;%IDF_GIT_DIR%;%PATH%"'
41
- %IDF_PATH%\\ export.bat'
42
- '''
43
-
44
-
45
- def get_idf_build_environment ():
46
- global spawn
47
-
48
- if sys .platform .startswith ('win' ):
49
-
50
- if not os .path .exists ('build' ):
51
- os .mkdir ('build' )
52
-
53
- import requests
54
-
55
- print ('downloading esp-idf toolkit for windows' )
56
-
57
- url = 'https://dl.espressif.com/dl/idf-installer/esp-idf-tools-setup-offline-5.0.4.exe'
58
-
59
- response = requests .get (url , stream = True )
60
- with open ("build/esp-idf-tools-setup-offline-5.0.4.exe" , mode = "wb" ) as file :
61
- for chunk in response .iter_content (chunk_size = 10 * 1024 ):
62
- file .write (chunk )
63
-
64
- with open ('build/install_esp-idf.ps1' , 'w' ) as file :
65
- file .write (install_ps_script )
66
-
67
- with open ('build/setup_environment.bat' , 'w' ) as file :
68
- file .write (idf_env_bat_script )
69
-
70
- cmd_ = ['C:\\ Windows\\ System32\\ WindowsPowerShell\\ v1.0\\ powershell.exe -ExecutionPolicy Bypass -NonInteractive -File "build\\ install_esp-idf.ps1"' ]
71
- result , _ = spawn (cmd_ )
72
- if result != 0 :
73
- sys .exit (result )
74
-
75
- old_spawn = spawn
76
-
77
- def _new_spawn (cmds , * args , ** kwargs ):
78
- framework_cmds = [
79
- ['build\\ setup_environment.bat' ]
80
- ]
81
-
82
- if isinstance (cmds [0 ], str ):
83
- cmds = [cmds [:]]
84
-
85
- framework_cmds .extend (cmds )
86
-
87
- return old_spawn (framework_cmds , * args , ** kwargs )
88
-
89
- spawn = _new_spawn
90
-
91
-
92
9
def get_partition_file_name (otp ):
93
10
if 'Running cmake in directory ' in otp :
94
11
build_path = otp .split ('Running cmake in directory ' , 1 )[- 1 ]
@@ -351,13 +268,18 @@ def build_commands(_, extra_args, __, lv_cflags, ___):
351
268
352
269
def get_idf_version ():
353
270
if 'ESP_IDF_VERSION' in os .environ :
354
- exit_code , data = spawn (['python3' , 'idf.py' , '--version' ], out_to_screen = False )
271
+ exit_code , data = spawn (
272
+ ['python3' , 'idf.py' , '--version' ],
273
+ out_to_screen = False
274
+ )
355
275
version = data .split ('v' )[- 1 ].split ('-' )[0 ]
356
276
if version :
357
277
return version
358
278
359
279
360
- def build_manifest (target , script_dir , lvgl_api , displays , indevs , frozen_manifest ):
280
+ def build_manifest (
281
+ target , script_dir , lvgl_api , displays , indevs , frozen_manifest
282
+ ):
361
283
update_mphalport (target )
362
284
363
285
with open (f'lib/micropython/ports/esp32/boards/sdkconfig.base' , 'r' ) as f :
@@ -374,7 +296,10 @@ def build_manifest(target, script_dir, lvgl_api, displays, indevs, frozen_manife
374
296
375
297
manifest_path = 'lib/micropython/ports/esp32/boards/manifest.py'
376
298
377
- generate_manifest (script_dir , lvgl_api , manifest_path , displays , indevs , frozen_manifest )
299
+ generate_manifest (
300
+ script_dir , lvgl_api , manifest_path ,
301
+ displays , indevs , frozen_manifest
302
+ )
378
303
379
304
380
305
def clean ():
@@ -400,13 +325,19 @@ def setup_idf_environ():
400
325
401
326
if os .path .exists (os .path .join (idf_path , 'export.sh' )):
402
327
403
- # this removes any IDF environment variable that may exist if the user
404
- # has the ESP-IDF installed
405
- env = {k : v for k , v in os .environ .items () if not k .startswith ('IDF' )}
328
+ # this removes any IDF environment variable that may
329
+ # exist if the user has the ESP-IDF installed
330
+ env = {
331
+ k : v for k , v in os .environ .items () if not k .startswith ('IDF' )
332
+ }
406
333
py_path = os .path .split (sys .executable )[0 ]
407
334
idf_path = os .path .abspath (idf_path )
408
335
idf_tools_path = os .path .join (idf_path , 'tools' )
409
- env ['PATH' ] = py_path + os .pathsep + os .pathsep + idf_tools_path + os .pathsep + env .get ('PATH' , '' )
336
+ env ['PATH' ] = (
337
+ py_path + os .pathsep +
338
+ os .pathsep + idf_tools_path +
339
+ os .pathsep + env .get ('PATH' , '' )
340
+ )
410
341
env ['IDF_PATH' ] = idf_path
411
342
412
343
cmds = [
@@ -419,12 +350,15 @@ def setup_idf_environ():
419
350
if 'GITHUB_RUN_ID' in env :
420
351
if sys .platform .startswith ('win' ):
421
352
env_cmds = [
422
- ['echo' , f"{ py_path } " , '|' , 'Out-File' , '-Append' ,
423
- '-FilePath' , '$env:GITHUB_PATH' , '-Encoding' , 'utf8' ],
424
- ['echo' , f"{ idf_path } " , '|' , 'Out-File' , '-Append' ,
425
- '-FilePath' , '$env:GITHUB_PATH' , '-Encoding' , 'utf8' ],
426
- ['echo' , f"{ idf_tools_path } " , '|' , 'Out-File' , '-Append' ,
427
- '-FilePath' , '$env:GITHUB_PATH' , '-Encoding' , 'utf8' ]
353
+ ['echo' , f"{ py_path } " , '|' , 'Out-File' ,
354
+ '-Append' , '-FilePath' , '$env:GITHUB_PATH' ,
355
+ '-Encoding' , 'utf8' ],
356
+ ['echo' , f"{ idf_path } " , '|' , 'Out-File' ,
357
+ '-Append' , '-FilePath' , '$env:GITHUB_PATH' ,
358
+ '-Encoding' , 'utf8' ],
359
+ ['echo' , f"{ idf_tools_path } " , '|' , 'Out-File' ,
360
+ '-Append' , '-FilePath' , '$env:GITHUB_PATH' ,
361
+ '-Encoding' , 'utf8' ]
428
362
]
429
363
else :
430
364
env_cmds = [
@@ -485,21 +419,24 @@ def submodules():
485
419
cmds = [
486
420
[f'export "IDF_PATH={ os .path .abspath (idf_path )} "' ],
487
421
['cd' , idf_path ],
488
- ['git' , 'submodule' , 'update' , '--init' ,
489
- 'components/bt/host/nimble/nimble' ,
490
- 'components/esp_wifi' ,
491
- 'components/esptool_py/esptool' ,
492
- 'components/lwip/lwip' ,
493
- 'components/mbedtls/mbedtls' ,
494
- 'components/bt/controller/lib_esp32' ,
495
- 'components/bt/controller/lib_esp32c3_family'
496
- ], ['./install.sh' , 'all' ]]
422
+ [
423
+ 'git' , 'submodule' , 'update' , '--init' ,
424
+ 'components/bt/host/nimble/nimble' ,
425
+ 'components/esp_wifi' ,
426
+ 'components/esptool_py/esptool' ,
427
+ 'components/lwip/lwip' ,
428
+ 'components/mbedtls/mbedtls' ,
429
+ 'components/bt/controller/lib_esp32' ,
430
+ 'components/bt/controller/lib_esp32c3_family'
431
+ ], ['./install.sh' , 'all' ]]
497
432
498
433
print ('setting up ESP-IDF v5.0.4' )
499
434
print ('this might take a bit...' )
500
435
print ()
501
436
502
- env = {k : v for k , v in os .environ .items () if not k .startswith ('IDF' )}
437
+ env = {
438
+ k : v for k , v in os .environ .items () if not k .startswith ('IDF' )
439
+ }
503
440
env ['IDF_PATH' ] = os .path .abspath (idf_path )
504
441
505
442
result , _ = spawn (cmds , env = env )
@@ -519,9 +456,7 @@ def submodules():
519
456
submodules_cmd
520
457
]
521
458
else :
522
- get_idf_build_environment ()
523
- cmds = submodules_cmd
524
- env = None
459
+ raise RuntimeError ('compiling on windows is not supported at this time' )
525
460
526
461
return_code , _ = spawn (cmds , env = env )
527
462
if return_code != 0 :
@@ -587,7 +522,11 @@ def compile(): # NOQA
587
522
588
523
base_config = '\n ' .join (base_config )
589
524
590
- with open ('lib/micropython/ports/esp32/boards/ESP32_GENERIC_S3/sdkconfig.board' , 'w' ) as f :
525
+ sdkconfig_board_path = (
526
+ 'lib/micropython/ports/esp32/'
527
+ 'boards/ESP32_GENERIC_S3/sdkconfig.board'
528
+ )
529
+ with open (sdkconfig_board_path , 'w' ) as f :
591
530
f .write (base_config + '\n ' )
592
531
593
532
if board in ('ESP32_GENERIC_S2' , 'ESP32_GENERIC_S3' ):
@@ -597,7 +536,10 @@ def compile(): # NOQA
597
536
with open (mphalport_path , 'rb' ) as f :
598
537
data = f .read ().decode ('utf-8' )
599
538
600
- data = data .replace ('#elif CONFIG_USB_OTG_SUPPORTED' , '#elif MP_USB_OTG' )
539
+ data = data .replace (
540
+ '#elif CONFIG_USB_OTG_SUPPORTED' ,
541
+ '#elif MP_USB_OTG'
542
+ )
601
543
602
544
with open (mphalport_path , 'wb' ) as f :
603
545
f .write (data .encode ('utf-8' ))
@@ -615,7 +557,10 @@ def compile(): # NOQA
615
557
with open (main_path , 'wb' ) as f :
616
558
f .write (data .encode ('utf-8' ))
617
559
618
- mpconfigboard_path = f'lib/micropython/ports/esp32/boards/{ board } /mpconfigboard.h'
560
+ mpconfigboard_path = (
561
+ f'lib/micropython/ports/esp32/boards/{ board } /mpconfigboard.h'
562
+ )
563
+
619
564
with open (mpconfigboard_path , 'rb' ) as f :
620
565
data = f .read ().decode ('utf-8' )
621
566
@@ -768,7 +713,10 @@ def compile(): # NOQA
768
713
769
714
esp_tool_path , output = output .split ('esptool.py ' , 1 )
770
715
esp_tool_path += 'esptool.py'
771
- esp_tool_path = esp_tool_path .replace ('../../../' , os .getcwd () + '/lib/' )
716
+ esp_tool_path = esp_tool_path .replace (
717
+ '../../../' ,
718
+ os .getcwd () + '/lib/'
719
+ )
772
720
773
721
out_cmd = []
774
722
@@ -830,9 +778,6 @@ def compile(): # NOQA
830
778
print (
831
779
python_path , esp_tool_path , '-p (PORT) -b 460800 erase_flash'
832
780
)
833
- # print()
834
- # print(python_path, esp_tool_path, out_cmd.replace('-b 460800', '-b 921600'))
835
- # print()
836
781
837
782
cmd = f'{ python_path } { esp_tool_path } { out_cmd } '
838
783
cmd = cmd .split ('write_flash' , 1 )[0 ]
0 commit comments