Skip to content
Open
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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ gumdrop = "0.8"
hmac-sha256 = "1.1"
serde = { version = "1.0", features = ["derive"] }
toml = "0.8"
cargo_metadata = "0.19"

[profile.release]
lto = true
Expand Down
10 changes: 10 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub(crate) enum Error {
MissingMuslTarget,
MissingLicense,
TargetNotAbsolute(PathBuf),
Metadata(cargo_metadata::Error),
}

impl Display for Error {
Expand All @@ -29,6 +30,9 @@ impl Display for Error {
Error::TargetNotAbsolute(p) => {
write!(f, "Target filepath is not absolute: {}", p.display())
}
Error::Metadata(m) => {
write!(f, "Failed to gather metadata: {}", m)
}
}
}
}
Expand All @@ -39,6 +43,12 @@ impl From<std::str::Utf8Error> for Error {
}
}

impl From<cargo_metadata::Error> for Error {
fn from(v: cargo_metadata::Error) -> Self {
Self::Metadata(v)
}
}

impl From<toml::de::Error> for Error {
fn from(v: toml::de::Error) -> Self {
Self::Toml(v)
Expand Down
14 changes: 9 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ mod error;

use crate::error::Error;
use cargo_aur::{GitHost, Package};
use cargo_metadata::MetadataCommand;
use colored::*;
use gumdrop::{Options, ParsingStyle};
use hmac_sha256::Hash;
Expand Down Expand Up @@ -99,12 +100,15 @@ fn work(args: Args) -> Result<(), Error> {
// Where cargo expects to read and write to. By default we want to read the
// built binary from `target/release` and we want to write our results to
// `target/cargo-aur`, but these are configurable by the user.
let cargo_target: PathBuf = match std::env::var_os("CARGO_TARGET_DIR") {
Some(p) => PathBuf::from(p),
None => PathBuf::from("target"),
};
let metadata = MetadataCommand::new().exec()?;
let cargo_target: PathBuf = metadata.target_directory.canonicalize()?;

let output = args.output.unwrap_or(cargo_target.join("cargo-aur"));
let output = if let Some(pkgname) = metadata.root_package() {
args.output
.unwrap_or(cargo_target.join("cargo-aur").join(&pkgname.name))
} else {
args.output.unwrap_or(cargo_target.join("cargo-aur"))
};

// Ensure the target can actually be written to. Otherwise the `tar`
// operation later on will fail.
Expand Down