From 6ea9720f902f737bfd4b274f23689d4f865cde8b Mon Sep 17 00:00:00 2001 From: Colin Woodbury Date: Fri, 22 Mar 2024 08:19:40 +0900 Subject: [PATCH] feat: inject custom commands into `package()` --- CHANGELOG.md | 9 +++++++++ Cargo.toml | 1 + README.md | 22 ++++++++++++++++++++++ src/lib.rs | 2 ++ src/main.rs | 4 ++++ 5 files changed, 38 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c43134..5ee177a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # `cargo-aur` Changelog +## Unreleased + +#### Added + +- A new `custom` field in `[package.metadata.aur]` which accepts a list of + strings that will be added as-is to the `package()` function of the PKGBUILD. + This allows the user to add specific extra commands to their build process. + See the README for more details. + ## 1.7.1 (2024-03-18) #### Fixed diff --git a/Cargo.toml b/Cargo.toml index 421abe6..0da1344 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,3 +28,4 @@ panic = "abort" [package.metadata.aur] # depends = ["blah"] # files = [[".github/dependabot.yml", "/usr/local/share/cargo-aur/dependabot.yml"]] +custom = ["echo hi"] diff --git a/README.md b/README.md index bfcc99a..29eac94 100644 --- a/README.md +++ b/README.md @@ -103,6 +103,28 @@ package() { } ``` +### Custom commands within `package()` + +The `custom` list can be used to add specific commands to the `package()` +function. This config: + +```toml +[package.metadata.aur] +custom = ["echo hi"] +``` + +yields: + +``` +package() { + install -Dm755 cargo-aur -t "$pkgdir/usr/bin" + install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE" + echo hi +} +``` + +**Note:** Caveat emptor. No attempt is made to verify the injected commands. + ### Static Binaries Run with `--musl` to produce a release binary that is statically linked via diff --git a/src/lib.rs b/src/lib.rs index 3dc379e..8f077f6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -164,4 +164,6 @@ pub struct AUR { optdepends: Vec, #[serde(default)] pub files: Vec<(PathBuf, PathBuf)>, + #[serde(default)] + pub custom: Vec, } diff --git a/src/main.rs b/src/main.rs index 58e5581..a172a5d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -253,6 +253,10 @@ where )?; } } + + for custom in aur.custom.iter() { + writeln!(file, " {}", custom)?; + } } writeln!(file, "}}")?;