Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
GCC Farm Build Script
#!/usr/bin/env bash
set -e
if [[ ! -r "./x.py" ]]; then
echo >&2 "error: not in 'rustc' repository"
exit 1
fi
GCC_FARM_PREBUILD=$'
/usr/bin/env bash -c \'
HOST_PATH="$HOST_PATH"
CONFIG_FILE="${HOST_PATH/#\~/\$HOME}/config.toml"
echo "Updating rustc config file \`\$CONFIG_FILE\`..."
CODEGEN_UNITS=$(( $(nproc) / 2 ))
sed -ibak -E "s/^#? ?(codegen-units) = .+$/\\1 = \$CODEGEN_UNITS/" "\$CONFIG_FILE"
\'
'
GCC_FARM_SYNC_BACK_PATH="src/test"
GCC_FARM_SYNC_BACK_RSYNC_ARGS=('--filter="show **/*.stdout"' '--filter="show **/*.stderr"' '--filter="show **/*.fixed"' '--filter="hide,! */"')
source gcc-farm
#!/usr/bin/env bash
set -e
PROGRAM_NAME="$(basename -- "$0")"
show_help() {
echo "usage: $PROGRAM_NAME -h | [-s] [-t] COMMAND"
}
(( SYNC=0 )) || true
(( SYNC_BACK=0 )) || true
(( OPTIND=1 ))
while getopts "hst" opt; do
case "$opt" in
h)
show_help
exit 0
;;
s)
(( SYNC=1 ))
;;
t)
(( SYNC_BACK=1 ))
;;
esac
done
shift $((OPTIND - 1))
[[ "$1" == "--" ]] && shift
if [[ -z "$GCC_FARM_SERVER" ]]; then
echo >&2 "error: \`GCC_FARM_SERVER\` environment variable not specified"
exit 1
fi
if (( SYNC )) && [[ ! -r "./.git" ]]; then
echo >&2 "error: working directory is not Git repository"
exit 1
fi
envsubst2() {
sed 's/\\\$/\${ENVSUBST_IGNORE}/g' | ENVSUBST_IGNORE='$' envsubst "$@"
}
HOST="$GCC_FARM_SERVER.fsffrance.org"
HOST_PORT="$GCC_FARM_PORT"
HOST_PATH="${GCC_FARM_PATH-~/src/$(basename "$PWD")}"
RUN_CMD="$@"
SSH_ARGS=()
RSYNC_ARGS=()
if [[ -n "$HOST_PORT" ]]; then
SSH_ARGS+=("-p" "$HOST_PORT")
RSYNC_ARGS+=("--port" "$RSYNC_ARGS")
fi
PREBUILD_CMD="$(echo "$GCC_FARM_PREBUILD" | HOST_PATH="$HOST_PATH" envsubst2)"
echo "Checking for master connection to '$HOST'..."
ssh "${SSH_ARGS[@]}" -O check "$HOST"
ssh "${SSH_ARGS[@]}" "$HOST" "mkdir -p "$HOST_PATH""
if (( SYNC )); then
echo "Syncing repository..."
rsync -ahz --delete "${RSYNC_ARGS[@]}" --info=progress2 --include="/config.toml" --exclude=".git/" --filter="protect /build/" --filter="dir-merge,-n /.gitignore" . "$HOST:$HOST_PATH"
fi
if [[ "$RUN_CMD" ]]; then
echo "Running \`$RUN_CMD\` on server..."
ssh "${SSH_ARGS[@]}" -t "$HOST" "cd "$HOST_PATH" && ${PREBUILD_CMD:-true} && ${RUN_CMD:-true}"
fi
if (( SYNC_BACK )); then
echo "Syncing back results..."
rsync -ahz "${RSYNC_ARGS[@]}" --info=progress2 --filter="protect .git/" "${GCC_FARM_SYNC_BACK_RSYNC_ARGS[@]}" "$HOST:$HOST_PATH/$GCC_FARM_SYNC_BACK_PATH" "./$GCC_FARM_SYNC_BACK_PATH"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.