Skip to content

Commit 38d2efe

Browse files
Address review feedback: improve error handling in script
- Validate --slangc/--repo have values before accessing $2 - Use -x instead of -f to check slangc is executable - Check slangc -version return code - Guard cd with || exit 1 - Handle git clone failure explicitly - Fail if zero shaders compiled (catches upstream breakage) Made-with: Cursor
1 parent e8a9209 commit 38d2efe

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

extras/compile-sascha-willems-shaders.sh

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,18 @@ REPO_DIR=""
4747
while [[ $# -gt 0 ]]; do
4848
case $1 in
4949
--slangc)
50+
if [[ $# -lt 2 ]]; then
51+
echo -e "${RED}Missing value for --slangc${NC}"
52+
exit 1
53+
fi
5054
SLANGC="$2"
5155
shift 2
5256
;;
5357
--repo)
58+
if [[ $# -lt 2 ]]; then
59+
echo -e "${RED}Missing value for --repo${NC}"
60+
exit 1
61+
fi
5462
REPO_DIR="$2"
5563
shift 2
5664
;;
@@ -81,7 +89,7 @@ log_error() { echo -e "${RED}[FAIL]${NC} $1"; }
8189

8290
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
8391
SLANG_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
84-
cd "$SLANG_ROOT"
92+
cd "$SLANG_ROOT" || exit 1
8593

8694
if [ ! -f "CMakeLists.txt" ]; then
8795
log_error "Cannot find Slang repository root"
@@ -102,13 +110,16 @@ if [ -z "$SLANGC" ]; then
102110
done
103111
fi
104112

105-
if [ -z "$SLANGC" ] || [ ! -f "$SLANGC" ]; then
106-
log_error "slangc not found. Build Slang first or pass --slangc PATH"
113+
if [ -z "$SLANGC" ] || [ ! -x "$SLANGC" ]; then
114+
log_error "slangc not found or not executable. Build Slang first or pass --slangc PATH"
107115
exit 1
108116
fi
109117

110118
log_info "Using slangc: $SLANGC"
111-
"$SLANGC" -version
119+
if ! "$SLANGC" -version; then
120+
log_error "Failed to execute slangc at $SLANGC"
121+
exit 1
122+
fi
112123

113124
# Clone or use existing repo
114125
if [ -z "$REPO_DIR" ]; then
@@ -122,7 +133,10 @@ fi
122133

123134
if [ ! -d "$REPO_DIR" ]; then
124135
log_info "Cloning SaschaWillems/Vulkan (shallow)..."
125-
git clone --depth 1 https://github.com/SaschaWillems/Vulkan.git "$REPO_DIR"
136+
if ! git clone --depth 1 https://github.com/SaschaWillems/Vulkan.git "$REPO_DIR"; then
137+
log_error "Failed to clone SaschaWillems/Vulkan into $REPO_DIR"
138+
exit 1
139+
fi
126140
log_success "Cloned to $REPO_DIR"
127141
else
128142
log_info "Using existing clone at $REPO_DIR"
@@ -269,8 +283,12 @@ if [ $skip_known -gt 0 ]; then
269283
echo ""
270284
fi
271285

272-
if [ $success -eq 0 ] && [ $fail -gt 0 ]; then
273-
log_error "All shader compilations failed!"
286+
if [ $success -eq 0 ]; then
287+
if [ $total -eq 0 ]; then
288+
log_error "No .slang files found under $SHADER_DIR"
289+
else
290+
log_error "No shaders compiled successfully"
291+
fi
274292
exit 1
275293
fi
276294

0 commit comments

Comments
 (0)