Skip to content

Commit 9afe0bb

Browse files
committed
ci(stm32cube): add option to use local STM32Cube Fw
Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
1 parent a7f1b81 commit 9afe0bb

File tree

1 file changed

+57
-3
lines changed

1 file changed

+57
-3
lines changed

CI/update/stm32cube.py

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from packaging import version
1111
from pathlib import Path
1212
from urllib.parse import urljoin
13+
from xml.dom.minidom import parse
1314

1415
script_path = Path(__file__).parent.resolve()
1516
sys.path.append(str(script_path.parent))
@@ -29,6 +30,7 @@
2930
repo_generic_name = "STM32Cube"
3031
repo_core_name = "Arduino_Core_STM32"
3132
repo_local_path = home / "STM32Cube_repo"
33+
local_cube_path = Path("")
3234

3335
# From
3436
# Relative to repo path
@@ -276,6 +278,45 @@ def updateCoreRepo():
276278
execute_cmd(cmd, None)
277279

278280

281+
def checkSTLocal():
282+
global local_cube_path
283+
global stm32_list
284+
# Handle local STM32Cube
285+
local_cube_path = Path(upargs.local)
286+
if not local_cube_path.exists():
287+
print(f"Could not find local copy: {local_cube_path}!")
288+
exit(1)
289+
cube_release = "Unknown"
290+
# Define the serie based on package.xml
291+
package_file = local_cube_path / "package.xml"
292+
if package_file.is_file():
293+
xml_file = parse(str(package_file))
294+
PackDescription_item = xml_file.getElementsByTagName("PackDescription")
295+
for item in PackDescription_item:
296+
cube_release = item.attributes["Release"].value
297+
if item.hasAttribute("Patch"):
298+
cube_release = item.attributes["Patch"].value
299+
else:
300+
print(f"Could not find: {package_file}!")
301+
exit(1)
302+
# Process Cube release
303+
release_regex = r"FW.(.+).(\d+.\d+.\d+)$"
304+
release_match = re.match(release_regex, cube_release)
305+
if release_match:
306+
serie = release_match.group(1)
307+
cube_release = release_match.group(2)
308+
print(f"Local STM32Cube {serie} release {cube_release}\n")
309+
else:
310+
print(
311+
f"Unable to define local STM32Cube serie and version of {local_cube_path}!"
312+
)
313+
exit(1)
314+
cube_versions[serie] = cube_release
315+
# Manage only one STM32Cube
316+
stm32_list = [serie.upper()]
317+
checkVersion(serie, local_cube_path)
318+
319+
279320
def updateSTRepo():
280321
# Handle STM32Cube repo
281322
for serie in stm32_list:
@@ -572,8 +613,11 @@ def updateMDFile(md_file, serie, version):
572613

573614
def updateCore():
574615
for serie in stm32_list:
575-
cube_name = f"{repo_generic_name}{serie}"
576-
cube_path = repo_local_path / cube_name
616+
if upargs.local:
617+
cube_path = local_cube_path
618+
else:
619+
cube_name = f"{repo_generic_name}{serie}"
620+
cube_path = repo_local_path / cube_name
577621
core_path = repo_local_path / repo_core_name
578622
core_HAL_ver = core_HAL_versions[serie]
579623
cube_HAL_ver = cube_HAL_versions[serie]
@@ -678,6 +722,12 @@ def updateCore():
678722
upparser.add_argument(
679723
"-c", "--check", help="Check versions. Default all.", action="store_true"
680724
)
725+
upparser.add_argument(
726+
"-l",
727+
"--local",
728+
metavar="local",
729+
help="Use local copy of one STM32cube instead of GitHub",
730+
)
681731
group = upparser.add_mutually_exclusive_group()
682732
group.add_argument(
683733
"-s", "--serie", metavar="pattern", help="Pattern of the STM32 serie(s) to update"
@@ -686,6 +736,7 @@ def updateCore():
686736
"-a", "--add", metavar="name", help="STM32 serie name to add. Ex: 'F1'"
687737
)
688738

739+
689740
upargs = upparser.parse_args()
690741

691742

@@ -701,7 +752,10 @@ def main():
701752
else:
702753
print(f"{upargs.add} can't be added as it already exists!")
703754
exit(1)
704-
updateSTRepo()
755+
if upargs.local:
756+
checkSTLocal()
757+
else:
758+
updateSTRepo()
705759
if upargs.check:
706760
printVersion()
707761
else:

0 commit comments

Comments
 (0)