Skip to content

Commit 088c087

Browse files
authored
set -e for ctx.actions.run_shell commands (#1360)
* set -e for ctx.actions.run_shall commands Actions might look like completed successfully even though one of the commands fail. This might cause remote-cache poisoning. * Add suggested option in long form
1 parent 3fe4b9f commit 088c087

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

scala/private/phases/phase_compile.bzl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,9 @@ def _build_nosrc_jar(ctx):
261261
zipper_arg_path = ctx.actions.declare_file("%s_zipper_args" % ctx.label.name)
262262
ctx.actions.write(zipper_arg_path, resources)
263263
cmd = """
264+
set -o errexit
265+
set -o nounset
266+
set -o pipefail
264267
rm -f {jar_output}
265268
{zipper} c {jar_output} @{path}
266269
# ensures that empty src targets still emit a statsfile and a diagnosticsfile

scala/private/phases/phase_scalafmt.bzl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,12 @@ def _formatter(ctx, manifest, files, template, output_runner):
5353
inputs = [template, manifest] + files,
5454
outputs = [output_runner],
5555
# replace %workspace% and %manifest% in template and rewrite it to output_runner
56-
command = "cat $1 | sed -e s#%workspace%#$2# -e s#%manifest%#$3# > $4",
56+
command = """
57+
set -o errexit
58+
set -o nounset
59+
set -o pipefail
60+
cat $1 | sed -e s#%workspace%#$2# -e s#%manifest%#$3# > $4
61+
""",
5762
arguments = [
5863
template.path,
5964
ctx.workspace_name,

thrift/thrift.bzl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ def _thrift_library_impl(ctx):
7777
# We move the files and touch them so that the output file is a purely deterministic
7878
# product of the _content_ of the inputs
7979
cmd = """
80+
set -o errexit
81+
set -o nounset
82+
set -o pipefail
8083
rm -f {out}
8184
{zipper} c {out} @{path}
8285
"""
@@ -103,6 +106,9 @@ rm -f {out}
103106
outputs = [ctx.outputs.libarchive],
104107
mnemonic = "ScalaThriftArchive",
105108
command = """
109+
set -o errexit
110+
set -o nounset
111+
set -o pipefail
106112
echo "empty" > {out}.contents
107113
rm -f {out}
108114
{zipper} c {out} {out}.contents

0 commit comments

Comments
 (0)