mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
Rust: use shared path utilities
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
use crate::path;
|
use codeql_extractor::file_paths;
|
||||||
use log::{debug, warn};
|
use log::{debug, warn};
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
@@ -15,12 +15,11 @@ impl Archiver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn try_archive(&self, source: &Path) -> std::io::Result<()> {
|
fn try_archive(&self, source: &Path) -> std::io::Result<()> {
|
||||||
let mut dest = self.root.clone();
|
let dest = file_paths::path_for(&self.root, source, "");
|
||||||
dest.push(path::key(source));
|
|
||||||
let parent = dest.parent().unwrap();
|
|
||||||
if fs::metadata(&dest).is_ok() {
|
if fs::metadata(&dest).is_ok() {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
let parent = dest.parent().unwrap();
|
||||||
fs::create_dir_all(parent)?;
|
fs::create_dir_all(parent)?;
|
||||||
fs::copy(source, dest)?;
|
fs::copy(source, dest)?;
|
||||||
debug!("archived {}", source.display());
|
debug!("archived {}", source.display());
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ use std::path::PathBuf;
|
|||||||
mod archive;
|
mod archive;
|
||||||
mod config;
|
mod config;
|
||||||
pub mod generated;
|
pub mod generated;
|
||||||
pub mod path;
|
|
||||||
mod translate;
|
mod translate;
|
||||||
pub mod trap;
|
pub mod trap;
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
|
||||||
}
|
|
||||||
@@ -1,9 +1,8 @@
|
|||||||
|
use crate::config;
|
||||||
use crate::config::Compression;
|
use crate::config::Compression;
|
||||||
use crate::{config, path};
|
use codeql_extractor::{extractor, file_paths, trap};
|
||||||
use codeql_extractor::{extractor, trap};
|
|
||||||
use log::debug;
|
use log::debug;
|
||||||
use ra_ap_ide_db::line_index::LineCol;
|
use ra_ap_ide_db::line_index::LineCol;
|
||||||
use std::ffi::OsString;
|
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
@@ -12,7 +11,6 @@ use std::path::{Path, PathBuf};
|
|||||||
pub use trap::Label as UntypedLabel;
|
pub use trap::Label as UntypedLabel;
|
||||||
pub use trap::Writer;
|
pub use trap::Writer;
|
||||||
|
|
||||||
//TODO: typed labels
|
|
||||||
pub trait AsTrapKeyPart {
|
pub trait AsTrapKeyPart {
|
||||||
fn as_key_part(&self) -> String;
|
fn as_key_part(&self) -> String;
|
||||||
}
|
}
|
||||||
@@ -210,19 +208,8 @@ impl TrapFileProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn create(&self, category: &str, key: &Path) -> TrapFile {
|
pub fn create(&self, category: &str, key: &Path) -> TrapFile {
|
||||||
let mut path = PathBuf::from(category);
|
let path = file_paths::path_for(&self.trap_dir.join(category), key, ".trap");
|
||||||
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()),
|
|
||||||
);
|
|
||||||
debug!("creating trap file {}", path.display());
|
debug!("creating trap file {}", path.display());
|
||||||
path = self.trap_dir.join(path);
|
|
||||||
let mut writer = trap::Writer::new();
|
let mut writer = trap::Writer::new();
|
||||||
extractor::populate_empty_location(&mut writer);
|
extractor::populate_empty_location(&mut writer);
|
||||||
TrapFile {
|
TrapFile {
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ assert cargo, "no cargo binary found on `PATH`"
|
|||||||
|
|
||||||
fmt = subprocess.run([cargo, "fmt", "--all", "--quiet"], cwd=this_dir)
|
fmt = subprocess.run([cargo, "fmt", "--all", "--quiet"], cwd=this_dir)
|
||||||
for manifest in this_dir.rglob("Cargo.toml"):
|
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"],
|
clippy = subprocess.run([cargo, "clippy", "--fix", "--allow-dirty", "--allow-staged", "--quiet"],
|
||||||
cwd=manifest.parent)
|
cwd=manifest.parent)
|
||||||
sys.exit(fmt.returncode or clippy.returncode)
|
sys.exit(fmt.returncode or clippy.returncode)
|
||||||
|
|||||||
Reference in New Issue
Block a user