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

Deleted incompatible_disable_custom_test_launcher and related code #1095

Merged
merged 1 commit into from
Jan 17, 2022
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
108 changes: 1 addition & 107 deletions rust/private/rust.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -326,98 +326,6 @@ def _rust_binary_impl(ctx):
),
)

def _create_test_launcher(ctx, toolchain, output, env, providers):
"""Create a process wrapper to ensure runtime environment variables are defined for the test binary

WARNING: This function is subject to deletion with the removal of
incompatible_disable_custom_test_launcher

Args:
ctx (ctx): The rule's context object
toolchain (rust_toolchain): The current rust toolchain
output (File): The output File that will be produced, depends on crate type.
env (dict): Dict of environment variables
providers (list): Providers from a rust compile action. See `rustc_compile_action`

Returns:
list: A list of providers similar to `rustc_compile_action` but with modified default info
"""

# TODO: It's unclear if the toolchain is in the same configuration as the `_launcher` attribute
# This should be investigated but for now, we generally assume if the target environment is windows,
# the execution environment is windows.
if toolchain.os == "windows":
launcher_filename = ctx.label.name + ".launcher.exe"
else:
launcher_filename = ctx.label.name + ".launcher"

launcher = ctx.actions.declare_file(launcher_filename)

# Because returned executables must be created from the same rule, the
# launcher target is simply symlinked and exposed.
ctx.actions.symlink(
output = launcher,
target_file = ctx.executable._launcher,
is_executable = True,
)

# Expand the environment variables and write them to a file
environ_file = ctx.actions.declare_file(launcher_filename + ".launchfiles/env")

# Convert the environment variables into a list to be written into a file.
environ_list = []
for key, value in sorted(env.items()):
environ_list.extend([key, value])

ctx.actions.write(
output = environ_file,
content = "\n".join(environ_list),
)

launcher_files = [environ_file]

# Replace the `DefaultInfo` provider in the returned list
default_info = None
for i in range(len(providers)):
if type(providers[i]) == "DefaultInfo":
default_info = providers[i]
providers.pop(i)
break

if not default_info:
fail("No DefaultInfo provider returned from `rustc_compile_action`")

output_group_info = OutputGroupInfo(
launcher_files = depset(launcher_files),
output = depset([output]),
)

# Binaries on Windows might provide a pdb file via an `OutputGroupInfo` that we need to merge
if toolchain.os == "windows":
for i in range(len(providers)):
if type(providers[i]) == "OutputGroupInfo":
output_group_info = OutputGroupInfo(
launcher_files = output_group_info.launcher_files,
output = output_group_info.output,
pdb_file = providers[i].pdb_file,
)
providers.pop(i)
break

providers.extend([
DefaultInfo(
files = default_info.files,
runfiles = default_info.default_runfiles.merge(
# The output is now also considered a runfile
ctx.runfiles(files = launcher_files + [output]),
),
executable = launcher,
),
output_group_info,
])

return providers

def _rust_test_common(ctx, toolchain, output):
"""Builds a Rust test binary.

Expand Down Expand Up @@ -499,12 +407,7 @@ def _rust_test_common(ctx, toolchain, output):
)
providers.append(testing.TestEnvironment(env))

if not toolchain._incompatible_disable_custom_test_launcher and any(["{pwd}" in v for v in env.values()]):
# Some of the environment variables require expanding {pwd} placeholder at runtime,
# we need a launcher for that.
return _create_test_launcher(ctx, toolchain, output, env, providers)
else:
return providers
return providers

def _rust_test_impl(ctx):
"""The implementation of the `rust_test` rule
Expand Down Expand Up @@ -734,15 +637,6 @@ _rust_test_attrs = {
default = Label("@bazel_tools//tools/cpp:grep-includes"),
executable = True,
),
"_launcher": attr.label(
executable = True,
default = Label("//util/launcher:launcher"),
cfg = "exec",
doc = dedent("""\
A launcher executable for loading environment and argument files passed in via the `env` attribute
and ensuring the variables are set for the underlying test executable.
"""),
),
}

_common_providers = [
Expand Down
6 changes: 0 additions & 6 deletions rust/settings/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ incompatible_flag(
issue = "https://github.com/bazelbuild/rules_rust/issues/1051",
)

incompatible_flag(
name = "incompatible_disable_custom_test_launcher",
build_setting_default = True,
issue = "https://github.com/bazelbuild/rules_rust/issues/1069",
)

# A flag controlling whether to rename first-party crates such that their names
# encode the Bazel package and target name, instead of just the target name.
#
Expand Down
5 changes: 0 additions & 5 deletions rust/toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,6 @@ def _rust_toolchain_impl(ctx):
fail("Do not specify both target_triple and target_json, either use a builtin triple or provide a custom specification file.")

remove_transitive_libs_from_dep_info = ctx.attr._incompatible_remove_transitive_libs_from_dep_info[IncompatibleFlagInfo]
disable_custom_test_launcher = ctx.attr._incompatible_disable_custom_test_launcher[IncompatibleFlagInfo]

rename_first_party_crates = ctx.attr._rename_first_party_crates[BuildSettingInfo].value
third_party_dir = ctx.attr._third_party_dir[BuildSettingInfo].value
Expand Down Expand Up @@ -289,7 +288,6 @@ def _rust_toolchain_impl(ctx):
crosstool_files = ctx.files._crosstool,
libstd_and_allocator_ccinfo = _make_libstd_and_allocator_ccinfo(ctx, ctx.attr.rust_lib, ctx.attr.allocator_library),
_incompatible_remove_transitive_libs_from_dep_info = remove_transitive_libs_from_dep_info.enabled,
_incompatible_disable_custom_test_launcher = disable_custom_test_launcher.enabled,
_rename_first_party_crates = rename_first_party_crates,
_third_party_dir = third_party_dir,
)
Expand Down Expand Up @@ -404,9 +402,6 @@ rust_toolchain = rule(
"_crosstool": attr.label(
default = Label("@bazel_tools//tools/cpp:current_cc_toolchain"),
),
"_incompatible_disable_custom_test_launcher": attr.label(
default = Label("@rules_rust//rust/settings:incompatible_disable_custom_test_launcher"),
),
"_incompatible_remove_transitive_libs_from_dep_info": attr.label(
default = "@rules_rust//rust/settings:incompatible_remove_transitive_libs_from_dep_info",
),
Expand Down
5 changes: 0 additions & 5 deletions test/unit/disable_custom_test_launcher/BUILD.bazel

This file was deleted.

This file was deleted.

12 changes: 0 additions & 12 deletions util/launcher/BUILD.bazel

This file was deleted.

114 changes: 0 additions & 114 deletions util/launcher/launcher_main.rs

This file was deleted.