Skip to content

Commit

Permalink
fix: ensure coverage providers are output from both py_library and py…
Browse files Browse the repository at this point in the history
…_binary rules (#168)
  • Loading branch information
mattem authored Jul 31, 2023
1 parent 88ebe87 commit 1fb1612
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 11 deletions.
37 changes: 29 additions & 8 deletions docs/py_library.md

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

0 comments on commit 1fb1612

Please sign in to comment.