Skip to content

Commit

Permalink
feat: support --manifest-filepatterns
Browse files Browse the repository at this point in the history
  • Loading branch information
hfudev committed Oct 3, 2024
1 parent b8e493b commit eb879bb
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
21 changes: 21 additions & 0 deletions idf_build_apps/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import argparse
import enum
import glob
import inspect
import logging
import os
Expand Down Expand Up @@ -191,6 +192,15 @@ class DependencyDrivenBuildArguments(GlobalArguments):
validation_alias=AliasChoices('manifest_files', 'manifest_file'),
default=None,
)
manifest_filepatterns: t.Optional[t.List[str]] = field(
FieldMetadata(
validate_method=[ValidateMethod.TO_LIST],
nargs='+',
),
description='space-separated list of file patterns to search for the manifest files. '
'The matched files will be loaded as the manifest files.',
default=None,
)
manifest_rootpath: str = field(
None,
description='Root path to resolve the relative paths defined in the manifest files. '
Expand Down Expand Up @@ -279,6 +289,17 @@ class DependencyDrivenBuildArguments(GlobalArguments):
def model_post_init(self, __context: Any) -> None:
super().model_post_init(__context)

if self.manifest_filepatterns:
matched_paths = set()
for pat in [to_absolute_path(p, self.manifest_rootpath) for p in self.manifest_filepatterns]:
matched_paths.update(glob.glob(str(pat), recursive=True))

if matched_paths:
if self.manifest_files:
self.manifest_files.extend(matched_paths)
else:
self.manifest_files = list(matched_paths)

Manifest.CHECK_MANIFEST_RULES = self.check_manifest_rules
if self.manifest_files:
App.MANIFEST = Manifest.from_files(
Expand Down
30 changes: 29 additions & 1 deletion tests/test_cmd.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Apache-2.0

import os
import sys
from pathlib import Path

Expand Down Expand Up @@ -67,3 +67,31 @@ def test_manifest_dump_sha_values(
f'foo:{sha_of_enable_only_esp32}\n'
f'foobar:{sha_of_enable_esp32_or_esp32s2}\n'
)


def test_manifest_patterns(tmp_path, monkeypatch, capsys):
manifest = tmp_path / 'manifest.yml'
manifest.write_text(
"""foo:
enable:
- if: IDF_TARGET == "esp32"
bar:
enable:
- if: IDF_TARGET == "esp32"
"""
)

with pytest.raises(SystemExit) as e:
with monkeypatch.context() as m:
m.setattr(
sys,
'argv',
['idf-build-apps', 'find', '--manifest-filepatterns', '**.whatever', '**/manifest.yml', '-vv'],
)
main()
assert e.retcode == 0

_, err = capsys.readouterr()
assert f'Loading manifest file {os.path.join(tmp_path, "manifest.yml")}' in err
assert f'"{os.path.join(tmp_path, "foo")}" does not exist' in err
assert f'"{os.path.join(tmp_path, "bar")}" does not exist' in err

0 comments on commit eb879bb

Please sign in to comment.