A CodeRunner language configuration may use a compile script as the first step in the process of running code. When enabled, the compile script is executed before invoking the run command.
If the compile script completes successfully (i.e. exits with a return status of 0), the run continues to the final step which is executing the run command. If a successful run of the compile script produces any output (to stdout), the final line of the output is made available to the run command in the environment variable $compiler
. The compile script and run command are executed in separate shells, so no other state is shared between the two.
A typical compile script does the following:
$CR_FILE
or $CR_FILENAME
, the output file as $CR_SUGGESTED_OUTPUT_FILE
, and additional user-defined compiler flags as ${@:1}
(positional arguments starting from $1).$compiler
variable.#!/bin/sh
clang -o "$CR_SUGGESTED_OUTPUT_FILE" "$CR_FILE" "${@:1}"
status=$?
if [ $status -eq 0 ]; then
echo "$CR_SUGGESTED_OUTPUT_FILE"
fi
exit $status
See environment variables for a list of available variables.