Skip to content

Commit

Permalink
src/generate: support sharing downloaded srcdirs
Browse files Browse the repository at this point in the history
  • Loading branch information
kaspar030 committed Dec 22, 2023
1 parent f431bf6 commit c1d3ce6
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ use itertools::Itertools;
use rayon::prelude::*;
use solvent::DepGraph;

use crate::utils::ContainingPath;

use super::{
build::Build,
data::{load, FileTreeState},
Expand Down Expand Up @@ -481,6 +483,7 @@ fn configure_build(
}

let mut module_build_dep_files: IndexMap<&String, IndexSet<Utf8PathBuf>> = IndexMap::new();
let mut download_dirs = IndexMap::new();

// now handle each module
for (module, module_env, module_build_deps) in modules_in_build_order.iter() {
Expand All @@ -501,6 +504,27 @@ fn configure_build(
// This is populated in data.rs, so unwrap() always succeeds.
let srcdir = module.srcdir.as_ref().unwrap();

let mut src_tagfile = None;

if let Some(download) = module.download.as_ref() {
// This module is downloading, so store it's download folder in
// `download_dirs`. Dependees can then, if their srcdir is the same
// or prefixed by it, mark their sources as being created by the tagfile.
// This prevents ninja complaining about missing files.
// TODO: catch download folder clash here
download_dirs.insert(srcdir, download.tagfile(srcdir));
} else {
// this module is not downloading itself, so look up it's srcdir in
// the so-far stored `download_dirs`. Any dependency of this module
// would have stored it's srcdir there.
let srcdir = Utf8PathBuf::from(
nested_env::expand_eval(srcdir, &flattened_env, IfMissing::Ignore).unwrap(),
);
if let Some(tagfile) = download_dirs.get_containing_path(&srcdir) {
src_tagfile = Some(tagfile);
}
}

//println!("{:#?}", builder.var_options);

// add optional sources, if needed
Expand Down Expand Up @@ -771,6 +795,13 @@ fn configure_build(
.unwrap();

ninja_entries.insert(format!("{build}"));
} else {
// 7. optionally create phony alias for a possibly downloaded
// file
if let Some(tagfile) = src_tagfile {
ninja_entries
.insert(crate::ninja::alias(tagfile.as_str(), srcpath.as_str()));
}
}
}
}
Expand Down

0 comments on commit c1d3ce6

Please sign in to comment.