Skip to content

Commit 62d3c00

Browse files
authored
feat: check_bindings failure message (#117)
1 parent b53f028 commit 62d3c00

1 file changed

Lines changed: 49 additions & 20 deletions

File tree

ffi.nimble

Lines changed: 49 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@ proc runOrQuit(cmd: string) =
4545
echo "error: ", e.msg
4646
quit(QuitFailure)
4747

48+
proc checkBindingsDiff(regenCmd: string, paths: openArray[string]) =
49+
# On a diff, print a remediation hint instead of a bare diff wall. Re-quitting
50+
# non-zero also dodges the nimble ≥2.2.10 exit-0-on-failure footgun (runOrQuit).
51+
try:
52+
exec "git diff --exit-code -- " & paths.join(" ")
53+
except OSError:
54+
echo "Checked-in bindings are stale. Run `" & regenCmd & "` and commit the result."
55+
quit(QuitFailure)
56+
4857
proc sanFlags(san: string): string =
4958
# Each --passC / --passL adds one literal flag to the C compiler / linker
5059
# invocation — avoids any quoting ambiguity that arises from putting
@@ -272,32 +281,52 @@ task genbindings_c_abi_echo, "Generate CBOR-free abi=c C bindings for the echo e
272281
" -o:/dev/null examples/echo/echo.nim"
273282

274283
task check_bindings_rust, "Verify checked-in Rust bindings match Nim source":
275-
exec "nimble genbindings_rust"
276-
exec "git diff --exit-code --" & " examples/timer/rust_bindings/Cargo.toml" &
277-
" examples/timer/rust_bindings/build.rs" & " examples/timer/rust_bindings/src"
284+
runOrQuit "nimble genbindings_rust"
285+
checkBindingsDiff(
286+
"nimble genbindings_rust",
287+
[
288+
"examples/timer/rust_bindings/Cargo.toml",
289+
"examples/timer/rust_bindings/build.rs", "examples/timer/rust_bindings/src",
290+
],
291+
)
278292

279293
task check_bindings_cpp, "Verify checked-in C++ bindings match Nim source":
280-
exec "nimble genbindings_cpp"
281-
exec "nimble genbindings_cpp_echo"
282-
exec "git diff --exit-code --" & " examples/timer/cpp_bindings/my_timer.hpp" &
283-
" examples/timer/cpp_bindings/CMakeLists.txt" &
284-
" examples/echo/cpp_bindings/echo.hpp" & " examples/echo/cpp_bindings/CMakeLists.txt"
294+
runOrQuit "nimble genbindings_cpp"
295+
runOrQuit "nimble genbindings_cpp_echo"
296+
checkBindingsDiff(
297+
"nimble genbindings_cpp && nimble genbindings_cpp_echo",
298+
[
299+
"examples/timer/cpp_bindings/my_timer.hpp",
300+
"examples/timer/cpp_bindings/CMakeLists.txt",
301+
"examples/echo/cpp_bindings/echo.hpp", "examples/echo/cpp_bindings/CMakeLists.txt",
302+
],
303+
)
285304

286305
task check_bindings_c, "Verify checked-in C bindings match Nim source":
287-
exec "nimble genbindings_c"
288-
exec "nimble genbindings_c_echo"
289-
exec "git diff --exit-code --" & " examples/timer/c_bindings/my_timer.h" &
290-
" examples/timer/c_bindings/nim_ffi_prelude.h" &
291-
" examples/timer/c_bindings/nim_ffi_cbor.h" &
292-
" examples/timer/c_bindings/CMakeLists.txt" & " examples/echo/c_bindings/echo.h" &
293-
" examples/echo/c_bindings/nim_ffi_prelude.h" &
294-
" examples/echo/c_bindings/nim_ffi_cbor.h" &
295-
" examples/echo/c_bindings/CMakeLists.txt"
306+
runOrQuit "nimble genbindings_c"
307+
runOrQuit "nimble genbindings_c_echo"
308+
checkBindingsDiff(
309+
"nimble genbindings_c && nimble genbindings_c_echo",
310+
[
311+
"examples/timer/c_bindings/my_timer.h",
312+
"examples/timer/c_bindings/nim_ffi_prelude.h",
313+
"examples/timer/c_bindings/nim_ffi_cbor.h",
314+
"examples/timer/c_bindings/CMakeLists.txt", "examples/echo/c_bindings/echo.h",
315+
"examples/echo/c_bindings/nim_ffi_prelude.h",
316+
"examples/echo/c_bindings/nim_ffi_cbor.h",
317+
"examples/echo/c_bindings/CMakeLists.txt",
318+
],
319+
)
296320

297321
task check_bindings_c_abi, "Verify checked-in abi=c C bindings match Nim source":
298-
exec "nimble genbindings_c_abi_echo"
299-
exec "git diff --exit-code --" & " examples/echo/c_abi_bindings/echo.h" &
300-
" examples/echo/c_abi_bindings/CMakeLists.txt"
322+
runOrQuit "nimble genbindings_c_abi_echo"
323+
checkBindingsDiff(
324+
"nimble genbindings_c_abi_echo",
325+
[
326+
"examples/echo/c_abi_bindings/echo.h",
327+
"examples/echo/c_abi_bindings/CMakeLists.txt",
328+
],
329+
)
301330

302331
task check_bindings, "Verify all checked-in example bindings match Nim source":
303332
exec "nimble check_bindings_rust"

0 commit comments

Comments
 (0)