-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
25 additions
and
82 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,11 @@ | ||
use anyhow::{bail, Context, Result}; | ||
use clap::{Parser, Subcommand}; | ||
use std::{ | ||
fs, | ||
os::unix::fs::PermissionsExt, | ||
path::{Path, PathBuf}, | ||
}; | ||
use xshell::{cmd, Shell}; | ||
|
||
#[derive(Parser)] | ||
#[command(author, version, about, long_about = None)] | ||
struct Cli { | ||
#[command(subcommand)] | ||
command: Commands, | ||
} | ||
|
||
#[derive(Subcommand)] | ||
enum Commands { | ||
/// Build the project | ||
Build, | ||
/// Install the project | ||
Install { | ||
#[arg(long, default_value = "/")] | ||
destdir: PathBuf, | ||
#[arg(long, default_value = "usr")] | ||
prefix: PathBuf, | ||
#[arg(long, default_value = "755")] | ||
mode: String, | ||
}, | ||
} | ||
use anyhow::Result; | ||
use clap::Parser; | ||
use xtask_common::{clap, Cli, Empty}; | ||
|
||
fn main() -> Result<()> { | ||
let cli = Cli::parse(); | ||
|
||
match &cli.command { | ||
Commands::Build => build(), | ||
Commands::Install { | ||
destdir, | ||
prefix, | ||
mode, | ||
} => install(destdir, prefix, mode), | ||
} | ||
} | ||
|
||
fn build() -> Result<()> { | ||
let sh = Shell::new()?; | ||
println!("Building release version..."); | ||
cmd!(sh, "cargo build --release").run()?; | ||
Ok(()) | ||
} | ||
|
||
fn install(destdir: &Path, prefix: &Path, mode: &str) -> Result<()> { | ||
if !fs::exists("target/release/verdi")? { | ||
bail!("You must build the project first!") | ||
} | ||
|
||
let binary_dir = destdir.join(prefix).join("bin"); | ||
|
||
// Create target directory if it doesn't exist | ||
fs::create_dir_all(&binary_dir).context("Failed to create binary directory")?; | ||
|
||
let target = binary_dir.join("verdi"); | ||
|
||
fs::copy("target/release/verdi", &target) | ||
.with_context(|| format!("Failed to copy binary to {:?}", target))?; | ||
|
||
// Parse octal mode string (e.g., "755" or "0755") | ||
let mode = u32::from_str_radix(mode.trim_start_matches('0'), 8) | ||
.with_context(|| format!("Invalid mode: {mode}"))?; | ||
let cli: Cli<Empty> = Cli::parse(); | ||
|
||
fs::set_permissions(&target, fs::Permissions::from_mode(mode)) | ||
.context("Failed to set binary permissions")?; | ||
cli.command.execute("verdi")?; | ||
|
||
println!("Installation complete!"); | ||
Ok(()) | ||
} |