Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copying additional files #24

Merged
merged 4 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/foo.txt" "$pkgdir/path/to/target/foo.txt"
}
```

#### Fixed

Expand Down
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@ strip = true
opt-level = "z"
codegen-units = 1
panic = "abort"

[package.metadata.aur]
# depends = ["blah"]
# files = [[".github/dependabot.yml", "/usr/local/share/cargo-aur/dependabot.yml"]]
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,26 @@ optdepends = ["sushi", "ramen"]

And these settings will be copied to your PKGBUILD.

### Including Additional Files

The `files` list can be used to designated initial files to be copied the user's
filesystem. So this:

```toml
[package.metadata.aur]
files = [["path/to/local/foo.txt", "/usr/local/share/your-app/foo.txt"]]
```

will result in this:

```toml
package() {
install -Dm755 your-app -t "$pkgdir/usr/bin"
install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
install -Dm644 "path/to/local/foo.txt" "$pkgdir/usr/local/share/your-app/foo.txt"
}
```

### Static Binaries

Run with `--musl` to produce a release binary that is statically linked via
Expand Down
6 changes: 5 additions & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Errors that can occur in this application.

use std::fmt::Display;
use std::{fmt::Display, path::PathBuf};

pub(crate) enum Error {
IO(std::io::Error),
Expand All @@ -9,6 +9,7 @@ pub(crate) enum Error {
Utf8OsString,
MissingMuslTarget,
MissingLicense,
TargetNotAbsolute(PathBuf),
}

impl Display for Error {
Expand All @@ -25,6 +26,9 @@ impl Display for Error {
Error::MissingLicense => {
write!(f, "Missing LICENSE file. See https://choosealicense.com/")
}
Error::TargetNotAbsolute(p) => {
write!(f, "Target filepath is not absolute: {}", p.display())
}
}
}
}
Expand Down
14 changes: 14 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -150,4 +162,6 @@ pub struct AUR {
depends: Vec<String>,
#[serde(default)]
optdepends: Vec<String>,
#[serde(default)]
pub files: Vec<(PathBuf, PathBuf)>,
}
33 changes: 31 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand All @@ -234,6 +237,21 @@ where
)?;
}

if let Some(aur) = package.metadata.as_ref().and_then(|m| m.aur.as_ref()) {
for (source, target) in aur.files.iter() {
if target.has_root().not() {
return Err(Error::TargetNotAbsolute(target.to_path_buf()));
} else {
writeln!(
file,
" install -Dm644 \"{}\" \"$pkgdir{}\"",
source.display(),
target.display()
)?;
}
}
}

writeln!(file, "}}")?;
Ok(())
}
Expand Down Expand Up @@ -280,6 +298,17 @@ fn tarball(
if let Some(lic) = license {
command.arg(lic.path());
}
if let Some(files) = config
.package
.metadata
.as_ref()
.and_then(|m| m.aur.as_ref())
.map(|a| a.files.as_slice())
{
for (file, _) in files {
command.arg(file);
}
}
command.status()?;

std::fs::remove_file(binary_name)?;
Expand Down