Skip to content

Commit

Permalink
Merge pull request #23 from ink0rr/dev
Browse files Browse the repository at this point in the history
rgl v0.9.0
  • Loading branch information
ink0rr authored Jun 7, 2024
2 parents 744a202 + 82dd566 commit e551967
Show file tree
Hide file tree
Showing 36 changed files with 1,275 additions and 1,005 deletions.
386 changes: 253 additions & 133 deletions Cargo.lock

Large diffs are not rendered by default.

17 changes: 8 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[package]
name = "rgl"
version = "0.8.1"
version = "0.9.0"
edition = "2021"

[[bin]]
name = "rgl"

[dependencies]
anyhow = "1.0.82"
clap = { version = "4.5.4", features = ["cargo"] }
anyhow = "1.0.86"
clap = { version = "4.5.6", features = ["cargo", "derive"] }
dialoguer = "0.11.0"
dunce = "1.0.4"
enum_dispatch = "0.3.13"
Expand All @@ -19,12 +19,11 @@ notify = "6.1.1"
notify-debouncer-mini = "0.4.1"
paris = { version = "1.5.15", features = ["macros"] }
rayon = "1.10.0"
semver = "1.0.22"
serde = { version = "1.0.198", features = ["derive"] }
serde_json = "1.0.116"
semver = "1.0.23"
serde = { version = "1.0.203", features = ["derive"] }
serde_json = "1.0.117"
tempfile = "3.10.1"
ureq = "2.9.6"
ureq = "2.9.7"
uuid = { version = "1.8.0", features = ["v4"] }
walkdir = "2.5.0"
which = "6.0.1"
zip = "0.6.6"
zip = "2.1.3"
39 changes: 22 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,48 @@ Fast and minimal implementation of Regolith.

## Benchmark

Benchmark result on a project with ~2300 files, no filters, and a total size of 9.2MB.
Benchmark result on a project with ~2700 files, no filters, and a total size of 14MB.

```
$ hyperfine --warmup 2 --runs 10 --setup 'rgl clean' 'regolith run build' 'rgl run build' 'rgl run build --cached'
$ hyperfine --warmup 3 --runs 10 --setup 'rgl clean' 'regolith run' 'regolith run --experiments size_time_check' 'rgl run' 'rgl run --cached'
Benchmark 1: regolith run build
Time (mean ± σ): 1.277 s ± 0.019 s [User: 0.028 s, System: 0.270 s]
Range (min … max): 1.256 s … 1.309 s 10 runs
Benchmark 1: regolith run
Time (mean ± σ): 1.543 s ± 0.017 s [User: 0.037 s, System: 0.427 s]
Range (min … max): 1.511 s … 1.577 s 10 runs
Benchmark 2: rgl run build
Time (mean ± σ): 278.0 ms ± 12.6 ms [User: 9.4 ms, System: 135.3 ms]
Range (min … max): 260.8 ms … 306.8 ms 10 runs
Benchmark 2: regolith run --experiments size_time_check
Time (mean ± σ): 438.5 ms ± 7.2 ms [User: 15.2 ms, System: 62.5 ms]
Range (min … max): 429.1 ms … 448.7 ms 10 runs
Benchmark 3: rgl run build --cached
Time (mean ± σ): 69.2 ms ± 0.8 ms [User: 3.1 ms, System: 54.1 ms]
Range (min … max): 68.2 ms … 70.4 ms 10 runs
Benchmark 3: rgl run
Time (mean ± σ): 384.8 ms ± 10.4 ms [User: 44.8 ms, System: 614.1 ms]
Range (min … max): 364.1 ms … 402.8 ms 10 runs
Benchmark 4: rgl run --cached
Time (mean ± σ): 76.1 ms ± 1.2 ms [User: 10.6 ms, System: 46.9 ms]
Range (min … max): 74.0 ms … 77.8 ms 10 runs
Summary
rgl run build --cached ran
4.02 ± 0.19 times faster than rgl run build
18.46 ± 0.34 times faster than regolith run build
rgl run --cached ran
5.06 ± 0.16 times faster than rgl run
5.76 ± 0.13 times faster than regolith run --experiments size_time_check
20.28 ± 0.39 times faster than regolith run
```

Results may vary depending on your machine, project size, and what kind of filters are used. In this case, rgl is 4x faster than Regolith and 18x faster when using the `--cached` flag.
Results may vary depending on your machine, project size, and what kind of filters are used. In this case, rgl is 4x faster than Regolith and 20x faster when using the `--cached` flag.

### Install

Shell (Mac, Linux):

```sh
curl -fsSL https://raw.githubusercontent.com/ink0rr/rgl/main/scripts/install.sh | sh
curl -fsSL rgl.ink0rr.dev/install.sh | sh
```

PowerShell (Windows):

```powershell
irm https://raw.githubusercontent.com/ink0rr/rgl/main/scripts/install.ps1 | iex
irm rgl.ink0rr.dev/install.ps1 | iex
```

### Uninstall
Expand Down
40 changes: 28 additions & 12 deletions src/commands/add.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,35 @@
use super::Command;
use crate::info;
use crate::rgl::{Config, FilterInstaller, FilterType, Session};
use anyhow::Result;
use clap::Args;

pub fn add_filters(filters: Vec<&String>, force: bool) -> Result<()> {
let mut config = Config::load()?;
let mut session = Session::lock()?;
let data_path = config.get_data_path();
for arg in filters {
info!("Adding filter <b>{}</>...", arg);
let filter = FilterInstaller::from_arg(arg)?;
if filter.install(FilterType::Remote, Some(&data_path), force)? {
info!("Filter <b>{}</> successfully added", filter.name);
config.add_filter(filter)?;
/// Add filter(s) to current project
#[derive(Args)]
pub struct Add {
#[arg(required = true)]
filters: Vec<String>,
#[arg(short, long)]
force: bool,
}

impl Command for Add {
fn dispatch(&self) -> Result<()> {
let mut config = Config::load()?;
let mut session = Session::lock()?;
let data_path = config.get_data_path();
for arg in &self.filters {
info!("Adding filter <b>{}</>...", arg);
let filter = FilterInstaller::from_arg(arg)?;
if filter.install(FilterType::Remote, Some(&data_path), self.force)? {
info!("Filter <b>{}</> successfully added", filter.name);
config.add_filter(filter)?;
}
}
config.save()?;
session.unlock()
}
fn error_context(&self) -> String {
"Error adding filter".to_owned()
}
config.save()?;
session.unlock()
}
64 changes: 46 additions & 18 deletions src/commands/apply.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,54 @@
use crate::fs::{empty_dir, try_symlink};
use crate::info;
use crate::rgl::{Config, Filter, FilterContext, Session};
use super::Command;
use crate::fs::{copy_dir, empty_dir, sync_dir, try_symlink};
use crate::rgl::{Config, Session};
use crate::{info, measure_time};
use anyhow::Result;
use clap::Args;
use std::path::Path;

pub fn apply(filter_name: &str, run_args: Vec<String>) -> Result<()> {
let config = Config::load()?;
let mut session = Session::lock()?;
/// Runs a profile and apply changes to the current project
#[derive(Args)]
pub struct Apply {
profile: String,
}

impl Command for Apply {
fn dispatch(&self) -> Result<()> {
let config = Config::load()?;
let mut session = Session::lock()?;

let bp = config.get_behavior_pack();
let rp = config.get_resource_pack();

let temp = Path::new(".regolith").join("tmp");
let temp_bp = temp.join("BP");
let temp_rp = temp.join("RP");

let temp = Path::new(".regolith").join("tmp");
let temp_bp = temp.join("BP");
let temp_rp = temp.join("RP");
empty_dir(&temp)?;
copy_dir(&bp, &temp_bp)?;
copy_dir(&rp, &temp_rp)?;
try_symlink(config.get_data_path(), temp.join("data"))?;

empty_dir(&temp)?;
try_symlink(config.get_behavior_pack(), temp_bp)?;
try_symlink(config.get_resource_pack(), temp_rp)?;
try_symlink(config.get_data_path(), temp.join("data"))?;
let profile = config.get_profile(&self.profile)?;
measure_time!(self.profile, {
info!("Running <b>{}</> profile", self.profile);
profile.run(&config, &temp, &self.profile)?;
});

let filter = config.get_filter(filter_name)?;
let context = FilterContext::new(filter.get_type(), filter_name)?;
filter.run(&context, &temp, &run_args)?;
info!("Successfully applied filter <b>{filter_name}</>");
info!(
"Applying changes to source directory: \n\
\tBP: {} \n\
\tRP: {}",
bp.display(),
rp.display()
);
sync_dir(temp_bp, bp)?;
sync_dir(temp_rp, rp)?;

session.unlock()
info!("Successfully applied profile <b>{}</>", self.profile);
session.unlock()
}
fn error_context(&self) -> String {
format!("Error applying profile <b>{}</>", self.profile)
}
}
31 changes: 21 additions & 10 deletions src/commands/clean.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
use super::Command;
use crate::fs::rimraf;
use crate::info;
use crate::rgl::{Config, Session};
use anyhow::Result;
use clap::Args;

pub fn clean() -> Result<()> {
// Make sure it's a valid project
let _ = Config::load()?;
let mut session = Session::lock()?;
info!("Cleaning .regolith folder...");
rimraf(".regolith")?;
info!("Cleaning build files...");
rimraf("build")?;
info!("Completed!");
session.unlock()
/// Clean the current project's cache and build files
#[derive(Args)]
pub struct Clean;

impl Command for Clean {
fn dispatch(&self) -> Result<()> {
// Make sure it's a valid project
let _ = Config::load()?;
let mut session = Session::lock()?;
info!("Cleaning .regolith folder...");
rimraf(".regolith")?;
info!("Cleaning build files...");
rimraf("build")?;
info!("Completed!");
session.unlock()
}
fn error_context(&self) -> String {
"Error cleaning files".to_owned()
}
}
89 changes: 59 additions & 30 deletions src/commands/exec.rs
Original file line number Diff line number Diff line change
@@ -1,38 +1,67 @@
use crate::fs::{empty_dir, read_json, try_symlink};
use super::Command;
use crate::fs::{copy_dir, empty_dir, read_json, sync_dir, try_symlink};
use crate::info;
use crate::rgl::{Config, Filter, FilterContext, FilterType, RemoteFilterConfig, Session};
use anyhow::{Context, Result};
use clap::Args;
use std::path::Path;

pub fn exec(filter_name: &str, run_args: Vec<String>) -> Result<()> {
let config = Config::load()?;
let mut session = Session::lock()?;

let temp = Path::new(".regolith").join("tmp");
let temp_bp = temp.join("BP");
let temp_rp = temp.join("RP");

empty_dir(&temp)?;
try_symlink(config.get_behavior_pack(), temp_bp)?;
try_symlink(config.get_resource_pack(), temp_rp)?;
try_symlink(config.get_data_path(), temp.join("data"))?;

if let Ok(filter) = config.get_filter(filter_name) {
info!("Running local filter <b>{filter_name}</>");
let context = FilterContext::new(filter.get_type(), filter_name)?;
filter.run(&context, &temp, &run_args)?;
} else {
info!("Running global filter <b>{filter_name}</>");
let context = FilterContext::new(FilterType::Tool, filter_name)?;
let config_path = context.filter_dir.join("filter.json");
let config = read_json::<RemoteFilterConfig>(config_path).context(format!(
"Failed to load config for tool <b>{filter_name}</>"
))?;

for filter in config.filters {
filter.run(&context, &temp, &run_args)?;
/// Executes a filter and apply changes to the current project
#[derive(Args)]
#[clap(alias = "x")]
pub struct Exec {
filter: String,
run_args: Vec<String>,
}

impl Command for Exec {
fn dispatch(&self) -> Result<()> {
let config = Config::load()?;
let mut session = Session::lock()?;

let bp = config.get_behavior_pack();
let rp = config.get_resource_pack();

let temp = Path::new(".regolith").join("tmp");
let temp_bp = temp.join("BP");
let temp_rp = temp.join("RP");

empty_dir(&temp)?;
copy_dir(&bp, &temp_bp)?;
copy_dir(&rp, &temp_rp)?;
try_symlink(config.get_data_path(), temp.join("data"))?;

if let Ok(filter) = config.get_filter(&self.filter) {
info!("Running local filter <b>{}</>", self.filter);
let context = FilterContext::new(filter.get_type(), &self.filter)?;
filter.run(&context, &temp, &self.run_args)?;
} else {
info!("Running global filter <b>{}</>", self.filter);
let context = FilterContext::new(FilterType::Global, &self.filter)?;
let config_path = context.filter_dir.join("filter.json");
let config = read_json::<RemoteFilterConfig>(config_path).context(format!(
"Failed to load config for filter <b>{}</>",
self.filter
))?;
for filter in config.filters {
filter.run(&context, &temp, &self.run_args)?;
}
}
}

session.unlock()
info!(
"Applying changes to source directory: \n\
\tBP: {} \n\
\tRP: {}",
bp.display(),
rp.display()
);
sync_dir(temp_bp, bp)?;
sync_dir(temp_rp, rp)?;

info!("Successfully executed filter <b>{}</>", self.filter);
session.unlock()
}
fn error_context(&self) -> String {
format!("Error executing filter <b>{}</>", self.filter)
}
}
Loading

0 comments on commit e551967

Please sign in to comment.