diff --git a/rust/extractor/src/archive.rs b/rust/extractor/src/archive.rs index cc1587ca957..248c0e85d9d 100644 --- a/rust/extractor/src/archive.rs +++ b/rust/extractor/src/archive.rs @@ -1,4 +1,4 @@ -use crate::path; +use codeql_extractor::file_paths; use log::{debug, warn}; use std::fs; use std::path::{Path, PathBuf}; @@ -15,12 +15,11 @@ impl Archiver { } fn try_archive(&self, source: &Path) -> std::io::Result<()> { - let mut dest = self.root.clone(); - dest.push(path::key(source)); - let parent = dest.parent().unwrap(); + let dest = file_paths::path_for(&self.root, source, ""); if fs::metadata(&dest).is_ok() { return Ok(()); } + let parent = dest.parent().unwrap(); fs::create_dir_all(parent)?; fs::copy(source, dest)?; debug!("archived {}", source.display()); diff --git a/rust/extractor/src/main.rs b/rust/extractor/src/main.rs index 8d1bcc98ab6..f1ddbdf4894 100644 --- a/rust/extractor/src/main.rs +++ b/rust/extractor/src/main.rs @@ -11,7 +11,6 @@ use std::path::PathBuf; mod archive; mod config; pub mod generated; -pub mod path; mod translate; pub mod trap; diff --git a/rust/extractor/src/path.rs b/rust/extractor/src/path.rs deleted file mode 100644 index 0da1cb2932f..00000000000 --- a/rust/extractor/src/path.rs +++ /dev/null @@ -1,10 +0,0 @@ -use std::fs::canonicalize; -use std::path::{absolute, Path, PathBuf}; - -pub fn key(p: &Path) -> PathBuf { - let normalized = canonicalize(p) - .or_else(|_| absolute(p)) - .unwrap_or_else(|_| p.into()); - let root = normalized.ancestors().last().unwrap(); // ancestors always yields at least one - normalized.strip_prefix(root).unwrap().into() // stripping an ancestor always works -} diff --git a/rust/extractor/src/trap.rs b/rust/extractor/src/trap.rs index f01aaebe5a8..6ad1742557d 100644 --- a/rust/extractor/src/trap.rs +++ b/rust/extractor/src/trap.rs @@ -1,9 +1,8 @@ +use crate::config; use crate::config::Compression; -use crate::{config, path}; -use codeql_extractor::{extractor, trap}; +use codeql_extractor::{extractor, file_paths, trap}; use log::debug; use ra_ap_ide_db::line_index::LineCol; -use std::ffi::OsString; use std::fmt::Debug; use std::hash::Hash; use std::marker::PhantomData; @@ -12,7 +11,6 @@ use std::path::{Path, PathBuf}; pub use trap::Label as UntypedLabel; pub use trap::Writer; -//TODO: typed labels pub trait AsTrapKeyPart { fn as_key_part(&self) -> String; } @@ -210,19 +208,8 @@ impl TrapFileProvider { } pub fn create(&self, category: &str, key: &Path) -> TrapFile { - let mut path = PathBuf::from(category); - path.push(path::key(key)); - path.set_extension( - path.extension() - .map(|e| { - let mut o: OsString = e.to_owned(); - o.push(".trap"); - o - }) - .unwrap_or("trap".into()), - ); + let path = file_paths::path_for(&self.trap_dir.join(category), key, ".trap"); debug!("creating trap file {}", path.display()); - path = self.trap_dir.join(path); let mut writer = trap::Writer::new(); extractor::populate_empty_location(&mut writer); TrapFile { diff --git a/rust/lint.py b/rust/lint.py index eb71cbd0b3d..3a231c157df 100755 --- a/rust/lint.py +++ b/rust/lint.py @@ -12,7 +12,7 @@ assert cargo, "no cargo binary found on `PATH`" fmt = subprocess.run([cargo, "fmt", "--all", "--quiet"], cwd=this_dir) for manifest in this_dir.rglob("Cargo.toml"): - if not manifest.is_relative_to(this_dir / "ql"): + if not manifest.is_relative_to(this_dir / "ql") and not manifest.is_relative_to(this_dir / "integration-tests"): clippy = subprocess.run([cargo, "clippy", "--fix", "--allow-dirty", "--allow-staged", "--quiet"], cwd=manifest.parent) sys.exit(fmt.returncode or clippy.returncode)