From 5341e8f9714d9c93bf6cfeb08fd76a5efda96799 Mon Sep 17 00:00:00 2001 From: Chris Olszewski Date: Wed, 22 Nov 2023 11:06:13 -0800 Subject: [PATCH] feat: add a go fallback flag (#6540) ### Description Gives an easy way to opt-into the Go binary without messing with environment variables. (For almost all cases env var makes more sense, but on Windows you can't just `EXPERIMENTAL_RUST_CODEPATH=false turbo build`) ### Testing Instructions Verify the following all work and invoke the correct binaries ``` # Rust binary turbo build EXPERIMENTAL_RUST_CODEPATH=true turbo build --filter=docs # Go binary turbo build --filter=docs --go-fallback EXPERIMENTAL_RUST_CODEPATH=true turbo build --filter=docs --go-fallback EXPERIMENTAL_RUST_CODEPATH=false turbo build --filter=docs ``` Closes TURBO-1734 --------- Co-authored-by: Chris Olszewski --- crates/turborepo-lib/src/cli/mod.rs | 8 +++++++- turborepo-tests/integration/tests/no-args.t | 1 + turborepo-tests/integration/tests/turbo-help.t | 6 ++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/crates/turborepo-lib/src/cli/mod.rs b/crates/turborepo-lib/src/cli/mod.rs index a9b4f22b0575d..db6ce12adf547 100644 --- a/crates/turborepo-lib/src/cli/mod.rs +++ b/crates/turborepo-lib/src/cli/mod.rs @@ -106,6 +106,10 @@ pub struct Args { /// The directory in which to run turbo #[clap(long, global = true, value_parser)] pub cwd: Option, + /// Fallback to use Go for task execution + #[serde(skip)] + #[clap(long, global = true)] + pub go_fallback: bool, /// Specify a file to save a pprof heap profile #[clap(long, global = true, value_parser)] pub heap: Option, @@ -821,7 +825,9 @@ pub async fn run( } let base = CommandBase::new(cli_args.clone(), repo_root, version, ui); - if env::var("EXPERIMENTAL_RUST_CODEPATH").as_deref() == Ok("false") { + let should_use_go = cli_args.go_fallback + || env::var("EXPERIMENTAL_RUST_CODEPATH").as_deref() == Ok("false"); + if should_use_go { Ok(Payload::Go(Box::new(base))) } else { use crate::commands::run; diff --git a/turborepo-tests/integration/tests/no-args.t b/turborepo-tests/integration/tests/no-args.t index b78a5692b3701..8a69528442d89 100644 --- a/turborepo-tests/integration/tests/no-args.t +++ b/turborepo-tests/integration/tests/no-args.t @@ -27,6 +27,7 @@ Make sure exit code is 2 when no args are passed --color Force color usage in the terminal --cpuprofile Specify a file to save a cpu profile --cwd The directory in which to run turbo + --go-fallback Fallback to use Go for task execution --heap Specify a file to save a pprof heap profile --login Override the login endpoint --no-color Suppress color usage in the terminal diff --git a/turborepo-tests/integration/tests/turbo-help.t b/turborepo-tests/integration/tests/turbo-help.t index 40cbd03de5779..cfcb23a1c9b1c 100644 --- a/turborepo-tests/integration/tests/turbo-help.t +++ b/turborepo-tests/integration/tests/turbo-help.t @@ -27,6 +27,7 @@ Test help flag --color Force color usage in the terminal --cpuprofile Specify a file to save a cpu profile --cwd The directory in which to run turbo + --go-fallback Fallback to use Go for task execution --heap Specify a file to save a pprof heap profile --login Override the login endpoint --no-color Suppress color usage in the terminal @@ -97,6 +98,7 @@ Test help flag --color Force color usage in the terminal --cpuprofile Specify a file to save a cpu profile --cwd The directory in which to run turbo + --go-fallback Fallback to use Go for task execution --heap Specify a file to save a pprof heap profile --login Override the login endpoint --no-color Suppress color usage in the terminal @@ -153,6 +155,7 @@ Test help flag for link command --color Force color usage in the terminal --cpuprofile Specify a file to save a cpu profile --cwd The directory in which to run turbo + --go-fallback Fallback to use Go for task execution --heap Specify a file to save a pprof heap profile --login Override the login endpoint --no-color Suppress color usage in the terminal @@ -179,6 +182,7 @@ Test help flag for unlink command --color Force color usage in the terminal --cpuprofile Specify a file to save a cpu profile --cwd The directory in which to run turbo + --go-fallback Fallback to use Go for task execution --heap Specify a file to save a pprof heap profile --login Override the login endpoint --no-color Suppress color usage in the terminal @@ -205,6 +209,7 @@ Test help flag for login command --color Force color usage in the terminal --cpuprofile Specify a file to save a cpu profile --cwd The directory in which to run turbo + --go-fallback Fallback to use Go for task execution --heap Specify a file to save a pprof heap profile --login Override the login endpoint --no-color Suppress color usage in the terminal @@ -230,6 +235,7 @@ Test help flag for logout command --color Force color usage in the terminal --cpuprofile Specify a file to save a cpu profile --cwd The directory in which to run turbo + --go-fallback Fallback to use Go for task execution --heap Specify a file to save a pprof heap profile --login Override the login endpoint --no-color Suppress color usage in the terminal