Skip to content

Commit

Permalink
chore: bazel run //:format (#682)
Browse files Browse the repository at this point in the history
  • Loading branch information
gregmagolan authored Dec 8, 2023
1 parent bb64a79 commit b1c342a
Show file tree
Hide file tree
Showing 21 changed files with 161 additions and 134 deletions.
4 changes: 2 additions & 2 deletions .aspect/workflows/terraform/workflows.tf
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ module "aspect_workflows" {

# Warming set definitions
warming_sets = {
default = {}
default = {}
}

# Resource types for use by runner groups
Expand All @@ -67,7 +67,7 @@ module "aspect_workflows" {
min_runners = 0
resource_type = "default"
scale_out_factor = 7
scaling_polling_frequency = 3 # check for queued jobs every 20s
scaling_polling_frequency = 3 # check for queued jobs every 20s
warming = true
}
# The warming runner group is used for the periodic warming job that creates
Expand Down
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[*.sh]
indent_style = space
indent_size = 2
4 changes: 2 additions & 2 deletions .github/workflows/release_prep.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ PREFIX="bazel-lib-${TAG:1}"
ARCHIVE="bazel-lib-$TAG.tar.gz"

# NB: configuration for 'git archive' is in /.gitattributes
git archive --format=tar --prefix=${PREFIX}/ ${TAG} | gzip > $ARCHIVE
git archive --format=tar --prefix=${PREFIX}/ ${TAG} | gzip >$ARCHIVE
SHA=$(shasum -a 256 $ARCHIVE | awk '{print $1}')

cat << EOF
cat <<EOF
## Using Bzlmod with Bazel 6:
Expand Down
21 changes: 14 additions & 7 deletions e2e/external_copy_to_directory/app/test.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
# --- begin runfiles.bash initialization v2 ---
# Copy-pasted from the Bazel Bash runfiles library v2.
set -uo pipefail; set +e; f=bazel_tools/tools/bash/runfiles/runfiles.bash
source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \
source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \
source "$0.runfiles/$f" 2>/dev/null || \
source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
{ echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e
set -uo pipefail
set +e
f=bazel_tools/tools/bash/runfiles/runfiles.bash
source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null ||
source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null ||
source "$0.runfiles/$f" 2>/dev/null ||
source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null ||
source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null ||
{
echo >&2 "ERROR: cannot find $f"
exit 1
}
f=
set -e
# --- end runfiles.bash initialization v2 ---

# Read external directory and make sure it exists with a file.
Expand Down
13 changes: 6 additions & 7 deletions e2e/run_jq_symlinked_bin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ set -o errexit -o nounset -o pipefail
BZLMOD_FLAG="${BZLMOD_FLAG:-}"

case "$(uname -s)" in
CYGWIN*|MINGW32*|MSYS*|MINGW*)
bazel run $BZLMOD_FLAG @jq//:jq.exe -- --null-input .a=5
;;
CYGWIN* | MINGW32* | MSYS* | MINGW*)
bazel run $BZLMOD_FLAG @jq//:jq.exe -- --null-input .a=5
;;

*)
bazel run $BZLMOD_FLAG @jq//:jq -- --null-input .a=5
;;
*)
bazel run $BZLMOD_FLAG @jq//:jq -- --null-input .a=5
;;
esac

12 changes: 6 additions & 6 deletions e2e/run_yq_symlinked_bin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ set -o errexit -o nounset -o pipefail
BZLMOD_FLAG="${BZLMOD_FLAG:-}"

case "$(uname -s)" in
CYGWIN*|MINGW32*|MSYS*|MINGW*)
bazel run $BZLMOD_FLAG @yq//:yq.exe -- --null-input .a=5
;;
CYGWIN* | MINGW32* | MSYS* | MINGW*)
bazel run $BZLMOD_FLAG @yq//:yq.exe -- --null-input .a=5
;;

*)
bazel run $BZLMOD_FLAG @yq//:yq -- --null-input .a=5
;;
*)
bazel run $BZLMOD_FLAG @yq//:yq -- --null-input .a=5
;;
esac
54 changes: 27 additions & 27 deletions e2e/write_source_files_symlinks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,35 @@ set -o errexit -o nounset -o pipefail
BZLMOD_FLAG="${BZLMOD_FLAG:-}"

function run_test {
bazel run $BZLMOD_FLAG //lib/tests/write_source_files:write_symlinks
bazel run $BZLMOD_FLAG //lib/tests/write_source_files:write_symlinks

local expected_out="lib/tests/write_source_files/symlink_test/a/test.txt"
if [ ! -e "$expected_out" ]; then
echo "ERROR: expected $expected_out to exist"
exit 1
fi
if [ -x "$expected_out" ]; then
echo "ERROR: expected $expected_out to not be executable"
exit 1
fi
if [ -L "$expected_out" ]; then
echo "ERROR: expected $expected_out to not be a symlink"
exit 1
fi
local expected_out="lib/tests/write_source_files/symlink_test/a/test.txt"
if [ ! -e "$expected_out" ]; then
echo "ERROR: expected $expected_out to exist"
exit 1
fi
if [ -x "$expected_out" ]; then
echo "ERROR: expected $expected_out to not be executable"
exit 1
fi
if [ -L "$expected_out" ]; then
echo "ERROR: expected $expected_out to not be a symlink"
exit 1
fi

local expected_out="lib/tests/write_source_files/symlink_test/b/test.txt"
if [ ! -e "$expected_out" ]; then
echo "ERROR: expected $expected_out to exist"
exit 1
fi
if [ -x "$expected_out" ]; then
echo "ERROR: expected $expected_out to not be executable"
exit 1
fi
if [ -L "$expected_out" ]; then
echo "ERROR: expected $expected_out to not be a symlink"
exit 1
fi
local expected_out="lib/tests/write_source_files/symlink_test/b/test.txt"
if [ ! -e "$expected_out" ]; then
echo "ERROR: expected $expected_out to exist"
exit 1
fi
if [ -x "$expected_out" ]; then
echo "ERROR: expected $expected_out to not be executable"
exit 1
fi
if [ -L "$expected_out" ]; then
echo "ERROR: expected $expected_out to not be a symlink"
exit 1
fi
}

# Run twice to make sure we can have permission to overwrite the outputs of a previous run
Expand Down
8 changes: 4 additions & 4 deletions lib/private/diff_test_tmpl.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/usr/bin/env bash
set -o errexit -o nounset -o pipefail
escape() {
echo "$1" \
| sed 's/&/\&amp;/g; s/</\&lt;/g; s/>/\&gt;/g; s/"/\&quot;/g; s/'"'"'/\&#39;/g' \
| awk 1 ORS='&#10;' # preserve newlines
echo "$1" |
sed 's/&/\&amp;/g; s/</\&lt;/g; s/>/\&gt;/g; s/"/\&quot;/g; s/'"'"'/\&#39;/g' |
awk 1 ORS='&#10;' # preserve newlines
}
fail() {
cat << EOF >"${XML_OUTPUT_FILE:-/dev/null}"
cat <<EOF >"${XML_OUTPUT_FILE:-/dev/null}"
<?xml version="1.0" encoding="UTF-8"?>
<testsuites name="$(escape "{name}")" tests="1" failures="1">
<testsuite name="$(escape "{name}")" tests="1" failures="1" id="0">
Expand Down
4 changes: 2 additions & 2 deletions lib/tests/copy_to_directory/case6.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ cd case_6
# A path that should be in the directory we have in data[]
path="f/f2/f2"
if [ ! -f "$path" ]; then
echo >&2 "Expected $path to exist in runfiles"
exit 1
echo >&2 "Expected $path to exist in runfiles"
exit 1
fi
5 changes: 2 additions & 3 deletions lib/tests/run_binary_expansions/expansions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ set -o errexit -o nounset -o pipefail
mkdir -p $(dirname $1)
outfile=$1
rm -f $outfile
for each in $@
do
for each in $@; do
sanitized=${each/darwin/PLATFORM}
sanitized=${sanitized/k8/PLATFORM}
echo $sanitized >> $outfile
echo $sanitized >>$outfile
done
4 changes: 2 additions & 2 deletions lib/tests/stamping/stamper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ set -o nounset
# https://github.com/bazelbuild/bazel/issues/11164#issuecomment-996186921
# is another option, which requires Bash 4 for associative arrays.
while IFS= read -r line; do
read key value <<< "$line"
read key value <<<"$line"
declare $key="$value"
done < <(cat "${BAZEL_STABLE_STATUS_FILE:-/dev/null}" "${BAZEL_VOLATILE_STATUS_FILE:-/dev/null}")

# A real program would do something useful with the stamp info, like pass it to a linker.
echo "${BUILD_USER:-unstamped}" > $1
echo "${BUILD_USER:-unstamped}" >$1
21 changes: 14 additions & 7 deletions lib/tests/tar/cat_src_file.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@

# --- begin runfiles.bash initialization v3 ---
# Copy-pasted from the Bazel Bash runfiles library v3.
set -uo pipefail; set +e; f=bazel_tools/tools/bash/runfiles/runfiles.bash
source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \
source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \
source "$0.runfiles/$f" 2>/dev/null || \
source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
{ echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e
set -uo pipefail
set +e
f=bazel_tools/tools/bash/runfiles/runfiles.bash
source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null ||
source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null ||
source "$0.runfiles/$f" 2>/dev/null ||
source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null ||
source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null ||
{
echo >&2 "ERROR: cannot find $f"
exit 1
}
f=
set -e
# --- end runfiles.bash initialization v3 ---

cat $(rlocation aspect_bazel_lib/lib/tests/tar/src_file)
2 changes: 1 addition & 1 deletion lib/tests/transitions/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ package main
import "fmt"

func main() {
fmt.Println("Hello World!")
fmt.Println("Hello World!")
}
15 changes: 7 additions & 8 deletions shlib/lib/assertions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@ fail() {
make_err_msg() {
local err_msg="${1}"
local prefix="${2:-}"
if [[ -n "${prefix:-}" ]]; then
if [[ -n "${prefix:-}" ]]; then
err_msg="${prefix} ${err_msg}"
fi
echo "${err_msg}"
}


# Asserts that the actual value equals the expected value.
#
# Args:
Expand All @@ -41,9 +40,9 @@ assert_equal() {
local expected="${1}"
local actual="${2}"
local err_msg
err_msg="$(\
err_msg="$(
make_err_msg \
"Expected to be equal. expected: ${expected}, actual: ${actual}" "${3:-}" \
"Expected to be equal. expected: ${expected}, actual: ${actual}" "${3:-}"
)"
if [[ "${expected}" != "${actual}" ]]; then
fail "${err_msg}"
Expand All @@ -64,9 +63,9 @@ assert_match() {
local pattern=${1}
local actual="${2}"
local err_msg
err_msg="$(\
err_msg="$(
make_err_msg \
"Expected to match. pattern: ${pattern}, actual: ${actual}" "${3:-}" \
"Expected to match. pattern: ${pattern}, actual: ${actual}" "${3:-}"
)"
if [[ ! "${actual}" =~ ${pattern} ]]; then
fail "${err_msg}"
Expand All @@ -87,9 +86,9 @@ assert_no_match() {
local pattern=${1}
local actual="${2}"
local err_msg
err_msg="$(\
err_msg="$(
make_err_msg \
"Expected not to match. pattern: ${pattern}, actual: ${actual}" "${3:-}" \
"Expected not to match. pattern: ${pattern}, actual: ${actual}" "${3:-}"
)"
if [[ "${actual}" =~ ${pattern} ]]; then
fail "${err_msg}"
Expand Down
25 changes: 15 additions & 10 deletions shlib/tests/lib_tests/assertions_tests/assert_equal_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,34 @@

# --- begin runfiles.bash initialization v2 ---
# Copy-pasted from the Bazel Bash runfiles library v2.
set -o nounset -o pipefail; f=bazel_tools/tools/bash/runfiles/runfiles.bash
set -o nounset -o pipefail
f=bazel_tools/tools/bash/runfiles/runfiles.bash
# shellcheck disable=SC1090
source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \
source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \
source "$0.runfiles/$f" 2>/dev/null || \
source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
{ echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e
source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null ||
source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null ||
source "$0.runfiles/$f" 2>/dev/null ||
source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null ||
source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null ||
{
echo >&2 "ERROR: cannot find $f"
exit 1
}
f=
set -e
# --- end runfiles.bash initialization v2 ---

assertions_sh_location=aspect_bazel_lib/shlib/lib/assertions.sh
assertions_sh="$(rlocation "${assertions_sh_location}")" || \
assertions_sh="$(rlocation "${assertions_sh_location}")" ||
(echo >&2 "Failed to locate ${assertions_sh_location}" && exit 1)
# shellcheck source=SCRIPTDIR/../../../lib/assertions.sh
source "${assertions_sh}"

assert_fail_sh_location=aspect_bazel_lib/shlib/tests/lib_tests/assertions_tests/assert_fail.sh
assert_fail_sh="$(rlocation "${assert_fail_sh_location}")" || \
assert_fail_sh="$(rlocation "${assert_fail_sh_location}")" ||
(echo >&2 "Failed to locate ${assert_fail_sh_location}" && exit 1)
# shellcheck source=SCRIPTDIR/assert_fail.sh
source "${assert_fail_sh}"


# MARK - Test assert_equal

reset_fail_err_msgs
Expand Down
18 changes: 9 additions & 9 deletions shlib/tests/lib_tests/assertions_tests/assert_fail.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ FAIL_ERR_MSGS=()

fail() {
local err_msg="${1:-"Unspecified error occurred."}"
FAIL_ERR_MSGS+=( "${err_msg}" )
FAIL_ERR_MSGS+=("${err_msg}")
}

reset_fail_err_msgs() {
FAIL_ERR_MSGS=()
}

new_fail(){
new_fail() {
local err_msg="${1:-}"
[[ -n "${err_msg}" ]] || err_msg="Unspecified error occurred."
echo >&2 "${err_msg}"
Expand All @@ -20,17 +20,17 @@ new_fail(){

assert_fail() {
local pattern=${1}
[[ ${#FAIL_ERR_MSGS[@]} == 0 ]] && \
[[ ${#FAIL_ERR_MSGS[@]} == 0 ]] &&
new_fail "Expected a failure. None found. pattern: ${pattern}"
[[ ${#FAIL_ERR_MSGS[@]} -gt 1 ]] && \
[[ ${#FAIL_ERR_MSGS[@]} -gt 1 ]] &&
new_fail "Expected a single failure. Found ${#FAIL_ERR_MSGS[@]}. pattern: ${pattern}"
[[ "${FAIL_ERR_MSGS[0]}" =~ ${pattern} ]] || \
[[ "${FAIL_ERR_MSGS[0]}" =~ ${pattern} ]] ||
new_fail "Unexpected failure. Found '${FAIL_ERR_MSGS[0]}'. pattern: ${pattern}"
}

assert_no_fail(){
[[ ${#FAIL_ERR_MSGS[@]} == 0 ]] || ( \
err_msg=$("${FAIL_ERR_MSGS[@]}") && \
new_fail "Expected no failures. Found ${#FAIL_ERR_MSGS[@]}. '${err_msg}'" \
assert_no_fail() {
[[ ${#FAIL_ERR_MSGS[@]} == 0 ]] || (
err_msg=$("${FAIL_ERR_MSGS[@]}") &&
new_fail "Expected no failures. Found ${#FAIL_ERR_MSGS[@]}. '${err_msg}'"
)
}
Loading

0 comments on commit b1c342a

Please sign in to comment.