Skip to content

Commit

Permalink
Java part of python nostamp mitigation support.
Browse files Browse the repository at this point in the history
The purpose of this change is to modify py_binary building so that when binaries are built with the --nostamp flag, most stamp info is still suppressed, but the build _target_ is still stamped.

This change will bring py_binary targets into line with current behaviour in C++, Java, Go and Rust.

PiperOrigin-RevId: 682299016
Change-Id: If33314ca3daf6c9b68daca3e539f7493119ddebf
  • Loading branch information
Googler authored and copybara-github committed Oct 4, 2024
1 parent 8472c9d commit 229c2c6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ public class PythonConfiguration extends Fragment implements StarlarkValue {
// TODO(brandjon): Remove this once migration to Python toolchains is complete.
private final boolean useToolchains;

/* Whether to include the build label in unstamped builds. */
private final boolean includeLabelInLinkstamp;

private final boolean defaultToExplicitInitPy;
private final boolean disablePy2;
@Nullable private final Label nativeRulesAllowlist;
Expand All @@ -70,6 +73,7 @@ public PythonConfiguration(BuildOptions buildOptions) {
this.disablePy2 = pythonOptions.disablePy2;
this.nativeRulesAllowlist = pythonOptions.nativeRulesAllowlist;
this.disallowNativeRules = pythonOptions.disallowNativeRules;
this.includeLabelInLinkstamp = pythonOptions.includeLabelInPyBinariesLinkstamp;
}

@Override
Expand Down Expand Up @@ -199,4 +203,13 @@ public boolean getDisallowNativeRules() {
public Label getNativeRulesAllowlist() {
return nativeRulesAllowlist;
}

/** Returns whether the build label is included in unstamped builds. */
@StarlarkMethod(
name = "include_label_in_linkstamp",
doc = "Whether the build label is included in unstamped builds.",
structField = true)
public boolean isIncludeLabelInLinkstamp() {
return includeLabelInLinkstamp;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,14 @@ public String getTypeDescription() {
+ " more information and migration instructions.")
public boolean disallowNativeRules;

@Option(
name = "experimental_py_binaries_include_label",
defaultValue = "false",
documentationCategory = OptionDocumentationCategory.OUTPUT_PARAMETERS,
effectTags = {OptionEffectTag.AFFECTS_OUTPUTS},
help = "py_binary targets include their label even when stamping is disabled.")
public boolean includeLabelInPyBinariesLinkstamp;

// Helper field to store hostForcePython in exec configuration
private PythonVersion defaultPythonVersion = null;

Expand Down

0 comments on commit 229c2c6

Please sign in to comment.