3333repo_ble_name = "STM32duinoBLE"
3434repo_local_path = home / "STM32Cube_repo"
3535local_cube_path = Path ("" )
36+ core_path = script_path .parent .parent .resolve ()
3637
3738# From
3839# Relative to repo path
@@ -93,7 +94,7 @@ def checkConfig():
9394 global md_HAL_path
9495 global md_CMSIS_path
9596 global stm32_def
96-
97+ global core_path
9798 config_file_path = script_path / "update_config.json"
9899 if config_file_path .is_file ():
99100 try :
@@ -105,19 +106,14 @@ def checkConfig():
105106 defaultConfig (config_file_path , path_config )
106107 else :
107108 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
109112 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
112115 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
121117 except IOError :
122118 print (f"Failed to open { config_file } !" )
123119 else :
@@ -229,18 +225,16 @@ def createSystemFiles(serie):
229225
230226
231227def updateCoreRepo ():
232- # Handle core repo
233- repo_path = repo_local_path / repo_core_name
234228 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 )
237231 # Get new tags from the remote
238232 git_cmds = [
239- ["git" , "-C" , repo_path , "fetch" ],
233+ ["git" , "-C" , core_path , "fetch" ],
240234 [
241235 "git" ,
242236 "-C" ,
243- repo_path ,
237+ core_path ,
244238 "checkout" ,
245239 "-B" ,
246240 bname ,
@@ -254,11 +248,30 @@ def updateCoreRepo():
254248 execute_cmd (cmd , None )
255249
256250
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+
257270def checkSTLocal ():
258271 global local_cube_path
259272 global stm32_list
260273 # Handle local STM32Cube
261- local_cube_path = Path (upargs .local )
274+ local_cube_path = Path (upargs .path ). resolve ( )
262275 if not local_cube_path .exists ():
263276 print (f"Could not find local copy: { local_cube_path } !" )
264277 exit (1 )
@@ -761,7 +774,7 @@ def updateBleReadme(filepath, version):
761774
762775
763776def updateBleLibrary ():
764- if upargs .local :
777+ if upargs .path :
765778 cube_path = local_cube_path
766779 else :
767780 cube_name = f"{ repo_generic_name } WB"
@@ -805,14 +818,13 @@ def updateBle():
805818
806819def updateOpenAmp ():
807820 print ("Updating OpenAmp Middleware" )
808- repo_path = repo_local_path / repo_core_name
809- if upargs .local :
821+ if upargs .path :
810822 cube_path = local_cube_path
811823 else :
812824 cube_name = f"{ repo_generic_name } MP1"
813825 cube_path = repo_local_path / cube_name
814826 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"
816828
817829 # First delete old HAL version
818830 deleteFolder (OpenAmp_core_path )
@@ -823,12 +835,11 @@ def updateOpenAmp():
823835
824836def updateCore ():
825837 for serie in stm32_list :
826- if upargs .local :
838+ if upargs .path :
827839 cube_path = local_cube_path
828840 else :
829841 cube_name = f"{ repo_generic_name } { serie } "
830842 cube_path = repo_local_path / cube_name
831- core_path = repo_local_path / repo_core_name
832843 core_HAL_ver = core_HAL_versions [serie ]
833844 cube_HAL_ver = cube_HAL_versions [serie ]
834845 core_CMSIS_ver = core_CMSIS_versions [serie ]
@@ -972,11 +983,17 @@ def updateCore():
972983upparser .add_argument (
973984 "-c" , "--check" , help = "Check versions. Default all." , action = "store_true"
974985)
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+ )
975992upparser .add_argument (
976993 "-l" ,
977994 "--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. " ,
980997)
981998group = upparser .add_mutually_exclusive_group ()
982999group .add_argument (
@@ -994,15 +1011,18 @@ def main():
9941011 global stm32_list
9951012 # check config have to be done first
9961013 checkConfig ()
997- updateCoreRepo ()
9981014 stm32_list = genSTM32List (hal_dest_path , upargs .serie )
1015+ if not upargs .local :
1016+ updateCoreRepo ()
1017+ else :
1018+ checkCoreRepo ()
9991019 if upargs .add :
10001020 if upargs .add .upper () not in stm32_list :
10011021 stm32_list = [upargs .add .upper ()]
10021022 else :
10031023 print (f"{ upargs .add } can't be added as it already exists!" )
10041024 exit (1 )
1005- if upargs .local :
1025+ if upargs .path :
10061026 checkSTLocal ()
10071027 else :
10081028 updateSTRepo ()
0 commit comments