Skip to content

Commit

Permalink
Merge branch 'dev' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
cwichel committed Apr 13, 2022
2 parents 12cff48 + 255bcef commit 180cd68
Show file tree
Hide file tree
Showing 51 changed files with 181 additions and 753 deletions.
1 change: 0 additions & 1 deletion docs/_source/embutils.repo.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ Submodules
:maxdepth: 4

embutils.repo.build
embutils.repo.version

Module contents
---------------
Expand Down
8 changes: 0 additions & 8 deletions docs/_source/embutils.repo.version.rst

This file was deleted.

1 change: 0 additions & 1 deletion docs/_source/embutils.utils.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ Submodules
embutils.utils.subprocess
embutils.utils.threading
embutils.utils.time
embutils.utils.version

Module contents
---------------
Expand Down
8 changes: 0 additions & 8 deletions docs/_source/embutils.utils.version.rst

This file was deleted.

4 changes: 2 additions & 2 deletions embutils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/python
# -*- coding: ascii -*-
# -*- coding: utf-8 -*-
"""
Embutils module.
Expand All @@ -9,4 +9,4 @@
:license: The MIT License (MIT)
"""
# -------------------------------------
__version__ = '0.8.4'
__version__ = '0.8.5'
3 changes: 1 addition & 2 deletions embutils/repo/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/python
# -*- coding: ascii -*-
# -*- coding: utf-8 -*-
"""
Embutils repository utilities.
Expand All @@ -10,4 +10,3 @@
"""
# -------------------------------------
from .build import *
from .version import *
87 changes: 64 additions & 23 deletions embutils/repo/build.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/python
# -*- coding: ascii -*-
# -*- coding: utf-8 -*-
"""
Project build utilities.
Expand All @@ -9,7 +9,12 @@
:license: The MIT License (MIT)
"""
# -------------------------------------
from ..utils.path import TPPath, Path

import shutil as su
import subprocess as sp

from ..utils.common import TPPath
from ..utils.path import Path
from ..utils.subprocess import execute


Expand All @@ -20,9 +25,27 @@


# -->> API <<--------------------------
def build_cubeide(name: str, config: str, project: TPPath, workspace: TPPath, indexer: bool = False,
log: TPPath = None, pipe: bool = False
) -> None:
def get_exec(name: str) -> Path:
"""
Get executable path.
:param str name: Executable name.
:return: Executable path.
:rtype: Path
:raises FileNotFoundError: Executable not found in PATH.
"""
find = su.which(name)
if find is None:
raise FileNotFoundError(f"Unable to find {name} executable on PATH!")
return Path(find)


def build_cubeide(
name: str, config: str, project: TPPath, workspace: TPPath, indexer: bool = False, clean: bool = True,
log: TPPath = None, pipe: bool = False, cwd: TPPath = None
) -> sp.CompletedProcess:
"""
Calls the STM32 CubeIDE headless builder on the specified project.
Expand All @@ -37,52 +60,70 @@ def build_cubeide(name: str, config: str, project: TPPath, workspace: TPPath, in
:param TPPath project: Path to CubeIDE project.
:param TPPath workspace: Path to CubeIDE workspace.
:param bool indexer: Runs the indexer on build.
:param bool clean: Performs a clean build.
:param TPPath log: Path to store the build logs.
:param bool pipe: Enable pipe output to terminal.
:param TPPath cwd: Execution CWD.
:return: Execution results.
:rtype: sp.CompletedProcess
"""
# Validate paths
workspace = Path.validate_dir(path=workspace)
project = Path.validate_dir(path=project, must_exist=True)
log = Path.validate_dir(path=log, none_ok=True)

# Build
idx = "-no-indexer" if not indexer else ""
cmd = f"stm32cubeidec --launcher.suppressErrors -nosplash {idx} " \
f"-application org.eclipse.cdt.managedbuilder.core.headlessbuild " \
f"-data '{workspace}' -cleanBuild '{name}/{config}' -import '{project}'"
res = execute(cmd=cmd, pipe=pipe, log=log)
wsp = Path.validate_dir(path=workspace)
prj = Path.validate_dir(path=project, must_exist=True)
log = Path.validate_dir(path=log, none_ok=True)
# Prepare
exe = get_exec(name="stm32cubeidec")
idx = "" if indexer else "-no-indexer"
bld = "-cleanBuild" if clean else "-build"
# Execute
cmd = f"{exe} --launcher.suppressErrors -nosplash -application org.eclipse.cdt.managedbuilder.core.headlessbuild " \
f"-data \"{wsp}\" -import \"{prj}\" {bld} \"{name}/{config}\" {idx}"
res = execute(cmd=cmd, pipe=pipe, log=log, cwd=cwd)
if not pipe and res.returncode:
print(f"Command:\n{cmd}\nFailed with error:\n{res.stderr}")
return res


def build_iar(config: str, project: TPPath,
log: TPPath = None, pipe: bool = False
) -> None:
def build_iar(
config: str, project: TPPath, clean: bool = True,
log: TPPath = None, pipe: bool = False, cwd: TPPath = None
) -> sp.CompletedProcess:
"""
Calls the IAR headless builder on the specified project.
:note:
- IarBuild executable must be in the PATH.
-
:param str config: Build configuration to be used. Ex: Debug, Release.
:param TPPath project: Path to EWARM project.
:param bool clean: Performs a clean build.
:param TPPath log: Path to store the build logs.
:param bool pipe: Enable pipe output to terminal.
:param TPPath cwd: Execution CWD.
:return: Execution results.
:rtype: sp.CompletedProcess
"""
# Validate paths
project = Path.validate_dir(path=project, must_exist=True)
prj = Path.validate_file(path=project, must_exist=True)
log = Path.validate_dir(path=log, none_ok=True)

# Build
cmd = f'IarBuild "{project}" -build "{config}"'
res = execute(cmd=cmd, pipe=pipe, log=log)
# Prepare
bld = "-build" if clean else "-make"
# Execute
exe = get_exec(name="IarBuild")
cmd = f"{exe} \"{prj}\" {bld} \"{config}\""
res = execute(cmd=cmd, pipe=pipe, log=log, cwd=cwd)
if not pipe and res.returncode:
print(f"Command:\n{cmd}\nFailed with error:\n{res.stderr}")
return res


# -->> Export <<-----------------------
__all__ = [
"get_exec",
"build_cubeide",
"build_iar",
]
Loading

0 comments on commit 180cd68

Please sign in to comment.