Skip to content

Commit

Permalink
Support turbo tasks inside of mod blocks (vercel/turborepo#8530)
Browse files Browse the repository at this point in the history
### Description
    
 I noticed this wasn't implemented when trying to write some unit tests inside of `mod tests`.
    
 The same visibility requirements apply (must be at least `pub(crate)`).

### Testing Instructions

Tested as part of vercel/turborepo#8529
  • Loading branch information
bgw authored Jun 24, 2024
1 parent 8f6b46a commit e8c9ce1
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions crates/turbo-tasks-build/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use std::{
collections::{HashMap, HashSet},
env::{
current_dir, {self},
},
env::{self, current_dir},
fmt::{Display, Write},
fs::read_dir,
path::{PathBuf, MAIN_SEPARATOR as PATH_SEP},
Expand Down Expand Up @@ -111,7 +109,7 @@ pub fn generate_register() {

file_path: &file_path,
prefix: &prefix,
mod_path: &mod_path,
mod_path,

register: &mut register_code,
values: &mut values,
Expand Down Expand Up @@ -191,7 +189,7 @@ struct RegisterContext<'a> {
queue: &'a mut Vec<(String, PathBuf)>,

file_path: &'a PathBuf,
mod_path: &'a str,
mod_path: String,
prefix: &'a str,

register: &'a mut String,
Expand Down Expand Up @@ -269,7 +267,15 @@ impl<'a> RegisterContext<'a> {
}

fn process_mod(&mut self, mod_item: ItemMod) -> Result<()> {
if mod_item.content.is_none() {
if let Some((_, items)) = mod_item.content {
let mod_name = mod_item.ident.to_string();
let child_mod_path = format!("{}::{}", self.mod_path, mod_name);
let parent_mod_path = std::mem::replace(&mut self.mod_path, child_mod_path);
for item in items {
self.process_item(item)?;
}
self.mod_path = parent_mod_path;
} else {
let name = mod_item.ident.to_string();
let parent_path = self.file_path.parent().unwrap();
let direct = parent_path.join(format!("{name}.rs"));
Expand Down Expand Up @@ -391,7 +397,7 @@ impl<'a> RegisterContext<'a> {
}

fn add_value(&mut self, ident: &Ident) {
let key: ValueKey = (self.mod_path.to_owned(), ident.clone());
let key: ValueKey = (self.mod_path.clone(), ident.clone());
let value: ValueEntry = (self.get_global_name(&[ident]), Vec::new());

assert!(
Expand Down Expand Up @@ -426,7 +432,7 @@ impl<'a> RegisterContext<'a> {
}

fn add_value_trait(&mut self, ident: &Ident, trait_ident: &Ident) {
let key: ValueKey = (self.mod_path.to_owned(), ident.clone());
let key: ValueKey = (self.mod_path.clone(), ident.clone());

let entry = self.values.get_mut(&key);
if entry.is_none() {
Expand Down

0 comments on commit e8c9ce1

Please sign in to comment.