File: join.rs

package info (click to toggle)
rust-rawler 0.7.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,460 kB
  • sloc: makefile: 2
file content (73 lines) | stat: -rw-r--r-- 2,388 bytes parent folder | download
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
use std::env;
use std::fs::File;
use std::io::prelude::*;
use std::path::Path;

extern crate glob;
use self::glob::glob;
extern crate toml;
use toml::Value;
extern crate rustc_version;
use rustc_version::{Version, version};

fn main() {
  join_cameras();
  join_lenses();
}

fn join_cameras() {
  let out_dir = env::var("OUT_DIR").expect("Missing ENV OUT_DIR");
  let dest_path = Path::new(&out_dir).join("cameras.toml");
  let mut out = File::create(dest_path).expect("Unable to create output file");

  for entry in glob("./data/cameras/*/**/*.toml").expect("Failed to read glob pattern") {
    out.write_all(b"[[cameras]]\n").expect("Failed to write camera TOML");
    let path = entry.expect("Invalid glob entry");
    let mut f = File::open(&path).expect("failed to open camera definition file");
    let mut toml = String::new();
    f.read_to_string(&mut toml).expect("Failed to read camera definition file");

    {
      match toml.parse::<Value>() {
        Ok(_) => {}
        Err(e) => panic!("Error parsing {:?}: {:?}", path, e),
      };
    }

    out.write_all(&toml.into_bytes()).expect("Failed to write");
    out.write_all(b"\n").expect("Failed to write");
  }

  // Check for a minimum version
  if version().expect("version failed") < Version::parse("1.31.0").expect("version parse failed") {
    println!("cargo:rustc-cfg=needs_chunks_exact");
  }
}

fn join_lenses() {
  let out_dir = env::var("OUT_DIR").expect("Missing ENV OUT_DIR");
  let dest_path = Path::new(&out_dir).join("lenses.toml");
  let mut out = File::create(dest_path).expect("Unable to create output file");

  for entry in glob("./data/lenses/*/**/*.toml").expect("Failed to read glob pattern") {
    let path = entry.expect("Invalid glob entry");
    let mut f = File::open(&path).expect("failed to open lens definition file");
    let mut toml = String::new();
    f.read_to_string(&mut toml).expect("Failed to read lens definition file");

    {
      match toml.parse::<Value>() {
        Ok(_) => {}
        Err(e) => panic!("Error parsing {:?}: {:?}", path, e),
      };
    }

    out.write_all(&toml.into_bytes()).expect("Failed to write");
    out.write_all(b"\n").expect("Failed to write");
  }

  // Check for a minimum version
  if version().expect("version failed") < Version::parse("1.31.0").expect("version parse failed") {
    println!("cargo:rustc-cfg=needs_chunks_exact");
  }
}