Skip to content

Commit

Permalink
Add xtask to update upstream submodule (#142)
Browse files Browse the repository at this point in the history
* Add `xtask` to update upstream submodule
  • Loading branch information
abrown authored Oct 7, 2024
1 parent 2388a25 commit 2981c7b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
5 changes: 5 additions & 0 deletions crates/xtask/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
mod bump;
mod codegen;
mod publish;
mod update;
mod util;

use anyhow::Result;
use bump::BumpCommand;
use clap::{Parser, Subcommand};
use codegen::CodegenCommand;
use publish::PublishCommand;
use update::UpdateCommand;

fn main() -> Result<()> {
let cli = Cli::parse();
Expand All @@ -29,6 +31,8 @@ struct Cli {

#[derive(Debug, Subcommand)]
enum XtaskCommand {
/// Update the upstream OpenVINO Git submodule.
Update(UpdateCommand),
/// Generate the Rust bindings for OpenVINO to use in the openvino-sys crate.
Codegen(CodegenCommand),
/// Increment the version of each of the publishable crates.
Expand All @@ -40,6 +44,7 @@ enum XtaskCommand {
impl XtaskCommand {
fn execute(&self) -> Result<()> {
match self {
Self::Update(update) => update.execute(),
Self::Codegen(codegen) => codegen.execute(),
Self::Bump(bump) => bump.execute(),
Self::Publish(publish) => publish.execute(),
Expand Down
23 changes: 23 additions & 0 deletions crates/xtask/src/update.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use crate::util::{exec, path_to_crates};
use anyhow::Result;
use clap::Args;
use std::process::Command;

#[derive(Debug, Args)]
pub struct UpdateCommand {
/// The upstream tag to update to; see <https://github.com/openvinotoolkit/openvino/releases>.
#[arg(name = "TAG")]
tag: String,
}

impl UpdateCommand {
/// Retrieve the requested tag and checkout the upstream submodule using `git`.
pub fn execute(&self) -> Result<()> {
let submodule = path_to_crates()?.join("openvino-sys/upstream");
let submodule = submodule.to_string_lossy();
exec(Command::new("git").args(["-C", &submodule, "fetch", "origin", "tag", &self.tag]))?;
exec(Command::new("git").args(["-C", &submodule, "checkout", &self.tag]))?;
println!("> to use the updated headers, run `cargo xtask codegen`");
Ok(())
}
}
1 change: 1 addition & 0 deletions crates/xtask/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use toml::Value;

/// Convenience wrapper for executing commands.
pub fn exec(command: &mut Command) -> Result<()> {
eprintln!("+ executing: {:?}", &command);
let status = command.status()?;
if status.success() {
Ok(())
Expand Down

0 comments on commit 2981c7b

Please sign in to comment.