visualizations.sh: use curly braces for variables

This commit is contained in:
Robur 2023-03-13 14:43:54 +00:00
parent 1924781bb6
commit 4cc81f9950

View file

@ -70,24 +70,24 @@ done
[ -z "${CACHE_DIR}" ] && die "The --cache-dir option must be specified" [ -z "${CACHE_DIR}" ] && die "The --cache-dir option must be specified"
[ -z "${DATA_DIR}" ] && die "The --data-dir option must be specified" [ -z "${DATA_DIR}" ] && die "The --data-dir option must be specified"
info "processing UUID '$UUID'" info "processing UUID '${UUID}'"
DB="${DATA_DIR}/builder.sqlite3" DB="${DATA_DIR}/builder.sqlite3"
get_main_binary () { get_main_binary () {
sqlite3 "${DB}" "SELECT ba.localpath FROM build AS b sqlite3 "${DB}" "SELECT ba.localpath FROM build AS b
JOIN build_artifact AS ba ON ba.build = b.id AND b.main_binary = ba.id JOIN build_artifact AS ba ON ba.build = b.id AND b.main_binary = ba.id
WHERE uuid = '$UUID';" WHERE uuid = '${UUID}';"
} }
BIN="${DATA_DIR}/$(get_main_binary)" || die "Failed to get main binary from database" BIN="${DATA_DIR}/$(get_main_binary)" || die "Failed to get main binary from database"
[ -z "${BIN}" ] && die "No main-binary found in db '$DB' for build '$UUID'" [ -z "${BIN}" ] && die "No main-binary found in db '${DB}' for build '${UUID}'"
get_debug_binary () { get_debug_binary () {
sqlite3 "${DB}" "SELECT ba.localpath FROM build AS b sqlite3 "${DB}" "SELECT ba.localpath FROM build AS b
JOIN build_artifact AS ba ON ba.build = b.id JOIN build_artifact AS ba ON ba.build = b.id
WHERE WHERE
uuid = '$UUID' uuid = '${UUID}'
AND ba.localpath LIKE '%.debug';" AND ba.localpath LIKE '%.debug';"
} }
@ -97,19 +97,19 @@ get_opam_switch () {
sqlite3 "${DB}" "SELECT ba.localpath FROM build AS b sqlite3 "${DB}" "SELECT ba.localpath FROM build AS b
JOIN build_artifact AS ba ON ba.build = b.id JOIN build_artifact AS ba ON ba.build = b.id
WHERE WHERE
uuid = '$UUID' uuid = '${UUID}'
AND ba.filepath = 'opam-switch';" AND ba.filepath = 'opam-switch';"
} }
OPAM_SWITCH="$(get_opam_switch)" || die "Failed to get opam switch from database" OPAM_SWITCH="$(get_opam_switch)" || die "Failed to get opam switch from database"
[ -z "${OPAM_SWITCH}" ] && die "No 'opam-switch' found in db '$DB' for build '$UUID'" [ -z "${OPAM_SWITCH}" ] && die "No 'opam-switch' found in db '${DB}' for build '${UUID}'"
OPAM_SWITCH="${DATA_DIR}/${OPAM_SWITCH}" OPAM_SWITCH="${DATA_DIR}/${OPAM_SWITCH}"
OPAM_GRAPH="opam-graph" OPAM_GRAPH="opam-graph"
MODULECTOMY="modulectomy" MODULECTOMY="modulectomy"
LATEST_TREEMAPVIZ_VERSION="$($MODULECTOMY --version)" || die "Failed to get modulectomy version" LATEST_TREEMAPVIZ_VERSION="$(${MODULECTOMY} --version)" || die "Failed to get modulectomy version"
LATEST_DEPENDENCIESVIZ_VERSION="$($OPAM_GRAPH --version)" || die "Failed to get opam-graph version" LATEST_DEPENDENCIESVIZ_VERSION="$(${OPAM_GRAPH} --version)" || die "Failed to get opam-graph version"
TREEMAP_CACHE_DIR="${CACHE_DIR}/treemap_${LATEST_TREEMAPVIZ_VERSION}" TREEMAP_CACHE_DIR="${CACHE_DIR}/treemap_${LATEST_TREEMAPVIZ_VERSION}"
DEPENDENCIES_CACHE_DIR="${CACHE_DIR}/dependencies_${LATEST_DEPENDENCIESVIZ_VERSION}" DEPENDENCIES_CACHE_DIR="${CACHE_DIR}/dependencies_${LATEST_DEPENDENCIESVIZ_VERSION}"
@ -136,7 +136,7 @@ trap cleanup EXIT
# /// Dependencies viz # /// Dependencies viz
if [ ! -d "${DEPENDENCIES_CACHE_DIR}" ]; then if [ ! -d "${DEPENDENCIES_CACHE_DIR}" ]; then
mkdir "${DEPENDENCIES_CACHE_DIR}" || die "Failed to create directory '$DEPENDENCIES_CACHE_DIR'" mkdir "${DEPENDENCIES_CACHE_DIR}" || die "Failed to create directory '${DEPENDENCIES_CACHE_DIR}'"
fi fi
OPAM_SWITCH_FILEPATH='opam-switch' OPAM_SWITCH_FILEPATH='opam-switch'
@ -144,8 +144,8 @@ OPAM_SWITCH_FILEPATH='opam-switch'
get_opam_switch_hash () { get_opam_switch_hash () {
sqlite3 "${DB}" "SELECT lower(hex(ba.sha256)) FROM build AS b sqlite3 "${DB}" "SELECT lower(hex(ba.sha256)) FROM build AS b
JOIN build_artifact AS ba ON ba.build = b.id JOIN build_artifact AS ba ON ba.build = b.id
WHERE uuid = '$UUID' WHERE uuid = '${UUID}'
AND ba.filepath = '$OPAM_SWITCH_FILEPATH';" AND ba.filepath = '${OPAM_SWITCH_FILEPATH}';"
} }
DEPENDENCIES_INPUT_HASH="$(get_opam_switch_hash)" || die "Failed to get opam-switch hash from database" DEPENDENCIES_INPUT_HASH="$(get_opam_switch_hash)" || die "Failed to get opam-switch hash from database"
@ -156,7 +156,7 @@ if [ -e "${DEPENDENCIES_VIZ_FILENAME}" ]; then
else else
if ${OPAM_GRAPH} --output-format=html "${OPAM_SWITCH}" > "${TMPDEPENDENCIES}"; then if ${OPAM_GRAPH} --output-format=html "${OPAM_SWITCH}" > "${TMPDEPENDENCIES}"; then
cp "${TMPDEPENDENCIES}" "${DEPENDENCIES_VIZ_FILENAME}" cp "${TMPDEPENDENCIES}" "${DEPENDENCIES_VIZ_FILENAME}"
rm "$TMPDEPENDENCIES" rm "${TMPDEPENDENCIES}"
else else
die "opam-graph failed to generate visualization" die "opam-graph failed to generate visualization"
fi fi
@ -174,16 +174,16 @@ stat_aux () {
fi fi
} }
SIZE="$(stat_aux "$BIN")" SIZE="$(stat_aux "${BIN}")"
if [ ! -d "${TREEMAP_CACHE_DIR}" ]; then if [ ! -d "${TREEMAP_CACHE_DIR}" ]; then
mkdir "${TREEMAP_CACHE_DIR}" || die "Failed to create directory '$TREEMAP_CACHE_DIR'" mkdir "${TREEMAP_CACHE_DIR}" || die "Failed to create directory '${TREEMAP_CACHE_DIR}'"
fi fi
get_debug_bin_hash () { get_debug_bin_hash () {
sqlite3 "${DB}" "SELECT lower(hex(ba.sha256)) FROM build AS b sqlite3 "${DB}" "SELECT lower(hex(ba.sha256)) FROM build AS b
JOIN build_artifact AS ba ON ba.build = b.id JOIN build_artifact AS ba ON ba.build = b.id
WHERE uuid = '$UUID' WHERE uuid = '${UUID}'
AND ba.filepath LIKE '%.debug';" AND ba.filepath LIKE '%.debug';"
} }
@ -203,7 +203,7 @@ if [ -n "${DEBUG_BIN_RELATIVE}" ]; then
> "${TMPTREE}" > "${TMPTREE}"
then then
cp "${TMPTREE}" "${TREEMAP_VIZ_FILENAME}" cp "${TMPTREE}" "${TREEMAP_VIZ_FILENAME}"
rm "$TMPTREE" rm "${TMPTREE}"
else else
die "modulectomy failed to generate visualization" die "modulectomy failed to generate visualization"
fi fi