Skip to content

Commit 728a808

Browse files
authored
refactor: rename files_to_build to default_outputs (bazel-contrib#3542)
The "files to build" term is the jargon used with the Bazel Java code, but in regular Starlark code, the term is "default outputs". This jargon leakage happened while porting the code from Java to Starlark.
1 parent 7827e0b commit 728a808

4 files changed

Lines changed: 20 additions & 37 deletions

File tree

python/private/common.bzl

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -109,27 +109,6 @@ def create_cc_details_struct(
109109
**kwargs
110110
)
111111

112-
def create_executable_result_struct(*, extra_files_to_build, output_groups, extra_runfiles = None):
113-
"""Creates a `CreateExecutableResult` struct.
114-
115-
This is the return value type of the semantics create_executable function.
116-
117-
Args:
118-
extra_files_to_build: depset of File; additional files that should be
119-
included as default outputs.
120-
output_groups: dict[str, depset[File]]; additional output groups that
121-
should be returned.
122-
extra_runfiles: A runfiles object of additional runfiles to include.
123-
124-
Returns:
125-
A `CreateExecutableResult` struct.
126-
"""
127-
return struct(
128-
extra_files_to_build = extra_files_to_build,
129-
output_groups = output_groups,
130-
extra_runfiles = extra_runfiles,
131-
)
132-
133112
def csv(values):
134113
"""Convert a list of strings to comma separated value string."""
135114
return ", ".join(sorted(values))

python/private/py_executable.bzl

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ load(
4242
"collect_runfiles",
4343
"create_binary_semantics_struct",
4444
"create_cc_details_struct",
45-
"create_executable_result_struct",
4645
"create_instrumented_files_info",
4746
"create_output_group_info",
4847
"create_py_info",
@@ -377,15 +376,15 @@ def _create_executable(
377376
runfiles = runfiles_details.runfiles_without_exe.merge(extra_runfiles),
378377
)
379378

380-
extra_files_to_build = []
379+
extra_default_outputs = []
381380

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

385384
# When --build_python_zip is enabled, then the zip file becomes
386385
# one of the default outputs.
387386
if build_zip_enabled:
388-
extra_files_to_build.append(zip_file)
387+
extra_default_outputs.append(zip_file)
389388

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

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

422421
if should_create_executable_zip:
423422
if bootstrap_output != None:
@@ -459,9 +458,14 @@ def _create_executable(
459458
# added to the zipped files.
460459
if venv and venv.interpreter:
461460
extra_runfiles = extra_runfiles.merge(ctx.runfiles([venv.interpreter]))
462-
return create_executable_result_struct(
463-
extra_files_to_build = depset(extra_files_to_build),
461+
return struct(
462+
# depset[File] of additional files that should be included as default
463+
# outputs.
464+
extra_default_outputs = depset(extra_default_outputs),
465+
# dict[str, depset[File]]; additional output groups that should be
466+
# returned.
464467
output_groups = {"python_zip_file": depset([zip_file])},
468+
# runfiles; additional runfiles to include.
465469
extra_runfiles = extra_runfiles,
466470
)
467471

@@ -1075,10 +1079,10 @@ def py_executable_base_impl(ctx, *, semantics, is_test, inherited_environment =
10751079
runfiles_details = runfiles_details,
10761080
extra_deps = extra_deps,
10771081
)
1078-
default_outputs.add(exec_result.extra_files_to_build)
1082+
default_outputs.add(exec_result.extra_default_outputs)
10791083

10801084
extra_exec_runfiles = exec_result.extra_runfiles.merge(
1081-
ctx.runfiles(transitive_files = exec_result.extra_files_to_build),
1085+
ctx.runfiles(transitive_files = exec_result.extra_default_outputs),
10821086
)
10831087

10841088
# Copy any existing fields in case of company patches.

tests/base_rules/py_executable_base_tests.bzl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -377,22 +377,22 @@ def _test_explicit_main_cannot_be_ambiguous_impl(env, target):
377377
matching.str_matches("foo.py*matches multiple"),
378378
)
379379

380-
def _test_files_to_build(name, config):
380+
def _test_default_outputs(name, config):
381381
rt_util.helper_target(
382382
config.rule,
383383
name = name + "_subject",
384384
srcs = [name + "_subject.py"],
385385
)
386386
analysis_test(
387387
name = name,
388-
impl = _test_files_to_build_impl,
388+
impl = _test_default_outputs_impl,
389389
target = name + "_subject",
390390
attrs = WINDOWS_ATTR,
391391
)
392392

393-
_tests.append(_test_files_to_build)
393+
_tests.append(_test_default_outputs)
394394

395-
def _test_files_to_build_impl(env, target):
395+
def _test_default_outputs_impl(env, target):
396396
default_outputs = env.expect.that_target(target).default_outputs()
397397
if pt_util.is_windows(env):
398398
default_outputs.contains("{package}/{test_name}_subject.exe")

tests/base_rules/py_library/py_library_tests.bzl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def _test_py_runtime_info_not_present_impl(env, target):
2727

2828
_tests.append(_test_py_runtime_info_not_present)
2929

30-
def _test_files_to_build(name, config):
30+
def _test_default_outputs(name, config):
3131
rt_util.helper_target(
3232
config.rule,
3333
name = name + "_subject",
@@ -36,15 +36,15 @@ def _test_files_to_build(name, config):
3636
analysis_test(
3737
name = name,
3838
target = name + "_subject",
39-
impl = _test_files_to_build_impl,
39+
impl = _test_default_outputs_impl,
4040
)
4141

42-
def _test_files_to_build_impl(env, target):
42+
def _test_default_outputs_impl(env, target):
4343
env.expect.that_target(target).default_outputs().contains_exactly([
4444
"{package}/lib.py",
4545
])
4646

47-
_tests.append(_test_files_to_build)
47+
_tests.append(_test_default_outputs)
4848

4949
def _test_srcs_can_contain_rule_generating_py_and_nonpy_files(name, config):
5050
rt_util.helper_target(

0 commit comments

Comments
 (0)