Skip to content
This repository was archived by the owner on Jul 16, 2025. It is now read-only.

Commit 5e6fee0

Browse files
feat: add xcode functionality (#537)
* first pass * fix: update tests * feat: allow for swift coverage * fix: rebase and tests
1 parent 3333bcb commit 5e6fee0

File tree

7 files changed

+44
-23
lines changed

7 files changed

+44
-23
lines changed

codecov_cli/commands/upload.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,10 @@ def _turn_env_vars_into_dict(ctx, params, value):
194194
"--gcov-executable",
195195
help="gcov executable to run. Defaults to 'gcov'",
196196
),
197+
click.option(
198+
"--swift-project",
199+
help="Specify the swift project",
200+
),
197201
]
198202

199203

@@ -238,6 +242,7 @@ def do_upload(
238242
pull_request_number: typing.Optional[str],
239243
report_type: str,
240244
slug: typing.Optional[str],
245+
swift_project: typing.Optional[str],
241246
token: typing.Optional[str],
242247
use_legacy_uploader: bool,
243248
):
@@ -286,6 +291,7 @@ def do_upload(
286291
pull_request_number=pull_request_number,
287292
report_code=report_code,
288293
slug=slug,
294+
swift_project=swift_project,
289295
token=token,
290296
upload_file_type=report_type,
291297
use_legacy_uploader=use_legacy_uploader,

codecov_cli/commands/upload_process.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ def upload_process(
5555
report_code: str,
5656
report_type: str,
5757
slug: typing.Optional[str],
58+
swift_project: typing.Optional[str],
5859
token: typing.Optional[str],
5960
use_legacy_uploader: bool,
6061
):
@@ -118,6 +119,7 @@ def upload_process(
118119
report_code=report_code,
119120
report_type=report_type,
120121
slug=slug,
122+
swift_project=swift_project,
121123
token=token,
122124
use_legacy_uploader=use_legacy_uploader,
123125
)

codecov_cli/plugins/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ def _get_plugin(cli_config, plugin_name, plugin_config):
8080
config = cli_config.get("plugins", {}).get("pycoverage", {})
8181
return Pycoverage(config)
8282
if plugin_name == "xcode":
83-
return XcodePlugin()
83+
return XcodePlugin(
84+
plugin_config.get("swift_project", None),
85+
)
8486
if plugin_name == "compress-pycoverage":
8587
config = cli_config.get("plugins", {}).get("compress-pycoverage", {})
8688
return CompressPycoverageContexts(config)

codecov_cli/plugins/xcode.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@
1616
class XcodePlugin(object):
1717
def __init__(
1818
self,
19+
app_name: typing.Optional[str] = None,
1920
derived_data_folder: typing.Optional[pathlib.Path] = None,
20-
app_name: typing.Optional[pathlib.Path] = None,
2121
):
22-
self.derived_data_folder = pathlib.Path(
23-
derived_data_folder or "~/Library/Developer/Xcode/DerivedData"
24-
).expanduser()
22+
self.derived_data_folder = (
23+
derived_data_folder
24+
or pathlib.Path("~/Library/Developer/Xcode/DerivedData").expanduser()
25+
)
2526

2627
# this is to speed up processing and to build reports for the project being tested,
2728
# if empty the plugin will build reports for every xcode project it finds

codecov_cli/services/upload/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ def do_upload_logic(
5555
pull_request_number: typing.Optional[str],
5656
report_code: str,
5757
slug: typing.Optional[str],
58+
swift_project: typing.Optional[str],
5859
token: str,
5960
upload_file_type: str = "coverage",
6061
use_legacy_uploader: bool = False,
@@ -66,6 +67,7 @@ def do_upload_logic(
6667
"gcov_ignore": gcov_ignore,
6768
"gcov_include": gcov_include,
6869
"project_root": files_search_root_folder,
70+
"swift_project": swift_project,
6971
}
7072
if upload_file_type == "coverage":
7173
preparation_plugins = select_preparation_plugins(

tests/commands/test_invoke_upload_process.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ def test_upload_process_options(mocker):
130130
" --gcov-ignore TEXT Paths to ignore during gcov gathering",
131131
" --gcov-include TEXT Paths to include during gcov gathering",
132132
" --gcov-executable TEXT gcov executable to run. Defaults to 'gcov'",
133+
" --swift-project TEXT Specify the swift project",
133134
" --parent-sha TEXT SHA (with 40 chars) of what should be the",
134135
" parent of this commit",
135136
" -h, --help Show this message and exit.",

tests/services/upload/test_upload_service.py

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ def test_do_upload_logic_happy_path_legacy_uploader(mocker):
7171
branch="branch",
7272
use_legacy_uploader=True,
7373
slug="slug",
74+
swift_project="App",
7475
pull_request_number="pr",
7576
git_service="git_service",
7677
enterprise_url=None,
@@ -85,7 +86,7 @@ def test_do_upload_logic_happy_path_legacy_uploader(mocker):
8586

8687
assert res == LegacyUploadSender.send_upload_data.return_value
8788
mock_select_preparation_plugins.assert_called_with(
88-
cli_config, ["first_plugin", "another", "forth"], {'folders_to_ignore': None, 'gcov_args': None, 'gcov_executable': None, 'gcov_ignore': None, 'gcov_include': None, 'project_root': None}
89+
cli_config, ["first_plugin", "another", "forth"], {'folders_to_ignore': None, 'gcov_args': None, 'gcov_executable': None, 'gcov_ignore': None, 'gcov_include': None, 'project_root': None, 'swift_project': 'App'}
8990
)
9091
mock_select_file_finder.assert_called_with(None, None, None, False, "coverage")
9192
mock_select_network_finder.assert_called_with(
@@ -171,6 +172,7 @@ def test_do_upload_logic_happy_path(mocker):
171172
token="token",
172173
branch="branch",
173174
slug="slug",
175+
swift_project="App",
174176
pull_request_number="pr",
175177
git_service="git_service",
176178
enterprise_url=None,
@@ -184,7 +186,7 @@ def test_do_upload_logic_happy_path(mocker):
184186

185187
assert res == UploadSender.send_upload_data.return_value
186188
mock_select_preparation_plugins.assert_called_with(
187-
cli_config, ["first_plugin", "another", "forth"], {'folders_to_ignore': None, 'gcov_args': None, 'gcov_executable': None, 'gcov_ignore': None, 'gcov_include': None, 'project_root': None}
189+
cli_config, ["first_plugin", "another", "forth"], {'folders_to_ignore': None, 'gcov_args': None, 'gcov_executable': None, 'gcov_ignore': None, 'gcov_include': None, 'project_root': None, 'swift_project': 'App'}
188190
)
189191
mock_select_file_finder.assert_called_with(None, None, None, False, "coverage")
190192
mock_select_network_finder.assert_called_with(
@@ -266,6 +268,7 @@ def test_do_upload_logic_dry_run(mocker):
266268
token="token",
267269
branch="branch",
268270
slug="slug",
271+
swift_project="App",
269272
pull_request_number="pr",
270273
dry_run=True,
271274
git_service="git_service",
@@ -282,7 +285,7 @@ def test_do_upload_logic_dry_run(mocker):
282285
assert mock_generate_upload_data.call_count == 1
283286
assert mock_send_upload_data.call_count == 0
284287
mock_select_preparation_plugins.assert_called_with(
285-
cli_config, ["first_plugin", "another", "forth"], {'folders_to_ignore': None, 'gcov_args': None, 'gcov_executable': None, 'gcov_ignore': None, 'gcov_include': None, 'project_root': None}
288+
cli_config, ["first_plugin", "another", "forth"], {'folders_to_ignore': None, 'gcov_args': None, 'gcov_executable': None, 'gcov_ignore': None, 'gcov_include': None, 'project_root': None, 'swift_project': 'App'}
286289
)
287290
assert out_bytes == [
288291
("info", "dry-run option activated. NOT sending data to Codecov."),
@@ -340,6 +343,7 @@ def test_do_upload_logic_verbose(mocker, use_verbose_option):
340343
pull_request_number="pr",
341344
report_code="report_code",
342345
slug="slug",
346+
swift_project="App",
343347
token="token",
344348
upload_file_type="coverage",
345349
use_legacy_uploader=True,
@@ -419,6 +423,7 @@ def side_effect(*args, **kwargs):
419423
token="token",
420424
branch="branch",
421425
slug="slug",
426+
swift_project="App",
422427
pull_request_number="pr",
423428
git_service="git_service",
424429
enterprise_url=None,
@@ -438,7 +443,7 @@ def side_effect(*args, **kwargs):
438443
text="No coverage reports found. Triggering notificaions without uploading.",
439444
)
440445
mock_select_preparation_plugins.assert_called_with(
441-
cli_config, ["first_plugin", "another", "forth"], {'folders_to_ignore': None, 'gcov_args': None, 'gcov_executable': None, 'gcov_ignore': None, 'gcov_include': None, 'project_root': None}
446+
cli_config, ["first_plugin", "another", "forth"], {'folders_to_ignore': None, 'gcov_args': None, 'gcov_executable': None, 'gcov_ignore': None, 'gcov_include': None, 'project_root': None, 'swift_project': 'App'}
442447
)
443448
mock_select_file_finder.assert_called_with(None, None, None, False, "coverage")
444449
mock_select_network_finder.assert_called_with(
@@ -511,6 +516,7 @@ def side_effect(*args, **kwargs):
511516
token="token",
512517
branch="branch",
513518
slug="slug",
519+
swift_project="App",
514520
pull_request_number="pr",
515521
git_service="git_service",
516522
enterprise_url=None,
@@ -521,7 +527,7 @@ def side_effect(*args, **kwargs):
521527
== "No coverage reports found. Please make sure you're generating reports successfully."
522528
)
523529
mock_select_preparation_plugins.assert_called_with(
524-
cli_config, ["first_plugin", "another", "forth"], {'folders_to_ignore': None, 'gcov_args': None, 'gcov_executable': None, 'gcov_ignore': None, 'gcov_include': None, 'project_root': None}
530+
cli_config, ["first_plugin", "another", "forth"], {'folders_to_ignore': None, 'gcov_args': None, 'gcov_executable': None, 'gcov_ignore': None, 'gcov_include': None, 'project_root': None, 'swift_project': 'App'}
525531
)
526532
mock_select_file_finder.assert_called_with(None, None, None, False, "coverage")
527533
mock_select_network_finder.assert_called_with(
@@ -564,33 +570,34 @@ def test_do_upload_logic_happy_path_test_results(mocker):
564570
cli_config,
565571
versioning_system,
566572
ci_adapter,
567-
upload_file_type="test_results",
568-
commit_sha="commit_sha",
569-
report_code="report_code",
573+
args={"args": "fake_args"},
574+
branch="branch",
570575
build_code="build_code",
571576
build_url="build_url",
572-
job_code="job_code",
577+
commit_sha="commit_sha",
578+
enterprise_url=None,
573579
env_vars=None,
580+
files_search_exclude_folders=None,
581+
files_search_explicitly_listed_files=None,
582+
files_search_root_folder=None,
574583
flags=None,
575584
gcov_args=None,
576585
gcov_executable=None,
577586
gcov_ignore=None,
578587
gcov_include=None,
588+
git_service="git_service",
589+
job_code="job_code",
579590
name="name",
580591
network_filter="some_dir",
581592
network_prefix="hello/",
582593
network_root_folder="root/",
583-
files_search_root_folder=None,
584-
files_search_exclude_folders=None,
585-
files_search_explicitly_listed_files=None,
586594
plugin_names=["first_plugin", "another", "forth"],
587-
token="token",
588-
branch="branch",
589-
slug="slug",
590595
pull_request_number="pr",
591-
git_service="git_service",
592-
enterprise_url=None,
593-
args={"args": "fake_args"},
596+
report_code="report_code",
597+
slug="slug",
598+
swift_project="App",
599+
token="token",
600+
upload_file_type="test_results",
594601
)
595602
out_bytes = parse_outstreams_into_log_lines(outstreams[0].getvalue())
596603
assert out_bytes == [

0 commit comments

Comments
 (0)