Skip to content

Commit

Permalink
Substitute cc_internal.strip with cc_helper.create_strip_action.
Browse files Browse the repository at this point in the history
* Move create_strip_action implementation from cc_binary to cc_helper.
* Switch cc_internal.strip implementations to cc_helper.create_strip_action in java_binary, go_binary and go_test.
* Delete cc_internal.strip.

PiperOrigin-RevId: 436161369
  • Loading branch information
Googler authored and copybara-github committed Mar 21, 2022
1 parent 00d74ff commit b95a61a
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,32 +91,6 @@ public CcStarlarkApiInfo createCcProvider(CcInfo ccInfo) {
return new CcStarlarkApiInfo(ccInfo);
}

@StarlarkMethod(
name = "strip",
documented = false,
parameters = {
@Param(name = "ctx", named = true, positional = false),
@Param(name = "toolchain", named = true, positional = false),
@Param(name = "input", named = true, positional = false),
@Param(name = "output", named = true, positional = false),
@Param(name = "feature_configuration", named = true, positional = false),
})
public void createStripAction(
StarlarkRuleContext ctx,
CcToolchainProvider toolchain,
Artifact input,
Artifact output,
FeatureConfigurationForStarlark featureConfig)
throws EvalException, RuleErrorException {
CppHelper.createStripAction(
ctx.getRuleContext(),
toolchain,
ctx.getRuleContext().getFragment(CppConfiguration.class),
input,
output,
featureConfig.getFeatureConfiguration());
}

@StarlarkMethod(
name = "init_make_variables",
documented = false,
Expand Down
43 changes: 1 addition & 42 deletions src/main/starlark/builtins_bzl/common/cc/cc_binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -155,47 +155,6 @@ def _create_debug_packager_actions(ctx, cc_toolchain, dwp_output, dwo_files):
outputs = packager["outputs"],
)

def _create_strip_action(ctx, cc_toolchain, cpp_config, input, output, feature_configuration):
if cc_common.is_enabled(feature_configuration = feature_configuration, feature_name = "no_stripping"):
ctx.actions.symlink(
output = output,
target_file = input,
progress_message = "Symlinking original binary as stripped binary",
)
return

if not cc_common.action_is_enabled(feature_configuration = feature_configuration, action_name = "strip"):
fail("Expected action_config for 'strip' to be configured.")

variables = cc_common.create_compile_variables(
cc_toolchain = cc_toolchain,
feature_configuration = feature_configuration,
output_file = output.path,
input_file = input.path,
strip_opts = cpp_config.strip_opts(),
)
command_line = cc_common.get_memory_inefficient_command_line(
feature_configuration = feature_configuration,
action_name = "strip",
variables = variables,
)
execution_info = {}
for execution_requirement in cc_common.get_tool_requirement_for_action(feature_configuration = feature_configuration, action_name = "strip"):
execution_info[execution_requirement] = ""
ctx.actions.run(
inputs = depset(
direct = [input],
transitive = [cc_toolchain.all_files],
),
outputs = [output],
use_default_shell_env = True,
executable = cc_common.get_tool_for_action(feature_configuration = feature_configuration, action_name = "strip"),
execution_requirements = execution_info,
progress_message = "Stripping {} for {}".format(output.short_path, ctx.label),
mnemonic = "CcStrip",
arguments = command_line,
)

def _is_stamping_enabled(ctx):
if ctx.configuration.is_tool_configuration():
return 0
Expand Down Expand Up @@ -858,7 +817,7 @@ def cc_binary_impl(ctx, additional_linkopts):

# Create the stripped binary but don't add it to filesToBuild; it's only built when requested.
stripped_file = ctx.outputs.stripped_binary
_create_strip_action(ctx, cc_toolchain, cpp_config, binary, stripped_file, feature_configuration)
cc_helper.create_strip_action(ctx, cc_toolchain, cpp_config, binary, stripped_file, feature_configuration)
dwo_files = _collect_transitive_dwo_artifacts(
cc_compilation_outputs,
cc_helper.merge_cc_debug_contexts(cc_compilation_outputs, _get_providers(ctx, cpp_config)),
Expand Down
42 changes: 42 additions & 0 deletions src/main/starlark/builtins_bzl/common/cc/cc_helper.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,47 @@ def _check_srcs_extensions(ctx, allowed_src_files, rule_name, allow_versioned_sh
if not at_least_one_good:
fail("'{}' does not produce any {} srcs files".format(str(src.label), rule_name), attr = "srcs")

def _create_strip_action(ctx, cc_toolchain, cpp_config, input, output, feature_configuration):
if cc_common.is_enabled(feature_configuration = feature_configuration, feature_name = "no_stripping"):
ctx.actions.symlink(
output = output,
target_file = input,
progress_message = "Symlinking original binary as stripped binary",
)
return

if not cc_common.action_is_enabled(feature_configuration = feature_configuration, action_name = "strip"):
fail("Expected action_config for 'strip' to be configured.")

variables = cc_common.create_compile_variables(
cc_toolchain = cc_toolchain,
feature_configuration = feature_configuration,
output_file = output.path,
input_file = input.path,
strip_opts = cpp_config.strip_opts(),
)
command_line = cc_common.get_memory_inefficient_command_line(
feature_configuration = feature_configuration,
action_name = "strip",
variables = variables,
)
execution_info = {}
for execution_requirement in cc_common.get_tool_requirement_for_action(feature_configuration = feature_configuration, action_name = "strip"):
execution_info[execution_requirement] = ""
ctx.actions.run(
inputs = depset(
direct = [input],
transitive = [cc_toolchain.all_files],
),
outputs = [output],
use_default_shell_env = True,
executable = cc_common.get_tool_for_action(feature_configuration = feature_configuration, action_name = "strip"),
execution_requirements = execution_info,
progress_message = "Stripping {} for {}".format(output.short_path, ctx.label),
mnemonic = "CcStrip",
arguments = command_line,
)

def _merge_cc_debug_contexts(compilation_outputs, dep_cc_infos):
debug_context = cc_common.create_debug_context(compilation_outputs)
debug_contexts = []
Expand Down Expand Up @@ -561,4 +602,5 @@ cc_helper = struct(
get_linked_artifact = _get_linked_artifact,
collect_compilation_prerequisites = _collect_compilation_prerequisites,
collect_native_cc_libraries = _collect_native_cc_libraries,
create_strip_action = _create_strip_action,
)

0 comments on commit b95a61a

Please sign in to comment.