diff options
| author | Michael Williamson <mike@zwobble.org> | 2025-01-12 15:11:04 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2025-01-12 15:11:04 +0000 |
| commit | 027d73dea19c4154d27c77cd82dd4b28649cdf3f (patch) | |
| tree | c5ef4e7e2d7bc096389c55507bae87793906a862 /src/main/java/org | |
| parent | 57de5c166aeab88d0da164171520e962519bc999 (diff) | |
Support recursive project dependencies
Diffstat (limited to 'src/main/java/org')
| -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>() { |
