aboutsummaryrefslogtreecommitdiffstats
path: root/xtask/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'xtask/src/main.rs')
-rw-r--r--xtask/src/main.rs66
1 files changed, 32 insertions, 34 deletions
diff --git a/xtask/src/main.rs b/xtask/src/main.rs
index 263c281..f4f8f82 100644
--- a/xtask/src/main.rs
+++ b/xtask/src/main.rs
@@ -12,14 +12,14 @@ use std::{
path::{Path, PathBuf},
};
-use anyhow::{anyhow, bail, ensure, Context, Result};
-use build_info::BuildInfo;
+use anyhow::{ensure, Context, Result};
use clap::{Parser, Subcommand, ValueEnum};
use flate2::{write::GzEncoder, Compression};
use once_cell::sync::Lazy;
use semver::{Prerelease, Version};
use tar::Builder;
+const TARGET: &str = env!("TARGET");
const PKG_NAME: &str = "projectr";
const PKG_VER: &str = env!("CARGO_PKG_VERSION");
const PKG_INCLUDE: &[&str] = &[
@@ -29,6 +29,22 @@ const PKG_INCLUDE: &[&str] = &[
"LICENSE",
];
+static PROJECT_ROOT: Lazy<PathBuf> = Lazy::new(|| {
+ let dir = std::env::current_dir().unwrap_or_else(|_| {
+ Path::new(env!("CARGO_MANIFEST_DIR"))
+ .parent()
+ .unwrap()
+ .to_path_buf()
+ });
+
+ dir.ancestors()
+ .find(|p| p.join(".git").is_dir())
+ .unwrap_or(&dir)
+ .to_path_buf()
+});
+static DIST_DIR: Lazy<PathBuf> = Lazy::new(|| PROJECT_ROOT.join("target").join("dist"));
+static RELEASE_DIR: Lazy<PathBuf> = Lazy::new(|| PROJECT_ROOT.join("target").join("release"));
+
fn main() -> Result<()> {
let cli = Cli::parse();
@@ -108,21 +124,22 @@ impl std::str::FromStr for Level {
}
fn version(force: bool) -> Result<Version> {
- use build_info::VersionControl::Git;
-
let version: Version = PKG_VER.parse()?;
- let BuildInfo {
- version_control: Some(Git(git)),
- ..
- } = build_info() else {
- bail!("Failed to get version control info.");
- };
-
- if force || git.tags.contains(&format!("v{version}")) {
+ if force {
Ok(version)
} else {
- Err(anyhow!("Failed to find git tag matching package version."))
+ let stdout = Command::new("git")
+ .arg("tag")
+ .arg("--points-at=HEAD")
+ .output()?
+ .stdout;
+
+ String::from_utf8(stdout)?
+ .lines()
+ .any(|s| s == format!("v{version}"))
+ .then_some(version)
+ .context("Failed to find git tag matching package version.")
}
}
@@ -130,7 +147,7 @@ fn out_dir() -> Result<PathBuf> {
RELEASE_DIR
.join("build")
.read_dir()
- .context("Failed to read build directory.")?
+ .context("Failed to read `target/release/build` directory.")?
.flatten()
.filter_map(|d| {
d.file_name()
@@ -152,8 +169,7 @@ fn out_dir() -> Result<PathBuf> {
}
fn generate_tar_gz(version: Version) -> Result<PathBuf> {
- let target = build_info::format!("{}", $.target.triple);
- let dist_pkg = DIST_DIR.join(format!("{PKG_NAME}-v{version}-{target}.tar.gz"));
+ let dist_pkg = DIST_DIR.join(format!("{PKG_NAME}-v{version}-{TARGET}.tar.gz"));
let binary = build_binary()?;
ensure!(binary.exists(), "Failed to find package binary",);
@@ -305,21 +321,3 @@ where
Ok(())
}
-
-static PROJECT_ROOT: Lazy<PathBuf> = Lazy::new(|| {
- let dir = std::env::current_dir().unwrap_or_else(|_| {
- Path::new(env!("CARGO_MANIFEST_DIR"))
- .parent()
- .unwrap()
- .to_path_buf()
- });
-
- dir.ancestors()
- .find(|p| p.join(".git").is_dir())
- .unwrap_or(&dir)
- .to_path_buf()
-});
-static DIST_DIR: Lazy<PathBuf> = Lazy::new(|| PROJECT_ROOT.join("target").join("dist"));
-static RELEASE_DIR: Lazy<PathBuf> = Lazy::new(|| PROJECT_ROOT.join("target").join("release"));
-
-build_info::build_info!(fn build_info);