Skip to content
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
21 changes: 0 additions & 21 deletions python/private/common.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -109,27 +109,6 @@ def create_cc_details_struct(
**kwargs
)

def create_executable_result_struct(*, extra_files_to_build, output_groups, extra_runfiles = None):
"""Creates a `CreateExecutableResult` struct.

This is the return value type of the semantics create_executable function.

Args:
extra_files_to_build: depset of File; additional files that should be
included as default outputs.
output_groups: dict[str, depset[File]]; additional output groups that
should be returned.
extra_runfiles: A runfiles object of additional runfiles to include.

Returns:
A `CreateExecutableResult` struct.
"""
return struct(
extra_files_to_build = extra_files_to_build,
output_groups = output_groups,
extra_runfiles = extra_runfiles,
)

def csv(values):
"""Convert a list of strings to comma separated value string."""
return ", ".join(sorted(values))
Expand Down
20 changes: 12 additions & 8 deletions python/private/py_executable.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ load(
"collect_runfiles",
"create_binary_semantics_struct",
"create_cc_details_struct",
"create_executable_result_struct",
"create_instrumented_files_info",
"create_output_group_info",
"create_py_info",
Expand Down Expand Up @@ -377,15 +376,15 @@ def _create_executable(
runfiles = runfiles_details.runfiles_without_exe.merge(extra_runfiles),
)

extra_files_to_build = []
extra_default_outputs = []

# NOTE: --build_python_zip defaults to true on Windows
build_zip_enabled = read_possibly_native_flag(ctx, "build_python_zip")

# When --build_python_zip is enabled, then the zip file becomes
# one of the default outputs.
if build_zip_enabled:
extra_files_to_build.append(zip_file)
extra_default_outputs.append(zip_file)

# The logic here is a bit convoluted. Essentially, there are 3 types of
# executables produced:
Expand Down Expand Up @@ -417,7 +416,7 @@ def _create_executable(

# The launcher looks for the non-zip executable next to
# itself, so add it to the default outputs.
extra_files_to_build.append(bootstrap_output)
extra_default_outputs.append(bootstrap_output)

if should_create_executable_zip:
if bootstrap_output != None:
Expand Down Expand Up @@ -459,9 +458,14 @@ def _create_executable(
# added to the zipped files.
if venv and venv.interpreter:
extra_runfiles = extra_runfiles.merge(ctx.runfiles([venv.interpreter]))
return create_executable_result_struct(
extra_files_to_build = depset(extra_files_to_build),
return struct(
# depset[File] of additional files that should be included as default
# outputs.
extra_default_outputs = depset(extra_default_outputs),
# dict[str, depset[File]]; additional output groups that should be
# returned.
output_groups = {"python_zip_file": depset([zip_file])},
# runfiles; additional runfiles to include.
extra_runfiles = extra_runfiles,
)

Expand Down Expand Up @@ -1078,10 +1082,10 @@ def py_executable_base_impl(ctx, *, semantics, is_test, inherited_environment =
runfiles_details = runfiles_details,
extra_deps = extra_deps,
)
default_outputs.add(exec_result.extra_files_to_build)
default_outputs.add(exec_result.extra_default_outputs)

extra_exec_runfiles = exec_result.extra_runfiles.merge(
ctx.runfiles(transitive_files = exec_result.extra_files_to_build),
ctx.runfiles(transitive_files = exec_result.extra_default_outputs),
)

# Copy any existing fields in case of company patches.
Expand Down
8 changes: 4 additions & 4 deletions tests/base_rules/py_executable_base_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -377,22 +377,22 @@ def _test_explicit_main_cannot_be_ambiguous_impl(env, target):
matching.str_matches("foo.py*matches multiple"),
)

def _test_files_to_build(name, config):
def _test_default_outputs(name, config):
rt_util.helper_target(
config.rule,
name = name + "_subject",
srcs = [name + "_subject.py"],
)
analysis_test(
name = name,
impl = _test_files_to_build_impl,
impl = _test_default_outputs_impl,
target = name + "_subject",
attrs = WINDOWS_ATTR,
)

_tests.append(_test_files_to_build)
_tests.append(_test_default_outputs)

def _test_files_to_build_impl(env, target):
def _test_default_outputs_impl(env, target):
default_outputs = env.expect.that_target(target).default_outputs()
if pt_util.is_windows(env):
default_outputs.contains("{package}/{test_name}_subject.exe")
Expand Down
8 changes: 4 additions & 4 deletions tests/base_rules/py_library/py_library_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def _test_py_runtime_info_not_present_impl(env, target):

_tests.append(_test_py_runtime_info_not_present)

def _test_files_to_build(name, config):
def _test_default_outputs(name, config):
rt_util.helper_target(
config.rule,
name = name + "_subject",
Expand All @@ -36,15 +36,15 @@ def _test_files_to_build(name, config):
analysis_test(
name = name,
target = name + "_subject",
impl = _test_files_to_build_impl,
impl = _test_default_outputs_impl,
)

def _test_files_to_build_impl(env, target):
def _test_default_outputs_impl(env, target):
env.expect.that_target(target).default_outputs().contains_exactly([
"{package}/lib.py",
])

_tests.append(_test_files_to_build)
_tests.append(_test_default_outputs)

def _test_srcs_can_contain_rule_generating_py_and_nonpy_files(name, config):
rt_util.helper_target(
Expand Down