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

Add utility to install git hooks. #787

Merged
merged 1 commit into from
Jun 14, 2022
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).

### Internal

- #787 - add installer for git hooks.
- #786 - Migrate build script to rust: `cargo build-docker-image $TARGET`
- #730 - make FreeBSD builds more resilient.
- #670 - Use serde for deserialization of Cross.toml
Expand Down
24 changes: 24 additions & 0 deletions xtask/src/install_git_hooks.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use clap::Args;

use std::path::Path;

#[derive(Args, Debug)]
pub struct InstallGitHooks {
/// Provide verbose diagnostic output.
#[clap(short, long)]
verbose: bool,
}

pub fn install_git_hooks(InstallGitHooks { verbose }: InstallGitHooks) -> cross::Result<()> {
let metadata = cross::cargo_metadata_with_args(
Some(Path::new(env!("CARGO_MANIFEST_DIR"))),
None,
verbose,
)?
.ok_or_else(|| eyre::eyre!("could not find cross workspace"))?;
let git_hooks = metadata.workspace_root.join(".git").join("hooks");
let cross_dev = metadata.workspace_root.join("xtask").join("src");
std::fs::copy(cross_dev.join("pre-commit"), git_hooks.join("pre-commit"))?;

Ok(())
}
6 changes: 6 additions & 0 deletions xtask/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#![deny(missing_debug_implementations, rust_2018_idioms)]

pub mod build_docker_image;
pub mod install_git_hooks;
pub mod target_info;

use std::path::PathBuf;

use clap::{Parser, Subcommand};

use self::build_docker_image::BuildDockerImage;
use self::install_git_hooks::InstallGitHooks;
use self::target_info::TargetInfo;

#[derive(Parser, Debug)]
Expand All @@ -22,6 +24,7 @@ enum Commands {
/// Extract and print info for targets.
TargetInfo(TargetInfo),
BuildDockerImage(BuildDockerImage),
InstallGitHooks(InstallGitHooks),
}

pub fn main() -> cross::Result<()> {
Expand All @@ -36,6 +39,9 @@ pub fn main() -> cross::Result<()> {
let engine = get_container_engine(args.engine.as_deref())?;
build_docker_image::build_docker_image(args, &engine)?;
}
Commands::InstallGitHooks(args) => {
install_git_hooks::install_git_hooks(args)?;
}
}

Ok(())
Expand Down
12 changes: 12 additions & 0 deletions xtask/src/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash

echo "Running rustfmt and clippy checks."

set -ex

flags=(--all-features --all-targets --workspace)
cargo fmt -- --check
cargo clippy "${flags[@]}" -- --deny warnings
if cargo +nightly >/dev/null 2>&1; then
cargo +nightly clippy "${flags[@]}" -- --deny warnings
fi