Skip to content

Commit cf2c774

Browse files
committed
fix: updates for latest static binaries
- use unified SHA512 checksums file - download binaries for windows arm64 also includes some changes that satisify new clippy lints (per Rust v1.97.0).
1 parent d41b370 commit cf2c774

4 files changed

Lines changed: 26 additions & 34 deletions

File tree

clang-tools-manager/src/downloader/static_dist.rs

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ pub enum StaticDistDownloadError {
1919
UnsupportedVersion,
2020

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

@@ -54,11 +53,9 @@ impl StaticDistDownloader {
5453
}
5554

5655
#[cfg(any(
57-
// Windows support is only for x86_64 architecture (for now)
58-
all(target_os = "windows", not(target_arch = "x86_64")),
59-
// Linux and macOS support only x86_64 and aarch64 architectures
56+
// Windows, Linux, and MacOS support only x86_64 and aarch64 architectures
6057
all(
61-
any(target_os = "linux", target_os = "macos"),
58+
any(target_os = "windows", target_os = "linux", target_os = "macos"),
6259
not(any(target_arch = "x86_64", target_arch = "aarch64"))
6360
),
6461
// Any OS other than Windows, Linux, or macOS is unsupported
@@ -81,15 +78,13 @@ mod unsupported_platform {
8178
}
8279
}
8380

84-
#[cfg(any(
85-
// Windows support is only for x86_64 architecture (for now)
86-
all(target_os = "windows", target_arch = "x86_64"),
87-
// Linux and macOS support only x86_64 and aarch64 architectures
81+
#[cfg(
82+
// Windows, Linux, and MacOS support only x86_64 and aarch64 architectures
8883
all(
89-
any(target_os = "linux", target_os = "macos"),
84+
any(target_os = "windows", target_os = "linux", target_os = "macos"),
9085
any(target_arch = "x86_64", target_arch = "aarch64")
9186
),
92-
))]
87+
)]
9388
mod supported_platform {
9489
use std::{
9590
fs,
@@ -129,12 +124,14 @@ mod supported_platform {
129124
/// (pointed to by `sha512_path`).
130125
fn verify_sha512(
131126
file_path: &Path,
127+
tool: &str,
132128
sha512_path: &Path,
133129
) -> Result<(), StaticDistDownloadError> {
134130
let checksum_file_content = fs::read_to_string(sha512_path)?;
135131
let expected = checksum_file_content
136-
.split(' ')
137-
.next()
132+
.lines()
133+
.find(|line| line.ends_with(tool))
134+
.and_then(|line| line.split(' ').next())
138135
.ok_or(StaticDistDownloadError::Sha512Corruption)?;
139136
HashAlgorithm::Sha512(expected.to_string()).verify(file_path)?;
140137
Ok(())
@@ -169,15 +166,14 @@ mod supported_platform {
169166
"linux"
170167
};
171168

172-
let base_url = format!(
173-
"{CLANG_TOOLS_REPO}/releases/download/{CLANG_TOOLS_TAG}/{tool}-{ver_str}_{platform}-{arch}",
174-
);
169+
let base_url = format!("{CLANG_TOOLS_REPO}/releases/download/{CLANG_TOOLS_TAG}/",);
175170
let suffix = if cfg!(target_os = "windows") {
176171
".exe"
177172
} else {
178173
""
179174
};
180-
let url = Url::parse(format!("{base_url}{suffix}").as_str())?;
175+
let tool_url_path = format!("{tool}-{ver_str}_{platform}-{arch}{suffix}");
176+
let url = Url::parse(format!("{base_url}{tool_url_path}").as_str())?;
181177
let cache_path = Self::get_cache_dir();
182178
let bin_name = format!("{tool}-{ver_str}{suffix}");
183179
let download_path = match directory {
@@ -196,22 +192,18 @@ mod supported_platform {
196192
#[cfg(unix)]
197193
super::super::chmod_file(&download_path, None)?;
198194
}
199-
let sha512_cache_path = cache_path
200-
.join("static_dist")
201-
.join(format!("{tool}-{ver_str}.sha512"));
195+
let sha512_cache_path = cache_path.join("static_dist").join("SHA512SUMS");
202196
if sha512_cache_path.exists() {
203197
log::info!(
204-
"Using cached SHA512 checksum for {tool} version {ver_str} from {:?}",
198+
"Using cached SHA512 checksums for static binaries from {:?}",
205199
sha512_cache_path.to_string_lossy()
206200
);
207201
} else {
208-
let sha512_url = Url::parse(format!("{base_url}{suffix}.sha512sum").as_str())?;
209-
log::info!(
210-
"Downloading SHA512 checksum for {tool} version {ver_str} from {sha512_url}"
211-
);
202+
let sha512_url = Url::parse(format!("{base_url}SHA512SUMS").as_str())?;
203+
log::info!("Downloading SHA512 checksum for static binaries from {sha512_url}");
212204
download(&sha512_url, &sha512_cache_path, 10).await?;
213205
}
214-
Self::verify_sha512(&download_path, &sha512_cache_path)?;
206+
Self::verify_sha512(&download_path, &tool_url_path, &sha512_cache_path)?;
215207
file_lock.unlock()?;
216208
Ok(download_path)
217209
}

cpp-linter/src/clang_tools/clang_tidy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ pub fn run_clang_tidy(
306306
if !ranges.is_empty() {
307307
let filter = format!(
308308
"[{{\"name\":{:?},\"lines\":{:?}}}]",
309-
&file_name.replace('/', if OS == "windows" { "\\" } else { "/" }),
309+
file_name.replace('/', if OS == "windows" { "\\" } else { "/" }),
310310
ranges
311311
.iter()
312312
.map(|r| [r.start(), r.end()])

cpp-linter/src/common_fs.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -258,15 +258,15 @@ impl FileObj {
258258
}
259259
let mut suggestion = format!(
260260
"### clang-tidy diagnostic\n**{file_name}:{}:{}** {}: [{}]\n\n> {}\n",
261-
&note.line,
262-
&note.cols,
263-
&note.severity,
261+
note.line,
262+
note.cols,
263+
note.severity,
264264
note.diagnostic_link(),
265-
&note.rationale
265+
note.rationale
266266
);
267267
if !note.suggestion.is_empty() {
268268
suggestion.push_str(
269-
format!("\n```{file_ext}\n{}\n```\n", &note.suggestion.join("\n"))
269+
format!("\n```{file_ext}\n{}\n```\n", note.suggestion.join("\n"))
270270
.as_str(),
271271
);
272272
}

docs/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ fn generate_cli_doc(metadata: HashMap<String, HashMap<String, Py<PyAny>>>) -> Py
3535
out.push_str(
3636
format!(
3737
"{}\n",
38-
&cmd.get_about()
38+
cmd.get_about()
3939
.ok_or(PyValueError::new_err(format!(
4040
"{} command has no help message",
4141
cmd.get_name()

0 commit comments

Comments
 (0)