From fb0a273f50d0b7d429d01260c384918eabdb065a Mon Sep 17 00:00:00 2001 From: Rajneesh Lakkundi Date: Mon, 7 Oct 2024 08:10:35 -0700 Subject: [PATCH] Move build_count to buck2_common to allow sharing Summary: BuildCountManager is presently used only in recorder. However, in the upcoming diffs, this will be used to determine if a build is cold/incremental. Moving it to buck2_common to allow sharing of the code. Reviewed By: stepancheg Differential Revision: D63633575 fbshipit-source-id: 91c2b6e54c9bcb51acc5a4d3ccac64cbe6cd884f --- app/buck2_client_ctx/src/lib.rs | 1 - app/buck2_client_ctx/src/subscribers/recorder.rs | 4 ++-- app/buck2_common/BUCK | 1 + app/buck2_common/Cargo.toml | 1 + app/{buck2_client_ctx => buck2_common}/src/build_count.rs | 5 +++-- app/buck2_common/src/lib.rs | 1 + 6 files changed, 8 insertions(+), 5 deletions(-) rename app/{buck2_client_ctx => buck2_common}/src/build_count.rs (99%) diff --git a/app/buck2_client_ctx/src/lib.rs b/app/buck2_client_ctx/src/lib.rs index d80c12f5eafd..bb75040b9ee6 100644 --- a/app/buck2_client_ctx/src/lib.rs +++ b/app/buck2_client_ctx/src/lib.rs @@ -19,7 +19,6 @@ #![feature(extract_if)] pub mod argfiles; -pub mod build_count; pub mod client_cpu_tracker; pub mod client_ctx; pub mod client_metadata; diff --git a/app/buck2_client_ctx/src/subscribers/recorder.rs b/app/buck2_client_ctx/src/subscribers/recorder.rs index ae22960c8b05..b6350fa19591 100644 --- a/app/buck2_client_ctx/src/subscribers/recorder.rs +++ b/app/buck2_client_ctx/src/subscribers/recorder.rs @@ -23,6 +23,8 @@ use std::time::SystemTime; use anyhow::Context; use async_trait::async_trait; use buck2_cli_proto::command_result; +use buck2_common::build_count::BuildCount; +use buck2_common::build_count::BuildCountManager; use buck2_common::convert::ProstDurationExt; use buck2_core::fs::fs_util; use buck2_core::fs::paths::abs_path::AbsPathBuf; @@ -59,8 +61,6 @@ use termwiz::istty::IsTty; use super::system_warning::check_download_speed; use super::system_warning::check_memory_pressure; use super::system_warning::check_remaining_disk_space; -use crate::build_count::BuildCount; -use crate::build_count::BuildCountManager; use crate::client_ctx::ClientCommandContext; use crate::client_metadata::ClientMetadata; use crate::common::CommonEventLogOptions; diff --git a/app/buck2_common/BUCK b/app/buck2_common/BUCK index 9305a8c2c28f..8ba26c55cef9 100644 --- a/app/buck2_common/BUCK +++ b/app/buck2_common/BUCK @@ -46,6 +46,7 @@ rust_library( "fbsource//third-party/rust:derive_more", "fbsource//third-party/rust:digest", "fbsource//third-party/rust:dirs", + "fbsource//third-party/rust:fs4", "fbsource//third-party/rust:futures", "fbsource//third-party/rust:globset", "fbsource//third-party/rust:hex", diff --git a/app/buck2_common/Cargo.toml b/app/buck2_common/Cargo.toml index 66f3e29cb70a..1dc371b98e3a 100644 --- a/app/buck2_common/Cargo.toml +++ b/app/buck2_common/Cargo.toml @@ -19,6 +19,7 @@ derive_more = { workspace = true } digest = { workspace = true } dirs = { workspace = true } fbinit = { workspace = true } +fs4 = { workspace = true } futures = { workspace = true } globset = { workspace = true } hex = { workspace = true } diff --git a/app/buck2_client_ctx/src/build_count.rs b/app/buck2_common/src/build_count.rs similarity index 99% rename from app/buck2_client_ctx/src/build_count.rs rename to app/buck2_common/src/build_count.rs index d370b28ab66b..c7882c8db640 100644 --- a/app/buck2_client_ctx/src/build_count.rs +++ b/app/buck2_common/src/build_count.rs @@ -11,7 +11,6 @@ use std::collections::HashMap; use std::time::Duration; use anyhow::Context; -use buck2_common::client_utils; use buck2_core::fs::async_fs_util; use buck2_core::fs::paths::abs_norm_path::AbsNormPathBuf; use buck2_core::fs::paths::file_name::FileName; @@ -20,6 +19,8 @@ use fs4::FileExt; use serde::Deserialize; use serde::Serialize; +use crate::client_utils; + // Version for serialized BuildCount on disk. // Update if changing BuildCount to allow building with deployed and compiled buck on the same rev. pub const BUILD_COUNT_VERSION: u64 = 1; @@ -76,7 +77,7 @@ impl BuildCountMap { return Default::default(); } - // If the target has never been succesfully built it won't be in the map, in that case its count is 0. + // If the target has never been successfully built it won't be in the map, in that case its count is 0. return patterns .target_patterns .iter() diff --git a/app/buck2_common/src/lib.rs b/app/buck2_common/src/lib.rs index 838da614e224..4e755da43ef9 100644 --- a/app/buck2_common/src/lib.rs +++ b/app/buck2_common/src/lib.rs @@ -20,6 +20,7 @@ pub mod argv; pub mod buckd_connection; +pub mod build_count; pub mod buildfiles; pub mod cas_digest; pub mod chunk_reader;