<commit_before>use std::env;
use std::fs;
use std::path::Path;
use std::io::BufWriter;
use std::io::Write;

fn main() {
    let out_dir = env::var("OUT_DIR").unwrap();
    let dest = Path::new(&out_dir);

    let base = Path::new("assets");
    let mut out = Vec::new();
    build_map(&mut out, &base);

    let mut file = BufWriter::new(fs::File::create(&dest.join("resources.rs")).unwrap());
    write!(file, "pub fn get_file(name: &str) -> Option<&'static [u8]> {{\n").unwrap();
    write!(file, "    match name {{\n").unwrap();
    for entry in &out {
    	let entry = entry.replace("\\", "/");
    	let short = &entry;
    	write!(file, "        {:?} => Some(include_bytes!(\"../{}\")),\n", short, entry).unwrap();
    }
    write!(file, "        _ => None\n    }}\n}}\n").unwrap();

}

fn build_map(out: &mut Vec<String>, path: &Path) {
    let files = fs::read_dir(path).unwrap();
    for entry in files {
    	let entry = entry.unwrap();
    	if fs::metadata(entry.path()).unwrap().is_dir() {
    		build_map(out, &entry.path());
    	} else {
    		out.push(entry.path().to_str().unwrap().to_owned());
    	}
    }
}<commit_msg>Use absolute paths when including resources. (Fixes #53)<commit_after>use std::env;
use std::fs;
use std::path::{Path, PathBuf};
use std::io::BufWriter;
use std::io::Write;

fn main() {
    let out_dir = env::var("OUT_DIR").unwrap();
    let dest = Path::new(&out_dir);

    let base = Path::new("assets");
    let mut out = Vec::new();
    build_map(&mut out, &base);

    let mut file = BufWriter::new(fs::File::create(&dest.join("resources.rs")).unwrap());
    write!(file, "pub fn get_file(name: &str) -> Option<&'static [u8]> {{\n").unwrap();
    write!(file, "    match name {{\n").unwrap();
    for path in &out {
        let mut absolute_path = std::env::current_dir().unwrap();
        absolute_path.push(path);

        let absolute = absolute_path.to_str().unwrap().replace("\\", "/");
        let relative = path.to_str().unwrap().replace("\\", "/");

        write!(file, "        {:?} => Some(include_bytes!(\"{}\")),\n", relative, absolute).unwrap();
    }
    write!(file, "        _ => None\n    }}\n}}\n").unwrap();

}

fn build_map(out: &mut Vec<PathBuf>, path: &Path) {
    let files = fs::read_dir(path).unwrap();
    for entry in files {
        let entry = entry.unwrap();
        if fs::metadata(entry.path()).unwrap().is_dir() {
            build_map(out, &entry.path());
        } else {
            out.push(entry.path());
        }
    }
}
{'fraction_non_alphanumeric': 0.22523961661341854, 'fraction_numerical': 0.001597444089456869, 'mean_word_length': 3.027331189710611, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7276100', 'n_tokens_mistral': 871, 'n_tokens_neox': 872, 'n_words': 179}