Add new crate leon-macros that provide template! with identical syntax as runtime parsing (#946)

`leon_macros::template!` can parse template at compile-time.
It accepts a utf-8 string literal and uses `leon` internally to parse it, then generate code that evaluates to `Template<'static>`.

 - Exclude fuzz from crate leon when publishing
 - Impl fn-like proc-macro `leon_macros::template!`
 - Add dep `leon-macros` to binstalk
 - Use `leon_macros::template!` in `binstalk::fetchers::gh_crate_meta::hosting`
 - Add doc for `leon-macros` in `leon`
 - Improve `std::fmt::Display` impl for `leon::ParseError`
 - Fixed broken infra link in leon

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
Jiahao XU 2023-04-17 14:50:58 +10:00 committed by GitHub
parent fa0455a417
commit 5683ca2476
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 373 additions and 91 deletions

View file

@ -1,5 +1,6 @@
use itertools::Itertools;
use leon::{template, Item, Template};
use leon::{Item, Template};
use leon_macros::template;
use url::Url;
use crate::errors::BinstallError;
@ -16,62 +17,36 @@ 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: &[Template<'_>] = &[
template!("/", { "name" }, "-", { "target" }, "-v", { "version" }, {
"archive-suffix"
}),
template!("/", { "name" }, "-", { "target" }, "-", { "version" }, {
"archive-suffix"
}),
template!("/", { "name" }, "-", { "version" }, "-", { "target" }, {
"archive-suffix"
}),
template!("/", { "name" }, "-v", { "version" }, "-", { "target" }, {
"archive-suffix"
}),
template!("/", { "name" }, "_", { "target" }, "_v", { "version" }, {
"archive-suffix"
}),
template!("/", { "name" }, "_", { "target" }, "_", { "version" }, {
"archive-suffix"
}),
template!("/", { "name" }, "_", { "version" }, "_", { "target" }, {
"archive-suffix"
}),
template!("/", { "name" }, "_v", { "version" }, "_", { "target" }, {
"archive-suffix"
}),
template!("/{ name }-{ target }-v{ version }{ archive-suffix }"),
template!("/{ name }-{ target }-{ version }{ archive-suffix }"),
template!("/{ name }-{ version }-{ target }{ archive-suffix }"),
template!("/{ name }-v{ version }-{ target }{ archive-suffix }"),
template!("/{ name }_{ target }_v{ version }{ archive-suffix }"),
template!("/{ name }_{ target }_{ version }{ archive-suffix }"),
template!("/{ name }_{ version }_{ target }{ archive-suffix }"),
template!("/{ name }_v{ version }_{ target }{ archive-suffix }"),
];
pub const NOVERSION_FILENAMES: &[Template<'_>] = &[
template!("/", { "name" }, "-", { "target" }, { "archive-suffix" }),
template!("/", { "name" }, "_", { "target" }, { "archive-suffix" }),
template!("/{ name }-{ target }{ archive-suffix }"),
template!("/{ name }_{ target }{ archive-suffix }"),
];
const GITHUB_RELEASE_PATHS: &[Template<'_>] = &[
template!({ "repo" }, "/releases/download/", { "version" }),
template!({ "repo" }, "/releases/download/v", { "version" }),
template!("{ repo }/releases/download/{ version }"),
template!("{ repo }/releases/download/v{ version }"),
];
const GITLAB_RELEASE_PATHS: &[Template<'_>] = &[
template!(
{ "repo" },
"/-/releases/",
{ "version" },
"/downloads/binaries"
),
template!(
{ "repo" },
"/-/releases/v",
{ "version" },
"/downloads/binaries"
),
template!("{ repo }/-/releases/{ version }/downloads/binaries"),
template!("{ repo }/-/releases/v{ version }/downloads/binaries"),
];
const BITBUCKET_RELEASE_PATHS: &[Template<'_>] = &[template!({ "repo" }, "/downloads")];
const BITBUCKET_RELEASE_PATHS: &[Template<'_>] = &[template!("{ repo }/downloads")];
const SOURCEFORGE_RELEASE_PATHS: &[Template<'_>] = &[
template!({ "repo" }, "/files/binaries/", { "version" }),
template!({ "repo" }, "/files/binaries/v", { "version" }),
template!("{ repo }/files/binaries/{ version }"),
template!("{ repo }/files/binaries/v{ version }"),
];
impl RepositoryHost {

View file

@ -1,7 +1,7 @@
use std::{future::Future, pin::Pin};
use tokio::sync::mpsc;
/// Given multiple futures with output = Result<Option<T>, E>,
/// Given multiple futures with output = `Result<Option<T>, E>`,
/// returns the the first one that returns either `Err(_)` or
/// `Ok(Some(_))`.
pub struct FuturesResolver<T, E> {