Skip to content

Commit

Permalink
More deleting and fixing
Browse files Browse the repository at this point in the history
  • Loading branch information
NicholasLYang committed Jan 8, 2024
1 parent abd9379 commit 0bddd7a
Show file tree
Hide file tree
Showing 12 changed files with 137 additions and 202 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/turborepo-lib/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let tonic_build_result = tonic_build::configure()
.build_server(true)
.file_descriptor_set_path("src/daemon/file_descriptor_set.bin")
.compile(&["turbod.proto"], &["../../cli/internal/turbodprotocol"]);
.compile(&["turbod.proto"], &["./src/daemon"]);
let capnpc_result = capnpc::CompilerCommand::new()
.file("./src/hash/proto.capnp")
.import_path("./src/hash/std") // we need to include the 'stdlib' for capnp-go
Expand Down
38 changes: 16 additions & 22 deletions crates/turborepo-lib/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ use crate::{
get_version,
shim::TurboState,
tracing::TurboSubscriber,
Payload,
};

mod error;
Expand Down Expand Up @@ -729,7 +728,7 @@ pub async fn run(
repo_state: Option<RepoState>,
#[allow(unused_variables)] logger: &TurboSubscriber,
ui: UI,
) -> Result<Payload, Error> {
) -> Result<i32, Error> {
let mut cli_args = Args::new();
let version = get_version();

Expand Down Expand Up @@ -836,7 +835,7 @@ pub async fn run(
.track_call();
bin::run()?;

Ok(Payload::Rust(Ok(0)))
Ok(0)
}
#[allow(unused_variables)]
Command::Daemon { command, idle_time } => {
Expand All @@ -847,15 +846,10 @@ pub async fn run(

match command {
Some(command) => daemon::daemon_client(command, &base).await,
#[cfg(not(feature = "go-daemon"))]
None => daemon::daemon_server(&base, idle_time, logger).await,
#[cfg(feature = "go-daemon")]
None => {
return Ok(Payload::Go(Box::new(base)));
}
}?;

Ok(Payload::Rust(Ok(0)))
Ok(0)
}
Command::Generate {
tag,
Expand All @@ -876,15 +870,15 @@ pub async fn run(
};
let child_event = event.child();
generate::run(tag, command, &args, child_event)?;
Ok(Payload::Rust(Ok(0)))
Ok(0)
}
Command::Telemetry { command } => {
let event = CommandEventBuilder::new("telemetry").with_parent(&root_telemetry);
event.track_call();
let mut base = CommandBase::new(cli_args.clone(), repo_root, version, ui);
let child_event = event.child();
telemetry::configure(command, &mut base, child_event);
Ok(Payload::Rust(Ok(0)))
Ok(0)
}
Command::Info { workspace, json } => {
CommandEventBuilder::new("info")
Expand All @@ -895,7 +889,7 @@ pub async fn run(
let mut base = CommandBase::new(cli_args, repo_root, version, ui);
info::run(&mut base, workspace.as_deref(), json).await?;

Ok(Payload::Rust(Ok(0)))
Ok(0)
}
Command::Link {
no_gitignore,
Expand All @@ -906,7 +900,7 @@ pub async fn run(
.track_call();
if cli_args.test_run {
println!("Link test run successful");
return Ok(Payload::Rust(Ok(0)));
return Ok(0);
}

let modify_gitignore = !*no_gitignore;
Expand All @@ -917,7 +911,7 @@ pub async fn run(
error!("error: {}", err.to_string())
}

Ok(Payload::Rust(Ok(0)))
Ok(0)
}
Command::Logout { .. } => {
let event = CommandEventBuilder::new("logout").with_parent(&root_telemetry);
Expand All @@ -927,14 +921,14 @@ pub async fn run(
let event_child = event.child();
logout::logout(&mut base, event_child).await?;

Ok(Payload::Rust(Ok(0)))
Ok(0)
}
Command::Login { sso_team } => {
let event = CommandEventBuilder::new("login").with_parent(&root_telemetry);
event.track_call();
if cli_args.test_run {
println!("Login test run successful");
return Ok(Payload::Rust(Ok(0)));
return Ok(0);
}

let sso_team = sso_team.clone();
Expand All @@ -948,23 +942,23 @@ pub async fn run(
login::login(&mut base, event_child).await?;
}

Ok(Payload::Rust(Ok(0)))
Ok(0)
}
Command::Unlink { target } => {
CommandEventBuilder::new("unlink")
.with_parent(&root_telemetry)
.track_call();
if cli_args.test_run {
println!("Unlink test run successful");
return Ok(Payload::Rust(Ok(0)));
return Ok(0);
}

let from = *target;
let mut base = CommandBase::new(cli_args, repo_root, version, ui);

unlink::unlink(&mut base, from)?;

Ok(Payload::Rust(Ok(0)))
Ok(0)
}
Command::Run(args) => {
let event = CommandEventBuilder::new("run").with_parent(&root_telemetry);
Expand All @@ -985,7 +979,7 @@ pub async fn run(
use crate::commands::run;
event.track_run_code_path(CodePath::Rust);
let exit_code = run::run(base).await?;
Ok(Payload::Rust(Ok(exit_code)))
Ok(exit_code)
}
Command::Prune {
scope,
Expand All @@ -1005,14 +999,14 @@ pub async fn run(
let base = CommandBase::new(cli_args, repo_root, version, ui);
let event_child = event.child();
prune::prune(&base, &scope, docker, &output_dir, event_child).await?;
Ok(Payload::Rust(Ok(0)))
Ok(0)
}
Command::Completion { shell } => {
CommandEventBuilder::new("completion")
.with_parent(&root_telemetry)
.track_call();
generate(*shell, &mut Args::command(), "turbo", &mut io::stdout());
Ok(Payload::Rust(Ok(0)))
Ok(0)
}
};

Expand Down
1 change: 0 additions & 1 deletion crates/turborepo-lib/src/commands/logout.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use tracing::error;
use turborepo_api_client::Client;
use turborepo_auth::{logout as auth_logout, read_or_create_auth_file, AuthToken};
use turborepo_telemetry::events::command::CommandEventBuilder;

Expand Down
2 changes: 1 addition & 1 deletion crates/turborepo-lib/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::cell::OnceCell;

use sha2::{Digest, Sha256};
use turbopath::{AbsoluteSystemPath, AbsoluteSystemPathBuf};
use turborepo_api_client::{APIAuth, APIClient, Client};
use turborepo_api_client::{APIAuth, APIClient};
use turborepo_auth::{
TURBOREPO_AUTH_FILE_NAME, TURBOREPO_CONFIG_DIR, TURBOREPO_LEGACY_AUTH_FILE_NAME,
};
Expand Down
104 changes: 104 additions & 0 deletions crates/turborepo-lib/src/daemon/turbod.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
syntax = "proto3";

option go_package = "github.com/vercel/turbo/cli/internal/turbodprotocol";

package turbodprotocol;

service Turbod {
rpc Hello (HelloRequest) returns (HelloResponse);
rpc Shutdown (ShutdownRequest) returns (ShutdownResponse);
rpc Status (StatusRequest) returns (StatusResponse);
// Implement cache watching
rpc NotifyOutputsWritten (NotifyOutputsWrittenRequest) returns (NotifyOutputsWrittenResponse);
rpc GetChangedOutputs (GetChangedOutputsRequest) returns (GetChangedOutputsResponse);

// Request the list of packages that the daemon is aware of.
//
// Since 1.11.0
rpc DiscoverPackages (DiscoverPackagesRequest) returns (DiscoverPackagesResponse);
}

message HelloRequest {
string version = 1;
string session_id = 2;

// The version compatibility range that the client requests.
// For example, if the client requests Patch level compatibility,
// then the server should trigger a failed precondition if the
// server's version is not identical down to the patch level.
VersionRange supported_version_range = 3;
}

enum VersionRange {
// Default to match old behaviour. Requires exact string match,
// performing no compatibility checks.
Exact = 0;
// The Major and Minor version must match, and the Patch version
// must be greater than or equal to the client's Patch version.
Patch = 1;
// The Major version must match, and the Minor version must be
// greater than or equal to the client's Minor version.
Minor = 2;
// The Major version must match. This is the most lenient check.
Major = 3;
}

message HelloResponse {}

message ShutdownRequest {}

message ShutdownResponse {}

message StatusRequest {}

message StatusResponse {
DaemonStatus daemonStatus = 1;
}

message NotifyOutputsWrittenRequest {
repeated string output_globs = 1;
string hash = 2;
repeated string output_exclusion_globs = 3;
uint64 time_saved = 4;
}

message NotifyOutputsWrittenResponse {}

message GetChangedOutputsRequest {
repeated string output_globs = 1;
string hash = 2;
}

message GetChangedOutputsResponse {
repeated string changed_output_globs = 1;
uint64 time_saved = 2;
}

message DaemonStatus {
string log_file = 1;
uint64 uptime_msec = 2;
}

message DiscoverPackagesRequest {

}

message DiscoverPackagesResponse {
repeated PackageFiles package_files = 1;
PackageManager package_manager = 2;
}

message PackageFiles {
string package_json = 1;
optional string turbo_json = 2;

}

enum PackageManager {
Berry = 0;
Npm = 1;
Pnpm = 2;
Pnpm6 = 3;
Yarn = 4;
Bun = 5;
}
34 changes: 2 additions & 32 deletions crates/turborepo-lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,8 @@ mod task_hash;
mod tracing;

pub use child::spawn_child;
use miette::Report;

pub use crate::{cli::Args, execution_state::ExecutionState};
use crate::{commands::CommandBase, shim::Error};

/// The payload from running main, if the program can complete without using Go
/// the Rust variant will be returned. If Go is needed then the execution state
/// that should be passed to Go will be returned.
pub enum Payload {
Rust(Result<i32, shim::Error>),
Go(Box<CommandBase>),
}

pub fn get_version() -> &'static str {
include_str!("../../../version.txt")
Expand All @@ -52,26 +42,6 @@ pub fn get_version() -> &'static str {
.trim_end()
}

pub fn main() -> Payload {
match shim::run() {
Ok(payload) => payload,
// We only print using miette for some errors because we want to keep
// compatibility with Go. When we've deleted the Go code we can
// move all errors to miette since it provides slightly nicer
// printing out of the box.
Err(err @ (Error::MultipleCwd(..) | Error::EmptyCwd { .. })) => {
println!("{:?}", Report::new(err));

Payload::Rust(Ok(1))
}
// We don't need to print "Turbo error" for Run errors
Err(err @ shim::Error::Cli(cli::Error::Run(_))) => Payload::Rust(Err(err)),
Err(err) => {
// This raw print matches the Go behavior, once we no longer care
// about matching formatting we should remove this.
println!("Turbo error: {err}");

Payload::Rust(Err(err))
}
}
pub fn main() -> Result<i32, shim::Error> {
shim::run()
}
2 changes: 1 addition & 1 deletion crates/turborepo-lib/src/run/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use itertools::Itertools;
use rayon::iter::ParallelBridge;
use tracing::debug;
use turborepo_analytics::{start_analytics, AnalyticsHandle, AnalyticsSender};
use turborepo_api_client::{APIAuth, APIClient, Client};
use turborepo_api_client::{APIAuth, APIClient};
use turborepo_cache::{AsyncCache, RemoteCacheOpts};
use turborepo_ci::Vendor;
use turborepo_env::EnvironmentVariableMap;
Expand Down
12 changes: 4 additions & 8 deletions crates/turborepo-lib/src/shim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use turborepo_repository::{
};
use turborepo_ui::UI;

use crate::{cli, get_version, spawn_child, tracing::TurboSubscriber, Payload};
use crate::{cli, get_version, spawn_child, tracing::TurboSubscriber};

#[derive(Debug, Error, Diagnostic)]
#[error("cannot have multiple `--cwd` flags in command")]
Expand Down Expand Up @@ -561,7 +561,7 @@ fn run_correct_turbo(
shim_args: ShimArgs,
subscriber: &TurboSubscriber,
ui: UI,
) -> Result<Payload, Error> {
) -> Result<i32, Error> {
if let Some(turbo_state) = LocalTurboState::infer(&repo_state.root) {
try_check_for_updates(&shim_args, &turbo_state.version);

Expand All @@ -573,11 +573,7 @@ fn run_correct_turbo(
debug!("Currently running turbo is local turbo.");
Ok(cli::run(Some(repo_state), subscriber, ui)?)
} else {
Ok(Payload::Rust(spawn_local_turbo(
&repo_state,
turbo_state,
shim_args,
)))
spawn_local_turbo(&repo_state, turbo_state, shim_args)
}
} else {
try_check_for_updates(&shim_args, get_version());
Expand Down Expand Up @@ -713,7 +709,7 @@ fn try_check_for_updates(args: &ShimArgs, current_version: &str) {
}
}

pub fn run() -> Result<Payload, Error> {
pub fn run() -> Result<i32, Error> {
let args = ShimArgs::parse()?;
let ui = args.ui();
if ui.should_strip_ansi {
Expand Down
1 change: 1 addition & 0 deletions crates/turborepo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ clap_complete = { workspace = true }
command-group = { version = "2.0.1", features = ["with-tokio"] }
dunce = { workspace = true }
human-panic = "1.2.1"
miette.workspace = true
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
serde_yaml = { workspace = true }
Expand Down
Loading

0 comments on commit 0bddd7a

Please sign in to comment.