Improve auto discover (#433)

* Add new field `gh_crate_meta::Context::archive_suffix`
* Support `archive_suffix = ""` for unix
* Use `archive-suffix` in `FULL_FILENAMES` & `NOVERSION_FILENAMES` to support `PkgFmt::Bin`
* Simplify `PkgFmt::extensions`
* Fix `default_bin_dir_template` in `infer_bin_dir_template`: Fix typo `archive_suffix`
* Test `default_bin_dir_template` in CI
* Fix installation of `PkgFmt::Bin`: `chmod +x $bin` on unix if fmt == Bin
* Add miniserve to `.github/scripts/tests.sh`
* Update `SUPPORT.md`
* Add github-test-Cargo2.toml to test Github pkg-url with bin-dir provided
* Avoid allocation on processing `path_normalized` in `BinFile::from_product`

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
Jiahao XU 2022-09-28 12:52:14 +10:00 committed by GitHub
parent c15903684f
commit 4ba1e221ea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 94 additions and 51 deletions

View file

@ -203,6 +203,9 @@ struct Context<'c> {
#[serde(rename = "archive-format")]
pub archive_format: &'c str,
#[serde(rename = "archive-suffix")]
pub archive_suffix: &'c str,
/// Filename extension on the binary, i.e. .exe on Windows, nothing otherwise
#[serde(rename = "binary-ext")]
pub binary_ext: &'c str,
@ -211,9 +214,18 @@ struct Context<'c> {
impl<'c> Context<'c> {
pub(self) fn from_data_with_repo(
data: &'c Data,
archive_format: &'c str,
archive_suffix: &'c str,
repo: Option<&'c str>,
) -> Self {
let archive_format = if archive_suffix.is_empty() {
// Empty archive_suffix means PkgFmt::Bin
"bin"
} else {
debug_assert!(archive_suffix.starts_with('.'), "{archive_suffix}");
&archive_suffix[1..]
};
Self {
name: &data.name,
repo,
@ -221,6 +233,7 @@ impl<'c> Context<'c> {
version: &data.version,
format: archive_format,
archive_format,
archive_suffix,
binary_ext: if data.target.contains("windows") {
".exe"
} else {
@ -267,7 +280,7 @@ mod test {
meta,
};
let ctx = Context::from_data(&data, "tgz");
let ctx = Context::from_data(&data, ".tgz");
assert_eq!(
ctx.render_url(DEFAULT_PKG_URL).unwrap(),
url("https://github.com/ryankurte/cargo-binstall/releases/download/v1.2.3/cargo-binstall-x86_64-unknown-linux-gnu-v1.2.3.tgz")
@ -286,7 +299,7 @@ mod test {
meta,
};
let ctx = Context::from_data(&data, "tgz");
let ctx = Context::from_data(&data, ".tgz");
ctx.render_url(data.meta.pkg_url.as_deref().unwrap())
.unwrap();
}
@ -306,7 +319,7 @@ mod test {
meta,
};
let ctx = Context::from_data(&data, "tgz");
let ctx = Context::from_data(&data, ".tgz");
assert_eq!(
ctx.render_url(data.meta.pkg_url.as_deref().unwrap()).unwrap(),
url("https://example.com/releases/download/v1.2.3/cargo-binstall-x86_64-unknown-linux-gnu-v1.2.3.tgz")
@ -330,7 +343,7 @@ mod test {
meta,
};
let ctx = Context::from_data(&data, "tgz");
let ctx = Context::from_data(&data, ".tgz");
assert_eq!(
ctx.render_url(data.meta.pkg_url.as_deref().unwrap()).unwrap(),
url("https://github.com/rust-iot/rust-radio-sx128x/releases/download/v0.14.1-alpha.5/sx128x-util-x86_64-unknown-linux-gnu-v0.14.1-alpha.5.tgz")
@ -352,7 +365,7 @@ mod test {
meta,
};
let ctx = Context::from_data(&data, "tgz");
let ctx = Context::from_data(&data, ".tgz");
assert_eq!(
ctx.render_url(data.meta.pkg_url.as_deref().unwrap()).unwrap(),
url("https://github.com/rust-iot/rust-radio-sx128x/releases/download/v0.14.1-alpha.5/sx128x-util-x86_64-unknown-linux-gnu-v0.14.1-alpha.5.tgz")
@ -378,7 +391,7 @@ mod test {
meta,
};
let ctx = Context::from_data(&data, "txz");
let ctx = Context::from_data(&data, ".txz");
assert_eq!(
ctx.render_url(data.meta.pkg_url.as_deref().unwrap()).unwrap(),
url("https://github.com/watchexec/cargo-watch/releases/download/v9.0.0/cargo-watch-v9.0.0-aarch64-apple-darwin.tar.xz")
@ -401,7 +414,7 @@ mod test {
meta,
};
let ctx = Context::from_data(&data, "bin");
let ctx = Context::from_data(&data, ".bin");
assert_eq!(
ctx.render_url(data.meta.pkg_url.as_deref().unwrap()).unwrap(),
url("https://github.com/watchexec/cargo-watch/releases/download/v9.0.0/cargo-watch-v9.0.0-aarch64-pc-windows-msvc.exe")

View file

@ -14,15 +14,15 @@ pub enum RepositoryHost {
/// Make sure to update possible_dirs in `bins::infer_bin_dir_template`
/// if you modified FULL_FILENAMES or NOVERSION_FILENAMES.
pub const FULL_FILENAMES: &[&str] = &[
"{ name }-{ target }-v{ version }.{ archive-format }",
"{ name }-{ target }-{ version }.{ archive-format }",
"{ name }-{ version }-{ target }.{ archive-format }",
"{ name }-v{ version }-{ target }.{ archive-format }",
"{ name }-{ target }-v{ version }{ archive-suffix }",
"{ name }-{ target }-{ version }{ archive-suffix }",
"{ name }-{ version }-{ target }{ archive-suffix }",
"{ name }-v{ version }-{ target }{ archive-suffix }",
];
pub const NOVERSION_FILENAMES: &[&str] = &[
"{ name }-{ target }.{ archive-format }",
"{ name }.{ archive-format }",
"{ name }-{ target }{ archive-suffix }",
"{ name }{ archive-suffix }",
];
impl RepositoryHost {