Skip to content
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

fix: ensure coverage providers are output from both py_library and py_binary rules #168

Merged
merged 1 commit into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified docs/py_binary.md
100755 → 100644
Empty file.
37 changes: 29 additions & 8 deletions docs/py_library.md
100755 → 100644

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions py/private/py_binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ def _py_binary_rule_imp(ctx):
)

imports = _py_library.make_imports_depset(ctx)
instrumented_files_info = _py_library.make_instrumented_files_info(
ctx,
extra_source_attributes = ["main"]
)

return [
DefaultInfo(
Expand All @@ -88,6 +92,7 @@ def _py_binary_rule_imp(ctx):
has_py3_only_sources = True,
uses_shared_libraries = False,
),
instrumented_files_info,
]

_attrs = dict({
Expand Down
18 changes: 15 additions & 3 deletions py/private/py_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ load("@bazel_skylib//lib:paths.bzl", "paths")
load("//py/private:providers.bzl", "PyWheelInfo")
load("//py/private:py_wheel.bzl", py_wheel = "py_wheel_lib")

def _make_instrumented_files_info(ctx, extra_source_attributes = [], extra_dependency_attributes = []):
return coverage_common.instrumented_files_info(
ctx,
source_attributes = ["srcs"] + extra_source_attributes,
dependency_attributes = ["data", "deps"] + extra_dependency_attributes,
extensions = ["py"],
)

def _make_srcs_depset(ctx):
return depset(
order = "postorder",
Expand Down Expand Up @@ -89,6 +97,7 @@ def _py_library_impl(ctx):
transitive_srcs = _make_srcs_depset(ctx)
imports = _make_imports_depset(ctx)
runfiles = _make_merged_runfiles(ctx)
instrumented_files_info = _make_instrumented_files_info(ctx)
py_wheel_info = py_wheel.make_py_wheel_info(ctx, ctx.attr.deps)

return [
Expand All @@ -104,6 +113,7 @@ def _py_library_impl(ctx):
uses_shared_libraries = False,
),
py_wheel_info,
instrumented_files_info,
]

_attrs = dict({
Expand All @@ -126,11 +136,13 @@ _providers = [
]

py_library_utils = struct(
make_srcs_depset = _make_srcs_depset,
# keep-sorted
attrs = _attrs,
implementation = _py_library_impl,
make_imports_depset = _make_imports_depset,
make_instrumented_files_info = _make_instrumented_files_info,
make_merged_runfiles = _make_merged_runfiles,
implementation = _py_library_impl,
attrs = _attrs,
make_srcs_depset = _make_srcs_depset,
py_library_providers = _providers,
)

Expand Down