feat: support files field in package metadata

This commit is contained in:
Colin Woodbury
2024-03-05 14:34:28 +09:00
parent 9707e33204
commit fc23ad83fe
4 changed files with 40 additions and 2 deletions
+11
View File
@@ -6,6 +6,17 @@
- The `--output` flag for customizing the location of the output produced by
`cargo aur`. If unused, the default remains `target/cargo-aur/`.
- A new `files` field in `[package.metadata.aur]`, which accepts a list-of-pairs
of additional files you want copied to the user's filesystem upon package
installation. Output looks like:
```
package() {
install -Dm755 cargo-aur -t "$pkgdir/usr/bin"
install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
install -Dm644 "/path/to/original" "/path/to/target"
}
```
#### Fixed
+4
View File
@@ -24,3 +24,7 @@ strip = true
opt-level = "z"
codegen-units = 1
panic = "abort"
[package.metadata.aur]
depends = ["blah"]
files = [["/path/to/original", "/path/to/target"]]
+14
View File
@@ -91,6 +91,18 @@ pub struct Metadata {
pub aur: Option<AUR>,
}
impl Metadata {
/// The metadata block actually has some contents.
pub fn non_empty(&self) -> bool {
self.depends.is_empty().not()
|| self.optdepends.is_empty().not()
|| self
.aur
.as_ref()
.is_some_and(|aur| aur.depends.is_empty().not() || aur.optdepends.is_empty().not())
}
}
impl std::fmt::Display for Metadata {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
// Reconcile which section to read extra dependency information from.
@@ -150,4 +162,6 @@ pub struct AUR {
depends: Vec<String>,
#[serde(default)]
optdepends: Vec<String>,
#[serde(default)]
pub files: Vec<(String, String)>,
}
+11 -2
View File
@@ -208,8 +208,11 @@ where
writeln!(file, "provides=(\"{}\")", package.name)?;
writeln!(file, "conflicts=(\"{}\")", package.name)?;
if let Some(metadata) = package.metadata.as_ref() {
writeln!(file, "{}", metadata)?;
match package.metadata.as_ref() {
Some(metadata) if metadata.non_empty() => {
writeln!(file, "{}", metadata)?;
}
Some(_) | None => {}
}
writeln!(file, "source=(\"{}\")", source)?;
@@ -234,6 +237,12 @@ where
)?;
}
if let Some(aur) = package.metadata.as_ref().and_then(|m| m.aur.as_ref()) {
for (source, target) in aur.files.iter() {
writeln!(file, " install -Dm644 \"{}\" \"{}\"", source, target)?;
}
}
writeln!(file, "}}")?;
Ok(())
}