Skip to content

Commit bef23f2

Browse files
authored
feat: add buckconfig and buckroot file (#1788)
* feat: add buckconfig and buckroot file * feat: change test test_init_mega_dir * fix: reslove cr problems
1 parent 8ff70d7 commit bef23f2

1 file changed

Lines changed: 54 additions & 1 deletion

File tree

jupiter/src/utils/converter.rs

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,8 @@ pub fn init_trees(
432432
blobs.push(blob);
433433
}
434434

435+
inject_root_buck_files(&mut root_items, &mut blobs, &mono_config.root_dirs);
436+
435437
let root = Tree::from_tree_items(root_items).unwrap();
436438
(
437439
trees.into_iter().map(|x| (x.id, x)).collect(),
@@ -440,6 +442,57 @@ pub fn init_trees(
440442
)
441443
}
442444

445+
/// Injects Buck configuration files (.buckroot and .buckconfig) into the root directory.
446+
fn inject_root_buck_files(
447+
root_items: &mut Vec<TreeItem>,
448+
blobs: &mut Vec<Blob>,
449+
root_dirs: &[String],
450+
) {
451+
// .buckroot
452+
let buckroot_content = generate_buckroot_content();
453+
let buckroot_blob = Blob::from_content(&buckroot_content);
454+
root_items.push(TreeItem {
455+
mode: TreeItemMode::Blob,
456+
id: buckroot_blob.id,
457+
name: String::from(".buckroot"),
458+
});
459+
blobs.push(buckroot_blob);
460+
461+
// .buckconfig
462+
let buckconfig_content = generate_buckconfig_content(root_dirs);
463+
let buckconfig_blob = Blob::from_content(&buckconfig_content);
464+
root_items.push(TreeItem {
465+
mode: TreeItemMode::Blob,
466+
id: buckconfig_blob.id,
467+
name: String::from(".buckconfig"),
468+
});
469+
blobs.push(buckconfig_blob);
470+
}
471+
472+
fn generate_buckroot_content() -> String {
473+
// The .buckroot file is usually empty or contains a simple identifier.
474+
String::new()
475+
}
476+
477+
/// Directories that should be excluded from Buck cell definitions.
478+
/// Currently only "doc" is excluded to preserve existing behavior.
479+
const EXCLUDED_BUCK_CELL_DIRS: &[&str] = &["doc"];
480+
481+
fn generate_buckconfig_content(root_dirs: &[String]) -> String {
482+
let cells = root_dirs
483+
.iter()
484+
.filter(|d| !EXCLUDED_BUCK_CELL_DIRS.contains(&d.as_str()))
485+
.map(|d| format!(" {d} = {d}"))
486+
.collect::<Vec<_>>()
487+
.join("\n");
488+
489+
if cells.is_empty() {
490+
"[cells]\n".to_string()
491+
} else {
492+
format!("[cells]\n{cells}\n")
493+
}
494+
}
495+
443496
pub struct MegaModelConverter {
444497
pub commit: Commit,
445498
pub root_tree: Tree,
@@ -742,7 +795,7 @@ mod test {
742795
let mega_blobs = converter.mega_blobs.borrow().clone();
743796
let dir_nums = mono_config.root_dirs.len();
744797
assert_eq!(mega_trees.len(), dir_nums + 1);
745-
assert_eq!(mega_blobs.len(), dir_nums);
798+
assert_eq!(mega_blobs.len(), dir_nums + 2); // 2 = .buckconfig + .buckroot
746799
}
747800

748801
#[test]

0 commit comments

Comments
 (0)