Skip to main content

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, SkewAsker, skew_gate};
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        // #1675: a second compiler, so its skew from the driver is acted on.
23        let asker = SkewAsker {
24            command: Some("check"),
25            has_flag: false,
26        };
27        if !skew_gate(compiler, asker, false) {
28            return ExitCode::FAILURE;
29        }
30        return crate::shell::delegate(
31            bynkc,
32            [
33                "check".as_ref(),
34                input.as_os_str(),
35                "--format".as_ref(),
36                format.as_bynkc_arg().as_ref(),
37            ],
38        );
39    }
40    check_in_process(&input, format)
41}
42
43/// The default path: the shared command body (#521, [`bynk_driver::run_check`]).
44fn check_in_process(input: &Path, format: CheckFormatArg) -> ExitCode {
45    bynk_driver::run_check("bynk", input, format == CheckFormatArg::Short)
46}