Merge pull request #228 from NobodyXu/fix/skip-on-custom-install

Fix updating metafiles: Skip on custom install path
This commit is contained in:
Jiahao XU 2022-07-23 19:57:58 +10:00 committed by GitHub
commit 1768392413
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 43 deletions

View file

@ -5,6 +5,9 @@ set -euxo pipefail
bins="cargo-deb cargo-llvm-cov cargo-binstall" bins="cargo-deb cargo-llvm-cov cargo-binstall"
test_bins="cargo-deb cargo-llvm-cov" test_bins="cargo-deb cargo-llvm-cov"
unset CARGO_INSTALL_ROOT
unset CARGO_HOME
# Install binaries using cargo-binstall # Install binaries using cargo-binstall
# shellcheck disable=SC2086 # shellcheck disable=SC2086
"./$1" binstall --log-level debug --no-confirm $bins "./$1" binstall --log-level debug --no-confirm $bins

View file

@ -1,8 +1,10 @@
use std::env;
use std::fmt::Debug; use std::fmt::Debug;
use std::fs; use std::fs;
use std::io; use std::io;
use std::ops; use std::ops;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::sync::Arc;
use bytes::Bytes; use bytes::Bytes;
use cargo_toml::Manifest; use cargo_toml::Manifest;
@ -189,32 +191,24 @@ pub async fn download_tar_based_and_visit<V: TarEntriesVisitor + Debug + Send +
/// Fetch install path from environment /// Fetch install path from environment
/// roughly follows <https://doc.rust-lang.org/cargo/commands/cargo-install.html#description> /// roughly follows <https://doc.rust-lang.org/cargo/commands/cargo-install.html#description>
pub fn get_install_path<P: AsRef<Path>>(install_path: Option<P>) -> Option<PathBuf> { ///
/// Return (install_path, is_custom_install_path)
pub fn get_install_path<P: AsRef<Path>>(install_path: Option<P>) -> (Option<Arc<Path>>, bool) {
// Command line override first first // Command line override first first
if let Some(p) = install_path { if let Some(p) = install_path {
return Some(PathBuf::from(p.as_ref())); return (Some(Arc::from(p.as_ref())), true);
} }
// Environmental variables // Environmental variables
if let Ok(p) = std::env::var("CARGO_INSTALL_ROOT") { if let Ok(p) = std::env::var("CARGO_INSTALL_ROOT") {
debug!("using CARGO_INSTALL_ROOT ({p})"); debug!("using CARGO_INSTALL_ROOT ({p})");
let b = PathBuf::from(p); let b = PathBuf::from(p);
return Some(b.join("bin")); return (Some(Arc::from(b.join("bin"))), true);
}
if let Ok(p) = std::env::var("CARGO_HOME") {
debug!("using CARGO_HOME ({p})");
let b = PathBuf::from(p);
return Some(b.join("bin"));
} }
// Standard $HOME/.cargo/bin if let Ok(p) = cargo_home() {
if let Some(d) = dirs::home_dir() { debug!("using ({}) as cargo home", p.display());
let d = d.join(".cargo/bin"); return (Some(p.join("bin").into()), false);
if d.exists() {
debug!("using $HOME/.cargo/bin");
return Some(d);
}
} }
// Local executable dir if no cargo is found // Local executable dir if no cargo is found
@ -224,7 +218,7 @@ pub fn get_install_path<P: AsRef<Path>>(install_path: Option<P>) -> Option<PathB
debug!("Fallback to {}", d.display()); debug!("Fallback to {}", d.display());
} }
dir (dir.map(Arc::from), true)
} }
/// Atomically install a file. /// Atomically install a file.

View file

@ -240,12 +240,11 @@ async fn entry(jobserver_client: LazyJobserverClient) -> Result<()> {
let desired_targets = get_desired_targets(&opts.targets); let desired_targets = get_desired_targets(&opts.targets);
// Compute install directory // Compute install directory
let install_path: Arc<Path> = Arc::from( let (install_path, custom_install_path) = get_install_path(opts.install_path.as_deref());
get_install_path(opts.install_path.as_deref()).ok_or_else(|| { let install_path = install_path.ok_or_else(|| {
error!("No viable install path found of specified, try `--install-path`"); error!("No viable install path found of specified, try `--install-path`");
miette!("No install path found or specified") miette!("No install path found or specified")
})?, })?;
);
debug!("Using install path: {}", install_path.display()); debug!("Using install path: {}", install_path.display());
// Create a temporary directory for downloads etc. // Create a temporary directory for downloads etc.
@ -343,6 +342,7 @@ async fn entry(jobserver_client: LazyJobserverClient) -> Result<()> {
} }
block_in_place(|| { block_in_place(|| {
if !custom_install_path {
debug!("Writing .crates.toml"); debug!("Writing .crates.toml");
metafiles::v1::CratesToml::append( metafiles::v1::CratesToml::append(
metadata_vec metadata_vec
@ -364,6 +364,7 @@ async fn entry(jobserver_client: LazyJobserverClient) -> Result<()> {
}, },
) )
}))?; }))?;
}
if opts.no_cleanup { if opts.no_cleanup {
// Consume temp_dir without removing it from fs. // Consume temp_dir without removing it from fs.