From 51af263fc249c7e30228e81d36e93951f5f50d93 Mon Sep 17 00:00:00 2001 From: Tudor Timi Date: Mon, 30 Dec 2024 17:18:09 +0100 Subject: [PATCH 1/5] Update example project to show desired DSL for configuring file that should be compiled last --- examples/sv-with-custom-order/build.gradle | 1 + examples/sv-with-custom-order/src/main/sv/dummy0.sv | 1 + examples/sv-with-custom-order/src/main/sv/dummy2.sv | 3 +++ 3 files changed, 5 insertions(+) create mode 100644 examples/sv-with-custom-order/src/main/sv/dummy2.sv diff --git a/examples/sv-with-custom-order/build.gradle b/examples/sv-with-custom-order/build.gradle index d4cdf0b..e1a13db 100644 --- a/examples/sv-with-custom-order/build.gradle +++ b/examples/sv-with-custom-order/build.gradle @@ -7,6 +7,7 @@ sourceSets { sv { order { first 'dummy1.sv' + last 'dummy0.sv' } } } diff --git a/examples/sv-with-custom-order/src/main/sv/dummy0.sv b/examples/sv-with-custom-order/src/main/sv/dummy0.sv index c9f16bd..4a3f8a8 100644 --- a/examples/sv-with-custom-order/src/main/sv/dummy0.sv +++ b/examples/sv-with-custom-order/src/main/sv/dummy0.sv @@ -1,3 +1,4 @@ package dummy0; import dummy1::*; + import dummy2::*; endpackage diff --git a/examples/sv-with-custom-order/src/main/sv/dummy2.sv b/examples/sv-with-custom-order/src/main/sv/dummy2.sv new file mode 100644 index 0000000..0cd110f --- /dev/null +++ b/examples/sv-with-custom-order/src/main/sv/dummy2.sv @@ -0,0 +1,3 @@ +package dummy2; + import dummy1::*; +endpackage From 3e0536e411b430f7a06ce751b344b547cb155d1a Mon Sep 17 00:00:00 2001 From: Tudor Timi Date: Mon, 30 Dec 2024 17:23:52 +0100 Subject: [PATCH 2/5] Add capability to DSL to configure files that should be compiled last --- .../gradle/hdvl/systemverilog/FileOrder.java | 7 +++++-- .../DefaultSystemVerilogSourceDirectorySet.java | 12 ++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/verificationgentleman/gradle/hdvl/systemverilog/FileOrder.java b/src/main/java/com/verificationgentleman/gradle/hdvl/systemverilog/FileOrder.java index 927f4c5..4529d7a 100644 --- a/src/main/java/com/verificationgentleman/gradle/hdvl/systemverilog/FileOrder.java +++ b/src/main/java/com/verificationgentleman/gradle/hdvl/systemverilog/FileOrder.java @@ -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); } diff --git a/src/main/java/com/verificationgentleman/gradle/hdvl/systemverilog/internal/DefaultSystemVerilogSourceDirectorySet.java b/src/main/java/com/verificationgentleman/gradle/hdvl/systemverilog/internal/DefaultSystemVerilogSourceDirectorySet.java index 7d6cad3..898d59a 100644 --- a/src/main/java/com/verificationgentleman/gradle/hdvl/systemverilog/internal/DefaultSystemVerilogSourceDirectorySet.java +++ b/src/main/java/com/verificationgentleman/gradle/hdvl/systemverilog/internal/DefaultSystemVerilogSourceDirectorySet.java @@ -54,6 +54,7 @@ public SystemVerilogSourceDirectorySet order(Action configureAction) private static class Order implements FileOrder, Serializable { private String first; + private String last; @Override public String getFirst() { @@ -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; + } } } From 425dceb22df0703d8f2cbe9d300ebc905a3e86b3 Mon Sep 17 00:00:00 2001 From: Tudor Timi Date: Mon, 30 Dec 2024 17:31:19 +0100 Subject: [PATCH 3/5] Implement ordering of SystemVerilog sources based on files that should be compiled last --- ...SystemVerilogPluginCompileOrderSpec.groovy | 29 ++++++++++++++++++ .../gradle/hdvl/AbstractGenArgsFile.java | 30 ++++++++++++++----- 2 files changed, 52 insertions(+), 7 deletions(-) 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 c73d7ff..6260e93 100644 --- a/src/functTest/groovy/com/verificationgentleman/gradle/hdvl/systemverilog/SystemVerilogPluginCompileOrderSpec.groovy +++ b/src/functTest/groovy/com/verificationgentleman/gradle/hdvl/systemverilog/SystemVerilogPluginCompileOrderSpec.groovy @@ -101,4 +101,33 @@ 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 + } } diff --git a/src/main/java/com/verificationgentleman/gradle/hdvl/AbstractGenArgsFile.java b/src/main/java/com/verificationgentleman/gradle/hdvl/AbstractGenArgsFile.java index c715317..81698c9 100644 --- a/src/main/java/com/verificationgentleman/gradle/hdvl/AbstractGenArgsFile.java +++ b/src/main/java/com/verificationgentleman/gradle/hdvl/AbstractGenArgsFile.java @@ -128,16 +128,32 @@ private void writeExportedHeaders(FileWriter writer) throws IOException { protected abstract String getIncdirOpt(String incdirPath); private Iterable getOrderedSystemVerilogSourceFiles() { - if (!getSvOrder().isPresent() || getSvOrder().get().getFirst() == null) + if (!getSvOrder().isPresent() || (getSvOrder().get().getFirst() == null && getSvOrder().get().getLast() == null)) return getSource(); - String first = getSvOrder().get().getFirst(); - FileTree firstFiles = getSource().matching(patternFilterable -> patternFilterable.include(first)); + if (getSvOrder().get().getFirst() != null) { + String first = getSvOrder().get().getFirst(); + FileTree firstFiles = getSource().matching(patternFilterable -> patternFilterable.include(first)); - List result = new ArrayList<>(); - result.addAll(firstFiles.getFiles()); - result.addAll(getSource().minus(firstFiles).getFiles()); + List result = new ArrayList<>(); + result.addAll(firstFiles.getFiles()); + result.addAll(getSource().minus(firstFiles).getFiles()); - return result; + return result; + } + + if (getSvOrder().get().getLast() != null) { + String last = getSvOrder().get().getLast(); + FileTree lastFiles = getSource().matching(patternFilterable -> patternFilterable.include(last)); + + List result = new ArrayList<>(); + result.addAll(getSource().minus(lastFiles).getFiles()); + result.addAll(lastFiles.getFiles()); + + return result; + } + + // FIXME Implement support for both `first` and `last` + return null; } } From 959dbf4d25a573612dd7e962dfff753bd5f59c66 Mon Sep 17 00:00:00 2001 From: Tudor Timi Date: Mon, 30 Dec 2024 17:49:37 +0100 Subject: [PATCH 4/5] Fix ordering to work when both `first` and `last` are configured --- ...SystemVerilogPluginCompileOrderSpec.groovy | 37 +++++++++++++++++++ .../gradle/hdvl/AbstractGenArgsFile.java | 33 +++++++---------- 2 files changed, 50 insertions(+), 20 deletions(-) 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 6260e93..1c18ec7 100644 --- a/src/functTest/groovy/com/verificationgentleman/gradle/hdvl/systemverilog/SystemVerilogPluginCompileOrderSpec.groovy +++ b/src/functTest/groovy/com/verificationgentleman/gradle/hdvl/systemverilog/SystemVerilogPluginCompileOrderSpec.groovy @@ -130,4 +130,41 @@ class SystemVerilogPluginCompileOrderSpec extends Specification { 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 + } } diff --git a/src/main/java/com/verificationgentleman/gradle/hdvl/AbstractGenArgsFile.java b/src/main/java/com/verificationgentleman/gradle/hdvl/AbstractGenArgsFile.java index 81698c9..e916120 100644 --- a/src/main/java/com/verificationgentleman/gradle/hdvl/AbstractGenArgsFile.java +++ b/src/main/java/com/verificationgentleman/gradle/hdvl/AbstractGenArgsFile.java @@ -131,29 +131,22 @@ private Iterable getOrderedSystemVerilogSourceFiles() { if (!getSvOrder().isPresent() || (getSvOrder().get().getFirst() == null && getSvOrder().get().getLast() == null)) return getSource(); - if (getSvOrder().get().getFirst() != null) { - String first = getSvOrder().get().getFirst(); - FileTree firstFiles = getSource().matching(patternFilterable -> patternFilterable.include(first)); + FileTree firstFiles = getProject().files().getAsFileTree(); + FileTree lastFiles = getProject().files().getAsFileTree(); - List result = new ArrayList<>(); - result.addAll(firstFiles.getFiles()); - result.addAll(getSource().minus(firstFiles).getFiles()); + String first = getSvOrder().get().getFirst(); + if (first != null) + firstFiles = getSource().matching(patternFilterable -> patternFilterable.include(first)); - return result; - } - - if (getSvOrder().get().getLast() != null) { - String last = getSvOrder().get().getLast(); - FileTree lastFiles = getSource().matching(patternFilterable -> patternFilterable.include(last)); + String last = getSvOrder().get().getLast(); + if (last != null) + lastFiles = getSource().matching(patternFilterable -> patternFilterable.include(last)); - List result = new ArrayList<>(); - result.addAll(getSource().minus(lastFiles).getFiles()); - result.addAll(lastFiles.getFiles()); - - return result; - } + List result = new ArrayList<>(); + result.addAll(firstFiles.getFiles()); + result.addAll(getSource().minus(firstFiles).minus(lastFiles).getFiles()); + result.addAll(lastFiles.getFiles()); - // FIXME Implement support for both `first` and `last` - return null; + return result; } } From efe2981944dd631f0ae2dbe9f0010367e5576236 Mon Sep 17 00:00:00 2001 From: Tudor Timi Date: Mon, 30 Dec 2024 17:52:37 +0100 Subject: [PATCH 5/5] Clarify expression by extracting method --- .../gradle/hdvl/AbstractGenArgsFile.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/verificationgentleman/gradle/hdvl/AbstractGenArgsFile.java b/src/main/java/com/verificationgentleman/gradle/hdvl/AbstractGenArgsFile.java index e916120..626559f 100644 --- a/src/main/java/com/verificationgentleman/gradle/hdvl/AbstractGenArgsFile.java +++ b/src/main/java/com/verificationgentleman/gradle/hdvl/AbstractGenArgsFile.java @@ -131,8 +131,8 @@ private Iterable getOrderedSystemVerilogSourceFiles() { if (!getSvOrder().isPresent() || (getSvOrder().get().getFirst() == null && getSvOrder().get().getLast() == null)) return getSource(); - FileTree firstFiles = getProject().files().getAsFileTree(); - FileTree lastFiles = getProject().files().getAsFileTree(); + FileTree firstFiles = newEmptyFileTree(); + FileTree lastFiles = newEmptyFileTree(); String first = getSvOrder().get().getFirst(); if (first != null) @@ -149,4 +149,8 @@ private Iterable getOrderedSystemVerilogSourceFiles() { return result; } + + private FileTree newEmptyFileTree() { + return getProject().files().getAsFileTree(); + } }