33
33
repo_ble_name = "STM32duinoBLE"
34
34
repo_local_path = home / "STM32Cube_repo"
35
35
local_cube_path = Path ("" )
36
+ core_path = script_path .parent .parent .resolve ()
36
37
37
38
# From
38
39
# Relative to repo path
@@ -93,7 +94,7 @@ def checkConfig():
93
94
global md_HAL_path
94
95
global md_CMSIS_path
95
96
global stm32_def
96
-
97
+ global core_path
97
98
config_file_path = script_path / "update_config.json"
98
99
if config_file_path .is_file ():
99
100
try :
@@ -105,19 +106,14 @@ def checkConfig():
105
106
defaultConfig (config_file_path , path_config )
106
107
else :
107
108
repo_local_path = Path (path_config ["REPO_LOCAL_PATH" ])
108
- hal_dest_path = repo_local_path / repo_core_name / hal_dest_path
109
+ if not upargs .local :
110
+ core_path = repo_local_path / repo_core_name
111
+ hal_dest_path = core_path / hal_dest_path
109
112
md_HAL_path = hal_dest_path / md_HAL_path
110
- cmsis_dest_path = repo_local_path / repo_core_name / cmsis_dest_path
111
- system_dest_path = repo_local_path / repo_core_name / system_dest_path
113
+ cmsis_dest_path = core_path / cmsis_dest_path
114
+ system_dest_path = core_path / system_dest_path
112
115
md_CMSIS_path = cmsis_dest_path / md_CMSIS_path
113
- stm32_def = (
114
- repo_local_path
115
- / repo_core_name
116
- / "libraries"
117
- / "SrcWrapper"
118
- / "inc"
119
- / stm32_def
120
- )
116
+ stm32_def = core_path / "libraries" / "SrcWrapper" / "inc" / stm32_def
121
117
except IOError :
122
118
print (f"Failed to open { config_file } !" )
123
119
else :
@@ -229,18 +225,16 @@ def createSystemFiles(serie):
229
225
230
226
231
227
def updateCoreRepo ():
232
- # Handle core repo
233
- repo_path = repo_local_path / repo_core_name
234
228
print (f"Updating { repo_core_name } ..." )
235
- if repo_path .exists ():
236
- rname , bname = getRepoBranchName (repo_path )
229
+ if core_path .exists ():
230
+ rname , bname = getRepoBranchName (core_path )
237
231
# Get new tags from the remote
238
232
git_cmds = [
239
- ["git" , "-C" , repo_path , "fetch" ],
233
+ ["git" , "-C" , core_path , "fetch" ],
240
234
[
241
235
"git" ,
242
236
"-C" ,
243
- repo_path ,
237
+ core_path ,
244
238
"checkout" ,
245
239
"-B" ,
246
240
bname ,
@@ -254,11 +248,30 @@ def updateCoreRepo():
254
248
execute_cmd (cmd , None )
255
249
256
250
251
+ def checkCoreRepo ():
252
+ # Check if the core repo exists
253
+ if not core_path .exists ():
254
+ print (f"Could not find core repo: { core_path } !" )
255
+ exit (1 )
256
+ # Check if the core repo is a git repository
257
+ if not (core_path / ".git" ).exists ():
258
+ print (f"{ core_path } is not a git repository!" )
259
+ exit (1 )
260
+ # Check if the core repo has no uncommitted changes
261
+ print (f"Checking { repo_core_name } ..." )
262
+ status = execute_cmd (["git" , "-C" , core_path , "status" ], None )
263
+ if "working tree clean" not in status :
264
+ print (f"{ repo_core_name } has modified or new files!" )
265
+ exit (1 )
266
+ status = execute_cmd (["git" , "-C" , core_path , "rev-parse" , "--abbrev-ref" , "HEAD" ], None )
267
+ print (f"Current branch: { status .strip ()} " )
268
+
269
+
257
270
def checkSTLocal ():
258
271
global local_cube_path
259
272
global stm32_list
260
273
# Handle local STM32Cube
261
- local_cube_path = Path (upargs .local )
274
+ local_cube_path = Path (upargs .path ). resolve ( )
262
275
if not local_cube_path .exists ():
263
276
print (f"Could not find local copy: { local_cube_path } !" )
264
277
exit (1 )
@@ -761,7 +774,7 @@ def updateBleReadme(filepath, version):
761
774
762
775
763
776
def updateBleLibrary ():
764
- if upargs .local :
777
+ if upargs .path :
765
778
cube_path = local_cube_path
766
779
else :
767
780
cube_name = f"{ repo_generic_name } WB"
@@ -805,14 +818,13 @@ def updateBle():
805
818
806
819
def updateOpenAmp ():
807
820
print ("Updating OpenAmp Middleware" )
808
- repo_path = repo_local_path / repo_core_name
809
- if upargs .local :
821
+ if upargs .path :
810
822
cube_path = local_cube_path
811
823
else :
812
824
cube_name = f"{ repo_generic_name } MP1"
813
825
cube_path = repo_local_path / cube_name
814
826
OpenAmp_cube_path = cube_path / "Middlewares" / "Third_Party" / "OpenAMP"
815
- OpenAmp_core_path = repo_path / "system" / "Middlewares" / "OpenAMP"
827
+ OpenAmp_core_path = core_path / "system" / "Middlewares" / "OpenAMP"
816
828
817
829
# First delete old HAL version
818
830
deleteFolder (OpenAmp_core_path )
@@ -823,12 +835,11 @@ def updateOpenAmp():
823
835
824
836
def updateCore ():
825
837
for serie in stm32_list :
826
- if upargs .local :
838
+ if upargs .path :
827
839
cube_path = local_cube_path
828
840
else :
829
841
cube_name = f"{ repo_generic_name } { serie } "
830
842
cube_path = repo_local_path / cube_name
831
- core_path = repo_local_path / repo_core_name
832
843
core_HAL_ver = core_HAL_versions [serie ]
833
844
cube_HAL_ver = cube_HAL_versions [serie ]
834
845
core_CMSIS_ver = core_CMSIS_versions [serie ]
@@ -972,11 +983,17 @@ def updateCore():
972
983
upparser .add_argument (
973
984
"-c" , "--check" , help = "Check versions. Default all." , action = "store_true"
974
985
)
986
+ upparser .add_argument (
987
+ "-p" ,
988
+ "--path" ,
989
+ metavar = "local cube" ,
990
+ help = "Path to a STM32cube directory to use instead of GitHub one." ,
991
+ )
975
992
upparser .add_argument (
976
993
"-l" ,
977
994
"--local" ,
978
- metavar = "local " ,
979
- help = "Use local copy of one STM32cube instead of GitHub " ,
995
+ action = "store_true " ,
996
+ help = "Do the update in the current STM32 core repo instead of a copy. " ,
980
997
)
981
998
group = upparser .add_mutually_exclusive_group ()
982
999
group .add_argument (
@@ -994,15 +1011,18 @@ def main():
994
1011
global stm32_list
995
1012
# check config have to be done first
996
1013
checkConfig ()
997
- updateCoreRepo ()
998
1014
stm32_list = genSTM32List (hal_dest_path , upargs .serie )
1015
+ if not upargs .local :
1016
+ updateCoreRepo ()
1017
+ else :
1018
+ checkCoreRepo ()
999
1019
if upargs .add :
1000
1020
if upargs .add .upper () not in stm32_list :
1001
1021
stm32_list = [upargs .add .upper ()]
1002
1022
else :
1003
1023
print (f"{ upargs .add } can't be added as it already exists!" )
1004
1024
exit (1 )
1005
- if upargs .local :
1025
+ if upargs .path :
1006
1026
checkSTLocal ()
1007
1027
else :
1008
1028
updateSTRepo ()
0 commit comments