From 229c2c690af1a8bcd4ecf4eef904bb2b34011bb9 Mon Sep 17 00:00:00 2001 From: Googler Date: Fri, 4 Oct 2024 06:33:00 -0700 Subject: [PATCH] Java part of python nostamp mitigation support. 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 --- .../build/lib/rules/python/PythonConfiguration.java | 13 +++++++++++++ .../build/lib/rules/python/PythonOptions.java | 8 ++++++++ 2 files changed, 21 insertions(+) diff --git a/src/main/java/com/google/devtools/build/lib/rules/python/PythonConfiguration.java b/src/main/java/com/google/devtools/build/lib/rules/python/PythonConfiguration.java index 77bb5844e14785..4d158fe44209f8 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/python/PythonConfiguration.java +++ b/src/main/java/com/google/devtools/build/lib/rules/python/PythonConfiguration.java @@ -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; @@ -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 @@ -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; + } } diff --git a/src/main/java/com/google/devtools/build/lib/rules/python/PythonOptions.java b/src/main/java/com/google/devtools/build/lib/rules/python/PythonOptions.java index 9360413dca5f6d..851ea6ff349928 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/python/PythonOptions.java +++ b/src/main/java/com/google/devtools/build/lib/rules/python/PythonOptions.java @@ -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;