Skip to content
This repository has been archived by the owner on Jul 30, 2020. It is now read-only.

Commit

Permalink
Update to use source file basename for error logs and also to put tem…
Browse files Browse the repository at this point in the history
…p source file inside generated temp dir
  • Loading branch information
Nicholas Omer Chiasson committed Feb 25, 2017
1 parent d829009 commit 28cd078
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/car.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
CWD="${PWD}"
SRC_FILE="$1"
SRC_FILE_BASENAME=`basename "${SRC_FILE}"`
TEMP_SRC_FILE="${TMPDIR}/${SRC_FILE_BASENAME}"
TEMP_OUT_FILE=$(mktemp -q)
TEMP_OUT_DIR=$(mktemp -qd)
TEMP_SRC_FILE="${TEMP_OUT_DIR}/${SRC_FILE_BASENAME}"
CXX=gcc
CXX_OUTPUT_FLAG=-o
VM=
Expand Down Expand Up @@ -119,7 +119,7 @@ rm -rf "${TEMP_SRC_FILE}"
cp -f "${SRC_FILE}" "${TEMP_SRC_FILE}"

# Look for shebang and remove it from temp source
NEW_SRC_FILE_CONTENTS=`sed -e 's/^#!.*$//g' "${TEMP_SRC_FILE}"` || Error 2 "failed sed operation on '${TEMP_SRC_FILE}'"
NEW_SRC_FILE_CONTENTS=`sed -e 's/^#!.*$//g' "${TEMP_SRC_FILE}"` || Error 2 "failed sed operation on '${SRC_FILE_BASENAME}'"
echo "${NEW_SRC_FILE_CONTENTS}" > "${TEMP_SRC_FILE}"

# Determine compiler to use based on file extension
Expand Down Expand Up @@ -168,13 +168,13 @@ case "${SRC_FILE_BASENAME##*.}" in
esac

# Perform compilation
${CXX} ${CXX_OUTPUT_FLAG}"${TEMP_OUT_FILE}" "${TEMP_SRC_FILE}" || Error 4 "failed to compile '${TEMP_SRC_FILE}' using ${CXX}"
${CXX} ${CXX_OUTPUT_FLAG}"${TEMP_OUT_FILE}" "${TEMP_SRC_FILE}" || Error 4 "failed to compile '${SRC_FILE_BASENAME}' using ${CXX}"

# Optional pre-run commands
eval "${PRERUN}"

# Execute ouput file passing any extra command-line arguments
${VM} "${TEMP_OUT_FILE}" ${@:2} || Error 5 "'${TEMP_SRC_FILE}' failed with exit code $?"
${VM} "${TEMP_OUT_FILE}" ${@:2} || Error 5 "'${SRC_FILE_BASENAME}' failed with exit code $?"

# Optional post-run commands
eval "${POSTRUN}"
Expand Down

0 comments on commit 28cd078

Please sign in to comment.