Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions clang-tools-manager/src/downloader/hashing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,25 @@ use std::{fs, io::Read, num::NonZero, path::Path};
#[derive(Debug, Clone)]
pub enum HashAlgorithm {
/// SHA-256 hash algorithm with the expected checksum value.
///
/// Used by the PyPI downloader.
Sha256(String),

/// BLAKE2b-256 hash algorithm with the expected checksum value.
///
/// Used by the PyPI downloader.
Blake2b256(String),

/// SHA-512 hash algorithm with the expected checksum value.
#[cfg(any(
// Windows support is only for x86_64 architecture (for now)
all(target_os = "windows", target_arch = "x86_64"),
// Linux and macOS support only x86_64 and aarch64 architectures
///
/// Used exclusively by the static distribution downloader.
#[cfg(
// Windows, Linux, and MacOS support only x86_64 and aarch64 architectures
all(
any(target_os = "linux", target_os = "macos"),
any(target_os = "windows", target_os = "linux", target_os = "macos"),
any(target_arch = "x86_64", target_arch = "aarch64")
),
))]
)
)]
Sha512(String),
}

Expand Down Expand Up @@ -85,15 +89,13 @@ impl HashAlgorithm {
let hasher = Blake2b::<U32>::new();
Self::hash_file(hasher, file_path, expected)
}
#[cfg(any(
// Windows support is only for x86_64 architecture (for now)
all(target_os = "windows", target_arch = "x86_64"),
// Linux and macOS support only x86_64 and aarch64 architectures
#[cfg(
// Windows, Linux, and MacOS support only x86_64 and aarch64 architectures
all(
any(target_os = "linux", target_os = "macos"),
any(target_os = "windows", target_os = "linux", target_os = "macos"),
any(target_arch = "x86_64", target_arch = "aarch64")
),
))]
)]
HashAlgorithm::Sha512(expected) => {
use sha2::{Digest, Sha512};

Expand Down
65 changes: 33 additions & 32 deletions clang-tools-manager/src/downloader/static_dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ pub enum StaticDistDownloadError {
UnsupportedVersion,

/// The static binaries are only built for
/// x86_64 and aarch64 architecture on Linux MacOS, and
/// Windows (not aarch64 for Windows currently).
/// x86_64 and aarch64 architecture on Linux, MacOS, and Windows.
#[error("The static binaries are not built for {OS} {ARCH} architecture")]
UnsupportedArchitecture,

Expand Down Expand Up @@ -54,11 +53,9 @@ impl StaticDistDownloader {
}

#[cfg(any(
// Windows support is only for x86_64 architecture (for now)
all(target_os = "windows", not(target_arch = "x86_64")),
// Linux and macOS support only x86_64 and aarch64 architectures
// Windows, Linux, and MacOS support only x86_64 and aarch64 architectures
all(
any(target_os = "linux", target_os = "macos"),
any(target_os = "windows", target_os = "linux", target_os = "macos"),
not(any(target_arch = "x86_64", target_arch = "aarch64"))
),
// Any OS other than Windows, Linux, or macOS is unsupported
Expand All @@ -81,18 +78,17 @@ mod unsupported_platform {
}
}

#[cfg(any(
// Windows support is only for x86_64 architecture (for now)
all(target_os = "windows", target_arch = "x86_64"),
// Linux and macOS support only x86_64 and aarch64 architectures
#[cfg(
// Windows, Linux, and MacOS support only x86_64 and aarch64 architectures
all(
any(target_os = "linux", target_os = "macos"),
any(target_os = "windows", target_os = "linux", target_os = "macos"),
any(target_arch = "x86_64", target_arch = "aarch64")
),
))]
)]
mod supported_platform {
use std::{
fs,
io::{BufRead, BufReader},
ops::RangeInclusive,
path::{Path, PathBuf},
};
Expand Down Expand Up @@ -125,18 +121,28 @@ mod supported_platform {

/// Verifies the SHA512 checksum of the downloaded file.
///
/// The expected checksum is extracted from another downloaded `*.sha512sum` file
/// The expected checksum is extracted from another downloaded `SHA512SUMS` file
/// (pointed to by `sha512_path`).
fn verify_sha512(
file_path: &Path,
tool: &str,
sha512_path: &Path,
) -> Result<(), StaticDistDownloadError> {
let checksum_file_content = fs::read_to_string(sha512_path)?;
let expected = checksum_file_content
.split(' ')
.next()
.ok_or(StaticDistDownloadError::Sha512Corruption)?;
HashAlgorithm::Sha512(expected.to_string()).verify(file_path)?;
let expected = {
let checksum_file_handle = fs::File::open(sha512_path)?;
let checksum_file_content = BufReader::new(checksum_file_handle);
let mut found = None;
for line in checksum_file_content.lines() {
let line = line?;
if line.ends_with(tool) {
found = line.split(' ').next().map(|s| s.trim().to_string());
break;
}
}
found
}
.ok_or(StaticDistDownloadError::Sha512Corruption)?;
HashAlgorithm::Sha512(expected).verify(file_path)?;
Ok(())
}

Expand Down Expand Up @@ -169,15 +175,14 @@ mod supported_platform {
"linux"
};

let base_url = format!(
"{CLANG_TOOLS_REPO}/releases/download/{CLANG_TOOLS_TAG}/{tool}-{ver_str}_{platform}-{arch}",
);
let base_url = format!("{CLANG_TOOLS_REPO}/releases/download/{CLANG_TOOLS_TAG}/",);
let suffix = if cfg!(target_os = "windows") {
".exe"
} else {
""
};
let url = Url::parse(format!("{base_url}{suffix}").as_str())?;
let tool_url_path = format!("{tool}-{ver_str}_{platform}-{arch}{suffix}");
let url = Url::parse(format!("{base_url}{tool_url_path}").as_str())?;
let cache_path = Self::get_cache_dir();
let bin_name = format!("{tool}-{ver_str}{suffix}");
let download_path = match directory {
Expand All @@ -196,22 +201,18 @@ mod supported_platform {
#[cfg(unix)]
super::super::chmod_file(&download_path, None)?;
}
let sha512_cache_path = cache_path
.join("static_dist")
.join(format!("{tool}-{ver_str}.sha512"));
let sha512_cache_path = cache_path.join("static_dist").join("SHA512SUMS");
if sha512_cache_path.exists() {
log::info!(
"Using cached SHA512 checksum for {tool} version {ver_str} from {:?}",
"Using cached SHA512 checksums for static binaries from {:?}",
sha512_cache_path.to_string_lossy()
);
} else {
let sha512_url = Url::parse(format!("{base_url}{suffix}.sha512sum").as_str())?;
log::info!(
"Downloading SHA512 checksum for {tool} version {ver_str} from {sha512_url}"
);
let sha512_url = Url::parse(format!("{base_url}SHA512SUMS").as_str())?;
log::info!("Downloading SHA512 checksum for static binaries from {sha512_url}");
download(&sha512_url, &sha512_cache_path, 10).await?;
}
Self::verify_sha512(&download_path, &sha512_cache_path)?;
Self::verify_sha512(&download_path, &tool_url_path, &sha512_cache_path)?;
file_lock.unlock()?;
Ok(download_path)
}
Expand Down
2 changes: 1 addition & 1 deletion cpp-linter/src/clang_tools/clang_tidy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ pub fn run_clang_tidy(
if !ranges.is_empty() {
let filter = format!(
"[{{\"name\":{:?},\"lines\":{:?}}}]",
&file_name.replace('/', if OS == "windows" { "\\" } else { "/" }),
file_name.replace('/', if OS == "windows" { "\\" } else { "/" }),
ranges
.iter()
.map(|r| [r.start(), r.end()])
Expand Down
10 changes: 5 additions & 5 deletions cpp-linter/src/common_fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,15 +258,15 @@ impl FileObj {
}
let mut suggestion = format!(
"### clang-tidy diagnostic\n**{file_name}:{}:{}** {}: [{}]\n\n> {}\n",
&note.line,
&note.cols,
&note.severity,
note.line,
note.cols,
note.severity,
note.diagnostic_link(),
&note.rationale
note.rationale
);
if !note.suggestion.is_empty() {
suggestion.push_str(
format!("\n```{file_ext}\n{}\n```\n", &note.suggestion.join("\n"))
format!("\n```{file_ext}\n{}\n```\n", note.suggestion.join("\n"))
.as_str(),
);
}
Expand Down
2 changes: 1 addition & 1 deletion docs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn generate_cli_doc(metadata: HashMap<String, HashMap<String, Py<PyAny>>>) -> Py
out.push_str(
format!(
"{}\n",
&cmd.get_about()
cmd.get_about()
.ok_or(PyValueError::new_err(format!(
"{} command has no help message",
cmd.get_name()
Expand Down
Loading