summaryrefslogtreecommitdiff
path: root/subplotlib/build.rs
blob: 5f948831dc4261af4fc0ea9b2a06e7cd4a389fbe (plain)
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
// Build script for subplotlib.
//
// We use the `subplot_build` crate to generate a Rust test code file
// with functions for the scenarios for each subplot file
// (subplot/*.md in the source tree). The generated file is written to
// the Cargo target directory. For each subplot foo.md there should be
// a tests/foo.rs in the source tree, which includes the generated
// file from the Cargo target tree. The source file should look like this:
//
// ```rust
// include!(concat!(env!("OUT_DIR"), "/foo.rs"));
// ```

use glob::glob;
use std::path::Path;

fn main() {
    let subplots = glob("*.md").expect("failed to find subplots in subplotlib");
    let tests = Path::new("tests");
    for entry in subplots {
        let entry = entry.expect("failed to get subplot dir entry in subplotlib");
        let mut inc = tests.join(&entry);
        inc.set_extension("rs");
        if !inc.exists() {
            panic!("missing include file: {}", inc.display());
        }
        println!("cargo:rerun-if-changed={}", inc.display());
        subplot_build::codegen(Path::new(&entry)).expect("failed to generate code with Subplot");
    }
}