Skip to content

Commit

Permalink
Merge pull request #83 from espressif/fix/rename_params_correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
hfudev authored Oct 25, 2023
2 parents 3abe4f1 + 2cf5380 commit a19883e
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 31 deletions.
34 changes: 21 additions & 13 deletions idf_build_apps/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ class App(BaseModel):
_work_dir: t.Optional[str] = None
_build_dir: t.Optional[str] = None

_build_log_path: t.Optional[str] = None
_size_json_path: t.Optional[str] = None
_build_log_filename: t.Optional[str] = None
_size_json_filename: t.Optional[str] = None

# Build related
dry_run: bool = False
Expand All @@ -140,8 +140,8 @@ def __init__(
config_name: t.Optional[str] = None,
work_dir: t.Optional[str] = None,
build_dir: str = 'build',
build_log_path: t.Optional[str] = None,
size_json_path: t.Optional[str] = None,
build_log_filename: t.Optional[str] = None,
size_json_filename: t.Optional[str] = None,
check_warnings: bool = False,
preserve: bool = True,
sdkconfig_defaults_str: t.Optional[str] = None,
Expand All @@ -166,8 +166,8 @@ def __init__(
self._work_dir = work_dir or app_dir
self._build_dir = build_dir or 'build'

self._build_log_path = build_log_path
self._size_json_path = size_json_path
self._build_log_filename = build_log_filename
self._size_json_filename = size_json_filename

# should be built or not
self._checked_should_build = False
Expand Down Expand Up @@ -257,25 +257,33 @@ def build_path(self) -> str:
if os.path.isabs(self.build_dir):
return self.build_dir

return os.path.realpath(os.path.join(self.work_dir, self.build_dir))
return os.path.join(self.work_dir, self.build_dir)

@computed_field
@property
def build_log_filename(self) -> t.Optional[str]:
return self._expand(self._build_log_filename)

@property
def build_log_path(self) -> t.Optional[str]:
if self._build_log_path:
return os.path.join(self.build_path, self._expand(self._build_log_path))
if self.build_log_filename:
return os.path.join(self.build_path, self.build_log_filename)

return None

@computed_field
@property
def size_json_path(self) -> t.Optional[str]:
def size_json_filename(self) -> t.Optional[str]:
if self.target == 'linux':
# esp-idf-size does not support linux target
return None

if self._size_json_path:
return os.path.join(self.build_path, self._expand(self._size_json_path))
return self._expand(self._size_json_filename)

@property
def size_json_path(self) -> t.Optional[str]:
if self.size_json_filename:
return os.path.join(self.build_path, self.size_json_filename)

return None

Expand Down Expand Up @@ -443,7 +451,7 @@ def build(
shutil.rmtree(self.build_path)

if not self.dry_run:
os.makedirs(self.build_path)
os.makedirs(self.build_path, exist_ok=True)

sdkconfig_file = os.path.join(self.work_dir, 'sdkconfig')
if os.path.exists(sdkconfig_file):
Expand Down
12 changes: 6 additions & 6 deletions idf_build_apps/finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ def _get_apps_from_path(
work_dir: t.Optional[str] = None,
build_dir: str = 'build',
config_rules_str: t.Union[t.List[str], str, None] = None,
build_log_path: t.Optional[str] = None,
size_json_path: t.Optional[str] = None,
build_log_filename: t.Optional[str] = None,
size_json_filename: t.Optional[str] = None,
check_warnings: bool = False,
preserve: bool = True,
manifest_rootpath: t.Optional[str] = None,
Expand Down Expand Up @@ -114,8 +114,8 @@ def _validate_app(_app: App) -> bool:
config_name=config_name,
work_dir=work_dir,
build_dir=build_dir,
build_log_path=build_log_path,
size_json_path=size_json_path,
build_log_filename=build_log_filename,
size_json_filename=size_json_filename,
check_warnings=check_warnings,
preserve=preserve,
sdkconfig_defaults_str=sdkconfig_defaults_str,
Expand All @@ -135,8 +135,8 @@ def _validate_app(_app: App) -> bool:
config_name=default_config_name,
work_dir=work_dir,
build_dir=build_dir,
build_log_path=build_log_path,
size_json_path=size_json_path,
build_log_filename=build_log_filename,
size_json_filename=size_json_filename,
check_warnings=check_warnings,
preserve=preserve,
sdkconfig_defaults_str=sdkconfig_defaults_str,
Expand Down
20 changes: 10 additions & 10 deletions idf_build_apps/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ def find_apps(
work_dir: t.Optional[str] = None,
build_dir: str = 'build',
config_rules_str: t.Optional[t.Union[t.List[str], str]] = None,
build_log_path: t.Optional[str] = None,
size_json_path: t.Optional[str] = None,
build_log_filename: t.Optional[str] = None,
size_json_filename: t.Optional[str] = None,
check_warnings: bool = False,
preserve: bool = True,
manifest_rootpath: t.Optional[str] = None,
Expand All @@ -115,10 +115,10 @@ def find_apps(
:param work_dir: directory where the app should be copied before building. Support placeholders
:param build_dir: directory where the build will be done. Support placeholders.
:param config_rules_str: mapping of sdkconfig file name patterns to configuration names
:param build_log_path: path of the build log. Support placeholders.
The logs will go to stdout/stderr if not specified
:param size_json_path: path of the size.json file. Support placeholders.
Will not generate size file for each app if not specified
:param build_log_filename: filename of the build log. Will be placed under the app.build_path.
Support placeholders. The logs will go to stdout/stderr if not specified
:param size_json_filename: filename to collect the app's size information. Will be placed under the app.build_path.
Support placeholders. The app's size information won't be collected if not specified
:param check_warnings: Check for warnings in the build log or not
:param preserve: Preserve the built binaries or not
:param manifest_rootpath: The root path of the manifest files. Usually the folders specified in the manifest files
Expand Down Expand Up @@ -173,8 +173,8 @@ def find_apps(
work_dir=work_dir,
build_dir=build_dir or 'build',
config_rules_str=config_rules_str,
build_log_path=build_log_path,
size_json_path=size_json_path,
build_log_filename=build_log_filename,
size_json_filename=size_json_filename,
check_warnings=check_warnings,
preserve=preserve,
manifest_rootpath=manifest_rootpath,
Expand Down Expand Up @@ -705,8 +705,8 @@ def main():
work_dir=args.work_dir,
build_dir=args.build_dir or 'build',
config_rules_str=args.config,
build_log_path=args.build_log,
size_json_path=args.size_file,
build_log_filename=args.build_log,
size_json_filename=args.size_file,
check_warnings=args.check_warnings,
manifest_rootpath=args.manifest_rootpath,
manifest_files=args.manifest_file,
Expand Down
4 changes: 2 additions & 2 deletions tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ def test_serialization():


def test_deserialization(tmp_path):
a = CMakeApp('foo', 'bar')
b = MakeApp('foo', 'bar')
a = CMakeApp('foo', 'bar', size_json_filename='size.json')
b = MakeApp('foo', 'bar', build_log_filename='build.log')

assert a != b

Expand Down

0 comments on commit a19883e

Please sign in to comment.