Skip to content

Commit

Permalink
More run implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
NicholasLYang committed May 9, 2023
1 parent 328a0b3 commit 6bd91da
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 9 deletions.
8 changes: 7 additions & 1 deletion crates/turborepo-lib/src/config/turbo.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use serde::{Deserialize, Serialize};

use crate::{opts::RemoteCacheOpts, pipeline::Pipeline};

#[derive(Serialize, Deserialize, Debug, Default)]
#[serde(rename_all = "camelCase")]
pub struct SpacesJson {
Expand All @@ -8,11 +10,15 @@ pub struct SpacesJson {
pub other: Option<serde_json::Value>,
}

#[derive(Serialize, Deserialize, Debug)]
#[derive(Serialize, Deserialize, Default, Debug)]
#[serde(rename_all = "camelCase")]
pub struct TurboJson {
#[serde(flatten)]
other: serde_json::Value,
// This is 'static just to get stuff working
pub(crate) remote_cache_opts: Option<RemoteCacheOpts<'static>>,
pub space_id: Option<&'static str>,
pub pipeline: Pipeline,
#[serde(skip_serializing_if = "Option::is_none")]
pub experimental_spaces: Option<SpacesJson>,
}
12 changes: 8 additions & 4 deletions crates/turborepo-lib/src/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ use std::collections::BTreeMap;
use anyhow::Result;
use turbopath::AbsoluteSystemPathBuf;

use crate::pipeline::{Pipeline, TaskDefinition};
use crate::{
config::TurboJson,
pipeline::{Pipeline, TaskDefinition},
};

pub struct CompleteGraph {
// TODO: This should actually be an acyclic graph type
Expand All @@ -27,13 +30,14 @@ impl CompleteGraph {
workspace_graph: petgraph::Graph<String, String>,
workspace_infos: WorkspaceCatalog,
repo_root: AbsoluteSystemPathBuf,
turbo_json: TurboJson,
) -> Self {
Self {
workspace_graph,
workspace_infos,
repo_root,
global_hash: None,
pipeline: Pipeline::default(),
pipeline: turbo_json.pipeline,
task_definitions: BTreeMap::new(),
task_hash_tracker: TaskHashTracker::default(),
}
Expand All @@ -43,9 +47,9 @@ impl CompleteGraph {
&self,
_workspace_name: &str,
_is_single_package: bool,
) -> Result<()> {
) -> Result<TurboJson> {
// TODO
Ok(())
Ok(TurboJson::default())
}
}

Expand Down
31 changes: 30 additions & 1 deletion crates/turborepo-lib/src/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,37 @@ use crate::{
};

pub struct Opts<'a> {
pub cache_opts: CacheOpts<'a>,
pub run_opts: RunOpts<'a>,
pub runcache_opts: RunCacheOpts,
}

#[derive(Default)]
struct CacheOpts<'a> {
override_dir: Option<&'a str>,
skip_remote: bool,
skip_filesystem: bool,
workers: u32,
pub(crate) remote_cache_opts: Option<RemoteCacheOpts<'a>>,
}

impl<'a> From<&'a RunArgs> for CacheOpts<'a> {
fn from(run_args: &'a RunArgs) -> std::result::Result<Self, Self::Error> {
Ok(CacheOpts {
override_dir: run_args.cache_dir.as_deref(),
skip_filesystem: run_args.remote_only,
workers: run_args.cache_workers,
..CacheOpts::default()
})
}
}

#[derive(Default)]
pub struct RemoteCacheOpts<'a> {
team_id: &'a str,
signature: bool,
}

impl<'a> TryFrom<&'a Args> for Opts<'a> {
type Error = anyhow::Error;

Expand All @@ -19,9 +46,11 @@ impl<'a> TryFrom<&'a Args> for Opts<'a> {
return Err(anyhow!("Expected run command"))
};
let run_opts = RunOpts::try_from(run_args.as_ref())?;
let cache_opts = CacheOpts::from(run_args.as_ref());

Ok(Self {
run_opts,
cache_opts,
runcache_opts: RunCacheOpts::default(),
})
}
Expand Down Expand Up @@ -49,7 +78,7 @@ pub struct RunOpts<'a> {
pub(crate) single_package: bool,
log_prefix: Option<LogPrefix>,
summarize: Option<Option<bool>>,
experimental_space_id: Option<&'a str>,
pub(crate) experimental_space_id: Option<&'a str>,
}

const DEFAULT_CONCURRENCY: u32 = 10;
Expand Down
14 changes: 11 additions & 3 deletions crates/turborepo-lib/src/run/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,22 @@ impl<'a> Run<'a> {
.validate()
.context("Invalid package dependency graph")?;

let turbo_json =
g.get_turbo_config_from_workspace(ROOT_PKG_NAME, self.opts.run_opts.single_package)?;

self.opts.cache_opts.remote_cache_opts = turbo_json.remote_cache_opts.clone();

if self.opts.run_opts.experimental_space_id.is_none() {
self.opts.run_opts.experimental_space_id = turbo_json.space_id.clone();
}

let g = CompleteGraph::new(
pkg_dep_graph.workspace_graph,
pkg_dep_graph.workspace_infos,
AbsoluteSystemPathBuf::new(self.base.repo_root.clone())?,
turbo_json,
);

let turbo_json =
g.get_turbo_config_from_workspace(ROOT_PKG_NAME, self.opts.run_opts.single_package)?;
// TODO: Check if .git directory exists for SCM

Ok(())
}
Expand Down

0 comments on commit 6bd91da

Please sign in to comment.