Skip to content

Commit

Permalink
feat: support build with profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
hfudev committed Jan 10, 2025
1 parent 92704cc commit 9addf0e
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 0 deletions.
2 changes: 2 additions & 0 deletions idf_ci/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__ = [
Expand All @@ -14,5 +15,6 @@
'PytestApp',
'PytestCase',
'TomlProfileManager',
'build',
'get_pytest_cases',
]
45 changes: 45 additions & 0 deletions idf_ci/cli/_options.py
Original file line number Diff line number Diff line change
@@ -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)
16 changes: 16 additions & 0 deletions idf_ci/cli/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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):
Expand Down
41 changes: 41 additions & 0 deletions idf_ci/scripts.py
Original file line number Diff line number Diff line change
@@ -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,
)

0 comments on commit 9addf0e

Please sign in to comment.