Repository: aptos-labs/aptos-core
File: testsuite/benchmark-workloads/package-generator/src/main.rs (Rust)

Code before:
use std::{
    fs, io,
    path::{Path, PathBuf},
};

#[derive(Parser)]
#[command(author, version, about)]
struct Args {
    /// Root directory where packages are stored.
    #[clap(long)]
    packages_path: Vec<PathBuf>,
    /// Root directory where packages are stored.
    #[clap(long)]
    experimental_packages_path: Vec<PathBuf>,
    /// Root directory where prebuilt packages binary will be saved.
    #[clap(long)]
    prebuilt_packages_file_dir: PathBuf,
    /// Root directory where the Rust file to access prebuilt packages will be saved.
    #[clap(long)]
    prebuilt_packages_rust_dir: PathBuf,
    /// If true, uses local aptos-framework from aptos-core.
    #[clap(long)]
    use_local_std: bool,
    /// Experiments for compiler optimization
    #[clap(long, num_args = 1.., value_delimiter = ',')]
    experiments: Vec<String>,
}

/// Recursively traverses a directory to extract paths of all Move packages inside it.
fn visit(
    dir: &Path,
    config: &PrebuiltPackageConfig,
    package_paths: &mut Vec<(PathBuf, PrebuiltPackageConfig)>,
) -> io::Result<()> {
    // Package found, do not recurse further.
    if dir.join("Move.toml").is_file() {
        package_paths.push((dir.to_path_buf(), config.clone()));
        return Ok(());
    }

    for entry in fs::read_dir(dir)? {
        let entry = entry?;
        if entry.file_type()?.is_dir() {
            visit(&entry.path(), config, package_paths)?;
        }
    }
    Ok(())
}

fn main() -> anyhow::Result<()> {
    let args = Args::parse();

Review comment (suggestion):
The script `generate.py` in this folder still works if no experiments are provided, right? If we are to pass some experiments for single-node perf, we need to make sure this Python script does the right thing.

Code after:
use std::{
    fs, io,
    path::{Path, PathBuf},
};

#[derive(Parser)]
#[command(author, version, about)]
struct Args {
    /// Root directory where packages are stored.
    #[clap(long)]
    packages_path: Vec<PathBuf>,
    /// Root directory where packages are stored.
    #[clap(long)]
    experimental_packages_path: Vec<PathBuf>,
    /// Root directory where prebuilt packages binary will be saved.
    #[clap(long)]
    prebuilt_packages_file_dir: PathBuf,
    /// Root directory where the Rust file to access prebuilt packages will be saved.
    #[clap(long)]
    prebuilt_packages_rust_dir: PathBuf,
    /// If true, uses local aptos-framework from aptos-core.
    #[clap(long)]
    use_local_std: bool,
    /// Experiments for compiler optimization.
    #[clap(long, num_args = 1.., value_delimiter = ',')]
    experiments: Vec<String>,
}

/// Recursively traverses a directory to extract paths of all Move packages inside it.
fn visit(
    dir: &Path,
    config: &PrebuiltPackageConfig,
    package_paths: &mut Vec<(PathBuf, PrebuiltPackageConfig)>,
) -> io::Result<()> {
    // Package found, do not recurse further.
    if dir.join("Move.toml").is_file() {
        package_paths.push((dir.to_path_buf(), config.clone()));
        return Ok(());
    }

    for entry in fs::read_dir(dir)? {
        let entry = entry?;
        if entry.file_type()?.is_dir() {
            visit(&entry.path(), config, package_paths)?;
        }
    }
    Ok(())
}

fn main() -> anyhow::Result<()> {
    let args = Args::parse();