mirror of
https://github.com/crate-ci/typos.git
synced 2024-11-22 09:01:04 -05:00
refactor(dict): Speed up build times by caching codegen
This commit is contained in:
parent
caaadb01a8
commit
23faf30f24
8 changed files with 36073 additions and 424 deletions
|
@ -12,6 +12,12 @@ matrix:
|
||||||
- rustup component add rustfmt
|
- rustup component add rustfmt
|
||||||
script:
|
script:
|
||||||
- cargo fmt --all -- --check
|
- cargo fmt --all -- --check
|
||||||
|
- env: CodeGen
|
||||||
|
rust: 1.35.0 # `stable`: Locking down for consistent behavior
|
||||||
|
install:
|
||||||
|
- rustup component add rustfmt
|
||||||
|
script:
|
||||||
|
- cargo run --package typos-codegen -- --input typos-dict/assets/words.csv --output typos-dict/src/dict_codegen.rs --check
|
||||||
- env: RUSTFLAGS="-D warnings"
|
- env: RUSTFLAGS="-D warnings"
|
||||||
rust: 1.35.0 # `stable`: Locking down for consistent behavior
|
rust: 1.35.0 # `stable`: Locking down for consistent behavior
|
||||||
install:
|
install:
|
||||||
|
|
755
Cargo.lock
generated
755
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -1,5 +1,5 @@
|
||||||
[workspace]
|
[workspace]
|
||||||
members = ["typos", "typos-dict"]
|
members = ["codegen", "typos", "typos-dict"]
|
||||||
|
|
||||||
[package]
|
[package]
|
||||||
name = "typos-cli"
|
name = "typos-cli"
|
||||||
|
|
24
codegen/Cargo.toml
Normal file
24
codegen/Cargo.toml
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
[package]
|
||||||
|
name = "typos-codegen"
|
||||||
|
version = "1.0.0"
|
||||||
|
authors = ["Ed Page <eopage@gmail.com>"]
|
||||||
|
description = "Source Code Spelling Correction"
|
||||||
|
repository = "https://github.com/crate-ci/imperative"
|
||||||
|
documentation = "https://docs.rs/imperative"
|
||||||
|
readme = "README.md"
|
||||||
|
categories = ["text-processing"]
|
||||||
|
license = "MIT"
|
||||||
|
edition = "2018"
|
||||||
|
publish = false
|
||||||
|
|
||||||
|
[badges]
|
||||||
|
travis-ci = { repository = "epage/typos" }
|
||||||
|
appveyor = { repository = "epage/typos" }
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
phf = { version = "0.7", features = ["unicase"] }
|
||||||
|
phf_codegen = "0.7"
|
||||||
|
csv = "1.0"
|
||||||
|
unicase = "1.1"
|
||||||
|
codegenrs = "0.1"
|
||||||
|
structopt = "0.3"
|
62
codegen/src/main.rs
Normal file
62
codegen/src/main.rs
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
use structopt::StructOpt;
|
||||||
|
|
||||||
|
fn generate<W: std::io::Write>(input: &[u8], file: &mut W) {
|
||||||
|
writeln!(
|
||||||
|
file,
|
||||||
|
"// This file is code-genned by {}",
|
||||||
|
env!("CARGO_PKG_NAME")
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
writeln!(file).unwrap();
|
||||||
|
writeln!(file, "use unicase::UniCase;").unwrap();
|
||||||
|
|
||||||
|
writeln!(
|
||||||
|
file,
|
||||||
|
"pub(crate) static WORD_DICTIONARY: phf::Map<unicase::UniCase<&'static str>, &'static str> = "
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
let mut builder = phf_codegen::Map::new();
|
||||||
|
let records: Vec<_> = csv::Reader::from_reader(input)
|
||||||
|
.records()
|
||||||
|
.map(|r| r.unwrap())
|
||||||
|
.collect();
|
||||||
|
for record in &records {
|
||||||
|
let value = format!(r#""{}""#, &record[1]);
|
||||||
|
builder.entry(unicase::UniCase(&record[0]), &value);
|
||||||
|
}
|
||||||
|
builder.build(file).unwrap();
|
||||||
|
writeln!(file, ";").unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, StructOpt)]
|
||||||
|
#[structopt(rename_all = "kebab-case")]
|
||||||
|
struct Options {
|
||||||
|
#[structopt(long, parse(from_os_str))]
|
||||||
|
input: std::path::PathBuf,
|
||||||
|
#[structopt(flatten)]
|
||||||
|
codegen: codegenrs::CodeGenArgs,
|
||||||
|
#[structopt(flatten)]
|
||||||
|
rustmft: codegenrs::RustfmtArgs,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run() -> Result<i32, Box<dyn std::error::Error>> {
|
||||||
|
let options = Options::from_args();
|
||||||
|
|
||||||
|
let content = {
|
||||||
|
let mut content = vec![];
|
||||||
|
let input = std::fs::read(&options.input)?;
|
||||||
|
generate(&input, &mut content);
|
||||||
|
content
|
||||||
|
};
|
||||||
|
|
||||||
|
let content = String::from_utf8(content)?;
|
||||||
|
let content = options.rustmft.reformat(&content)?;
|
||||||
|
options.codegen.write_str(&content)?;
|
||||||
|
|
||||||
|
Ok(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let code = run().unwrap();
|
||||||
|
std::process::exit(code);
|
||||||
|
}
|
|
@ -24,8 +24,3 @@ typos = { version = "0.1", path = "../typos" }
|
||||||
phf = { version = "0.7", features = ["unicase"] }
|
phf = { version = "0.7", features = ["unicase"] }
|
||||||
unicase = "1.1"
|
unicase = "1.1"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
|
|
||||||
[build-dependencies]
|
|
||||||
phf_codegen = "0.7"
|
|
||||||
csv = "1.0"
|
|
||||||
unicase = "1.1"
|
|
||||||
|
|
|
@ -1,33 +0,0 @@
|
||||||
use std::env;
|
|
||||||
use std::fs::File;
|
|
||||||
use std::io::{BufWriter, Write};
|
|
||||||
use std::path::Path;
|
|
||||||
|
|
||||||
pub const CORPUS: &[u8] = include_bytes!("./assets/words.csv");
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
let path = Path::new(&env::var("OUT_DIR").unwrap()).join("codegen.rs");
|
|
||||||
let mut file = BufWriter::new(File::create(&path).unwrap());
|
|
||||||
|
|
||||||
println!("rerun-if-changed=./assets/words.csv");
|
|
||||||
write!(&mut file, "use unicase::UniCase;").unwrap();
|
|
||||||
|
|
||||||
write!(
|
|
||||||
&mut file,
|
|
||||||
"pub(crate) static WORD_DICTIONARY: phf::Map<unicase::UniCase<&'static str>, &'static str> = "
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
let mut builder = phf_codegen::Map::new();
|
|
||||||
let records: Vec<_> = csv::Reader::from_reader(CORPUS)
|
|
||||||
.records()
|
|
||||||
.map(|r| r.unwrap())
|
|
||||||
.collect();
|
|
||||||
for record in &records {
|
|
||||||
let value = format!(r#""{}""#, &record[1]);
|
|
||||||
builder.entry(unicase::UniCase(&record[0]), &value);
|
|
||||||
#[cfg(features = "iterate_unstable")]
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
builder.build(&mut file).unwrap();
|
|
||||||
write!(&mut file, ";\n").unwrap();
|
|
||||||
}
|
|
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue