Skip to content

Commit

Permalink
Generalize the use of camino instead of std::path
Browse files Browse the repository at this point in the history
  • Loading branch information
Krusty/Benediction committed Aug 3, 2024
1 parent be6ad2f commit ead6904
Show file tree
Hide file tree
Showing 67 changed files with 276 additions and 296 deletions.
39 changes: 24 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ bitflags = "2.6.0"
bitvec = "1.0.1"
built = { version = "0.7.4", features = ["chrono"] }
camino = "1.1.7"
camino-tempfile = "1.1.1"
cc = "1.1.7"
cfg-if = "1.0.0"
chardetng = { version = "0.1.17", features = ["multithreading"] }
Expand Down Expand Up @@ -155,7 +156,6 @@ strsim = "0.11.1"
subprocess = { version = "0.2.9" }
substring = "1.4.5"
syn = "2.0.72"
tempfile = "3.10.1"
term_grid = { version = "0.2.0" }
termize = { version = "0.1.1" }
test-generator = "0.3.1"
Expand Down
3 changes: 1 addition & 2 deletions cpclib-asm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ cpclib-image.workspace = true

arrayref.workspace = true
assert_matches.workspace = true
camino.workspace = true
camino-tempfile.workspace = true
cfg-if.workspace = true
choice_nocase.workspace = true
codespan-reporting.workspace = true
Expand All @@ -47,7 +47,6 @@ rust-embed = { workspace = true, features = ["compression", "debug-embed"] }
serde = { workspace = true, features = ["derive"] }
smartstring.workspace = true
substring.workspace = true
tempfile.workspace = true
velcro.workspace = true

rayon-cond = {version="0.3.0", optional= true}
Expand Down
2 changes: 1 addition & 1 deletion cpclib-asm/src/assembler/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::collections::VecDeque;
use std::fs::File;
use std::io::Read;

use camino::{Utf8Path, Utf8PathBuf};
use cpclib_common::camino::{Utf8Path, Utf8PathBuf};
use cpclib_disc::amsdos::AmsdosHeader;
use either::Either;

Expand Down
6 changes: 3 additions & 3 deletions cpclib-asm/src/assembler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ use std::ops::{Deref, Neg};
use std::sync::{Arc, RwLock};
use std::time::Instant;

use camino::{Utf8Path, Utf8PathBuf};
use cpclib_basic::*;
use cpclib_common::bitvec::prelude::BitVec;
use cpclib_common::camino::{Utf8Path, Utf8PathBuf};
use cpclib_common::itertools::Itertools;
use cpclib_common::smallvec::SmallVec;
use cpclib_common::smol_str::SmolStr;
Expand Down Expand Up @@ -1746,11 +1746,11 @@ impl Env {
self.sna_version
}

pub fn save_sna<P: AsRef<std::path::Path>>(&self, fname: P) -> Result<(), std::io::Error> {
pub fn save_sna<P: AsRef<Utf8Path>>(&self, fname: P) -> Result<(), std::io::Error> {
self.sna().save(fname, self.sna_version())
}

pub fn save_cpr<P: AsRef<std::path::Path>>(&self, fname: P) -> Result<(), AssemblerError> {
pub fn save_cpr<P: AsRef<Utf8Path>>(&self, fname: P) -> Result<(), AssemblerError> {
let cpr_asm = self.cpr.as_ref().unwrap();
let cpr = cpr_asm.build_cpr()?;
cpr.save(fname)
Expand Down
2 changes: 1 addition & 1 deletion cpclib-asm/src/assembler/processed_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::fmt::{Debug, Formatter};
use std::ops::Deref;
use std::sync::Arc;

use camino::Utf8PathBuf;
use cpclib_common::camino::Utf8PathBuf;
use cpclib_common::itertools::Itertools;
#[cfg(all(not(target_arch = "wasm32"), feature = "rayon"))]
use cpclib_common::rayon::prelude::*;
Expand Down
2 changes: 1 addition & 1 deletion cpclib-asm/src/assembler/report.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::fmt::Display;
use std::time::Instant;

use camino::Utf8PathBuf;
use cpclib_common::camino::Utf8PathBuf;
use cpclib_common::itertools::Itertools;

use super::Env;
Expand Down
2 changes: 1 addition & 1 deletion cpclib-asm/src/assembler/save_command.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::convert::TryFrom;

use camino::Utf8PathBuf;
use cpclib_common::camino::Utf8PathBuf;
use cpclib_disc::amsdos::{AmsdosFile, AmsdosFileName};
use cpclib_disc::disc::Disc;
use cpclib_disc::edsk::Head;
Expand Down
2 changes: 1 addition & 1 deletion cpclib-asm/src/implementation/listing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::borrow::Borrow;
use std::collections::HashMap;
use std::fmt;

use camino::Utf8Path;
use cpclib_common::camino::Utf8Path;
use cpclib_tokens::tokens::*;

use crate::error::*;
Expand Down
1 change: 1 addition & 0 deletions cpclib-asm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#![feature(slice_take)]
#![feature(write_all_vectored)]

// mod rewrite;
/// Implementation of various behavior for the tokens of cpclib_tokens
pub mod implementation;

Expand Down
21 changes: 12 additions & 9 deletions cpclib-asm/src/parser/context.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::borrow::{Borrow, Cow};
use std::collections::HashSet;
use std::ops::Deref;
use std::path::{Path, PathBuf};
use std::path::PathBuf;
use std::sync::{LazyLock, RwLock};

use camino::{Utf8Path, Utf8PathBuf};
use cpclib_common::camino::{Utf8Path, Utf8PathBuf};
use cpclib_common::winnow::BStr;
use either::Either;
use regex::Regex;
Expand Down Expand Up @@ -356,12 +356,11 @@ impl ParserOptions {
return Ok(current_path);
}
else {
let glob =
GlobBuilder::new(current_path.as_path().as_str())
.case_insensitive(true)
.literal_separator(true)
.build()
.unwrap();
let glob = GlobBuilder::new(current_path.as_path().as_str())
.case_insensitive(true)
.literal_separator(true)
.build()
.unwrap();
let matcher = glob.compile_matcher();

for entry in std::fs::read_dir(search).unwrap() {
Expand Down Expand Up @@ -487,7 +486,11 @@ impl ParserContext {
#[inline]
pub fn set_current_filename<P: Into<Utf8PathBuf>>(&mut self, file: P) {
let file = file.into();
self.current_filename = Some(file.canonicalize().map(|p| Utf8PathBuf::from_path_buf(p).unwrap()).unwrap_or(file))
self.current_filename = Some(
file.canonicalize()
.map(|p| Utf8PathBuf::from_path_buf(p).unwrap())
.unwrap_or(file)
)
}

#[inline]
Expand Down
2 changes: 1 addition & 1 deletion cpclib-asm/src/progress.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use core::time::Duration;
use std::sync::{Arc, LazyLock, Mutex, MutexGuard};

use camino::Utf8Path;
use cpclib_common::camino::Utf8Path;
use cpclib_common::itertools::Itertools;
#[cfg(feature = "indicatif")]
use indicatif::{MultiProgress, ProgressBar, ProgressStyle};
Expand Down
3 changes: 0 additions & 3 deletions cpclib-basic/build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
use std::env;
use std::path::Path;

fn main() {
built::write_built_file().expect("Failed to acquire build-time information");
}
3 changes: 1 addition & 2 deletions cpclib-basic/src/bin/locomotive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

use std::fs::File;
use std::io::{Read, Write};
use std::path::PathBuf;

use cpclib_basic::{binary_parser, BasicProgram};
use cpclib_common::clap;
Expand All @@ -32,7 +31,7 @@ fn main() -> std::io::Result<()> {
.short('b')
.help("Amstrad basic file")
.action(ArgAction::Set)
.value_parser(clap::value_parser!(PathBuf))
.value_parser(cpclib_common::utf8pathbuf_value_parser(true))
.required_unless_present("BASIC_SOURCE")
)
.arg(
Expand Down
3 changes: 1 addition & 2 deletions cpclib-basm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@ cpclib-xfer = {workspace=true, default-features=false, optional=true}
cpclib-disc.workspace = true


camino.workspace = true
const_format.workspace = true
diff = "0.1.13"
parking_lot.workspace = true
time.workspace = true

[dev-dependencies]
test-generator.workspace = true
tempfile.workspace = true
camino-tempfile.workspace = true
pretty_assertions.workspace = true
criterion.workspace = true
globset.workspace = true
Expand Down
Loading

0 comments on commit ead6904

Please sign in to comment.