Skip to content

Commit 6973f0f

Browse files
committed
[sbt-bridge] Sort sources before compilation
1 parent 013ed36 commit 6973f0f

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

sbt-bridge/src/xsbt/CompilerBridgeDriver.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
import xsbti.*;
1818
import xsbti.compile.Output;
1919

20+
import java.util.Comparator;
21+
import java.util.Arrays;
22+
2023
public class CompilerBridgeDriver extends Driver {
2124
private final String[] scalacOptions;
2225
private final String[] args;
@@ -66,8 +69,20 @@ synchronized public void run(VirtualFile[] sources, AnalysisCallback callback, L
6669
log.debug(this::prettyPrintCompilationArguments);
6770
Compiler compiler = newCompiler(context);
6871

72+
VirtualFile[] sortedSources = new VirtualFile[sources.length];
73+
System.arraycopy(sources, 0, sortedSources, 0, sources.length);
74+
Arrays.sort(
75+
sortedSources,
76+
new Comparator<VirtualFile>() {
77+
@Override
78+
public int compare(VirtualFile x0, VirtualFile x1) {
79+
return x0.id().compareTo(x1.id());
80+
}
81+
}
82+
);
83+
6984
ListBuffer<AbstractFile> sourcesBuffer = new ListBuffer<>();
70-
for (VirtualFile file: sources)
85+
for (VirtualFile file: sortedSources)
7186
sourcesBuffer.append(AbstractZincFile.of(file));
7287
doCompileFiles(compiler, sourcesBuffer.toList(), context);
7388

0 commit comments

Comments
 (0)