@@ -14,19 +14,20 @@ use crate::build::compile::{mark_modules_with_deleted_deps_dirty, mark_modules_w
1414use crate :: helpers:: emojis:: * ;
1515use crate :: helpers:: { self , get_workspace_root} ;
1616use crate :: sourcedirs;
17+ use ahash:: AHashSet ;
1718use anyhow:: { Result , anyhow} ;
1819use build_types:: * ;
1920use console:: style;
2021use indicatif:: { ProgressBar , ProgressStyle } ;
2122use log:: log_enabled;
2223use serde:: Serialize ;
2324use std:: ffi:: OsString ;
24- use std:: fmt;
2525use std:: fs:: File ;
2626use std:: io:: { Write , stdout} ;
2727use std:: path:: { Path , PathBuf } ;
2828use std:: process:: Stdio ;
2929use std:: time:: { Duration , Instant } ;
30+ use std:: { fmt, fs} ;
3031
3132fn is_dirty ( module : & Module ) -> bool {
3233 match module. source_type {
@@ -469,6 +470,50 @@ pub fn write_build_ninja(build_state: &BuildState) {
469470 }
470471}
471472
473+ #[ derive( Serialize , Debug ) ]
474+ pub struct SourceDirsMeta {
475+ pub dirs : Vec < String > ,
476+ pub pkgs : Vec < ( String , String ) > ,
477+ pub generated : Vec < String > ,
478+ }
479+
480+ fn generate_sourcedirs_meta ( build_state : & BuildState ) {
481+ let mut dir_set: AHashSet < String > = AHashSet :: new ( ) ;
482+ let mut pkgs: Vec < ( String , String ) > = vec ! [ ] ;
483+ for package in build_state. packages . values ( ) {
484+ if package. is_local_dep {
485+ if let Some ( source_files) = & package. source_files {
486+ for source_file in source_files. keys ( ) {
487+ if let Some ( parent) = source_file. parent ( ) {
488+ dir_set. insert ( parent. to_string_lossy ( ) . into_owned ( ) ) ;
489+ }
490+ }
491+ }
492+ } else {
493+ pkgs. push ( ( package. name . clone ( ) , package. path . to_string_lossy ( ) . into_owned ( ) ) ) ;
494+ }
495+ }
496+
497+ let meta = SourceDirsMeta {
498+ dirs : dir_set. into_iter ( ) . collect ( ) ,
499+ pkgs,
500+ generated : vec ! [ ] ,
501+ } ;
502+
503+ let json = serde_json:: to_string ( & meta) ;
504+ match json {
505+ Err ( err) => {
506+ println ! ( "Error serializing .sourcedirs.json: {}" , err) ;
507+ }
508+ Ok ( json) => {
509+ let output_path = build_state. project_root . join ( "lib/bs/.sourcedirs.json" ) ;
510+ if let Err ( e) = fs:: write ( output_path, json) {
511+ println ! ( "Error writing sourcedirs.json: {}" , e) ;
512+ }
513+ }
514+ }
515+ }
516+
472517pub fn build (
473518 filter : & Option < regex:: Regex > ,
474519 path : & Path ,
@@ -494,6 +539,8 @@ pub fn build(
494539 )
495540 . map_err ( |e| anyhow ! ( "Could not initialize build. Error: {e}" ) ) ?;
496541
542+ generate_sourcedirs_meta ( & build_state) ;
543+
497544 match incremental_build (
498545 & mut build_state,
499546 default_timing,
0 commit comments