mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-05-28 22:52:57 +00:00
Split {format} and allow use of {binary-ext} in pkg-url (#95)
This from feedback in #19: > wrt. bin-dir and bin-path, this appears to be a typo / should all be called bin-dir This is only a readme fix afaict, I changed all occurences of `bin-path` in there to `bin-dir`. > wrt. format, those are actually two (unfortunately named) different concepts, the first refers to the archive format (eg. .tgz), the second to the binary format (which needs a .exe appended for windows). This introduces two new substitutions: - `binary-ext` is the old "`format` in `bin-dir`" - `archive-format` is the old "`format` in `pkg-url`" Contents are unchanged: `binary-ext` includes the dot, `archive-format` doesn't. That makes it easy to upgrade and also personally I slightly prefer it that way. The old contextual `format` is still available, "soft deprecated": it will be accepted silently so everything will work, but all documentation will use the new syntax. In the future we could move to a "hard deprecated" model where installing a package that uses `format` will warn the user / tell them to report that to the maintainer. I don't think we'll ever really be able to remove it but that should be good enough. A cool new feature is that `binary-ext` is now usable in `pkg-url`, which will be useful for raw binary downloads: ```toml pkg_url = "{ repo }/releases/download/v{ version }/{ name }-v{ version }-{ target }{ binary-ext }" ``` I've also added a bunch of tests to GhCrateMeta around the templating for `pkg-url`.
This commit is contained in:
parent
370ae05620
commit
6dcb1dd1b4
5 changed files with 215 additions and 34 deletions
26
src/bins.rs
26
src/bins.rs
|
@ -16,18 +16,20 @@ impl BinFile {
|
|||
pub fn from_product(data: &Data, product: &Product) -> Result<Self, anyhow::Error> {
|
||||
let base_name = product.name.clone().unwrap();
|
||||
|
||||
// Generate binary path via interpolation
|
||||
let binary_ext = if data.target.contains("windows") {
|
||||
".exe"
|
||||
} else {
|
||||
""
|
||||
};
|
||||
|
||||
let ctx = Context {
|
||||
name: &data.name,
|
||||
repo: data.repo.as_ref().map(|s| &s[..]),
|
||||
target: &data.target,
|
||||
version: &data.version,
|
||||
format: if data.target.contains("windows") {
|
||||
".exe"
|
||||
} else {
|
||||
""
|
||||
},
|
||||
bin: &base_name,
|
||||
format: binary_ext,
|
||||
binary_ext,
|
||||
};
|
||||
|
||||
// Generate install paths
|
||||
|
@ -39,8 +41,8 @@ impl BinFile {
|
|||
data.bin_path.join(&source_file_path)
|
||||
};
|
||||
|
||||
// Destination path is the install dir + base-name-version{.format}
|
||||
let dest_file_path = ctx.render("{ bin }-v{ version }{ format }")?;
|
||||
// Destination path is the install dir + base-name-version{.extension}
|
||||
let dest_file_path = ctx.render("{ bin }-v{ version }{ binary-ext }")?;
|
||||
let dest = data.install_path.join(dest_file_path);
|
||||
|
||||
// Link at install dir + base name
|
||||
|
@ -118,8 +120,14 @@ struct Context<'c> {
|
|||
pub repo: Option<&'c str>,
|
||||
pub target: &'c str,
|
||||
pub version: &'c str,
|
||||
pub format: &'c str,
|
||||
pub bin: &'c str,
|
||||
|
||||
/// Soft-deprecated alias for binary-ext
|
||||
pub format: &'c str,
|
||||
|
||||
/// Filename extension on the binary, i.e. .exe on Windows, nothing otherwise
|
||||
#[serde(rename = "binary-ext")]
|
||||
pub binary_ext: &'c str,
|
||||
}
|
||||
|
||||
impl<'c> Template for Context<'c> {}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue