bynk/check.rs
1//! `bynk check` — type-check a `.bynk` file or project without writing output.
2//!
3//! Runs the linked pipeline in-process (v0.138, #487): a directory routes
4//! through [`bynk_emit::project::compile_project`], a single file through
5//! [`bynk_emit::compile_with_warnings`] — exactly `bynkc check`'s two branches, so the
6//! output is identical. The escape hatch matches `bynk dev`: when the driver
7//! resolved `bynkc` via a `BYNK_BYNKC` override, the pinned compiler is shelled
8//! instead so an externally-managed toolchain still governs the result.
9
10use std::path::{Path, PathBuf};
11use std::process::ExitCode;
12
13use crate::cli::CheckFormatArg;
14use crate::compiler::{Compiler, Origin};
15
16/// Run `bynk check`. `compiler` carries the driver's resolution so an override
17/// can be honoured by shelling the pinned `bynkc`.
18pub fn run(compiler: &Compiler, input: PathBuf, format: CheckFormatArg) -> ExitCode {
19 // Escape hatch (mirrors `bynk dev`): a `BYNK_BYNKC` override pins an external
20 // compiler, so `check` shells *that* `bynkc` rather than the linked pipeline.
21 if let (Some(Origin::Override), Some(bynkc)) = (compiler.origin, compiler.path.as_deref()) {
22 return crate::shell::delegate(
23 bynkc,
24 [
25 "check".as_ref(),
26 input.as_os_str(),
27 "--format".as_ref(),
28 format.as_bynkc_arg().as_ref(),
29 ],
30 );
31 }
32 check_in_process(&input, format)
33}
34
35/// The default path: the shared command body (#521, [`bynk_driver::run_check`]).
36fn check_in_process(input: &Path, format: CheckFormatArg) -> ExitCode {
37 bynk_driver::run_check("bynk", input, format == CheckFormatArg::Short)
38}