Skip to content

Commit

Permalink
python: Implement has_pyX_only_sources computation for Starlark impl
Browse files Browse the repository at this point in the history
This is a bit moot with Python 2 being dropped, but there's an assert for it
mixed in with some tests for other behavior, it shows up in PyInfo, and it's easy to compute with simple logic, so might as well.

Work towards #15897

PiperOrigin-RevId: 503465342
Change-Id: I3d5ab6fc1e8bd0dec25c2d71c94f1a59af8d4e38
  • Loading branch information
rickeylev authored and hvadehra committed Feb 14, 2023
1 parent 3c53a53 commit dfc63d7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/main/starlark/builtins_bzl/common/python/common.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,8 @@ def create_py_info(ctx, *, direct_sources, imports):
necessary for deprecated extra actions support).
"""
uses_shared_libraries = False
has_py2_only_sources = ctx.attr.srcs_version in ("PY2", "PY2ONLY")
has_py3_only_sources = ctx.attr.srcs_version in ("PY3", "PY3ONLY")
transitive_sources_depsets = [] # list of depsets
transitive_sources_files = [] # list of Files
for target in ctx.attr.deps:
Expand All @@ -350,6 +352,8 @@ def create_py_info(ctx, *, direct_sources, imports):
info = target[PyInfo]
transitive_sources_depsets.append(info.transitive_sources)
uses_shared_libraries = uses_shared_libraries or info.uses_shared_libraries
has_py2_only_sources = has_py2_only_sources or info.has_py2_only_sources
has_py3_only_sources = has_py3_only_sources or info.has_py3_only_sources
else:
# TODO(b/228692666): Remove this once non-PyInfo targets are no
# longer supported in `deps`.
Expand Down Expand Up @@ -395,8 +399,8 @@ def create_py_info(ctx, *, direct_sources, imports):
# NOTE: This isn't strictly correct, but with Python 2 gone,
# the srcs_version logic is largely defunct, so shouldn't matter in
# practice.
has_py2_only_sources = False,
has_py3_only_sources = False,
has_py2_only_sources = has_py2_only_sources,
has_py3_only_sources = has_py3_only_sources,
uses_shared_libraries = uses_shared_libraries,
)
return py_info, deps_transitive_sources
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ public void librarySandwich() throws Exception {
" deps = [':pylib'],",
" imports = ['upperuserlib_path'],",
")");
// TODO(bazel-team): Implement support for `imports` attribute
setBuildLanguageOptions("--experimental_builtins_injection_override=-py_library");
ConfiguredTarget target = getConfiguredTarget("//pkg:upperuserlib");

PyInfo info = target.get(PyInfo.PROVIDER);
Expand Down

0 comments on commit dfc63d7

Please sign in to comment.