diff --git a/src/functTest/groovy/com/verificationgentleman/gradle/hdvl/systemverilog/SystemVerilogPluginCompileOrderSpec.groovy b/src/functTest/groovy/com/verificationgentleman/gradle/hdvl/systemverilog/SystemVerilogPluginCompileOrderSpec.groovy index b9a8677..c73d7ff 100644 --- a/src/functTest/groovy/com/verificationgentleman/gradle/hdvl/systemverilog/SystemVerilogPluginCompileOrderSpec.groovy +++ b/src/functTest/groovy/com/verificationgentleman/gradle/hdvl/systemverilog/SystemVerilogPluginCompileOrderSpec.groovy @@ -26,6 +26,7 @@ import static org.gradle.testkit.runner.TaskOutcome.SUCCESS class SystemVerilogPluginCompileOrderSpec extends Specification { @Rule TemporaryFolder testProjectDir = new TemporaryFolder() File buildFile + File mainSv def setup() { buildFile = testProjectDir.newFile('build.gradle') @@ -34,10 +35,11 @@ class SystemVerilogPluginCompileOrderSpec extends Specification { id 'com.verificationgentleman.gradle.hdvl.systemverilog' } """ + + mainSv = testProjectDir.newFolder('src', 'main', 'sv') } def "can compile a given sv source file first"() { - File mainSv = testProjectDir.newFolder('src', 'main', 'sv') new File(mainSv, "file0.sv").createNewFile() new File(mainSv, "file1.sv").createNewFile() @@ -65,4 +67,38 @@ class SystemVerilogPluginCompileOrderSpec extends Specification { lineWithFile1 < lineWithFile0 } + + def "can compile matching source files first"() { + new File(mainSv, 'another_file.sv').createNewFile() + new File(mainSv, 'file0.sv').createNewFile() + new File(mainSv, 'file1.sv').createNewFile() + + buildFile << """ + sourceSets.main.sv.order.first 'file*.sv' + """ + + when: + def result = GradleRunner.create() + .withProjectDir(testProjectDir.root) + .withPluginClasspath() + .withArguments(':genXrunArgsFile') + .build() + + then: + result.task(":genXrunArgsFile").outcome == SUCCESS + def xrunArgsFile = new File(testProjectDir.root, 'build/xrun_args.f') + def lines = xrunArgsFile.text.split('\n') + + def lineWithFile0 = lines.findIndexOf { it.contains('file0.sv') } + lineWithFile0 != -1 + + def lineWithFile1 = lines.findIndexOf { it.contains('file1.sv') } + lineWithFile1 != -1 + + def lineWithAnotherFile = lines.findIndexOf { it.contains('another_file.sv') } + lineWithFile1 != -1 + + lineWithFile0 < lineWithAnotherFile + lineWithFile1 < lineWithAnotherFile + } } diff --git a/src/main/java/com/verificationgentleman/gradle/hdvl/AbstractGenArgsFile.java b/src/main/java/com/verificationgentleman/gradle/hdvl/AbstractGenArgsFile.java index e09d0d1..c715317 100644 --- a/src/main/java/com/verificationgentleman/gradle/hdvl/AbstractGenArgsFile.java +++ b/src/main/java/com/verificationgentleman/gradle/hdvl/AbstractGenArgsFile.java @@ -30,7 +30,6 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; -import java.util.stream.IntStream; public abstract class AbstractGenArgsFile extends SourceTask { @@ -129,23 +128,15 @@ private void writeExportedHeaders(FileWriter writer) throws IOException { protected abstract String getIncdirOpt(String incdirPath); private Iterable getOrderedSystemVerilogSourceFiles() { - List result = new ArrayList<>(getSource().getFiles()); - if (!getSvOrder().isPresent() || getSvOrder().get().getFirst() == null) - return result; + return getSource(); String first = getSvOrder().get().getFirst(); + FileTree firstFiles = getSource().matching(patternFilterable -> patternFilterable.include(first)); - int indexOfFirstFile = IntStream.range(0, result.size()) - .filter(i -> result.get(i).getName().equals(first)) - .findFirst() - .orElse(-1); - - if (indexOfFirstFile > 0) { - File firstFile = result.get(indexOfFirstFile); - result.remove(indexOfFirstFile); - result.add(0, firstFile); - } + List result = new ArrayList<>(); + result.addAll(firstFiles.getFiles()); + result.addAll(getSource().minus(firstFiles).getFiles()); return result; }