mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-06-16 07:36:38 +00:00
Fix v1 manifest format for git and local path
Fixed #1815 Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
f9f25c9d6f
commit
e1ec8a21da
4 changed files with 63 additions and 19 deletions
|
@ -8,6 +8,7 @@ use std::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use binstalk_fetchers::FETCHER_GH_CRATE_META;
|
use binstalk_fetchers::FETCHER_GH_CRATE_META;
|
||||||
|
use binstalk_types::crate_info::{CrateSource, SourceType};
|
||||||
use compact_str::{CompactString, ToCompactString};
|
use compact_str::{CompactString, ToCompactString};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use leon::Template;
|
use leon::Template;
|
||||||
|
@ -15,6 +16,7 @@ use maybe_owned::MaybeOwned;
|
||||||
use semver::{Version, VersionReq};
|
use semver::{Version, VersionReq};
|
||||||
use tokio::task::spawn_blocking;
|
use tokio::task::spawn_blocking;
|
||||||
use tracing::{debug, error, info, instrument, warn};
|
use tracing::{debug, error, info, instrument, warn};
|
||||||
|
use url::Url;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
bins,
|
bins,
|
||||||
|
@ -195,6 +197,7 @@ async fn resolve_inner(
|
||||||
new_version: package_info.version,
|
new_version: package_info.version,
|
||||||
name: package_info.name,
|
name: package_info.name,
|
||||||
version_req: version_req_str,
|
version_req: version_req_str,
|
||||||
|
source: package_info.source,
|
||||||
bin_files,
|
bin_files,
|
||||||
})));
|
})));
|
||||||
} else {
|
} else {
|
||||||
|
@ -365,6 +368,7 @@ struct PackageInfo {
|
||||||
binaries: Vec<Bin>,
|
binaries: Vec<Bin>,
|
||||||
name: CompactString,
|
name: CompactString,
|
||||||
version_str: CompactString,
|
version_str: CompactString,
|
||||||
|
source: CrateSource,
|
||||||
version: Version,
|
version: Version,
|
||||||
repo: Option<String>,
|
repo: Option<String>,
|
||||||
overrides: BTreeMap<String, PkgOverride>,
|
overrides: BTreeMap<String, PkgOverride>,
|
||||||
|
@ -387,43 +391,70 @@ impl PackageInfo {
|
||||||
use CargoTomlFetchOverride::*;
|
use CargoTomlFetchOverride::*;
|
||||||
|
|
||||||
// Fetch crate via crates.io, git, or use a local manifest path
|
// Fetch crate via crates.io, git, or use a local manifest path
|
||||||
let manifest = match opts.cargo_toml_fetch_override.as_ref() {
|
let (manifest, source) = match opts.cargo_toml_fetch_override.as_ref() {
|
||||||
Some(Path(manifest_path)) => {
|
Some(Path(manifest_path)) => (
|
||||||
let manifest_path = manifest_path.clone();
|
spawn_blocking({
|
||||||
let name = name.clone();
|
let manifest_path = manifest_path.clone();
|
||||||
|
let name = name.clone();
|
||||||
|
|
||||||
spawn_blocking(move || load_manifest_path(manifest_path, &name)).await??
|
move || load_manifest_path(manifest_path, &name)
|
||||||
}
|
})
|
||||||
|
.await??,
|
||||||
|
CrateSource {
|
||||||
|
source_type: SourceType::Path,
|
||||||
|
url: MaybeOwned::Owned(Url::parse(&format!(
|
||||||
|
"file://{}",
|
||||||
|
manifest_path.display()
|
||||||
|
))?),
|
||||||
|
},
|
||||||
|
),
|
||||||
#[cfg(feature = "git")]
|
#[cfg(feature = "git")]
|
||||||
Some(Git(git_url)) => {
|
Some(Git(git_url)) => {
|
||||||
use crate::helpers::git::{GitCancellationToken, Repository as GitRepository};
|
use crate::helpers::git::{GitCancellationToken, Repository as GitRepository};
|
||||||
|
|
||||||
let git_url = git_url.clone();
|
|
||||||
let name = name.clone();
|
|
||||||
let cancellation_token = GitCancellationToken::default();
|
let cancellation_token = GitCancellationToken::default();
|
||||||
// Cancel git operation if the future is cancelled (dropped).
|
// Cancel git operation if the future is cancelled (dropped).
|
||||||
let cancel_on_drop = cancellation_token.clone().cancel_on_drop();
|
let cancel_on_drop = cancellation_token.clone().cancel_on_drop();
|
||||||
|
|
||||||
let ret = spawn_blocking(move || {
|
let (ret, commit_hash) = spawn_blocking({
|
||||||
let dir = tempfile::TempDir::new()?;
|
let git_url = git_url.clone();
|
||||||
GitRepository::shallow_clone(git_url, dir.as_ref(), Some(cancellation_token))?;
|
let name = name.clone();
|
||||||
|
move || {
|
||||||
|
let dir = tempfile::TempDir::new()?;
|
||||||
|
let repo = GitRepository::shallow_clone(
|
||||||
|
git_url,
|
||||||
|
dir.as_ref(),
|
||||||
|
Some(cancellation_token),
|
||||||
|
)?;
|
||||||
|
|
||||||
load_manifest_from_workspace(dir.as_ref(), &name).map_err(BinstallError::from)
|
Ok::<_, BinstallError>((
|
||||||
|
load_manifest_from_workspace(dir.as_ref(), &name)
|
||||||
|
.map_err(BinstallError::from)?,
|
||||||
|
repo.get_head_commit_hash()?,
|
||||||
|
))
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.await??;
|
.await??;
|
||||||
|
|
||||||
// Git operation done, disarm it
|
// Git operation done, disarm it
|
||||||
cancel_on_drop.disarm();
|
cancel_on_drop.disarm();
|
||||||
|
|
||||||
ret
|
(
|
||||||
|
ret,
|
||||||
|
CrateSource {
|
||||||
|
source_type: SourceType::Git,
|
||||||
|
url: MaybeOwned::Owned(Url::parse(&format!("{git_url}#{commit_hash}"))?),
|
||||||
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
None => {
|
None => (
|
||||||
Box::pin(
|
Box::pin(
|
||||||
opts.registry
|
opts.registry
|
||||||
.fetch_crate_matched(client, &name, version_req),
|
.fetch_crate_matched(client, &name, version_req),
|
||||||
)
|
)
|
||||||
.await?
|
.await?,
|
||||||
}
|
CrateSource::cratesio_registry(),
|
||||||
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
let Some(mut package) = manifest.package else {
|
let Some(mut package) = manifest.package else {
|
||||||
|
@ -479,6 +510,7 @@ impl PackageInfo {
|
||||||
meta,
|
meta,
|
||||||
binaries,
|
binaries,
|
||||||
name,
|
name,
|
||||||
|
source,
|
||||||
version_str: new_version_str,
|
version_str: new_version_str,
|
||||||
version: new_version,
|
version: new_version,
|
||||||
repo: package.repository().map(ToString::to_string),
|
repo: package.repository().map(ToString::to_string),
|
||||||
|
|
|
@ -22,6 +22,7 @@ pub struct ResolutionFetch {
|
||||||
pub name: CompactString,
|
pub name: CompactString,
|
||||||
pub version_req: CompactString,
|
pub version_req: CompactString,
|
||||||
pub bin_files: Vec<bins::BinFile>,
|
pub bin_files: Vec<bins::BinFile>,
|
||||||
|
pub source: CrateSource,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ResolutionSource {
|
pub struct ResolutionSource {
|
||||||
|
@ -84,7 +85,7 @@ impl ResolutionFetch {
|
||||||
name: self.name,
|
name: self.name,
|
||||||
version_req: self.version_req,
|
version_req: self.version_req,
|
||||||
current_version: self.new_version,
|
current_version: self.new_version,
|
||||||
source: CrateSource::cratesio_registry(),
|
source: self.source,
|
||||||
target: self.fetcher.target().to_compact_string(),
|
target: self.fetcher.target().to_compact_string(),
|
||||||
bins: self
|
bins: self
|
||||||
.bin_files
|
.bin_files
|
||||||
|
|
|
@ -45,17 +45,25 @@ cp -r manifests/workspace/* "$GIT"
|
||||||
cd "$GIT"
|
cd "$GIT"
|
||||||
git add .
|
git add .
|
||||||
git commit -m 'Update to workspace'
|
git commit -m 'Update to workspace'
|
||||||
|
git rev-parse HEAD
|
||||||
)
|
)
|
||||||
|
COMMIT_HASH="$(cd "$GIT" && git rev-parse HEAD)"
|
||||||
|
|
||||||
# Install binaries using `--git`
|
# Install cargo-binstall using `--git`
|
||||||
"./$1" binstall --force --git "file://$GIT" --no-confirm cargo-binstall
|
"./$1" binstall --force --git "file://$GIT" --no-confirm cargo-binstall
|
||||||
|
|
||||||
test_cargo_binstall_install
|
test_cargo_binstall_install
|
||||||
|
|
||||||
# Install binaries using `--git`
|
cat "$CARGO_HOME/.crates.toml"
|
||||||
|
grep -F "cargo-binstall 0.12.0 (git+file://$GIT#$COMMIT_HASH)" <"$CARGO_HOME/.crates.toml"
|
||||||
|
|
||||||
|
# Install cargo-binstall using `--git`
|
||||||
"./$1" binstall --force --git "file://$GIT" --no-confirm cargo-watch
|
"./$1" binstall --force --git "file://$GIT" --no-confirm cargo-watch
|
||||||
|
|
||||||
cargo_watch_version="$(cargo watch -V)"
|
cargo_watch_version="$(cargo watch -V)"
|
||||||
echo "$cargo_watch_version"
|
echo "$cargo_watch_version"
|
||||||
|
|
||||||
[ "$cargo_watch_version" = "cargo-watch 8.4.0" ]
|
[ "$cargo_watch_version" = "cargo-watch 8.4.0" ]
|
||||||
|
|
||||||
|
cat "$CARGO_HOME/.crates.toml"
|
||||||
|
grep -F "cargo-watch 8.4.0 (git+file://$GIT#$COMMIT_HASH)" <"$CARGO_HOME/.crates.toml"
|
||||||
|
|
|
@ -19,3 +19,6 @@ cargo_binstall_version="$(cargo binstall -V)"
|
||||||
echo "$cargo_binstall_version"
|
echo "$cargo_binstall_version"
|
||||||
|
|
||||||
[ "$cargo_binstall_version" = "cargo-binstall 0.12.0" ]
|
[ "$cargo_binstall_version" = "cargo-binstall 0.12.0" ]
|
||||||
|
|
||||||
|
cat "$CARGO_HOME/.crates.toml"
|
||||||
|
grep -F "cargo-binstall 0.12.0 (path+file://manifests/github-test-Cargo.toml)" <"$CARGO_HOME/.crates.toml"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue