From 7a3a3d6b90c3ce5bd6dc8b64220e15dfed11a7fd Mon Sep 17 00:00:00 2001 From: alexion Date: Thu, 17 Sep 2026 14:09:47 -0400 Subject: [PATCH] feat(xatu): scaffold source collection --- Cargo.lock | 8 +++++ Cargo.toml | 1 + src/xatu/BUILD | 18 ++++++++++ src/xatu/Cargo.toml | 15 ++++++++ src/xatu/xatu.rs | 16 +++++++++ src/xatu/xatu_main.rs | 80 +++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 138 insertions(+) create mode 100644 src/xatu/BUILD create mode 100644 src/xatu/Cargo.toml create mode 100644 src/xatu/xatu.rs create mode 100644 src/xatu/xatu_main.rs diff --git a/Cargo.lock b/Cargo.lock index 598e909..7db0b5b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -251,6 +251,14 @@ dependencies = [ "windows-link", ] +[[package]] +name = "xatu" +version = "0.1.0" +dependencies = [ + "clap", + "monorepo", +] + [[package]] name = "zmij" version = "1.0.23" diff --git a/Cargo.toml b/Cargo.toml index 06ff695..9bdfe2d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,6 +3,7 @@ members = [ "src/ariadne", "src/machoke", "src/monorepo", + "src/xatu", ] resolver = "3" diff --git a/src/xatu/BUILD b/src/xatu/BUILD new file mode 100644 index 0000000..7eb3699 --- /dev/null +++ b/src/xatu/BUILD @@ -0,0 +1,18 @@ +load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_library") + +rust_library( + name = "xatu_lib", + crate_name = "xatu", + srcs = ["xatu.rs"], +) + +rust_binary( + name = "xatu", + crate_name = "xatu_cli", + srcs = ["xatu_main.rs"], + deps = [ + ":xatu_lib", + "//src/monorepo:monorepo", + "//third_party/crates:clap", + ], +) diff --git a/src/xatu/Cargo.toml b/src/xatu/Cargo.toml new file mode 100644 index 0000000..aa1d37b --- /dev/null +++ b/src/xatu/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "xatu" +version = "0.1.0" +edition = "2024" + +[lib] +path = "xatu.rs" + +[[bin]] +name = "xatu" +path = "xatu_main.rs" + +[dependencies] +clap = { workspace = true, features = ["derive"] } +monorepo = { workspace = true } diff --git a/src/xatu/xatu.rs b/src/xatu/xatu.rs new file mode 100644 index 0000000..ac8d3a5 --- /dev/null +++ b/src/xatu/xatu.rs @@ -0,0 +1,16 @@ +use std::path::PathBuf; + +pub fn run(files: Vec) -> Result<()> { + for file in files { + println!("{}", file.path.display()); + } + Ok(()) +} + +pub type Result = std::result::Result; + +#[derive(Debug)] +pub struct SourceFile { + pub path: PathBuf, + pub source: String, +} diff --git a/src/xatu/xatu_main.rs b/src/xatu/xatu_main.rs new file mode 100644 index 0000000..567dfe1 --- /dev/null +++ b/src/xatu/xatu_main.rs @@ -0,0 +1,80 @@ +use clap::Parser; +use std::path::{Path, PathBuf}; +use xatu::SourceFile; + +fn is_nix_file(path: &Path) -> bool { + path.extension().is_some_and(|extension| extension == "nix") +} + +// TODO: Add configurable exclusions. +fn is_excluded_dir(path: &Path) -> bool { + path.file_name() + .and_then(|name| name.to_str()) + .is_some_and(|name| { + matches!( + name, + ".git" + | "bazel-bin" + | "bazel-dev" + | "bazel-out" + | "bazel-testlogs" + | "target" + | "third_party" + ) || name == "result" + || name.starts_with("result-") + }) +} + +fn collect_source_files(path: &Path) -> xatu::Result> { + let metadata = std::fs::symlink_metadata(path)?; + + if metadata.file_type().is_dir() { + if is_excluded_dir(path) { + return Ok(Vec::new()); + } + + let mut files = Vec::new(); + + for entry in std::fs::read_dir(path)? { + let entry = entry?; + files.extend(collect_source_files(&entry.path())?); + } + + return Ok(files); + } + + if metadata.file_type().is_file() && is_nix_file(path) { + return Ok(vec![SourceFile { + path: path.to_path_buf(), + source: std::fs::read_to_string(path)?, + }]); + } + + Ok(Vec::new()) +} + +#[derive(Debug, Parser)] +struct Args { + #[arg(value_name = "PATH", default_value = ".")] + paths: Vec, +} + +fn main() -> xatu::Result<()> { + let args = Args::parse(); + + let paths: Vec = args + .paths + .into_iter() + .map(monorepo::workspace::resolve_workspace_path) + .collect(); + + let files: Vec = paths + .iter() + .map(|path| collect_source_files(path)) + .collect::>>()? + .into_iter() + .flatten() + .collect(); + + xatu::run(files) +}