Function foundry_compilers::flatten::collect_ordered_deps
source · pub fn collect_ordered_deps<D: ParsedSource + MaybeSolData>(
path: &PathBuf,
paths: &ProjectPathsConfig<D::Language>,
graph: &Graph<D>,
) -> Result<Vec<PathBuf>>Expand description
We want to make order in which sources are written to resulted flattened file deterministic.
We can’t just sort files alphabetically as it might break compilation, because Solidity does not allow base class definitions to appear after derived contract definitions.
Instead, we sort files by the number of their dependencies (imports of any depth) in ascending order. If files have the same number of dependencies, we sort them alphabetically. Target file is always placed last.