Skip to content

Commit

Permalink
feat: add xcode functionality (#537)
Browse files Browse the repository at this point in the history
* first pass

* fix: update tests

* feat: allow for swift coverage

* fix: rebase and tests
  • Loading branch information
thomasrockhu-codecov authored Oct 17, 2024
1 parent 3333bcb commit 5e6fee0
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 23 deletions.
6 changes: 6 additions & 0 deletions codecov_cli/commands/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ def _turn_env_vars_into_dict(ctx, params, value):
"--gcov-executable",
help="gcov executable to run. Defaults to 'gcov'",
),
click.option(
"--swift-project",
help="Specify the swift project",
),
]


Expand Down Expand Up @@ -238,6 +242,7 @@ def do_upload(
pull_request_number: typing.Optional[str],
report_type: str,
slug: typing.Optional[str],
swift_project: typing.Optional[str],
token: typing.Optional[str],
use_legacy_uploader: bool,
):
Expand Down Expand Up @@ -286,6 +291,7 @@ def do_upload(
pull_request_number=pull_request_number,
report_code=report_code,
slug=slug,
swift_project=swift_project,
token=token,
upload_file_type=report_type,
use_legacy_uploader=use_legacy_uploader,
Expand Down
2 changes: 2 additions & 0 deletions codecov_cli/commands/upload_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def upload_process(
report_code: str,
report_type: str,
slug: typing.Optional[str],
swift_project: typing.Optional[str],
token: typing.Optional[str],
use_legacy_uploader: bool,
):
Expand Down Expand Up @@ -118,6 +119,7 @@ def upload_process(
report_code=report_code,
report_type=report_type,
slug=slug,
swift_project=swift_project,
token=token,
use_legacy_uploader=use_legacy_uploader,
)
4 changes: 3 additions & 1 deletion codecov_cli/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ def _get_plugin(cli_config, plugin_name, plugin_config):
config = cli_config.get("plugins", {}).get("pycoverage", {})
return Pycoverage(config)
if plugin_name == "xcode":
return XcodePlugin()
return XcodePlugin(
plugin_config.get("swift_project", None),
)
if plugin_name == "compress-pycoverage":
config = cli_config.get("plugins", {}).get("compress-pycoverage", {})
return CompressPycoverageContexts(config)
Expand Down
9 changes: 5 additions & 4 deletions codecov_cli/plugins/xcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
class XcodePlugin(object):
def __init__(
self,
app_name: typing.Optional[str] = None,
derived_data_folder: typing.Optional[pathlib.Path] = None,
app_name: typing.Optional[pathlib.Path] = None,
):
self.derived_data_folder = pathlib.Path(
derived_data_folder or "~/Library/Developer/Xcode/DerivedData"
).expanduser()
self.derived_data_folder = (
derived_data_folder
or pathlib.Path("~/Library/Developer/Xcode/DerivedData").expanduser()
)

# this is to speed up processing and to build reports for the project being tested,
# if empty the plugin will build reports for every xcode project it finds
Expand Down
2 changes: 2 additions & 0 deletions codecov_cli/services/upload/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def do_upload_logic(
pull_request_number: typing.Optional[str],
report_code: str,
slug: typing.Optional[str],
swift_project: typing.Optional[str],
token: str,
upload_file_type: str = "coverage",
use_legacy_uploader: bool = False,
Expand All @@ -66,6 +67,7 @@ def do_upload_logic(
"gcov_ignore": gcov_ignore,
"gcov_include": gcov_include,
"project_root": files_search_root_folder,
"swift_project": swift_project,
}
if upload_file_type == "coverage":
preparation_plugins = select_preparation_plugins(
Expand Down
1 change: 1 addition & 0 deletions tests/commands/test_invoke_upload_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ def test_upload_process_options(mocker):
" --gcov-ignore TEXT Paths to ignore during gcov gathering",
" --gcov-include TEXT Paths to include during gcov gathering",
" --gcov-executable TEXT gcov executable to run. Defaults to 'gcov'",
" --swift-project TEXT Specify the swift project",
" --parent-sha TEXT SHA (with 40 chars) of what should be the",
" parent of this commit",
" -h, --help Show this message and exit.",
Expand Down
43 changes: 25 additions & 18 deletions tests/services/upload/test_upload_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def test_do_upload_logic_happy_path_legacy_uploader(mocker):
branch="branch",
use_legacy_uploader=True,
slug="slug",
swift_project="App",
pull_request_number="pr",
git_service="git_service",
enterprise_url=None,
Expand All @@ -85,7 +86,7 @@ def test_do_upload_logic_happy_path_legacy_uploader(mocker):

assert res == LegacyUploadSender.send_upload_data.return_value
mock_select_preparation_plugins.assert_called_with(
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}
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'}
)
mock_select_file_finder.assert_called_with(None, None, None, False, "coverage")
mock_select_network_finder.assert_called_with(
Expand Down Expand Up @@ -171,6 +172,7 @@ def test_do_upload_logic_happy_path(mocker):
token="token",
branch="branch",
slug="slug",
swift_project="App",
pull_request_number="pr",
git_service="git_service",
enterprise_url=None,
Expand All @@ -184,7 +186,7 @@ def test_do_upload_logic_happy_path(mocker):

assert res == UploadSender.send_upload_data.return_value
mock_select_preparation_plugins.assert_called_with(
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}
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'}
)
mock_select_file_finder.assert_called_with(None, None, None, False, "coverage")
mock_select_network_finder.assert_called_with(
Expand Down Expand Up @@ -266,6 +268,7 @@ def test_do_upload_logic_dry_run(mocker):
token="token",
branch="branch",
slug="slug",
swift_project="App",
pull_request_number="pr",
dry_run=True,
git_service="git_service",
Expand All @@ -282,7 +285,7 @@ def test_do_upload_logic_dry_run(mocker):
assert mock_generate_upload_data.call_count == 1
assert mock_send_upload_data.call_count == 0
mock_select_preparation_plugins.assert_called_with(
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}
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'}
)
assert out_bytes == [
("info", "dry-run option activated. NOT sending data to Codecov."),
Expand Down Expand Up @@ -340,6 +343,7 @@ def test_do_upload_logic_verbose(mocker, use_verbose_option):
pull_request_number="pr",
report_code="report_code",
slug="slug",
swift_project="App",
token="token",
upload_file_type="coverage",
use_legacy_uploader=True,
Expand Down Expand Up @@ -419,6 +423,7 @@ def side_effect(*args, **kwargs):
token="token",
branch="branch",
slug="slug",
swift_project="App",
pull_request_number="pr",
git_service="git_service",
enterprise_url=None,
Expand All @@ -438,7 +443,7 @@ def side_effect(*args, **kwargs):
text="No coverage reports found. Triggering notificaions without uploading.",
)
mock_select_preparation_plugins.assert_called_with(
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}
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'}
)
mock_select_file_finder.assert_called_with(None, None, None, False, "coverage")
mock_select_network_finder.assert_called_with(
Expand Down Expand Up @@ -511,6 +516,7 @@ def side_effect(*args, **kwargs):
token="token",
branch="branch",
slug="slug",
swift_project="App",
pull_request_number="pr",
git_service="git_service",
enterprise_url=None,
Expand All @@ -521,7 +527,7 @@ def side_effect(*args, **kwargs):
== "No coverage reports found. Please make sure you're generating reports successfully."
)
mock_select_preparation_plugins.assert_called_with(
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}
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'}
)
mock_select_file_finder.assert_called_with(None, None, None, False, "coverage")
mock_select_network_finder.assert_called_with(
Expand Down Expand Up @@ -564,33 +570,34 @@ def test_do_upload_logic_happy_path_test_results(mocker):
cli_config,
versioning_system,
ci_adapter,
upload_file_type="test_results",
commit_sha="commit_sha",
report_code="report_code",
args={"args": "fake_args"},
branch="branch",
build_code="build_code",
build_url="build_url",
job_code="job_code",
commit_sha="commit_sha",
enterprise_url=None,
env_vars=None,
files_search_exclude_folders=None,
files_search_explicitly_listed_files=None,
files_search_root_folder=None,
flags=None,
gcov_args=None,
gcov_executable=None,
gcov_ignore=None,
gcov_include=None,
git_service="git_service",
job_code="job_code",
name="name",
network_filter="some_dir",
network_prefix="hello/",
network_root_folder="root/",
files_search_root_folder=None,
files_search_exclude_folders=None,
files_search_explicitly_listed_files=None,
plugin_names=["first_plugin", "another", "forth"],
token="token",
branch="branch",
slug="slug",
pull_request_number="pr",
git_service="git_service",
enterprise_url=None,
args={"args": "fake_args"},
report_code="report_code",
slug="slug",
swift_project="App",
token="token",
upload_file_type="test_results",
)
out_bytes = parse_outstreams_into_log_lines(outstreams[0].getvalue())
assert out_bytes == [
Expand Down

0 comments on commit 5e6fee0

Please sign in to comment.