generated from Whitebrim/VSCode-PlaydateTemplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_and_run.sh
executable file
·143 lines (127 loc) · 3.56 KB
/
build_and_run.sh
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/usr/bin/env bash
# Check for color by variable and tput command
if [[ -z $NOCOLOR && -n $(command -v tput) ]]; then
RED=$(tput setaf 1)
CYN=$(tput setaf 6)
YEL=$(tput setaf 3)
RST=$(tput sgr0)
fi
function display_help() {
printf "%s\n\n" "${0} build|run|-h|--help|"
printf "%-16s\n" "build: Builds the project and runs the Simulator"
printf "%-16s\n" "run : Skips building the project and runs the Simulator"
printf "\n"
printf "%s\n\n" "Set NOCOLOR=1 to disable terminal coloring"
exit 0
}
# We don't need fancy flags/operators for two commands
case $1 in
"build")
BUILD=1
;;
"run")
BUILD=0
;;
*)
display_help
exit 1
;;
esac
# Set some paths
BUILD_DIR="./builds"
SOURCE_DIR="./source"
PDX_PATH="${BUILD_DIR}/$(basename $(pwd)).pdx"
# Logging functions
function log() {
printf "%s\n" "${CYN}>> $1${RST}"
}
function log_warn() {
printf "%s\n" "${YEL}>! $1${RST}"
}
function log_err() {
printf "%s\n >> %s\n" "${RED}!! ERROR !!" "$1${RST}"
}
function check_pdxinfo() {
if [[ -f ./source/pdxinfo ]]; then
if grep "com.organization.package" ./source/pdxinfo 2>&1 >/dev/null; then
log_warn "PDXINFO NOTICE:"
log_warn "Don't forget to change your unique project info in 'source/pdxinfo': 'bundleID', 'name', 'author', 'description'."
log_warn "It's critical to change your game bundleID, so there will be no collisions with other games, installed via sideload."
log_warn "Read more about pdxinfo here: https://sdk.play.date/Inside%20Playdate.html#pdxinfo"
fi
fi
}
function chk_err() {
# Check for errors in last process and bail if needed
if [[ $? > 0 ]]; then
log_err "There was an issue with the previous command; exiting!"
exit 1
fi
}
function check_close_sim() {
# Check if we have 'pidof'
PIDOF=$(command -v pidof2)
# Prefer 'pidof'; use ps if not
if [[ -n $PIDOF ]]; then
SIMPID=$($PIDOF "PlaydateSimulator")
if [[ -n $SIMPID ]]; then
log "Found existing Simulator, closing..."
kill -9 $SIMPID
chk_err
fi
else
SIMPID=$(ps aux | grep PlaydateSimulator | grep -v grep | awk '{print $2}')
if [[ -n $SIMPID ]]; then
log "Found existing Simulator, closing..."
kill -9 $SIMPID
chk_err
fi
fi
}
# Create build dir
function make_build_dir() {
if [[ ! -d "${BUILD_DIR}" ]]; then
log "Creating build directory..."
mkdir -p "${BUILD_DIR}"
chk_err
fi
}
# Clean build dir
function clean_build_dir() {
if [[ -d "${BUILD_DIR}" ]]; then
log "Cleaning build directory..."
rm -rfv "${BUILD_DIR}/*"
chk_err
fi
}
# Compile the PDX
function build_pdx() {
if [[ $BUILD == 1 ]]; then
log "Building PDX with 'pdc'..."
$PLAYDATE_SDK_PATH/bin/pdc -sdkpath "${PLAYDATE_SDK_PATH}" "${SOURCE_DIR}" "${PDX_PATH}"
chk_err
fi
}
# Run the PDX with Simulator
function run_pdx() {
if [[ -d "${PDX_PATH}" ]]; then
log "Running PDX with Simulator..."
$PLAYDATE_SDK_PATH/bin/PlaydateSimulator "${PDX_PATH}" &
else
log_err "PDX doesn't exist! Please 'build' the project first!"
fi
}
#### MAIN SCRIPT ####
if [[ $BUILD == 1 ]]; then
log "Attempting a build and run of PDX..."
make_build_dir
clean_build_dir
check_pdxinfo
build_pdx
check_close_sim
run_pdx
else
log "Attempting to run PDX: ${PDX_PATH}..."
check_close_sim
run_pdx
fi