Skip to content

Commit

Permalink
chore: remove globalDotEnv and dotEnv fields (#8181)
Browse files Browse the repository at this point in the history
### Description

This PR removes `globalDotEnv`/`dotEnv` in favor of `globalDependencies`
and `inputs` which is now fairly ergonomic to use with the addition of
`$TURBO_DEFAULTS$`.

This PR does *not* update the corresponding JS types.

### Testing Instructions

Updated existing integration tests
  • Loading branch information
chris-olszewski committed May 22, 2024
1 parent 97ee648 commit ac9f709
Show file tree
Hide file tree
Showing 68 changed files with 235 additions and 452 deletions.
7 changes: 0 additions & 7 deletions crates/turborepo-lib/src/engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use petgraph::Graph;
use thiserror::Error;
use turborepo_errors::Spanned;
use turborepo_repository::package_graph::{PackageGraph, PackageName};
use turborepo_telemetry::events::generic::GenericEventBuilder;

use crate::{run::task_id::TaskId, task_graph::TaskDefinition};

Expand Down Expand Up @@ -380,12 +379,6 @@ impl Engine<Built> {
&self.task_definitions
}

pub fn track_usage(&self, telemetry: &GenericEventBuilder) {
for task in self.task_definitions.values() {
telemetry.track_dot_env(task.dot_env.as_deref());
}
}

pub fn validate(
&self,
package_graph: &PackageGraph,
Expand Down
27 changes: 2 additions & 25 deletions crates/turborepo-lib/src/hash/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ pub struct TaskHashable<'a> {
pub(crate) resolved_env_vars: EnvVarPairs,
pub(crate) pass_through_env: &'a [String],
pub(crate) env_mode: ResolvedEnvMode,
pub(crate) dot_env: &'a [turbopath::RelativeUnixPathBuf],
}

#[derive(Debug, Clone)]
Expand All @@ -74,7 +73,6 @@ pub struct GlobalHashable<'a> {
pub pass_through_env: &'a [String],
pub env_mode: EnvMode,
pub framework_inference: bool,
pub dot_env: &'a [turbopath::RelativeUnixPathBuf],
}

pub struct LockFilePackages(pub Vec<turborepo_lockfiles::Package>);
Expand Down Expand Up @@ -253,15 +251,6 @@ impl From<TaskHashable<'_>> for Builder<HeapAllocator> {
}
}

{
let mut dotenv_builder = builder
.reborrow()
.init_dot_env(task_hashable.dot_env.len() as u32);
for (i, env) in task_hashable.dot_env.iter().enumerate() {
dotenv_builder.set(i as u32, env.as_str());
}
}

{
let mut resolved_env_vars_builder = builder
.reborrow()
Expand Down Expand Up @@ -352,15 +341,6 @@ impl From<GlobalHashable<'_>> for Builder<HeapAllocator> {

builder.set_framework_inference(hashable.framework_inference);

{
let mut dot_env = builder
.reborrow()
.init_dot_env(hashable.dot_env.len() as u32);
for (i, env) in hashable.dot_env.iter().enumerate() {
dot_env.set(i as u32, env.as_str());
}
}

// We're okay to unwrap here because we haven't hit the nesting
// limit and the message will not have cycles.
let size = builder
Expand Down Expand Up @@ -407,10 +387,9 @@ mod test {
resolved_env_vars: vec![],
pass_through_env: &["pass_thru_env".to_string()],
env_mode: ResolvedEnvMode::Loose,
dot_env: &[turbopath::RelativeUnixPathBuf::new("dotenv".to_string()).unwrap()],
};

assert_eq!(task_hashable.hash(), "ff765ee2f83bc034");
assert_eq!(task_hashable.hash(), "1f8b13161f57fca1");
}

#[test]
Expand All @@ -431,11 +410,9 @@ mod test {
pass_through_env: &["pass_through_env".to_string()],
env_mode: EnvMode::Infer,
framework_inference: true,

dot_env: &[turbopath::RelativeUnixPathBuf::new("dotenv".to_string()).unwrap()],
};

assert_eq!(global_hash.hash(), "c0ddf8138bd686e8");
assert_eq!(global_hash.hash(), "2144612ff08bddb9");
}

#[test_case(vec![], "459c029558afe716" ; "empty")]
Expand Down
1 change: 0 additions & 1 deletion crates/turborepo-lib/src/hash/proto.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ struct GlobalHashable {
passThroughEnv @5 :List(Text);
envMode @6 :EnvMode;
frameworkInference @7 :Bool;
dotEnv @8 :List(Text);


enum EnvMode {
Expand Down
2 changes: 0 additions & 2 deletions crates/turborepo-lib/src/run/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,6 @@ impl RunBuilder {
&root_package_json,
is_single_package,
)?;
root_turbo_json.track_usage(&run_telemetry);

pkg_dep_graph.validate()?;

Expand Down Expand Up @@ -375,7 +374,6 @@ impl RunBuilder {
pkg_dep_graph.remove_package_dependencies();
engine = self.build_engine(&pkg_dep_graph, &root_turbo_json, &filtered_pkgs)?;
}
engine.track_usage(&run_telemetry);

let color_selector = ColorSelector::default();

Expand Down
19 changes: 1 addition & 18 deletions crates/turborepo-lib/src/run/global_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ pub struct GlobalHashableInputs<'a> {
pub pass_through_env: Option<&'a [String]>,
pub env_mode: EnvMode,
pub framework_inference: bool,
pub dot_env: Option<&'a [RelativeUnixPathBuf]>,
pub env_at_execution_start: &'a EnvironmentVariableMap,
}

Expand All @@ -63,7 +62,6 @@ pub fn get_global_hash_inputs<'a, L: ?Sized + Lockfile>(
global_pass_through_env: Option<&'a [String]>,
env_mode: EnvMode,
framework_inference: bool,
dot_env: Option<&'a [RelativeUnixPathBuf]>,
hasher: &SCM,
) -> Result<GlobalHashableInputs<'a>, Error> {
let global_hashable_env_vars =
Expand All @@ -90,19 +88,7 @@ pub fn get_global_hash_inputs<'a, L: ?Sized + Lockfile>(
.map(|p| root_path.anchor(p).expect("path should be from root"))
.collect::<Vec<_>>();

let mut global_file_hash_map =
hasher.get_hashes_for_files(root_path, &global_deps_paths, false)?;

if !dot_env.unwrap_or_default().is_empty() {
let system_dot_env = dot_env
.into_iter()
.flatten()
.map(|p| p.to_anchored_system_path_buf());

let dot_env_object = hasher.hash_existing_of(root_path, system_dot_env)?;

global_file_hash_map.extend(dot_env_object);
}
let global_file_hash_map = hasher.get_hashes_for_files(root_path, &global_deps_paths, false)?;

debug!(
"external deps hash: {}",
Expand All @@ -118,7 +104,6 @@ pub fn get_global_hash_inputs<'a, L: ?Sized + Lockfile>(
pass_through_env: global_pass_through_env,
env_mode,
framework_inference,
dot_env,
env_at_execution_start,
})
}
Expand Down Expand Up @@ -190,7 +175,6 @@ impl<'a> GlobalHashableInputs<'a> {
pass_through_env: self.pass_through_env.unwrap_or_default(),
env_mode: self.env_mode,
framework_inference: self.framework_inference,
dot_env: self.dot_env.unwrap_or_default(),
};

global_hashable.hash()
Expand Down Expand Up @@ -240,7 +224,6 @@ mod tests {
None,
EnvMode::Infer,
false,
None,
&SCM::new(&root),
);
assert!(result.is_ok());
Expand Down
1 change: 0 additions & 1 deletion crates/turborepo-lib/src/run/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,6 @@ impl Run {
pass_through_env,
env_mode,
self.opts.run_opts.framework_inference,
self.root_turbo_json.global_dot_env.as_deref(),
&self.scm,
)?
};
Expand Down
4 changes: 0 additions & 4 deletions crates/turborepo-lib/src/run/summary/global_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ pub struct GlobalHashSummary<'a> {
pub root_key: &'static str,
pub files: BTreeMap<RelativeUnixPathBuf, String>,
pub hash_of_external_dependencies: &'a str,
pub global_dot_env: Option<&'a [RelativeUnixPathBuf]>,
pub environment_variables: GlobalEnvVarSummary<'a>,
}

Expand All @@ -46,7 +45,6 @@ impl<'a> TryFrom<GlobalHashableInputs<'a>> for GlobalHashSummary<'a> {
env,
resolved_env_vars,
pass_through_env,
dot_env,
env_at_execution_start,
..
} = global_hashable_inputs;
Expand Down Expand Up @@ -80,8 +78,6 @@ impl<'a> TryFrom<GlobalHashableInputs<'a>> for GlobalHashSummary<'a> {
.map(|vars| vars.by_source.matching.to_secret_hashable()),
pass_through,
},

global_dot_env: dot_env,
})
}
}
20 changes: 0 additions & 20 deletions crates/turborepo-lib/src/run/summary/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,16 +499,6 @@ impl<'a> RunSummary<'a> {
" Global Cache Key\t=\t{}",
self.global_hash_summary.root_key
)?;
cwriteln!(
tab_writer,
ui,
GREY,
" Global .env Files Considered\t=\t{}",
self.global_hash_summary
.global_dot_env
.unwrap_or_default()
.len()
)?;
cwriteln!(
tab_writer,
ui,
Expand Down Expand Up @@ -661,16 +651,6 @@ impl<'a> RunSummary<'a> {
" Inputs Files Considered\t=\t{}",
task.shared.inputs.len()
)?;
cwriteln!(
tab_writer,
ui,
GREY,
" .env Files Considered\t=\t{}",
task.shared
.dot_env
.as_ref()
.map_or(0, |dot_env| dot_env.len())
)?;

cwriteln!(
tab_writer,
Expand Down
8 changes: 0 additions & 8 deletions crates/turborepo-lib/src/run/summary/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ pub(crate) struct SharedTaskSummary<T> {
pub framework: String,
pub env_mode: EnvMode,
pub environment_variables: TaskEnvVarSummary,
pub dot_env: Option<Vec<RelativeUnixPathBuf>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub execution: Option<TaskExecutionSummary>,
}
Expand All @@ -104,7 +103,6 @@ pub struct TaskSummaryTaskDefinition {
persistent: bool,
env: Vec<String>,
pass_through_env: Option<Vec<String>>,
dot_env: Option<Vec<RelativeUnixPathBuf>>,
interactive: bool,
}

Expand Down Expand Up @@ -233,7 +231,6 @@ impl From<SharedTaskSummary<TaskId<'static>>> for SharedTaskSummary<String> {
execution,
env_mode,
environment_variables,
dot_env,
..
} = value;
Self {
Expand Down Expand Up @@ -261,7 +258,6 @@ impl From<SharedTaskSummary<TaskId<'static>>> for SharedTaskSummary<String> {
execution,
env_mode,
environment_variables,
dot_env,
}
}
}
Expand All @@ -277,7 +273,6 @@ impl From<TaskDefinition> for TaskSummaryTaskDefinition {
cache,
mut env,
pass_through_env,
dot_env,
topological_dependencies,
task_dependencies,
mut inputs,
Expand Down Expand Up @@ -318,8 +313,6 @@ impl From<TaskDefinition> for TaskSummaryTaskDefinition {
interactive,
env,
pass_through_env,
// This should _not_ be sorted.
dot_env,
}
}
}
Expand Down Expand Up @@ -378,7 +371,6 @@ mod test {
"interactive": false,
"env": [],
"passThroughEnv": null,
"dotEnv": null,
})
; "resolved task definition"
)]
Expand Down
1 change: 0 additions & 1 deletion crates/turborepo-lib/src/run/summary/task_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ impl<'a> TaskSummaryFactory<'a> {
self.env_at_start,
)
.expect("invalid glob in task definition should have been caught earlier"),
dot_env: task_definition.dot_env.clone(),
execution,
})
}
Expand Down
3 changes: 0 additions & 3 deletions crates/turborepo-lib/src/task_graph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ pub struct TaskDefinition {

pub(crate) pass_through_env: Option<Vec<String>>,

pub(crate) dot_env: Option<Vec<RelativeUnixPathBuf>>,

// TopologicalDependencies are tasks from package dependencies.
// E.g. "build" is a topological dependency in:
// dependsOn: ['^build'].
Expand Down Expand Up @@ -92,7 +90,6 @@ impl Default for TaskDefinition {
inputs: Default::default(),
output_logs: Default::default(),
persistent: Default::default(),
dot_env: Default::default(),
interactive: Default::default(),
}
}
Expand Down
19 changes: 1 addition & 18 deletions crates/turborepo-lib/src/task_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ impl PackageInputsHashes {
}
}
});
let mut hash_object = match hash_object {
let hash_object = match hash_object {
Some(hash_object) => hash_object,
None => {
let local_hash_result = scm.get_package_file_hashes(
Expand All @@ -193,22 +193,6 @@ impl PackageInputsHashes {
}
}
};
if let Some(dot_env) = &task_definition.dot_env {
if !dot_env.is_empty() {
let absolute_package_path = repo_root.resolve(package_path);
let dot_env_object = match scm.hash_existing_of(
&absolute_package_path,
dot_env.iter().map(|p| p.to_anchored_system_path_buf()),
) {
Ok(dot_env_object) => dot_env_object,
Err(err) => return Some(Err(err.into())),
};

for (key, value) in dot_env_object {
hash_object.insert(key, value);
}
}
}

let file_hashes = FileHashes(hash_object);
let hash = file_hashes.clone().hash();
Expand Down Expand Up @@ -404,7 +388,6 @@ impl<'a> TaskHasher<'a> {
.as_deref()
.unwrap_or_default(),
env_mode: task_env_mode,
dot_env: task_definition.dot_env.as_deref().unwrap_or_default(),
};

let task_hash = task_hashable.calculate_task_hash();
Expand Down
Loading

0 comments on commit ac9f709

Please sign in to comment.