diff options
Diffstat (limited to 'src/main/java/org/shedlang/compiler/ShedCompiler.java')
| -rw-r--r-- | src/main/java/org/shedlang/compiler/ShedCompiler.java | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/src/main/java/org/shedlang/compiler/ShedCompiler.java b/src/main/java/org/shedlang/compiler/ShedCompiler.java index af47ff5c..34cdad23 100644 --- a/src/main/java/org/shedlang/compiler/ShedCompiler.java +++ b/src/main/java/org/shedlang/compiler/ShedCompiler.java @@ -36,12 +36,7 @@ public class ShedCompiler { ) throws IOException, InterruptedException { var config = ProjectConfig.read(projectRoot); - // TODO: recursive dependencies - var projectRoots = new ArrayList<Path>(); - projectRoots.add(projectRoot); - for (var dependency : config.dependencies()) { - projectRoots.add(dependency.path()); - } + var projectRoots = findProjectRoots(config); var untypedNamespaceNodes = projectRoots.stream() .flatMap(root -> { @@ -102,6 +97,29 @@ public class ShedCompiler { ); } + /** + * Find the roots of any projects that require compilation, including + * transitive dependencies. + */ + private LinkedHashSet<Path> findProjectRoots(ProjectConfig config) throws IOException { + var projectRoots = new LinkedHashSet<Path>(); + var pendingProjects = new ArrayDeque<Path>(); + pendingProjects.add(config.root()); + // TODO: detect cycles + + while (!pendingProjects.isEmpty()) { + var projectRoot = pendingProjects.removeFirst(); + if (projectRoots.add(projectRoot)) { + var projectConfig = ProjectConfig.read(projectRoot); + for (var dependency : projectConfig.dependencies()) { + pendingProjects.add(dependency.path()); + } + } + } + + return projectRoots; + } + private List<Path> collectSourceFilePaths(Path sourceRoot) throws IOException { var paths = new ArrayList<Path>(); Files.walkFileTree(sourceRoot, new SimpleFileVisitor<Path>() { |
