+// TODO kb refactor and check for correctness
+fn detached_files_to_crate_graph(
+ rustc_cfg: Vec<CfgFlag>,
+ load: &mut dyn FnMut(&AbsPath) -> Option<FileId>,
+ detached_files: &[AbsPathBuf],
+ sysroot: &Sysroot,
+) -> CrateGraph {
+ let _p = profile::span("detached_files_to_crate_graph");
+ let mut crate_graph = CrateGraph::default();
+ let (public_deps, _libproc_macro) =
+ sysroot_to_crate_graph(&mut crate_graph, sysroot, rustc_cfg.clone(), load);
+
+ let mut cfg_options = CfgOptions::default();
+ cfg_options.extend(rustc_cfg);
+
+ for detached_file in detached_files {
+ let file_id = load(&detached_file).unwrap();
+ let detached_file_crate = crate_graph.add_crate_root(
+ file_id,
+ Edition::Edition2018,
+ None,
+ cfg_options.clone(),
+ Env::default(),
+ Vec::new(),
+ );
+
+ for (name, krate) in public_deps.iter() {
+ add_dep(&mut crate_graph, detached_file_crate, name.clone(), *krate);
+ }
+ }
+ crate_graph
+}
+