Skip to content

Commit

Permalink
refactor: move constants
Browse files Browse the repository at this point in the history
  • Loading branch information
KSXGitHub committed Oct 22, 2023
1 parent 00a47c4 commit 060c98f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
5 changes: 5 additions & 0 deletions tasks/integrated-benchmark/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@
pub const SCRIPT_EXECUTOR: &str = "bash";
#[cfg(windows)]
pub const SCRIPT_EXECUTOR: &str = "powershell";

#[cfg(unix)]
pub const SCRIPT_NAME: &str = "install.bash";
#[cfg(windows)]
pub const SCRIPT_NAME: &str = "install.ps1";
12 changes: 4 additions & 8 deletions tasks/integrated-benchmark/src/work_env.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
cli_args::{BenchmarkScenario, HyperfineOptions},
constants::SCRIPT_EXECUTOR,
constants::{SCRIPT_EXECUTOR, SCRIPT_NAME},
fixtures::PACKAGE_JSON,
};
use itertools::Itertools;
Expand Down Expand Up @@ -30,10 +30,6 @@ pub struct WorkEnv {
impl WorkEnv {
const INIT_PROXY_CACHE: BenchId<'static> = BenchId::Static(".init-proxy-cache");
const PNPM: BenchId<'static> = BenchId::Static("pnpm");
#[cfg(unix)]
const SCRIPT_NAME: &str = "install.bash";
#[cfg(windows)]
const SCRIPT_NAME: &str = "install.ps1";

fn root(&self) -> &'_ Path {
&self.root
Expand All @@ -60,7 +56,7 @@ impl WorkEnv {
}

fn script_path(&self, id: BenchId) -> PathBuf {
self.bench_dir(id).join(WorkEnv::SCRIPT_NAME)
self.bench_dir(id).join(SCRIPT_NAME)
}

fn revision_repo(&self, revision: &str) -> PathBuf {
Expand Down Expand Up @@ -107,7 +103,7 @@ impl WorkEnv {
SCRIPT_EXECUTOR
.pipe(Command::new)
.arg(self.script_path(WorkEnv::INIT_PROXY_CACHE))
.pipe_mut(executor(WorkEnv::SCRIPT_NAME))
.pipe_mut(executor(SCRIPT_NAME))
}

fn build(&self) {
Expand Down Expand Up @@ -234,7 +230,7 @@ fn may_create_lockfile(dir: &Path, scenario: BenchmarkScenario) {
}

fn create_install_script(dir: &Path, scenario: BenchmarkScenario, for_pnpm: bool) {
let path = dir.join(WorkEnv::SCRIPT_NAME);
let path = dir.join(SCRIPT_NAME);

eprintln!("Creating script {path:?}...");
let mut file = File::create(&path).expect("create install script");
Expand Down

0 comments on commit 060c98f

Please sign in to comment.