Skip to content

Commit

Permalink
build: support build from non-repo
Browse files Browse the repository at this point in the history
  • Loading branch information
fioncat committed Dec 26, 2024
1 parent 2c7cc19 commit c70942e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 30 deletions.
19 changes: 0 additions & 19 deletions PKGBUILD

This file was deleted.

26 changes: 15 additions & 11 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,20 @@ use std::process::Command;
use simple_error::bail;
use vergen::{BuildBuilder, CargoBuilder, Emitter, RustcBuilder, SysinfoBuilder};

fn uncommitted_count() -> Result<usize, Box<dyn Error>> {
let output = exec_git(&["status", "-s"])?;
fn uncommitted_count() -> usize {
let output = match _exec_git(&["status", "-s"]) {
Ok(output) => output,
Err(_) => return 0,
};
let lines = output.trim().split('\n');
Ok(lines.filter(|line| !line.trim().is_empty()).count())
lines.filter(|line| !line.trim().is_empty()).count()
}

fn exec_git(args: &[&str]) -> String {
_exec_git(args).unwrap_or(String::from("unknown"))
}

fn exec_git(args: &[&str]) -> Result<String, Box<dyn Error>> {
fn _exec_git(args: &[&str]) -> Result<String, Box<dyn Error>> {
let mut cmd = Command::new("git");
let output = cmd.args(args).output()?;
if !output.status.success() {
Expand All @@ -35,12 +42,9 @@ fn main() -> Result<(), Box<dyn Error>> {
.add_instructions(&si)?
.emit()?;

let describe = match exec_git(&["describe", "--tags"]) {
Ok(d) => d,
Err(_) => String::from("unknown"),
};
let sha = exec_git(&["rev-parse", "HEAD"])?;
let short_sha = exec_git(&["rev-parse", "--short", "HEAD"])?;
let describe = exec_git(&["describe", "--tags"]);
let sha = exec_git(&["rev-parse", "HEAD"]);
let short_sha = exec_git(&["rev-parse", "--short", "HEAD"]);

let cargo_version = env!("CARGO_PKG_VERSION");
let stable_tag = format!("v{cargo_version}");
Expand All @@ -58,7 +62,7 @@ fn main() -> Result<(), Box<dyn Error>> {
(format!("{cargo_version}-dev_{short_sha}"), "dev")
};

let uncommitted_count = uncommitted_count()?;
let uncommitted_count = uncommitted_count();
if uncommitted_count > 0 {
version = format!("{version}-uncommitted");
build_type = "dev-uncommitted";
Expand Down

0 comments on commit c70942e

Please sign in to comment.