Skip to content

Commit 89d9a7e

Browse files
authored
fix: do not fail on check for tool presence (via package managers) (#345)
- ref: #342 I added some debug logs and ran the `clang-tools` binary in a docker container. I found that the `apt` package manager support was failing because the check for any existing clang tool failed when the tool was not installed. I converted the check for a clang tool's presence into a soft check. Meaning, if it somehow fails then just fall back to installing the clang tool as if doing a fresh/normal install. > [!note] > The container I used seemed to be too new; the LLVM install script does not yet support Ubuntu "resolute". But at least the `clang-tools` binary was able to fall back to static binaries. Plus, the debug and error logs are explanatory enough. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved package installation reliability by gracefully handling detection failures and proceeding with installation attempts when needed. * **Chores** * Enhanced diagnostic logging for package installation operations to aid troubleshooting. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent b213c8a commit 89d9a7e

2 files changed

Lines changed: 24 additions & 10 deletions

File tree

clang-tools-manager/src/downloader/native_packages/mod.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,16 @@ pub async fn try_install_package(
8383
for mgr in os_pkg_managers {
8484
log::info!("Trying to install {tool} v{min_version} using {mgr} package manager.");
8585
let pkg_name = mgr.get_package_name(tool);
86-
if mgr.is_installed_package(&pkg_name, Some(min_version)) {
87-
let path =
88-
tool.get_exe_path(&RequestedVersion::Requirement(version_req.clone()))?;
89-
let version = tool.capture_version(&path)?;
90-
if version_req.matches(&version) {
91-
log::info!(
92-
"Found {tool} version matching {version_req} installed via {mgr} package manager."
93-
);
94-
return Ok(Some(ClangVersion { version, path }));
95-
}
86+
if mgr.is_installed_package(&pkg_name, Some(min_version))
87+
&& let Ok(path) =
88+
tool.get_exe_path(&RequestedVersion::Requirement(version_req.clone()))
89+
&& let Ok(version) = tool.capture_version(&path)
90+
&& version_req.matches(&version)
91+
{
92+
log::info!(
93+
"Found {tool} version matching {version_req} installed via {mgr} package manager."
94+
);
95+
return Ok(Some(ClangVersion { version, path }));
9696
} else {
9797
log::info!(
9898
"{mgr} package manager does not have a version of {tool} matching {version_req} installed."

clang-tools-manager/src/downloader/native_packages/unix.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,22 @@ impl PackageManager for UnixPackageManager {
127127
}
128128
}
129129
let output = if Self::has_sudo() && !matches!(self, UnixPackageManager::Homebrew) {
130+
log::debug!(
131+
"Running `sudo {} {} {package_id}`",
132+
self.as_str(),
133+
args.join(" ")
134+
);
130135
Command::new("sudo")
131136
.arg(self.as_str())
132137
.args(args)
133138
.arg(package_id.as_str())
134139
.output()?
135140
} else {
141+
log::debug!(
142+
"Running `{} {} {package_id}`",
143+
self.as_str(),
144+
args.join(" ")
145+
);
136146
Command::new(self.as_str())
137147
.args(args)
138148
.arg(package_id.as_str())
@@ -145,6 +155,10 @@ impl PackageManager for UnixPackageManager {
145155
if matches!(self, UnixPackageManager::Apt)
146156
&& let Some(version) = version
147157
{
158+
log::error!(
159+
"Failed to install {package_id} via apt: {}",
160+
String::from_utf8_lossy(&output.stderr)
161+
);
148162
log::info!(
149163
"trying to install from official LLVM PPA repository (for Debian-based `apt` package manager)"
150164
);

0 commit comments

Comments
 (0)