Make binaries with required-features optional (#438)

* Make binaries with `required-features` optional so that crates like `sccache` would work as expected.
* Fix `infer_bin_dir_template`: concat with `data.bin_path` introduced in #417 
* Always `chmod +x $bin` on unix in case the archive (e.g. `sccache`) did not set the executable bit of fmt == Bin.
* CI: Install `sccache` but do not run it since it requires cargo env to be ready

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
Jiahao XU 2022-09-28 13:46:55 +10:00 committed by GitHub
parent 4ba1e221ea
commit f482e362ba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 18 deletions

View file

@ -327,11 +327,36 @@ async fn download_extract_and_verify(
no_symlinks,
)?;
for bin_file in bin_files.iter() {
bin_file.check_source_exists()?;
}
let name = &package.name;
Ok(bin_files)
binaries
.iter()
.zip(bin_files)
.filter_map(|(bin, bin_file)| {
match bin_file.check_source_exists() {
Ok(()) => Some(Ok(bin_file)),
// This binary is optional
Err(err) => {
let required_features = &bin.required_features;
if required_features.is_empty() {
// This bin is not optional, error
Some(Err(err))
} else {
// Optional, print a warning and continue.
let bin_name = bin.name.as_deref().unwrap();
let features = required_features.join(",");
warn!(
"When resolving {name} bin {bin_name} is not found. \
But since it requies features {features}, this bin is ignored."
);
None
}
}
}
})
.collect::<Result<Vec<bins::BinFile>, BinstallError>>()
})
}