-
Notifications
You must be signed in to change notification settings - Fork 111
Add support for Enable Code Coverage for all targets in scheme test action options #3111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add support for Enable Code Coverage for all targets in scheme test action options #3111
Conversation
205a377 to
f0b4bdf
Compare
brentleyjones
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you rebase?
tools/generators/xcschemes/test/CreateAutomaticSchemeInfoTests.swift
Outdated
Show resolved
Hide resolved
tools/generators/xcschemes/test/CreateAutomaticSchemeInfoTests.swift
Outdated
Show resolved
Hide resolved
|
curious, was there a change that would make coverage work now? this is just for the schema and we'd still need something like this #1119 (comment) correct? |
|
AFAIK coverage in Xcode is still broken. |
Yes, I will check everything I have here to do a rebase, and modify something if necessary.
The coverage is still broken, what is done here is just to set it as an option to enable, here we use internal adjustments to achieve coverage. |
b76b73f to
d493a75
Compare
69fa079 to
0900ce5
Compare
|
@brentleyjones After a while I went back to implement it, I did a rebase to incorporate the latest changes, and I also tested it in the project, and everything worked :) One point to note is that Xcode coverage is still not working. This is just an option to enable it. Internally, we use a workaround to have coverage, which is why we implemented this option to enable it by default. |
|
What’s the workaround? |
It would be following the same approach as here: #1119 (comment) However, implemented differently. In this case, internally at PicPay, we looked at the path of two apps and then at where several modules are located. Specific configurations were added to the module target, and the apps were separated (in this case, we have two apps). diff --git a/tools/worker/swift_runner.cc b/tools/worker/swift_runner.cc
index 6610e589e..e0807a4ee 100644
--- a/tools/worker/swift_runner.cc
+++ b/tools/worker/swift_runner.cc
@@ -302,6 +302,25 @@ bool SwiftRunner::ProcessArgument(
}
#endif
};
+
+ auto add_prefix_map_flags_for_custom_coverage = [&](const std::string& flag, const std::string& modules_dir_name) {
+ // cwd real (execution root)
+ const auto cwd = std::filesystem::current_path();
+
+ // Calcula target_path = canonical(cwd / modules_dir_name).parent_path();
+ const auto target_path = std::filesystem::canonical(cwd / modules_dir_name).parent_path();
+
+ consumer(flag);
+ consumer(std::filesystem::current_path().string() + "=" + target_path.string());
+
+#if __APPLE__
+ std::string developer_dir = "__BAZEL_XCODE_DEVELOPER_DIR__";
+ if (bazel_placeholder_substitutions_.Apply(developer_dir)) {
+ consumer(flag);
+ consumer(developer_dir + "=/PLACEHOLDER_DEVELOPER_DIR");
+ }
+#endif
+ };
if (arg[0] == '@') {
changed = ProcessPossibleResponseFile(arg, consumer);
@@ -313,6 +332,15 @@ bool SwiftRunner::ProcessArgument(
// without breaking hermiticity.
add_prefix_map_flags("-debug-prefix-map");
changed = true;
+ } else if (new_arg == "-app-coverage-hack") {
+ add_prefix_map_flags_for_custom_coverage("-coverage-prefix-map", "Modules");
+ changed = true;
+ } else if (new_arg == "-app-coverage-hack-app-app1") {
+ add_prefix_map_flags_for_custom_coverage("-coverage-prefix-map", "App1");
+ changed = true;
+ } else if (new_arg == "-app-coverage-hack-app-app2") {
+ add_prefix_map_flags_for_custom_coverage("-coverage-prefix-map", "App2");
+ changed = true;
} else if (new_arg == "-coverage-prefix-pwd-is-dot") {
// Replace the $PWD with . to make the paths relative to the workspace
// without breaking hermiticity.
in swift_library(
name = "App1.library",
srcs = [":App1SourceCode"],
copts = select({
"//Bazel_rules:scheme_prod": [],
"//Bazel_rules:coverage_in_xcode": [
"-Xwrapped-swift=-app-coverage-hack-app-1",
"-D",
"DEBUG",
],
"//conditions:default": [
"-D",
"DEBUG",
],
}),
features = select({
"//Bazel_rules:coverage_in_xcode": [
"-swift.coverage_prefix_map",
"-swift.file_prefix_map",
"swift.coverage",
],
"//conditions:default": [],
}),
linkopts = select({
"//Bazel_rules:coverage_in_xcode": [
"-fprofile-instr-generate",
],
"//conditions:default": [],
}),
module_name = "App1",
tags = ["manual"],
visibility = ["//visibility:public"],
deps = [...]
alwayslink = True,
)And in in string_flag(
name = "enable_coverage_in_xcode",
build_setting_default = "no_coverage",
visibility = ["//visibility:public"],
)
config_setting(
name = "coverage_in_xcode",
flag_values = {
":enable_coverage_in_xcode": "coverage",
},
visibility = ["//visibility:public"],
) |
0900ce5 to
873875e
Compare
Signed-off-by: Lucas Romano <[email protected]> update autogeneration_config docs Signed-off-by: Lucas Romano <[email protected]> Update tools/generators/xcschemes/test/CreateAutomaticSchemeInfoTests.swift Co-authored-by: Brentley Jones <[email protected]> Signed-off-by: Lucas Romano <[email protected]> Update tools/generators/xcschemes/test/CreateAutomaticSchemeInfoTests.swift Co-authored-by: Brentley Jones <[email protected]> Signed-off-by: Lucas Romano <[email protected]> Update tools/generators/xcschemes/src/Generator/Generator.swift Signed-off-by: Lucas Romano <[email protected]>
873875e to
93d6116
Compare
Added support for enable code coverage for all targets.
For auto scheme generation default valou ir False
For configure in scheme: