During flag parsing, verify that `--embed_changelist` does not contain a newline character.
Document that neither this flag nor any key/value in the workspace status info may contain a newline, and that there should be no duplicate keys.
The build will already fail during build info parsing if `--embed_changelist` contains a newline. This change makes it fail faster.
PiperOrigin-RevId: 344884670
diff --git a/site/docs/user-manual.html b/site/docs/user-manual.html
index 20933c4..bea8fd5 100644
--- a/site/docs/user-manual.html
+++ b/site/docs/user-manual.html
@@ -1423,7 +1423,8 @@
The program should print zero or more key/value pairs to standard output, one entry on each line,
then exit with zero (otherwise the build fails). The key names can be anything but they may only
use upper case letters and underscores. The first space after the key name separates it from the
- value. The value is the rest of the line (including additional whitespaces).
+ value. The value is the rest of the line (including additional whitespaces). Neither the key nor
+ the value may span multiple lines. Keys must not be duplicated.
</p>
<p>
Bazel partitions the keys into two buckets: "stable" and "volatile". (The names "stable" and
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/WorkspaceStatusAction.java b/src/main/java/com/google/devtools/build/lib/analysis/WorkspaceStatusAction.java
index e22f504..8116818 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/WorkspaceStatusAction.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/WorkspaceStatusAction.java
@@ -31,10 +31,12 @@
import com.google.devtools.build.lib.vfs.FileSystemUtils;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.PathFragment;
+import com.google.devtools.common.options.Converter;
import com.google.devtools.common.options.Option;
import com.google.devtools.common.options.OptionDocumentationCategory;
import com.google.devtools.common.options.OptionEffectTag;
import com.google.devtools.common.options.OptionsBase;
+import com.google.devtools.common.options.OptionsParsingException;
import com.google.devtools.common.options.OptionsProvider;
import java.io.IOException;
import java.util.HashMap;
@@ -62,7 +64,7 @@
@Option(
name = "embed_label",
defaultValue = "",
- valueHelp = "<string>",
+ converter = OneLineStringConverter.class,
documentationCategory = OptionDocumentationCategory.UNCATEGORIZED,
effectTags = {OptionEffectTag.UNKNOWN},
help = "Embed source control revision or release label in binary")
@@ -232,4 +234,21 @@
.setWorkspaceStatus(WorkspaceStatus.newBuilder().setCode(detailedCode))
.build());
}
+
+ /** Converter for {@code --embed_label} which rejects strings that span multiple lines. */
+ public static final class OneLineStringConverter implements Converter<String> {
+
+ @Override
+ public String convert(String input) throws OptionsParsingException {
+ if (input.contains("\n")) {
+ throw new OptionsParsingException("Value must not contain multiple lines");
+ }
+ return input;
+ }
+
+ @Override
+ public String getTypeDescription() {
+ return "a one-line string";
+ }
+ }
}
diff --git a/src/test/shell/integration/workspace_status_test.sh b/src/test/shell/integration/workspace_status_test.sh
index a0fe511..c10cc23 100755
--- a/src/test/shell/integration/workspace_status_test.sh
+++ b/src/test/shell/integration/workspace_status_test.sh
@@ -122,4 +122,10 @@
expect_log "wscmissing.sh: No such file or directory\|wscmissing.sh: not found"
}
+function test_embed_label_must_be_single_line() {
+ bazel build --embed_label="$(echo -e 'abc\nxyz')" >& "$TEST_log" \
+ && fail "Expected failure"
+ expect_log "Value must not contain multiple lines"
+}
+
run_suite "${PRODUCT_NAME} workspace status command tests"