-
Notifications
You must be signed in to change notification settings - Fork 1
/
run
executable file
·85 lines (70 loc) · 1.51 KB
/
run
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#! /bin/bash
# Runs a target solution file, compiling if necessary.
#
# Supports:
# - JavaScript
# - Python
# - C
# - Rust
# - Clojure
#
# Example:
# ./run 01-some-puzzle/1.c
SOLUTION_PATH="$1"
if [ -z SOLUTION_PATH ]; then
echo "Must provide a path to a solution file!"
exit 1
fi
SOLUTION_NAME="$(basename "$1")"
SOLUTION_NAME="${SOLUTION_NAME%.*}"
SOLUTION_EXTENSION="${1##*.}"
SOLUTION_DIR="$(dirname "$1")"
BUILD_DIR="$SOLUTION_DIR/build"
## Utilities ##
function make_build_dir {
if [ ! -d "$BUILD_DIR" ]; then
mkdir "$BUILD_DIR"
fi
if [ -n $1 ]; then
if [ ! -d "$BUILD_DIR/$1" ]; then
mkdir "$BUILD_DIR/$1"
fi
fi
}
## Runners ##
function run_js {
npm start "$SOLUTION_PATH"
}
function run_py {
python "$SOLUTION_PATH"
}
function run_c {
local BUILD_PATH="$BUILD_DIR/c/$SOLUTION_NAME"
make_build_dir c
gcc "$SOLUTION_PATH" -o "$BUILD_PATH"
"./$BUILD_PATH"
}
function run_rs {
local BUILD_PATH="$BUILD_DIR/rs/$SOLUTION_NAME"
make_build_dir rs
rustc "$SOLUTION_PATH" -o "$BUILD_PATH"
"./$BUILD_PATH"
}
function run_clj {
clj -M "$SOLUTION_PATH"
}
## Run Solution ##
if [ $SOLUTION_EXTENSION == 'js' ]; then
run_js
elif [ $SOLUTION_EXTENSION == 'py' ]; then
run_py
elif [ $SOLUTION_EXTENSION == 'c' ]; then
run_c
elif [ $SOLUTION_EXTENSION == 'rs' ]; then
run_rs
elif [ $SOLUTION_EXTENSION == 'clj' ]; then
run_clj
else
echo "File type not supported: .$SOLUTION_EXTENSION"
exit 1
fi