Impl try multiple default bin dirs (#417)

From @passcod :

* Make bin-dir an Option
* Use cargo-release as a test case
* WIP: Try multiple default bin dirs
* Update bins.rs
* Update cargo_toml_binstall.rs

From @NobodyXu :
* Optimize & Prepare for support multi `bin-path`s
* Ensure quickinstall bin_dir work as usual.
* Rm dup entries in `FULL_FILENAMES`
* Add second version of `NOVERSION_FILENAMES`
* Impl multiple default `bin-dir`s
* Improve doc for `BinFile::from_product`
* Fix tests.sh

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
Co-authored-by: Félix Saparelli <felix@passcod.name>
This commit is contained in:
Jiahao XU 2022-09-25 22:15:20 +10:00 committed by GitHub
parent c27c3b80b5
commit e034d69e12
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 88 additions and 67 deletions

View file

@ -176,6 +176,11 @@ async fn resolve_inner(
manifest.bin,
);
// Check binaries
if binaries.is_empty() {
return Err(BinstallError::UnspecifiedBinaries);
}
let desired_targets = opts.desired_targets.get().await;
let mut handles: Vec<(Arc<dyn Fetcher>, _)> = Vec::with_capacity(desired_targets.len() * 2);
@ -229,7 +234,7 @@ async fn resolve_inner(
&bin_path,
&package,
&install_path,
binaries.clone(),
&binaries,
)
.await
{
@ -266,26 +271,17 @@ async fn resolve_inner(
}
/// * `fetcher` - `fetcher.find()` must return `Ok(true)`.
/// * `binaries` - must not be empty
async fn download_extract_and_verify(
fetcher: &dyn Fetcher,
bin_path: &Path,
package: &Package<Meta>,
install_path: &Path,
// TODO: Use &[Product]
binaries: Vec<Product>,
binaries: &[Product],
) -> Result<Vec<bins::BinFile>, BinstallError> {
// Build final metadata
let meta = fetcher.target_meta();
let bin_files = collect_bin_files(
fetcher,
package,
meta,
binaries,
bin_path.to_path_buf(),
install_path.to_path_buf(),
)?;
// Download and extract it.
// If that fails, then ignore this fetcher.
fetcher.fetch_and_extract(bin_path).await?;
@ -316,6 +312,15 @@ async fn download_extract_and_verify(
// Verify that all the bin_files exist
block_in_place(|| {
let bin_files = collect_bin_files(
fetcher,
package,
meta,
binaries,
bin_path.to_path_buf(),
install_path.to_path_buf(),
)?;
for bin_file in bin_files.iter() {
bin_file.check_source_exists()?;
}
@ -324,25 +329,15 @@ async fn download_extract_and_verify(
})
}
/// * `binaries` - must not be empty
fn collect_bin_files(
fetcher: &dyn Fetcher,
package: &Package<Meta>,
mut meta: PkgMeta,
binaries: Vec<Product>,
meta: PkgMeta,
binaries: &[Product],
bin_path: PathBuf,
install_path: PathBuf,
) -> Result<Vec<bins::BinFile>, BinstallError> {
// Update meta
if fetcher.source_name() == "QuickInstall" {
// TODO: less of a hack?
meta.bin_dir = "{ bin }{ binary-ext }".to_string();
}
// Check binaries
if binaries.is_empty() {
return Err(BinstallError::UnspecifiedBinaries);
}
// List files to be installed
// based on those found via Cargo.toml
let bin_data = bins::Data {