Skip to content

Commit

Permalink
Add Starlark implementation of dll_hash_suffix method.
Browse files Browse the repository at this point in the history
Delete obsolete methods from native code.

PiperOrigin-RevId: 440316854
  • Loading branch information
Googler authored and copybara-github committed Apr 8, 2022
1 parent e34d6e4 commit 3636aaf
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,20 +176,6 @@ public FileApi createShareableArtifact(StarlarkRuleContext ruleContext, String p
.getShareableArtifact(PathFragment.create(path), ruleContext.getBinDirectory());
}

@StarlarkMethod(
name = "dll_hash_suffix",
documented = false,
parameters = {
@Param(name = "ctx", positional = false, named = true),
@Param(name = "feature_configuration", named = true, positional = false),
})
public String getDLLHashSuffix(
StarlarkRuleContext starlarkRuleContext,
FeatureConfigurationForStarlark featureConfiguration) {
return CppHelper.getDLLHashSuffix(
starlarkRuleContext.getRuleContext(), featureConfiguration.getFeatureConfiguration());
}

static class DefParserComputedDefault extends ComputedDefault
implements NativeComputedDefaultApi {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,7 @@ public static Artifact getWindowsDefFileForLinking(
}
}

// TODO(gnish): Delete this method once cc_library is fully migrated to Starlark implementation.
/** Returns the suffix (_{hash}) for artifacts generated by cc_library on Windows. */
public static String getDLLHashSuffix(
RuleContext ruleContext, FeatureConfiguration featureConfiguration) {
Expand Down
11 changes: 9 additions & 2 deletions src/main/starlark/builtins_bzl/common/cc/cc_helper.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,15 @@ def _build_output_groups_for_emitting_compile_providers(

return output_groups_builder

def _dll_hash_suffix(ctx, feature_configuration):
return cc_internal.dll_hash_suffix(ctx = ctx, feature_configuration = feature_configuration)
def _dll_hash_suffix(ctx, feature_configuration, cpp_config):
if cpp_config.dynamic_mode() != "OFF":
if cc_common.is_enabled(feature_configuration = feature_configuration, feature_name = "targets_windows"):
if not hasattr(ctx.attr, "win_def_file") or ctx.file.win_def_file == None:
# Note: ctx.label.workspace_name strips leading @,
# which is different from the native behavior.
string_to_hash = ctx.label.workspace_name + ctx.label.package
return "_%x" % hash(string_to_hash)
return ""

def _gen_empty_def_file(ctx):
trivial_def_file = ctx.actions.declare_file(ctx.label.name + ".gen.empty.def")
Expand Down
2 changes: 1 addition & 1 deletion src/main/starlark/builtins_bzl/common/cc/cc_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def _cc_library_impl(ctx):
feature_configuration = feature_configuration,
feature_name = "targets_windows",
):
dll_name_suffix = cc_helper.dll_hash_suffix(ctx = ctx, feature_configuration = feature_configuration)
dll_name_suffix = cc_helper.dll_hash_suffix(ctx, feature_configuration, ctx.fragments.cpp)
generated_def_file = None

def_parser = ctx.file._def_parser
Expand Down

0 comments on commit 3636aaf

Please sign in to comment.