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"
test_bins="cargo-deb cargo-llvm-cov"
unset CARGO_INSTALL_ROOT
unset CARGO_HOME
# Install binaries using cargo-binstall
# shellcheck disable=SC2086
"./$1" binstall --log-level debug --no-confirm $bins

View file

@ -1,8 +1,10 @@
use std::env;
use std::fmt::Debug;
use std::fs;
use std::io;
use std::ops;
use std::path::{Path, PathBuf};
use std::sync::Arc;
use bytes::Bytes;
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
/// 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
if let Some(p) = install_path {
return Some(PathBuf::from(p.as_ref()));
return (Some(Arc::from(p.as_ref())), true);
}
// Environmental variables
if let Ok(p) = std::env::var("CARGO_INSTALL_ROOT") {
debug!("using CARGO_INSTALL_ROOT ({p})");
let b = PathBuf::from(p);
return Some(b.join("bin"));
}
if let Ok(p) = std::env::var("CARGO_HOME") {
debug!("using CARGO_HOME ({p})");
let b = PathBuf::from(p);
return Some(b.join("bin"));
return (Some(Arc::from(b.join("bin"))), true);
}
// Standard $HOME/.cargo/bin
if let Some(d) = dirs::home_dir() {
let d = d.join(".cargo/bin");
if d.exists() {
debug!("using $HOME/.cargo/bin");
return Some(d);
}
if let Ok(p) = cargo_home() {
debug!("using ({}) as cargo home", p.display());
return (Some(p.join("bin").into()), false);
}
// 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());
}
dir
(dir.map(Arc::from), true)
}
/// 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);
// Compute install directory
let install_path: Arc<Path> = Arc::from(
get_install_path(opts.install_path.as_deref()).ok_or_else(|| {
error!("No viable install path found of specified, try `--install-path`");
miette!("No install path found or specified")
})?,
);
let (install_path, custom_install_path) = get_install_path(opts.install_path.as_deref());
let install_path = install_path.ok_or_else(|| {
error!("No viable install path found of specified, try `--install-path`");
miette!("No install path found or specified")
})?;
debug!("Using install path: {}", install_path.display());
// Create a temporary directory for downloads etc.
@ -343,27 +342,29 @@ async fn entry(jobserver_client: LazyJobserverClient) -> Result<()> {
}
block_in_place(|| {
debug!("Writing .crates.toml");
metafiles::v1::CratesToml::append(
metadata_vec
.iter()
.map(|metadata| (&metadata.cvs, metadata.bins.clone())),
)?;
if !custom_install_path {
debug!("Writing .crates.toml");
metafiles::v1::CratesToml::append(
metadata_vec
.iter()
.map(|metadata| (&metadata.cvs, metadata.bins.clone())),
)?;
debug!("Writing .crates2.json");
metafiles::v2::Crates2Json::append(metadata_vec.into_iter().map(|metadata| {
(
metadata.cvs,
metafiles::v2::CrateInfo {
version_req: Some(metadata.version_req),
bins: metadata.bins,
profile: "release".into(),
target: metadata.target,
rustc: format!("{} {}", env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION")),
..Default::default()
},
)
}))?;
debug!("Writing .crates2.json");
metafiles::v2::Crates2Json::append(metadata_vec.into_iter().map(|metadata| {
(
metadata.cvs,
metafiles::v2::CrateInfo {
version_req: Some(metadata.version_req),
bins: metadata.bins,
profile: "release".into(),
target: metadata.target,
rustc: format!("{} {}", env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION")),
..Default::default()
},
)
}))?;
}
if opts.no_cleanup {
// Consume temp_dir without removing it from fs.