From 3baa3f58c294620af4fd2b7f252baf00cc8ba262 Mon Sep 17 00:00:00 2001 From: Tudor Timi Date: Thu, 12 Jan 2023 01:12:22 +0200 Subject: [PATCH 1/9] Add example of project using SVUnit and external test dependency The plugin should be able to get artifacts from both SVUnit (i.e. the root directory) and from test_utils (i.e. its args files). --- .../build.gradle | 9 +++++ .../gradlew | 3 ++ .../settings.gradle | 11 ++++++ .../src/main/sv/some_class.svh | 7 ++++ .../src/main/sv/some_package.sv | 5 +++ .../src/test/sv/some_unit_test.sv | 36 +++++++++++++++++++ .../test_utils/build.gradle | 5 +++ .../test_utils/settings.gradle | 1 + .../test_utils/src/main/sv/test_utils.sv | 7 ++++ 9 files changed, 84 insertions(+) create mode 100644 examples/svunit-with-test-compile-dependency/build.gradle create mode 100755 examples/svunit-with-test-compile-dependency/gradlew create mode 100644 examples/svunit-with-test-compile-dependency/settings.gradle create mode 100644 examples/svunit-with-test-compile-dependency/src/main/sv/some_class.svh create mode 100644 examples/svunit-with-test-compile-dependency/src/main/sv/some_package.sv create mode 100644 examples/svunit-with-test-compile-dependency/src/test/sv/some_unit_test.sv create mode 100644 examples/svunit-with-test-compile-dependency/test_utils/build.gradle create mode 100644 examples/svunit-with-test-compile-dependency/test_utils/settings.gradle create mode 100644 examples/svunit-with-test-compile-dependency/test_utils/src/main/sv/test_utils.sv diff --git a/examples/svunit-with-test-compile-dependency/build.gradle b/examples/svunit-with-test-compile-dependency/build.gradle new file mode 100644 index 0000000..f968946 --- /dev/null +++ b/examples/svunit-with-test-compile-dependency/build.gradle @@ -0,0 +1,9 @@ +plugins { + id 'com.verificationgentleman.gradle.hdvl.systemverilog' + id 'com.verificationgentleman.gradle.hdvl.svunit' +} + +dependencies { + testCompile "org.svunit:svunit:v3.34.2" + testCompile "com.verificationgentleman.gradle.hdvl.examples.svunit:test_utils" +} diff --git a/examples/svunit-with-test-compile-dependency/gradlew b/examples/svunit-with-test-compile-dependency/gradlew new file mode 100755 index 0000000..9130eac --- /dev/null +++ b/examples/svunit-with-test-compile-dependency/gradlew @@ -0,0 +1,3 @@ +#!/usr/bin/env sh + +exec "$(dirname "$0")/../../gradlew" "$@" diff --git a/examples/svunit-with-test-compile-dependency/settings.gradle b/examples/svunit-with-test-compile-dependency/settings.gradle new file mode 100644 index 0000000..bb544f8 --- /dev/null +++ b/examples/svunit-with-test-compile-dependency/settings.gradle @@ -0,0 +1,11 @@ +includeBuild("../..") +includeBuild("test_utils") + +sourceControl { + gitRepository("https://github.com/svunit/svunit.git") { + producesModule("org.svunit:svunit") + plugins { + id "com.verificationgentleman.gradle.hdvl.svunit-build-injector" + } + } +} diff --git a/examples/svunit-with-test-compile-dependency/src/main/sv/some_class.svh b/examples/svunit-with-test-compile-dependency/src/main/sv/some_class.svh new file mode 100644 index 0000000..7088e20 --- /dev/null +++ b/examples/svunit-with-test-compile-dependency/src/main/sv/some_class.svh @@ -0,0 +1,7 @@ +class some_class; + + function bit is_working(); + return 1; + endfunction + +endclass diff --git a/examples/svunit-with-test-compile-dependency/src/main/sv/some_package.sv b/examples/svunit-with-test-compile-dependency/src/main/sv/some_package.sv new file mode 100644 index 0000000..c6ad11d --- /dev/null +++ b/examples/svunit-with-test-compile-dependency/src/main/sv/some_package.sv @@ -0,0 +1,5 @@ +package some_package; + + `include "some_class.svh" + +endpackage diff --git a/examples/svunit-with-test-compile-dependency/src/test/sv/some_unit_test.sv b/examples/svunit-with-test-compile-dependency/src/test/sv/some_unit_test.sv new file mode 100644 index 0000000..563b527 --- /dev/null +++ b/examples/svunit-with-test-compile-dependency/src/test/sv/some_unit_test.sv @@ -0,0 +1,36 @@ +module some_class_unit_test; + + import svunit_pkg::svunit_testcase; + `include "svunit_defines.svh" + + string name = "some_class_unit_test"; + svunit_testcase svunit_ut; + + + import some_package::*; + import test_utils::*; + + + function void build(); + svunit_ut = new(name); + endfunction + + task setup(); + svunit_ut.setup(); + endtask + + task teardown(); + svunit_ut.teardown(); + endtask + + + `SVUNIT_TESTS_BEGIN + + `SVTEST(is_working__returns_1) + some_class obj = new(); + `FAIL_UNLESS(confirm(obj.is_working())) + `SVTEST_END + + `SVUNIT_TESTS_END + +endmodule diff --git a/examples/svunit-with-test-compile-dependency/test_utils/build.gradle b/examples/svunit-with-test-compile-dependency/test_utils/build.gradle new file mode 100644 index 0000000..3ee5101 --- /dev/null +++ b/examples/svunit-with-test-compile-dependency/test_utils/build.gradle @@ -0,0 +1,5 @@ +plugins { + id 'com.verificationgentleman.gradle.hdvl.systemverilog' +} + +group = "com.verificationgentleman.gradle.hdvl.examples.svunit" diff --git a/examples/svunit-with-test-compile-dependency/test_utils/settings.gradle b/examples/svunit-with-test-compile-dependency/test_utils/settings.gradle new file mode 100644 index 0000000..5885289 --- /dev/null +++ b/examples/svunit-with-test-compile-dependency/test_utils/settings.gradle @@ -0,0 +1 @@ +// Intentionally empty diff --git a/examples/svunit-with-test-compile-dependency/test_utils/src/main/sv/test_utils.sv b/examples/svunit-with-test-compile-dependency/test_utils/src/main/sv/test_utils.sv new file mode 100644 index 0000000..1ab8303 --- /dev/null +++ b/examples/svunit-with-test-compile-dependency/test_utils/src/main/sv/test_utils.sv @@ -0,0 +1,7 @@ +package test_utils; + + function bit confirm(bit val); + return val; + endfunction + +endpackage From 4612c0c1eb3a77731bfbdd138c4fd8fca298bd7a Mon Sep 17 00:00:00 2001 From: Tudor Timi Date: Thu, 12 Jan 2023 01:14:53 +0200 Subject: [PATCH 2/9] Add separate configuration for SVUnit root dir This configuration will inherit only the dependency on SVUnit from the `testCompile` configuration. --- .../gradle/hdvl/svunit/SVUnitBuildPlugin.java | 1 + .../gradle/hdvl/svunit/SVUnitPlugin.java | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/verificationgentleman/gradle/hdvl/svunit/SVUnitBuildPlugin.java b/src/main/java/com/verificationgentleman/gradle/hdvl/svunit/SVUnitBuildPlugin.java index ee03350..8a0e452 100644 --- a/src/main/java/com/verificationgentleman/gradle/hdvl/svunit/SVUnitBuildPlugin.java +++ b/src/main/java/com/verificationgentleman/gradle/hdvl/svunit/SVUnitBuildPlugin.java @@ -18,6 +18,7 @@ import org.gradle.api.Plugin; import org.gradle.api.Project; +import org.gradle.api.artifacts.Configuration; public class SVUnitBuildPlugin implements Plugin { public void apply(Project project) { diff --git a/src/main/java/com/verificationgentleman/gradle/hdvl/svunit/SVUnitPlugin.java b/src/main/java/com/verificationgentleman/gradle/hdvl/svunit/SVUnitPlugin.java index 909e094..c32cf3a 100644 --- a/src/main/java/com/verificationgentleman/gradle/hdvl/svunit/SVUnitPlugin.java +++ b/src/main/java/com/verificationgentleman/gradle/hdvl/svunit/SVUnitPlugin.java @@ -45,6 +45,7 @@ public void apply(Project project) { final SourceSet testSourceSet = sourceSets.create("test"); configureConfiguration(project); + configureSVUnitRootConfiguration(project); configureToolChain(project); sourceSets.named("test", new Action() { @@ -66,6 +67,15 @@ public void execute(SourceSet sourceSet) { private void configureConfiguration(Project project) { Configuration testCompileConfiguration = project.getConfigurations().create("testCompile"); + testCompileConfiguration.setCanBeConsumed(false); + testCompileConfiguration.setCanBeResolved(false); + } + + private void configureSVUnitRootConfiguration(Project project) { + Configuration svUnitRoot = project.getConfigurations().create("svUnitRoot"); + svUnitRoot.extendsFrom(project.getConfigurations().getByName("testCompile")); + svUnitRoot.setCanBeConsumed(false); + svUnitRoot.setCanBeResolved(true); } private void configureToolChain(Project project) { @@ -81,7 +91,7 @@ private void configureTestTask(Project project, SystemVerilogSourceSet testSourc = (GenFullArgsFile) project.getTasks().getByName(Names.getGenFullArgsFileTaskName(toolName)); AbstractGenArgsFile genTestArgsFile = (AbstractGenArgsFile) project.getTasks().getByName(Names.getGenArgsFileTaskName("test", toolName)); - Configuration testCompileConfiguration = project.getConfigurations().getByName("testCompile"); + Configuration svUnitRoot = project.getConfigurations().getByName("svUnitRoot"); project.getTasks().register(Names.getTestTaskName(toolName), TestTask.class, new Action() { @Override public void execute(TestTask testTask) { @@ -90,7 +100,7 @@ public void execute(TestTask testTask) { testTask.getMainArgsFile().set(genFullArgsFile.getDestination()); testTask.getTestArgsFile().set(genTestArgsFile.getDestination()); testTask.setTestsRoot(testSourceSet.getSv().getSourceDirectories().getSingleFile()); - testTask.setSvunitRoot(testCompileConfiguration); + testTask.setSvunitRoot(svUnitRoot); testTask.getWorkingDir().set(new File(project.getBuildDir(), "svunit")); testTask.getExtraArgs().set(toolChains.getRunSVUnit().getArgs()); } From 54991fa4ee9e9ed6ec676fdd4759c038152c2596 Mon Sep 17 00:00:00 2001 From: Tudor Timi Date: Sun, 15 Jan 2023 19:07:21 +0200 Subject: [PATCH 3/9] Split SVUnit out of `testCompile` configuration We want to use the SVUnit dependency to extract its root directory. We want to use any other `testCompile` dependencies to produce args files to pass to SVUnit. --- .../gradle/hdvl/svunit/SVUnitPlugin.java | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/verificationgentleman/gradle/hdvl/svunit/SVUnitPlugin.java b/src/main/java/com/verificationgentleman/gradle/hdvl/svunit/SVUnitPlugin.java index c32cf3a..2e676ab 100644 --- a/src/main/java/com/verificationgentleman/gradle/hdvl/svunit/SVUnitPlugin.java +++ b/src/main/java/com/verificationgentleman/gradle/hdvl/svunit/SVUnitPlugin.java @@ -18,6 +18,7 @@ import com.verificationgentleman.gradle.hdvl.AbstractGenArgsFile; import com.verificationgentleman.gradle.hdvl.GenFullArgsFile; +import com.verificationgentleman.gradle.hdvl.HDVLBasePlugin; import com.verificationgentleman.gradle.hdvl.SourceSet; import com.verificationgentleman.gradle.hdvl.internal.Names; import com.verificationgentleman.gradle.hdvl.svunit.internal.DefaultToolChains; @@ -30,8 +31,10 @@ import org.gradle.api.artifacts.Configuration; import org.gradle.api.internal.HasConvention; import org.gradle.api.reflect.TypeOf; +import org.gradle.util.GUtil; import java.io.File; +import java.util.Collections; public class SVUnitPlugin implements Plugin { @@ -46,6 +49,12 @@ public void apply(Project project) { configureConfiguration(project); configureSVUnitRootConfiguration(project); + + String[] toolNames = {"Xrun", "Qrun"}; + for (String toolName: toolNames) { + configureArgsFilesConfiguration(project, toolName); + } + configureToolChain(project); sourceSets.named("test", new Action() { @@ -73,9 +82,22 @@ private void configureConfiguration(Project project) { private void configureSVUnitRootConfiguration(Project project) { Configuration svUnitRoot = project.getConfigurations().create("svUnitRoot"); - svUnitRoot.extendsFrom(project.getConfigurations().getByName("testCompile")); svUnitRoot.setCanBeConsumed(false); svUnitRoot.setCanBeResolved(true); + project.getConfigurations().getByName("testCompile").getDependencies().whenObjectAdded(dependency -> { + if (dependency.getGroup().equals("org.svunit")) { + svUnitRoot.getDependencies().add(dependency); + } + }); + } + + private void configureArgsFilesConfiguration(Project project, String toolName) { + Configuration argsFiles = project.getConfigurations().create(GUtil.toLowerCamelCase(toolName + "TestArgsFiles")); + argsFiles.extendsFrom(project.getConfigurations().getByName("testCompile")); + argsFiles.exclude(Collections.singletonMap("group", "org.svunit")); + argsFiles.setCanBeConsumed(true); + argsFiles.setCanBeResolved(true); + argsFiles.getAttributes().attribute(HDVLBasePlugin.TOOL_ATTRIBUTE, toolName); } private void configureToolChain(Project project) { From df4a0902540a604a10887ccf2b315c529f15e352 Mon Sep 17 00:00:00 2001 From: Tudor Timi Date: Sun, 15 Jan 2023 19:16:31 +0200 Subject: [PATCH 4/9] Reflect removals from `testCompile` configuration in `svunitRoot` --- .../gradle/hdvl/svunit/SVUnitPlugin.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/com/verificationgentleman/gradle/hdvl/svunit/SVUnitPlugin.java b/src/main/java/com/verificationgentleman/gradle/hdvl/svunit/SVUnitPlugin.java index 2e676ab..d5f8b6a 100644 --- a/src/main/java/com/verificationgentleman/gradle/hdvl/svunit/SVUnitPlugin.java +++ b/src/main/java/com/verificationgentleman/gradle/hdvl/svunit/SVUnitPlugin.java @@ -89,6 +89,11 @@ private void configureSVUnitRootConfiguration(Project project) { svUnitRoot.getDependencies().add(dependency); } }); + project.getConfigurations().getByName("testCompile").getDependencies().whenObjectRemoved(dependency -> { + if (dependency.getGroup().equals("org.svunit")) { + svUnitRoot.getDependencies().remove(dependency); + } + }); } private void configureArgsFilesConfiguration(Project project, String toolName) { From d1c264d4f290431274cde67d809dffda558375ea Mon Sep 17 00:00:00 2001 From: Tudor Timi Date: Sun, 15 Jan 2023 19:19:52 +0200 Subject: [PATCH 5/9] Extract method that determines whether a dependency is SVUnit --- .../gradle/hdvl/svunit/SVUnitPlugin.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/verificationgentleman/gradle/hdvl/svunit/SVUnitPlugin.java b/src/main/java/com/verificationgentleman/gradle/hdvl/svunit/SVUnitPlugin.java index d5f8b6a..a82ccc1 100644 --- a/src/main/java/com/verificationgentleman/gradle/hdvl/svunit/SVUnitPlugin.java +++ b/src/main/java/com/verificationgentleman/gradle/hdvl/svunit/SVUnitPlugin.java @@ -29,6 +29,7 @@ import org.gradle.api.Plugin; import org.gradle.api.Project; import org.gradle.api.artifacts.Configuration; +import org.gradle.api.artifacts.Dependency; import org.gradle.api.internal.HasConvention; import org.gradle.api.reflect.TypeOf; import org.gradle.util.GUtil; @@ -85,17 +86,21 @@ private void configureSVUnitRootConfiguration(Project project) { svUnitRoot.setCanBeConsumed(false); svUnitRoot.setCanBeResolved(true); project.getConfigurations().getByName("testCompile").getDependencies().whenObjectAdded(dependency -> { - if (dependency.getGroup().equals("org.svunit")) { + if (isSVUnit(dependency)) { svUnitRoot.getDependencies().add(dependency); } }); project.getConfigurations().getByName("testCompile").getDependencies().whenObjectRemoved(dependency -> { - if (dependency.getGroup().equals("org.svunit")) { + if (isSVUnit(dependency)) { svUnitRoot.getDependencies().remove(dependency); } }); } + private boolean isSVUnit(Dependency dependency) { + return dependency.getGroup().equals("org.svunit"); + } + private void configureArgsFilesConfiguration(Project project, String toolName) { Configuration argsFiles = project.getConfigurations().create(GUtil.toLowerCamelCase(toolName + "TestArgsFiles")); argsFiles.extendsFrom(project.getConfigurations().getByName("testCompile")); From 89683843c7bb39986bb19c4160c2f91f477c78cc Mon Sep 17 00:00:00 2001 From: Tudor Timi Date: Sun, 15 Jan 2023 19:27:44 +0200 Subject: [PATCH 6/9] Also check module of dependencies to find SVUnit If we were to depend on SVMock, it would probably also have the `org.svunit` group. We wouldn't want to accidentally filter it out. --- .../gradle/hdvl/svunit/SVUnitPlugin.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/verificationgentleman/gradle/hdvl/svunit/SVUnitPlugin.java b/src/main/java/com/verificationgentleman/gradle/hdvl/svunit/SVUnitPlugin.java index a82ccc1..45f174a 100644 --- a/src/main/java/com/verificationgentleman/gradle/hdvl/svunit/SVUnitPlugin.java +++ b/src/main/java/com/verificationgentleman/gradle/hdvl/svunit/SVUnitPlugin.java @@ -36,6 +36,8 @@ import java.io.File; import java.util.Collections; +import java.util.HashMap; +import java.util.Map; public class SVUnitPlugin implements Plugin { @@ -98,18 +100,25 @@ private void configureSVUnitRootConfiguration(Project project) { } private boolean isSVUnit(Dependency dependency) { - return dependency.getGroup().equals("org.svunit"); + return dependency.getGroup().equals("org.svunit") && dependency.getName().equals("svunit"); } private void configureArgsFilesConfiguration(Project project, String toolName) { Configuration argsFiles = project.getConfigurations().create(GUtil.toLowerCamelCase(toolName + "TestArgsFiles")); argsFiles.extendsFrom(project.getConfigurations().getByName("testCompile")); - argsFiles.exclude(Collections.singletonMap("group", "org.svunit")); + argsFiles.exclude(getExcludeForSVUnit()); argsFiles.setCanBeConsumed(true); argsFiles.setCanBeResolved(true); argsFiles.getAttributes().attribute(HDVLBasePlugin.TOOL_ATTRIBUTE, toolName); } + private Map getExcludeForSVUnit() { + HashMap exclude = new HashMap<>(); + exclude.put("group", "org.svunit"); + exclude.put("module", "svunit"); + return exclude; + } + private void configureToolChain(Project project) { toolChains = project.getExtensions().create(ToolChains.class, "toolChains", DefaultToolChains.class); } From 6563be28f21f5f61c2d4d4f8a901621f3a843405 Mon Sep 17 00:00:00 2001 From: Tudor Timi Date: Wed, 18 Jan 2023 00:09:32 +0200 Subject: [PATCH 7/9] Add `genFullXArgsFile` task for "test" source set Its output will be wired to the `test` task. --- .../gradle/hdvl/svunit/SVUnitPlugin.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/main/java/com/verificationgentleman/gradle/hdvl/svunit/SVUnitPlugin.java b/src/main/java/com/verificationgentleman/gradle/hdvl/svunit/SVUnitPlugin.java index 45f174a..e85a9c0 100644 --- a/src/main/java/com/verificationgentleman/gradle/hdvl/svunit/SVUnitPlugin.java +++ b/src/main/java/com/verificationgentleman/gradle/hdvl/svunit/SVUnitPlugin.java @@ -56,6 +56,7 @@ public void apply(Project project) { String[] toolNames = {"Xrun", "Qrun"}; for (String toolName: toolNames) { configureArgsFilesConfiguration(project, toolName); + configureGenFullArgsFile(project, toolName); } configureToolChain(project); @@ -119,6 +120,20 @@ private Map getExcludeForSVUnit() { return exclude; } + private void configureGenFullArgsFile(Project project, String toolName) { + AbstractGenArgsFile genArgsFile = (AbstractGenArgsFile) project.getTasks() + .getByName(Names.getGenArgsFileTaskName("test", toolName)); + project.getTasks().register("genFullTest" + toolName + "ArgsFile", GenFullArgsFile.class, new Action() { + @Override + public void execute(GenFullArgsFile genFullArgsFile) { + genFullArgsFile.setDescription("Generates an argument file for the test source code and its dependencies."); + genFullArgsFile.getSource().set(genArgsFile.getDestination()); + genFullArgsFile.getDestination().set(new File(project.getBuildDir(), "full_test_" + toolName.toLowerCase() + "_args.f")); + genFullArgsFile.setArgsFiles(project.getConfigurations().getByName(GUtil.toLowerCamelCase(toolName + "TestArgsFiles"))); + } + }); + } + private void configureToolChain(Project project) { toolChains = project.getExtensions().create(ToolChains.class, "toolChains", DefaultToolChains.class); } From 9e5b9b54bf02d69b14c80b25965cbb87fcddc46c Mon Sep 17 00:00:00 2001 From: Tudor Timi Date: Wed, 18 Jan 2023 00:17:53 +0200 Subject: [PATCH 8/9] Use full args file for test source set when running SVUnit --- .../gradle/hdvl/svunit/SVUnitPluginSpec.groovy | 4 ++-- .../gradle/hdvl/svunit/SVUnitPlugin.java | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/functTest/groovy/com/verificationgentleman/gradle/hdvl/svunit/SVUnitPluginSpec.groovy b/src/functTest/groovy/com/verificationgentleman/gradle/hdvl/svunit/SVUnitPluginSpec.groovy index 9dc2593..c2c95e3 100644 --- a/src/functTest/groovy/com/verificationgentleman/gradle/hdvl/svunit/SVUnitPluginSpec.groovy +++ b/src/functTest/groovy/com/verificationgentleman/gradle/hdvl/svunit/SVUnitPluginSpec.groovy @@ -348,7 +348,7 @@ class SVUnitPluginSpec extends Specification { !lines.any { it.contains('some_other_unit_test.sv') } } - def "'testWithXrun' task passes args file for 'test' source set to 'runSVUnit'"() { + def "'testWithXrun' task passes full args file for 'test' source set to 'runSVUnit'"() { File mainSv = testProjectDir.newFolder('src', 'main', 'sv') new File(mainSv, 'dummy_main.sv').createNewFile() @@ -365,7 +365,7 @@ class SVUnitPluginSpec extends Specification { then: result.task(":testWithXrun").outcome == SUCCESS def dummyLog = new File(testProjectDir.root, 'build/svunit/runSVUnit.log') - dummyLog.text.contains "-f ${testProjectDir.root}/build/test_xrun_args.f" + dummyLog.text.contains "-f ${testProjectDir.root}/build/full_test_xrun_args.f" } def newGradleRunnerWithFakeRunSVunit() { diff --git a/src/main/java/com/verificationgentleman/gradle/hdvl/svunit/SVUnitPlugin.java b/src/main/java/com/verificationgentleman/gradle/hdvl/svunit/SVUnitPlugin.java index e85a9c0..689c6e5 100644 --- a/src/main/java/com/verificationgentleman/gradle/hdvl/svunit/SVUnitPlugin.java +++ b/src/main/java/com/verificationgentleman/gradle/hdvl/svunit/SVUnitPlugin.java @@ -145,8 +145,8 @@ private void ignoreUnitTests(SystemVerilogSourceSet svSourceSet) { private void configureTestTask(Project project, SystemVerilogSourceSet testSourceSet, String toolName) { GenFullArgsFile genFullArgsFile = (GenFullArgsFile) project.getTasks().getByName(Names.getGenFullArgsFileTaskName(toolName)); - AbstractGenArgsFile genTestArgsFile - = (AbstractGenArgsFile) project.getTasks().getByName(Names.getGenArgsFileTaskName("test", toolName)); + GenFullArgsFile genFullTestArgsFile + = (GenFullArgsFile) project.getTasks().getByName("genFullTest" + toolName + "ArgsFile"); Configuration svUnitRoot = project.getConfigurations().getByName("svUnitRoot"); project.getTasks().register(Names.getTestTaskName(toolName), TestTask.class, new Action() { @Override @@ -154,7 +154,7 @@ public void execute(TestTask testTask) { testTask.setDescription("Runs the unit tests using SVUnit."); testTask.getToolName().set(toolName.toLowerCase()); testTask.getMainArgsFile().set(genFullArgsFile.getDestination()); - testTask.getTestArgsFile().set(genTestArgsFile.getDestination()); + testTask.getTestArgsFile().set(genFullTestArgsFile.getDestination()); testTask.setTestsRoot(testSourceSet.getSv().getSourceDirectories().getSingleFile()); testTask.setSvunitRoot(svUnitRoot); testTask.getWorkingDir().set(new File(project.getBuildDir(), "svunit")); From 6b77290ede24fe0075810c918992b4bdfef445a7 Mon Sep 17 00:00:00 2001 From: Tudor Timi Date: Wed, 18 Jan 2023 00:48:05 +0200 Subject: [PATCH 9/9] Extend naming scheme to handle any source set name --- .../gradle/hdvl/HDVLBasePlugin.java | 10 +++++----- .../gradle/hdvl/internal/Names.java | 18 ++++++++++++------ .../gradle/hdvl/svunit/SVUnitPlugin.java | 12 ++++++------ 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/verificationgentleman/gradle/hdvl/HDVLBasePlugin.java b/src/main/java/com/verificationgentleman/gradle/hdvl/HDVLBasePlugin.java index 081560b..9e84b88 100644 --- a/src/main/java/com/verificationgentleman/gradle/hdvl/HDVLBasePlugin.java +++ b/src/main/java/com/verificationgentleman/gradle/hdvl/HDVLBasePlugin.java @@ -84,13 +84,13 @@ private Class getGenArgsFileClass(String toolName private void configureGenFullArgsFile(Project project, String toolName) { AbstractGenArgsFile genArgsFile = (AbstractGenArgsFile) project.getTasks() .getByName(Names.getMainGenArgsFileTaskName(toolName)); - project.getTasks().register(Names.getGenFullArgsFileTaskName(toolName), GenFullArgsFile.class, new Action() { + project.getTasks().register(Names.getGenFullArgsFileTaskName("main", toolName), GenFullArgsFile.class, new Action() { @Override public void execute(GenFullArgsFile genFullArgsFile) { genFullArgsFile.setDescription("Generates an argument file for the main source code and its dependencies."); genFullArgsFile.getSource().set(genArgsFile.getDestination()); - genFullArgsFile.getDestination().set(new File(project.getBuildDir(), Names.getFullArgsFileName(toolName))); - genFullArgsFile.setArgsFiles(project.getConfigurations().getByName(Names.getArgsFilesConfigurationName(toolName))); + genFullArgsFile.getDestination().set(new File(project.getBuildDir(), Names.getFullArgsFileName("main", toolName))); + genFullArgsFile.setArgsFiles(project.getConfigurations().getByName(Names.getArgsFilesConfigurationName("main", toolName))); } }); } @@ -104,7 +104,7 @@ private void configureCompileConfiguration(Project project) { } private void configureArgsFilesConfiguration(Project project, String toolName) { - Configuration argsFiles = project.getConfigurations().create(Names.getArgsFilesConfigurationName(toolName)); + Configuration argsFiles = project.getConfigurations().create(Names.getArgsFilesConfigurationName("main", toolName)); argsFiles.extendsFrom(project.getConfigurations().getByName("compile")); argsFiles.setCanBeConsumed(true); argsFiles.setCanBeResolved(true); @@ -120,7 +120,7 @@ public void execute(ConfigurablePublishArtifact configurablePublishArtifact) { configurablePublishArtifact.builtBy(genArgsFile); } }; - project.getArtifacts().add(Names.getArgsFilesConfigurationName(toolName), genArgsFile.getDestination(), configureAction); + project.getArtifacts().add(Names.getArgsFilesConfigurationName("main", toolName), genArgsFile.getDestination(), configureAction); } } diff --git a/src/main/java/com/verificationgentleman/gradle/hdvl/internal/Names.java b/src/main/java/com/verificationgentleman/gradle/hdvl/internal/Names.java index c6491b7..e603390 100644 --- a/src/main/java/com/verificationgentleman/gradle/hdvl/internal/Names.java +++ b/src/main/java/com/verificationgentleman/gradle/hdvl/internal/Names.java @@ -12,17 +12,23 @@ public static String getGenArgsFileTaskName(String sourceSetName, String toolNam return GUtil.toLowerCamelCase("gen" + " " + sourceSetName + "" + toolName + "ArgsFile"); } - public static String getGenFullArgsFileTaskName(String toolName) { - return "genFull" + toolName + "ArgsFile"; + public static String getGenFullArgsFileTaskName(String sourceSetName, String toolName) { + if (sourceSetName.equals("main")) + return "genFull" + toolName + "ArgsFile"; + return GUtil.toLowerCamelCase("genFull" + " " + sourceSetName + "" + toolName + "ArgsFile"); } - public static String getFullArgsFileName(String toolName) { + public static String getFullArgsFileName(String sourceSetName, String toolName) { String toolNameLower = toolName.toLowerCase(); - return "full" + "_" + toolNameLower + "_" + "args.f"; + if (sourceSetName.equals("main")) + return "full" + "_" + toolNameLower + "_" + "args.f"; + return "full" + "_" + sourceSetName + "_"+ toolNameLower + "_" + "args.f"; } - public static String getArgsFilesConfigurationName(String toolName) { - return GUtil.toLowerCamelCase(toolName + "ArgsFiles"); + public static String getArgsFilesConfigurationName(String sourceSetName, String toolName) { + if (sourceSetName.equals("main")) + return GUtil.toLowerCamelCase(toolName + "ArgsFiles"); + return GUtil.toLowerCamelCase(sourceSetName + " " + toolName + "ArgsFiles"); } public static String getTestTaskName(String toolName) { diff --git a/src/main/java/com/verificationgentleman/gradle/hdvl/svunit/SVUnitPlugin.java b/src/main/java/com/verificationgentleman/gradle/hdvl/svunit/SVUnitPlugin.java index 689c6e5..5ce34d6 100644 --- a/src/main/java/com/verificationgentleman/gradle/hdvl/svunit/SVUnitPlugin.java +++ b/src/main/java/com/verificationgentleman/gradle/hdvl/svunit/SVUnitPlugin.java @@ -105,7 +105,7 @@ private boolean isSVUnit(Dependency dependency) { } private void configureArgsFilesConfiguration(Project project, String toolName) { - Configuration argsFiles = project.getConfigurations().create(GUtil.toLowerCamelCase(toolName + "TestArgsFiles")); + Configuration argsFiles = project.getConfigurations().create(Names.getArgsFilesConfigurationName("test", toolName)); argsFiles.extendsFrom(project.getConfigurations().getByName("testCompile")); argsFiles.exclude(getExcludeForSVUnit()); argsFiles.setCanBeConsumed(true); @@ -123,13 +123,13 @@ private Map getExcludeForSVUnit() { private void configureGenFullArgsFile(Project project, String toolName) { AbstractGenArgsFile genArgsFile = (AbstractGenArgsFile) project.getTasks() .getByName(Names.getGenArgsFileTaskName("test", toolName)); - project.getTasks().register("genFullTest" + toolName + "ArgsFile", GenFullArgsFile.class, new Action() { + project.getTasks().register(Names.getGenFullArgsFileTaskName("test", toolName), GenFullArgsFile.class, new Action() { @Override public void execute(GenFullArgsFile genFullArgsFile) { genFullArgsFile.setDescription("Generates an argument file for the test source code and its dependencies."); genFullArgsFile.getSource().set(genArgsFile.getDestination()); - genFullArgsFile.getDestination().set(new File(project.getBuildDir(), "full_test_" + toolName.toLowerCase() + "_args.f")); - genFullArgsFile.setArgsFiles(project.getConfigurations().getByName(GUtil.toLowerCamelCase(toolName + "TestArgsFiles"))); + genFullArgsFile.getDestination().set(new File(project.getBuildDir(), Names.getFullArgsFileName("test", toolName))); + genFullArgsFile.setArgsFiles(project.getConfigurations().getByName(Names.getArgsFilesConfigurationName("test", toolName))); } }); } @@ -144,9 +144,9 @@ private void ignoreUnitTests(SystemVerilogSourceSet svSourceSet) { private void configureTestTask(Project project, SystemVerilogSourceSet testSourceSet, String toolName) { GenFullArgsFile genFullArgsFile - = (GenFullArgsFile) project.getTasks().getByName(Names.getGenFullArgsFileTaskName(toolName)); + = (GenFullArgsFile) project.getTasks().getByName(Names.getGenFullArgsFileTaskName("main", toolName)); GenFullArgsFile genFullTestArgsFile - = (GenFullArgsFile) project.getTasks().getByName("genFullTest" + toolName + "ArgsFile"); + = (GenFullArgsFile) project.getTasks().getByName(Names.getGenFullArgsFileTaskName("test", toolName)); Configuration svUnitRoot = project.getConfigurations().getByName("svUnitRoot"); project.getTasks().register(Names.getTestTaskName(toolName), TestTask.class, new Action() { @Override