Skip to content

Commit

Permalink
Add possibility to use wildcards in order.first
Browse files Browse the repository at this point in the history
The supported patterns are the same as those used by `include` and `exclude`.
  • Loading branch information
tudortimi committed Dec 30, 2024
1 parent 937f5dd commit 4cc5bc5
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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()

Expand Down Expand Up @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -129,23 +128,15 @@ private void writeExportedHeaders(FileWriter writer) throws IOException {
protected abstract String getIncdirOpt(String incdirPath);

private Iterable<File> getOrderedSystemVerilogSourceFiles() {
List<File> 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<File> result = new ArrayList<>();
result.addAll(firstFiles.getFiles());
result.addAll(getSource().minus(firstFiles).getFiles());

return result;
}
Expand Down

0 comments on commit 4cc5bc5

Please sign in to comment.