Skip to content

Commit

Permalink
Merge pull request #165 from tudortimi/add-possibility-to-specify-whi…
Browse files Browse the repository at this point in the history
…ch-systemverilog-files-should-be-compiled-last

Add possibility to specify which SystemVerilog files should be compiled last
  • Loading branch information
tudortimi authored Dec 30, 2024
2 parents 6ef7146 + efe2981 commit 25694b3
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 5 deletions.
1 change: 1 addition & 0 deletions examples/sv-with-custom-order/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ sourceSets {
sv {
order {
first 'dummy1.sv'
last 'dummy0.sv'
}
}
}
Expand Down
1 change: 1 addition & 0 deletions examples/sv-with-custom-order/src/main/sv/dummy0.sv
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
package dummy0;
import dummy1::*;
import dummy2::*;
endpackage
3 changes: 3 additions & 0 deletions examples/sv-with-custom-order/src/main/sv/dummy2.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package dummy2;
import dummy1::*;
endpackage
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,70 @@ class SystemVerilogPluginCompileOrderSpec extends Specification {
lineWithFile0 < lineWithAnotherFile
lineWithFile1 < lineWithAnotherFile
}

def "can compile a given source file last"() {
new File(mainSv, "file0.sv").createNewFile()
new File(mainSv, "file1.sv").createNewFile()

buildFile << """
sourceSets.main.sv.order.last 'file0.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

lineWithFile0 > lineWithFile1
}

def "can specify both first and last for compile order"() {
new File(mainSv, "file0.sv").createNewFile()
new File(mainSv, "file1.sv").createNewFile()
new File(mainSv, "file2.sv").createNewFile()

buildFile << """
sourceSets.main.sv.order.first 'file1.sv'
sourceSets.main.sv.order.last 'file0.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 lineWithFile2 = lines.findIndexOf { it.contains('file2.sv') }
lineWithFile2 != -1

lineWithFile1 < lineWithFile0
lineWithFile1 < lineWithFile2
lineWithFile0 > lineWithFile1
lineWithFile0 > lineWithFile2
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,29 @@ private void writeExportedHeaders(FileWriter writer) throws IOException {
protected abstract String getIncdirOpt(String incdirPath);

private Iterable<File> getOrderedSystemVerilogSourceFiles() {
if (!getSvOrder().isPresent() || getSvOrder().get().getFirst() == null)
if (!getSvOrder().isPresent() || (getSvOrder().get().getFirst() == null && getSvOrder().get().getLast() == null))
return getSource();

FileTree firstFiles = newEmptyFileTree();
FileTree lastFiles = newEmptyFileTree();

String first = getSvOrder().get().getFirst();
FileTree firstFiles = getSource().matching(patternFilterable -> patternFilterable.include(first));
if (first != null)
firstFiles = getSource().matching(patternFilterable -> patternFilterable.include(first));

String last = getSvOrder().get().getLast();
if (last != null)
lastFiles = getSource().matching(patternFilterable -> patternFilterable.include(last));

List<File> result = new ArrayList<>();
result.addAll(firstFiles.getFiles());
result.addAll(getSource().minus(firstFiles).getFiles());
result.addAll(getSource().minus(firstFiles).minus(lastFiles).getFiles());
result.addAll(lastFiles.getFiles());

return result;
}

private FileTree newEmptyFileTree() {
return getProject().files().getAsFileTree();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
package com.verificationgentleman.gradle.hdvl.systemverilog;

public interface FileOrder {
String getFirst();
FileOrder first(String first);
String getFirst();
FileOrder first(String first);

String getLast();
FileOrder last(String last);
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public SystemVerilogSourceDirectorySet order(Action<FileOrder> configureAction)

private static class Order implements FileOrder, Serializable {
private String first;
private String last;

@Override
public String getFirst() {
Expand All @@ -65,5 +66,16 @@ public FileOrder first(String first) {
this.first = first;
return this;
}

@Override
public String getLast() {
return last;
}

@Override
public FileOrder last(String last) {
this.last = last;
return this;
}
}
}

0 comments on commit 25694b3

Please sign in to comment.