Skip to content

Commit eeebc61

Browse files
committed
fix: add disabled apps to junit with --include-all-apps flag
1 parent b8463f4 commit eeebc61

File tree

4 files changed

+91
-7
lines changed

4 files changed

+91
-7
lines changed

idf_build_apps/app.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,9 @@ def build(
511511
BuildStatus.UNKNOWN,
512512
BuildStatus.SHOULD_BE_BUILT,
513513
):
514-
self.build_comment = f'Build {self.build_status.value}. Skipping...'
514+
if not self.build_comment:
515+
self.build_comment = f'Build {self.build_status.value}. Skipping...'
516+
515517
return
516518

517519
# real build starts here

idf_build_apps/main.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
BuildArguments,
2323
DumpManifestShaArguments,
2424
FindArguments,
25+
FindBuildArguments,
2526
add_args_to_parser,
2627
apply_config_file,
2728
)
@@ -386,23 +387,32 @@ def main():
386387
sys.exit(0)
387388

388389
kwargs = vars(args)
390+
kwargs_without_none = drop_none_kwargs(kwargs)
389391
action = kwargs.pop('action')
390392
config_file = kwargs.pop('config_file')
391393
if config_file:
392394
apply_config_file(config_file)
393395

394396
if action == 'dump-manifest-sha':
395-
arguments = DumpManifestShaArguments(**drop_none_kwargs(kwargs))
397+
arguments = DumpManifestShaArguments(**kwargs_without_none)
396398
Manifest.from_files(arguments.manifest_files).dump_sha_values(arguments.output)
397399
sys.exit(0)
398-
elif action == 'find':
399-
arguments = FindArguments(**drop_none_kwargs(kwargs))
400+
401+
if action == 'find':
402+
arguments = FindArguments(**kwargs_without_none)
403+
find_arguments = arguments
400404
else:
401-
arguments = BuildArguments(**drop_none_kwargs(kwargs))
405+
arguments = BuildArguments(**kwargs_without_none)
406+
407+
# Because build needs to find apps, we need to create find_arguments here
408+
find_arguments = FindArguments(
409+
**{k: v for k, v in kwargs_without_none.items() if k in FindBuildArguments.model_fields}
410+
)
402411

403412
# real call starts here
404413
# build also needs to find first
405-
apps = find_apps(args.paths, args.target, find_arguments=arguments)
414+
apps = find_apps(args.paths, args.target, find_arguments=find_arguments)
415+
406416
if isinstance(arguments, FindArguments): # find only
407417
if arguments.output:
408418
os.makedirs(os.path.dirname(os.path.realpath(arguments.output)), exist_ok=True)
@@ -444,6 +454,12 @@ def main():
444454
for app in failed_apps:
445455
print(f' {app}')
446456

457+
disabled_apps = [app for app in apps if app.build_status == BuildStatus.DISABLED]
458+
if disabled_apps:
459+
print('Disabled the following apps:')
460+
for app in disabled_apps:
461+
print(f' {app}')
462+
447463
if ret_code != 0:
448464
sys.exit(ret_code)
449465

tests/test_cmd.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@
33
import os
44
import sys
55
from pathlib import Path
6+
from textwrap import dedent
7+
from xml.etree import ElementTree
68

79
import pytest
10+
from conftest import create_project
811

12+
from idf_build_apps.constants import SUPPORTED_TARGETS
913
from idf_build_apps.main import main
1014
from idf_build_apps.utils import InvalidCommand
1115

@@ -95,3 +99,65 @@ def test_manifest_patterns(tmp_path, monkeypatch, capsys):
9599
assert f'Loading manifest file {os.path.join(tmp_path, "manifest.yml")}' in err
96100
assert f'"{os.path.join(tmp_path, "foo")}" does not exist' in err
97101
assert f'"{os.path.join(tmp_path, "bar")}" does not exist' in err
102+
103+
104+
def test_build_include_all_apps(tmp_path, monkeypatch, capsys):
105+
create_project('foo', tmp_path)
106+
107+
manifest = tmp_path / 'manifest.yml'
108+
manifest.write_text(
109+
dedent("""\
110+
foo:
111+
disable:
112+
- if: IDF_TARGET == "esp32"
113+
""")
114+
)
115+
116+
with monkeypatch.context() as m:
117+
m.setattr(
118+
sys,
119+
'argv',
120+
[
121+
'idf-build-apps',
122+
'build',
123+
'--paths',
124+
'foo',
125+
'--manifest-files',
126+
str(manifest),
127+
'--check-manifest-rules',
128+
'--include-all-apps',
129+
'--junitxml',
130+
str(tmp_path / 'junit.xml'),
131+
'--dry-run',
132+
],
133+
)
134+
main()
135+
136+
out, err = capsys.readouterr()
137+
assert err == ''
138+
assert 'Disabled the following apps' in out
139+
assert out.count('Disabled by manifest rule: IDF_TARGET == "esp32"') == 1
140+
141+
with open(str(tmp_path / 'junit.xml')) as f:
142+
xml = ElementTree.fromstring(f.read())
143+
144+
test_suite = xml.findall('testsuite')[0]
145+
assert test_suite.attrib['tests'] == '0'
146+
assert test_suite.attrib['failures'] == '0'
147+
assert test_suite.attrib['errors'] == '0'
148+
assert test_suite.attrib['skipped'] == str(len(SUPPORTED_TARGETS))
149+
150+
disabled_testcases = 0
151+
152+
for case in test_suite.findall('testcase'):
153+
if case.get('name') != 'foo/build':
154+
continue
155+
156+
skipped = case.find('skipped')
157+
if skipped is None:
158+
continue
159+
160+
if skipped.get('message') == 'Disabled by manifest rule: IDF_TARGET == "esp32"':
161+
disabled_testcases += 1
162+
163+
assert disabled_testcases == 1

tests/test_finder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def test_include_disabled_apps(self, tmp_path):
138138
for app in apps:
139139
assert app.build_status == BuildStatus.DISABLED
140140
app.build()
141-
assert app.build_comment == 'Build disabled. Skipping...'
141+
assert app.build_comment.startswith('Not enabled by manifest rules:')
142142

143143

144144
class TestFindWithModifiedFilesComponents:

0 commit comments

Comments
 (0)