Skip to content

Commit 04e1b3a

Browse files
authored
ci: reintroduce logging of important build commands (#6609)
Rebrand `io::log_cmdline` as `io::log_and_run`, which, as the name suggests, now also executes the command so as to eliminate duplication at the call site. This version also adds quoting. Introduce `io::log_and_run` into the `ci/cloudbuild/build.sh` script. Additions to any of the `ci/cloudbuild/builds/*.sh` scripts can be made as the need arises.
1 parent 80f0fec commit 04e1b3a

2 files changed

Lines changed: 17 additions & 7 deletions

File tree

ci/cloudbuild/build.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,8 @@ if [[ "${DOCKER_FLAG}" = "true" ]]; then
236236
mkdir -p "${out_cmake}" "${out_home}/.config/gcloud"
237237
image="gcb-${DISTRO_FLAG}:latest"
238238
io::log_h2 "Building docker image: ${image}"
239-
docker build -t "${image}" "--build-arg=NCPU=$(nproc)" \
239+
io::run \
240+
docker build -t "${image}" "--build-arg=NCPU=$(nproc)" \
240241
-f "ci/cloudbuild/dockerfiles/${DISTRO_FLAG}.Dockerfile" ci
241242
io::log_h2 "Starting docker container: ${image}"
242243
run_flags=(
@@ -277,7 +278,7 @@ if [[ "${DOCKER_FLAG}" = "true" ]]; then
277278
printf "\n\n"
278279
cmd=("bash")
279280
fi
280-
docker run "${run_flags[@]}" "${image}" "${cmd[@]}"
281+
io::run docker run "${run_flags[@]}" "${image}" "${cmd[@]}"
281282
exit
282283
fi
283284

@@ -321,4 +322,4 @@ args=(
321322
"--substitutions=$(printf "%s," "${subs[@]}")"
322323
"--project=${project}"
323324
)
324-
gcloud builds submit "${args[@]}" .
325+
io::run gcloud builds submit "${args[@]}" .

ci/lib/io.sh

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,19 @@ function io::log_red() {
7575
io::internal::log_impl "${IO_COLOR_RED}" "$@"
7676
}
7777

78-
# Logs the arguments, in bold with a timestamp, like they were a command
79-
# executed under "set -x" in the shell (i.e., with a ${PS4} prefix).
80-
function io::log_cmdline() {
81-
io::internal::log_impl "${IO_BOLD}" "${PS4}$*"
78+
# Logs the given message in bold with a timestamp.
79+
function io::log_bold() {
80+
io::internal::log_impl "${IO_BOLD}" "$@"
81+
}
82+
83+
# Logs the arguments, in bold with a timestamp, and then executes them.
84+
# This is like executing a command under "set -x" in the shell (including
85+
# the ${PS4} prefix).
86+
function io::run() {
87+
local cmd
88+
cmd="$(printf ' %q' "$@")"
89+
io::log_bold "${PS4}${cmd# }"
90+
"$@"
8291
}
8392

8493
# Logs an "H1" heading. This looks like a blank line, followed by the message

0 commit comments

Comments
 (0)