diff --git a/idf_ci/__init__.py b/idf_ci/__init__.py index ad83d09..3d60167 100644 --- a/idf_ci/__init__.py +++ b/idf_ci/__init__.py @@ -5,6 +5,7 @@ from .idf_pytest.plugin import IdfPytestPlugin from .idf_pytest.scripts import get_pytest_cases from .profiles import IniProfileManager, TomlProfileManager +from .scripts import build from .settings import CiSettings __all__ = [ @@ -14,5 +15,6 @@ 'PytestApp', 'PytestCase', 'TomlProfileManager', + 'build', 'get_pytest_cases', ] diff --git a/idf_ci/cli/_options.py b/idf_ci/cli/_options.py new file mode 100644 index 0000000..a38912f --- /dev/null +++ b/idf_ci/cli/_options.py @@ -0,0 +1,45 @@ +# SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD +# SPDX-License-Identifier: Apache-2.0 + +import click + +_OPTION_PATHS_HELP = """ +List of directories to process. Support passing multiple times. + +\b +Example: + --paths component_1 --paths component_2 + -p component_1 -p component_2 +""" + + +def option_paths(func): + return click.option( + '--paths', + '-p', + multiple=True, + type=click.Path(dir_okay=True, file_okay=False, exists=True), + help=_OPTION_PATHS_HELP, + )(func) + + +_OPTION_PROFILES_HELP = """ +\b +List of profiles to apply. Could be "default" or file path to a custom profile. +Support passing multiple times. The later profiles will override the previous ones. +[default: default] + +\b +Example: + --profiles default --profiles custom.toml +""" + + +def option_profiles(func): + return click.option( + '--profiles', + multiple=True, + default=['default'], + show_default=False, + help=_OPTION_PROFILES_HELP, + )(func) diff --git a/idf_ci/cli/build.py b/idf_ci/cli/build.py index 8cb5cdf..694d98a 100644 --- a/idf_ci/cli/build.py +++ b/idf_ci/cli/build.py @@ -6,6 +6,10 @@ import click +from idf_ci import build as build_cmd + +from ._options import option_paths, option_profiles + @click.group() def build(): @@ -15,6 +19,18 @@ def build(): pass +@build.command() +@option_paths +@click.option('--target', '-t', default='all', help='Target to be built. Or "all" to build all targets.') +@option_profiles +def run(paths, target, profiles): + """ + Run build according to the given profiles + """ + click.echo(f'Building {target} with profiles {profiles} at {paths}') + build_cmd(paths, target, profiles=profiles) + + @build.command() @click.option('--path', default=os.getcwd(), help='Path to create the build profile') def init_profile(path: str): diff --git a/idf_ci/scripts.py b/idf_ci/scripts.py new file mode 100644 index 0000000..082e15f --- /dev/null +++ b/idf_ci/scripts.py @@ -0,0 +1,41 @@ +# SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD +# SPDX-License-Identifier: Apache-2.0 + +import os.path +import subprocess +import typing as t + +from ._compat import UNDEF, PathLike, Undefined +from .profiles import TomlProfileManager + + +def build( + paths: t.List[str], + target: str, + *, + profiles: t.List[PathLike] = UNDEF, # type: ignore +): + if isinstance(profiles, Undefined): + profiles = ['default'] + + profile_o = TomlProfileManager( + profiles=profiles, + default_profile_path=os.path.join(os.path.dirname(__file__), 'templates', 'default_build_profile.toml'), + ) + + print(profile_o.merged_profile_path) + + subprocess.run( + [ + 'idf-build-apps', + 'build', + '-p', + *paths, + '-t', + target, + '--config-file', + profile_o.merged_profile_path, + '-vvv', + ], + check=True, + )