diff --git a/CHANGELOG.md b/CHANGELOG.md index c42cd6e..e3eb2e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ All notable changes to this project will be documented in this file. +## latest + +### Feat + +- Support customer App class. + ## v2.0.0b3 (2023-10-26) ### Fix diff --git a/idf_build_apps/app.py b/idf_build_apps/app.py index eb76e4c..a8206bd 100644 --- a/idf_build_apps/app.py +++ b/idf_build_apps/app.py @@ -158,9 +158,6 @@ def __init__( } ) super().__init__(**kwargs) - self._logger = LOGGER.getChild(str(hash(self))) - self._logger.addFilter(_AppBuildStageFilter(app=self)) - # These internal variables store the paths with environment variables and placeholders; # Public properties with similar names use the _expand method to get the actual paths. self._work_dir = work_dir or app_dir @@ -177,8 +174,18 @@ def __init__( self._sdkconfig_files = None self._sdkconfig_files_defined_target = None + # create logger and process sdkconfig files + self._initialize_hook(**kwargs) + self._logger = LOGGER.getChild(str(hash(self))) + self._logger.addFilter(_AppBuildStageFilter(app=self)) self._process_sdkconfig_files() + def _initialize_hook(self, **kwargs): + """ + Called after variables initialized, before actions such as creating logger. + """ + pass + def __str__(self): return '({}) App {}, target {}, sdkconfig {}, build in {}, {} in {}s'.format( self.build_system, diff --git a/idf_build_apps/finder.py b/idf_build_apps/finder.py index ee483c4..2c15c36 100644 --- a/idf_build_apps/finder.py +++ b/idf_build_apps/finder.py @@ -14,7 +14,6 @@ from .app import ( App, CMakeApp, - MakeApp, ) from .constants import ( BuildStatus, @@ -29,7 +28,7 @@ def _get_apps_from_path( path: str, target: str, - build_system: str = 'cmake', + app_cls: t.Type[App] = CMakeApp, work_dir: t.Optional[str] = None, build_dir: str = 'build', config_rules_str: t.Union[t.List[str], str, None] = None, @@ -64,13 +63,6 @@ def _validate_app(_app: App) -> bool: return True - if build_system == 'cmake': - app_cls = CMakeApp - elif build_system == 'make': - app_cls = MakeApp - else: - raise ValueError('Only Support "make" and "cmake"') - if not app_cls.is_app(path): LOGGER.debug('Skipping. %s is not an app', path) return [] @@ -154,21 +146,21 @@ def _validate_app(_app: App) -> bool: def _find_apps( path: str, target: str, - build_system: str = 'cmake', + app_cls: t.Type[App] = CMakeApp, recursive: bool = False, exclude_list: t.Optional[t.List[str]] = None, **kwargs, ) -> t.List[App]: exclude_list = exclude_list or [] LOGGER.debug( - 'Looking for %s apps in %s%s with target %s', build_system, path, ' recursively' if recursive else '', target + 'Looking for %s apps in %s%s with target %s', app_cls.__name__, path, ' recursively' if recursive else '', target ) if not recursive: if exclude_list: LOGGER.warning('--exclude option is ignored when used without --recursive') - return _get_apps_from_path(path, target, build_system, **kwargs) + return _get_apps_from_path(path, target, app_cls, **kwargs) # The remaining part is for recursive == True apps = [] @@ -187,7 +179,7 @@ def _find_apps( del dirs[:] continue - _found_apps = _get_apps_from_path(root, target, build_system, **kwargs) + _found_apps = _get_apps_from_path(root, target, app_cls, **kwargs) if _found_apps: # root has at least one app LOGGER.debug('=> Stop iteration sub dirs of %s since it has apps', root) del dirs[:] diff --git a/idf_build_apps/main.py b/idf_build_apps/main.py index fa3b9d8..b633049 100644 --- a/idf_build_apps/main.py +++ b/idf_build_apps/main.py @@ -18,6 +18,8 @@ ) from .app import ( App, + CMakeApp, + MakeApp, ) from .build_job import ( BuildJob, @@ -84,7 +86,7 @@ def find_apps( paths: t.Union[t.List[str], str], target: str, *, - build_system: str = 'cmake', + build_system: t.Union[t.Type[App], str] = CMakeApp, recursive: bool = False, exclude_list: t.Optional[t.List[str]] = None, work_dir: t.Optional[str] = None, @@ -109,7 +111,7 @@ def find_apps( :param paths: list of app directories (can be / usually will be a relative path) :param target: desired value of IDF_TARGET; apps incompatible with the given target are skipped. - :param build_system: name of the build system, now only support cmake + :param build_system: class of the build system, default CMakeApp :param recursive: Recursively search into the nested sub-folders if no app is found or not :param exclude_list: list of paths to be excluded from the recursive search :param work_dir: directory where the app should be copied before building. Support placeholders @@ -139,6 +141,16 @@ def find_apps( LOGGER.info('Overriding DEFAULT_BUILD_TARGETS to %s', default_build_targets) FolderRule.DEFAULT_BUILD_TARGETS = default_build_targets + if isinstance(build_system, str): + # backwards compatible + if build_system == 'cmake': + build_system = CMakeApp + elif build_system == 'make': + build_system = MakeApp + else: + raise ValueError('Only Support "make" and "cmake"') + app_cls = build_system + # always set the manifest rootpath at the very beginning of find_apps in case ESP-IDF switches the branch. Manifest.ROOTPATH = to_absolute_path(manifest_rootpath or os.curdir) Manifest.CHECK_MANIFEST_RULES = check_manifest_rules @@ -167,7 +179,7 @@ def find_apps( _find_apps( path, target, - build_system, + app_cls, recursive, exclude_list or [], work_dir=work_dir,