From 49ed88774dd8b071502d13a118c97ac1adf73437 Mon Sep 17 00:00:00 2001 From: Edwin Smith Date: Mon, 16 Jan 2023 03:24:52 -0800 Subject: [PATCH] Refactor as hhdg multitool with diff subcommand Summary: We'd like to consolidate a number of different ad-hoc tools for working with hhdg files (dep graphs) into one multitool with subcommands. Reviewed By: CatherineGasnier Differential Revision: D42519414 fbshipit-source-id: 85c0783bca6e56e5b0b67d5b272d515f538cb023 --- .../cargo/hhdgdiff => hhdg/cargo/hhdg}/Cargo.toml | 8 +++---- .../{hhdgdiff/hhdgdiff.rs => hhdg/diff.rs} | 12 +++------- hphp/hack/src/depgraph/hhdg/hhdg.rs | 26 ++++++++++++++++++++++ 3 files changed, 33 insertions(+), 13 deletions(-) rename hphp/hack/src/depgraph/{hhdgdiff/cargo/hhdgdiff => hhdg/cargo/hhdg}/Cargo.toml (73%) rename hphp/hack/src/depgraph/{hhdgdiff/hhdgdiff.rs => hhdg/diff.rs} (95%) create mode 100644 hphp/hack/src/depgraph/hhdg/hhdg.rs diff --git a/hphp/hack/src/depgraph/hhdgdiff/cargo/hhdgdiff/Cargo.toml b/hphp/hack/src/depgraph/hhdg/cargo/hhdg/Cargo.toml similarity index 73% rename from hphp/hack/src/depgraph/hhdgdiff/cargo/hhdgdiff/Cargo.toml rename to hphp/hack/src/depgraph/hhdg/cargo/hhdg/Cargo.toml index 9557b464723..cdeb22e2699 100644 --- a/hphp/hack/src/depgraph/hhdgdiff/cargo/hhdgdiff/Cargo.toml +++ b/hphp/hack/src/depgraph/hhdg/cargo/hhdg/Cargo.toml @@ -1,12 +1,12 @@ -# @generated by autocargo from //hphp/hack/src/depgraph/hhdgdiff:hhdgdiff +# @generated by autocargo from //hphp/hack/src/depgraph/hhdg:hhdg [package] -name = "hhdgdiff" +name = "hhdg" version = "0.0.0" edition = "2021" [[bin]] -name = "hhdgdiff" -path = "../../hhdgdiff.rs" +name = "hhdg" +path = "../../hhdg.rs" [dependencies] anyhow = "1.0.65" diff --git a/hphp/hack/src/depgraph/hhdgdiff/hhdgdiff.rs b/hphp/hack/src/depgraph/hhdg/diff.rs similarity index 95% rename from hphp/hack/src/depgraph/hhdgdiff/hhdgdiff.rs rename to hphp/hack/src/depgraph/hhdg/diff.rs index 4cdb88efaad..cb34874a0d3 100644 --- a/hphp/hack/src/depgraph/hhdgdiff/hhdgdiff.rs +++ b/hphp/hack/src/depgraph/hhdg/diff.rs @@ -1,4 +1,4 @@ -// Copyright (c) Facebook, Inc. and its affiliates. +// Copyright (c) Meta Platforms, Inc. and its affiliates. // // This source code is licensed under the MIT license found in the // LICENSE file in the "hack" directory of this source tree. @@ -78,8 +78,7 @@ fn compare(dg1: &DepGraph<'_>, dg2: &DepGraph<'_>, prefix: &str, nodes: &Nodes) num_different } -fn main() -> Result<()> { - let opts = Opts::parse(); +pub(crate) fn run(opts: Opts) -> Result { let opener = DepGraphOpener::from_path(&opts.dg1).with_context(|| opts.dg1.display().to_string())?; let dg1 = (opener.open()) @@ -113,12 +112,7 @@ fn main() -> Result<()> { } } - let num_different = compare(&dg1, &dg2, "-", &nodes) + compare(&dg2, &dg1, "+", &nodes); - - if num_different != 0 { - std::process::exit(1); - } - Ok(()) + Ok(compare(&dg1, &dg2, "-", &nodes) + compare(&dg2, &dg1, "+", &nodes)) } #[derive(Default)] diff --git a/hphp/hack/src/depgraph/hhdg/hhdg.rs b/hphp/hack/src/depgraph/hhdg/hhdg.rs new file mode 100644 index 00000000000..9b7f865b72f --- /dev/null +++ b/hphp/hack/src/depgraph/hhdg/hhdg.rs @@ -0,0 +1,26 @@ +// Copyright (c) Meta Platforms, Inc. and its affiliates. +// +// This source code is licensed under the MIT license found in the +// LICENSE file in the "hack" directory of this source tree. +mod diff; +use anyhow::Result; +use clap::Parser; + +/// A mult-tool for working with hhdg files +#[derive(Parser, Debug)] +pub enum Command { + /// Compare two hhdg files and show differences with human readable hash labels + Diff(diff::Opts), +} + +fn main() -> Result<()> { + match Command::parse() { + Command::Diff(opts) => { + let num_different = diff::run(opts)?; + if num_different != 0 { + std::process::exit(1); + } + Ok(()) + } + } +} -- 2.11.4.GIT