process_artifacts: Refactor modules
Introduce module hierarchy for better organization and rename a few
symbols for consistency.
This is a pure refactoring change.
BUG=b:331890379
TEST=bazel test //bazel/portage/tools/process_artifacts:all
Change-Id: I707df16cd46bed561bea5bd1a4032df711f4e45c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/bazel/+/5528442
Reviewed-by: Raul Rangel <rrangel@chromium.org>
Commit-Queue: Shuhei Takahashi <nya@chromium.org>
Tested-by: Shuhei Takahashi <nya@chromium.org>
diff --git a/portage/tools/process_artifacts/src/archive_logs.rs b/portage/tools/process_artifacts/src/commands/archive_logs.rs
similarity index 98%
rename from portage/tools/process_artifacts/src/archive_logs.rs
rename to portage/tools/process_artifacts/src/commands/archive_logs.rs
index 9f5f37f..c2a78c4 100644
--- a/portage/tools/process_artifacts/src/archive_logs.rs
+++ b/portage/tools/process_artifacts/src/commands/archive_logs.rs
@@ -11,14 +11,14 @@
use anyhow::{ensure, Result};
-use crate::build_event_processor::BuildEventProcessor;
+use crate::processors::build_event::BuildEventProcessor;
pub fn archive_logs(
output_path: &Path,
workspace_dir: &Path,
- events: &BuildEventProcessor,
+ processor: &BuildEventProcessor,
) -> Result<()> {
- let files = events.output_group_files("transitive_logs")?;
+ let files = processor.get_output_group_files("transitive_logs")?;
let mut input_file = tempfile::tempfile()?;
for relative_path in files {
diff --git a/portage/tools/process_artifacts/src/commands/mod.rs b/portage/tools/process_artifacts/src/commands/mod.rs
new file mode 100644
index 0000000..fb3082d
--- /dev/null
+++ b/portage/tools/process_artifacts/src/commands/mod.rs
@@ -0,0 +1,6 @@
+// Copyright 2024 The ChromiumOS Authors
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+pub mod archive_logs;
+pub mod prebuilts;
diff --git a/portage/tools/process_artifacts/src/prebuilts.rs b/portage/tools/process_artifacts/src/commands/prebuilts.rs
similarity index 97%
rename from portage/tools/process_artifacts/src/prebuilts.rs
rename to portage/tools/process_artifacts/src/commands/prebuilts.rs
index 58173dc..52f6b59 100644
--- a/portage/tools/process_artifacts/src/prebuilts.rs
+++ b/portage/tools/process_artifacts/src/commands/prebuilts.rs
@@ -8,7 +8,7 @@
use anyhow::{Context, Result};
use itertools::Itertools;
-use crate::{build_event_processor::BuildEventProcessor, proto::ebuild_metadata::EbuildMetadata};
+use crate::{processors::build_event::BuildEventProcessor, proto::ebuild_metadata::EbuildMetadata};
const PREBUILT_HEADER: &str = r#"# Provides the CAS location for all ebuild binary packages
# used by the build. This is useful when modifying primordial code such as
@@ -37,12 +37,12 @@
let Some(remote_instance_name) = processor.get_command_flag("remote_instance_name") else {
write!(output, "# --remote_instance_name was not set.")?;
- return Ok(())
+ return Ok(());
};
write!(output, "{PREBUILT_HEADER}")?;
- let metadata_files = processor.output_group_files("ebuild_metadata")?;
+ let metadata_files = processor.get_output_group_files("ebuild_metadata")?;
let metadata = metadata_files
.into_iter()
diff --git a/portage/tools/process_artifacts/src/main.rs b/portage/tools/process_artifacts/src/main.rs
index 41875db..095dc61 100644
--- a/portage/tools/process_artifacts/src/main.rs
+++ b/portage/tools/process_artifacts/src/main.rs
@@ -11,15 +11,13 @@
};
use anyhow::{Context, Result};
-use archive_logs::archive_logs;
-use build_event_processor::BuildEventProcessor;
use clap::Parser;
-use prebuilts::compute_prebuilts;
+use commands::{archive_logs::archive_logs, prebuilts::compute_prebuilts};
+use processors::build_event::BuildEventProcessor;
use proto::build_event_stream::BuildEvent;
-mod archive_logs;
-mod build_event_processor;
-mod prebuilts;
+mod commands;
+mod processors;
mod proto;
/// Loads a newline-deliminated JSON file containing Build Event Protocol data.
diff --git a/portage/tools/process_artifacts/src/build_event_processor.rs b/portage/tools/process_artifacts/src/processors/build_event.rs
similarity index 97%
rename from portage/tools/process_artifacts/src/build_event_processor.rs
rename to portage/tools/process_artifacts/src/processors/build_event.rs
index b1ab315..98a347f 100644
--- a/portage/tools/process_artifacts/src/build_event_processor.rs
+++ b/portage/tools/process_artifacts/src/processors/build_event.rs
@@ -110,7 +110,7 @@
impl BuildEventProcessor<'_> {
/// Returns the workspace relative path to all files in the specified output group.
- pub fn output_group_files(&self, output_group_name: &str) -> Result<Vec<PathBuf>> {
+ pub fn get_output_group_files(&self, output_group_name: &str) -> Result<Vec<PathBuf>> {
let mut fileset = FastFileSet::new();
for event in self.events {
@@ -244,7 +244,7 @@
},
];
- let files = BuildEventProcessor::from(&events).output_group_files("transitive_logs")?;
+ let files = BuildEventProcessor::from(&events).get_output_group_files("transitive_logs")?;
assert_eq!(files, vec![PathBuf::from("a.txt")]);
@@ -316,7 +316,7 @@
}),
});
- let files = BuildEventProcessor::from(&events).output_group_files("transitive_logs")?;
+ let files = BuildEventProcessor::from(&events).get_output_group_files("transitive_logs")?;
assert_eq!(
files.into_iter().sorted().collect_vec(),
diff --git a/portage/tools/process_artifacts/src/processors/mod.rs b/portage/tools/process_artifacts/src/processors/mod.rs
new file mode 100644
index 0000000..b441cfc
--- /dev/null
+++ b/portage/tools/process_artifacts/src/processors/mod.rs
@@ -0,0 +1,5 @@
+// Copyright 2024 The ChromiumOS Authors
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+pub mod build_event;