Skip to content

Commit

Permalink
Merge pull request #88 from xd-ydchen/main
Browse files Browse the repository at this point in the history
Feature: find_apps support customer app class (RDT-589)
  • Loading branch information
hfudev authored Nov 20, 2023
2 parents 270639c + 8f51545 commit 2c9b5f1
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 19 deletions.
23 changes: 20 additions & 3 deletions idf_build_apps/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -177,8 +174,28 @@ def __init__(
self._sdkconfig_files = None
self._sdkconfig_files_defined_target = None

# pass all parameters to initialize hook method
kwargs.update(
{
'work_dir': work_dir,
'build_dir': build_dir,
'build_log_filename': build_log_filename,
'size_json_filename': size_json_filename,
'sdkconfig_defaults_str': sdkconfig_defaults_str,
}
)
self._initialize_hook(**kwargs)
# create logger and process sdkconfig files
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,
Expand Down
22 changes: 9 additions & 13 deletions idf_build_apps/finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from .app import (
App,
CMakeApp,
MakeApp,
)
from .constants import (
BuildStatus,
Expand All @@ -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,
Expand Down Expand Up @@ -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 []
Expand Down Expand Up @@ -154,21 +146,25 @@ 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 = []
Expand All @@ -187,7 +183,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[:]
Expand Down
18 changes: 15 additions & 3 deletions idf_build_apps/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
)
from .app import (
App,
CMakeApp,
MakeApp,
)
from .build_job import (
BuildJob,
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -167,7 +179,7 @@ def find_apps(
_find_apps(
path,
target,
build_system,
app_cls,
recursive,
exclude_list or [],
work_dir=work_dir,
Expand Down

0 comments on commit 2c9b5f1

Please sign in to comment.