From 4d6bbb73af5e3cec7f25d1205e8301fc9949c9be Mon Sep 17 00:00:00 2001 From: Tudor Timi Date: Sun, 30 Jul 2023 19:03:22 +0300 Subject: [PATCH 1/3] Create DVT default build file without `dvt_cli.sh` script This allows us to create the build file without having to install a distribution of DVT. Not all users will have the DVT distribution, as they might be using the DVT extension directly in VS Code. --- .../gradle/hdvl/dvt/DVTPluginSpec.groovy | 161 ++---------------- .../gradle/hdvl/dvt/DVTTask.java | 37 ++-- 2 files changed, 24 insertions(+), 174 deletions(-) diff --git a/src/functTest/groovy/com/verificationgentleman/gradle/hdvl/dvt/DVTPluginSpec.groovy b/src/functTest/groovy/com/verificationgentleman/gradle/hdvl/dvt/DVTPluginSpec.groovy index 8c8a264..4e3edf7 100644 --- a/src/functTest/groovy/com/verificationgentleman/gradle/hdvl/dvt/DVTPluginSpec.groovy +++ b/src/functTest/groovy/com/verificationgentleman/gradle/hdvl/dvt/DVTPluginSpec.groovy @@ -60,7 +60,7 @@ class DVTPluginSpec extends Specification { result.output.contains('dvt') } - def "'dvt' task calls 'dvt_cli.sh createProject'"() { + def "'dvt' task creates 'default.build' in xrun compatibility mode"() { buildFile << """ plugins { id 'com.verificationgentleman.gradle.hdvl.systemverilog' @@ -68,137 +68,7 @@ class DVTPluginSpec extends Specification { """ when: - def result = newGradleRunnerWithFakeDvtCli() - .withProjectDir(testProjectDir.root) - .withPluginClasspath() - .withArguments(':dvt') - .build() - - then: - result.task(":dvt").outcome == SUCCESS - def dummyLog = new File(testProjectDir.root, 'dvt_cli.sh.log') - dummyLog.exists() - dummyLog.text.contains('createProject') - } - - def "'dvt' task passes project path"() { - buildFile << """ - plugins { - id 'com.verificationgentleman.gradle.hdvl.systemverilog' - } - """ - - when: - def result = newGradleRunnerWithFakeDvtCli() - .withProjectDir(testProjectDir.root) - .withPluginClasspath() - .withArguments(':dvt') - .build() - - then: - result.task(":dvt").outcome == SUCCESS - def dummyLog = new File(testProjectDir.root, 'dvt_cli.sh.log') - dummyLog.exists() - dummyLog.text.contains(testProjectDir.root.absolutePath) - } - - def "'dvt' task adds '-lang vlog' when 'systemverilog' plugin is imported"() { - buildFile << """ - plugins { - id 'com.verificationgentleman.gradle.hdvl.systemverilog' - } - """ - - when: - def result = newGradleRunnerWithFakeDvtCli() - .withProjectDir(testProjectDir.root) - .withPluginClasspath() - .withArguments(':dvt') - .build() - - then: - result.task(":dvt").outcome == SUCCESS - def dummyLog = new File(testProjectDir.root, 'dvt_cli.sh.log') - dummyLog.exists() - dummyLog.text.contains('-lang vlog') - } - - def "'dvt' task adds single '-lang' when only 'systemverilog' plugin is imported"() { - buildFile << """ - plugins { - id 'com.verificationgentleman.gradle.hdvl.systemverilog' - } - """ - - when: - def result = newGradleRunnerWithFakeDvtCli() - .withProjectDir(testProjectDir.root) - .withPluginClasspath() - .withArguments(':dvt') - .build() - - then: - result.task(":dvt").outcome == SUCCESS - def dummyLog = new File(testProjectDir.root, 'dvt_cli.sh.log') - dummyLog.exists() - dummyLog.text.count('-lang') == 1 - } - - def "'dvt' task adds '-lang cpp' when 'c' plugin is imported"() { - File sv = testProjectDir.newFolder('src', 'main', 'c') - new File(sv, "dummy.c").createNewFile() - - buildFile << """ - plugins { - id 'com.verificationgentleman.gradle.hdvl.c' - } - """ - - when: - def result = newGradleRunnerWithFakeDvtCli() - .withProjectDir(testProjectDir.root) - .withPluginClasspath() - .withArguments(':dvt') - .build() - - then: - result.task(":dvt").outcome == SUCCESS - def dummyLog = new File(testProjectDir.root, 'dvt_cli.sh.log') - dummyLog.exists() - dummyLog.text.contains('-lang c') - } - - def "'dvt' task adds two '-lang' options when both 'systemverilog' and 'c' plugins are imported"() { - buildFile << """ - plugins { - id 'com.verificationgentleman.gradle.hdvl.systemverilog' - id 'com.verificationgentleman.gradle.hdvl.c' - } - """ - - when: - def result = newGradleRunnerWithFakeDvtCli() - .withProjectDir(testProjectDir.root) - .withPluginClasspath() - .withArguments(':dvt') - .build() - - then: - result.task(":dvt").outcome == SUCCESS - def dummyLog = new File(testProjectDir.root, 'dvt_cli.sh.log') - dummyLog.exists() - dummyLog.text.count('-lang') == 2 - } - - def "'dvt' task passes '-force' option"() { - buildFile << """ - plugins { - id 'com.verificationgentleman.gradle.hdvl.systemverilog' - } - """ - - when: - def result = newGradleRunnerWithFakeDvtCli() + def result = GradleRunner.create() .withProjectDir(testProjectDir.root) .withPluginClasspath() .withArguments(':dvt') @@ -206,12 +76,12 @@ class DVTPluginSpec extends Specification { then: result.task(":dvt").outcome == SUCCESS - def dummyLog = new File(testProjectDir.root, 'dvt_cli.sh.log') - dummyLog.exists() - dummyLog.text.contains('-force') + def defaultBuild = new File(testProjectDir.root, '.dvt/default.build') + defaultBuild.exists() + defaultBuild.text.contains('+dvt_init+xcelium.xrun') } - def "'dvt' task includes args file"() { + def "'dvt' task includes full xrun args file in 'default.build'"() { buildFile << """ plugins { id 'com.verificationgentleman.gradle.hdvl.systemverilog' @@ -219,7 +89,7 @@ class DVTPluginSpec extends Specification { """ when: - def result = newGradleRunnerWithFakeDvtCli() + def result = GradleRunner.create() .withProjectDir(testProjectDir.root) .withPluginClasspath() .withArguments(':dvt') @@ -227,18 +97,9 @@ class DVTPluginSpec extends Specification { then: result.task(":dvt").outcome == SUCCESS - result.task(":genFullXrunArgsFile").outcome == SUCCESS - def dummyLog = new File(testProjectDir.root, 'dvt_cli.sh.log') - dummyLog.text.contains('-default.build') - dummyLog.text.contains('+dvt_init+ius.irun') - dummyLog.text.contains("-f ${testProjectDir.root}/build/full_xrun_args.f") - } - - def newGradleRunnerWithFakeDvtCli() { - def dvtCliFake = new File(getClass().getResource('/dvt_cli.sh').toURI()) - def env = System.getenv() - - return GradleRunner.create() - .withEnvironment(["PATH": [dvtCliFake.parent, env.PATH].join(':')]) + def defaultBuild = new File(testProjectDir.root, '.dvt/default.build') + defaultBuild.exists() + defaultBuild.text.contains('-f') + defaultBuild.text.contains('full_xrun_args.f') } } diff --git a/src/main/java/com/verificationgentleman/gradle/hdvl/dvt/DVTTask.java b/src/main/java/com/verificationgentleman/gradle/hdvl/dvt/DVTTask.java index fd4aca1..f4891c0 100644 --- a/src/main/java/com/verificationgentleman/gradle/hdvl/dvt/DVTTask.java +++ b/src/main/java/com/verificationgentleman/gradle/hdvl/dvt/DVTTask.java @@ -1,13 +1,13 @@ package com.verificationgentleman.gradle.hdvl.dvt; -import com.verificationgentleman.gradle.hdvl.c.CPlugin; -import com.verificationgentleman.gradle.hdvl.systemverilog.SystemVerilogPlugin; -import org.gradle.api.Action; import org.gradle.api.DefaultTask; import org.gradle.api.file.RegularFileProperty; import org.gradle.api.tasks.InputFile; import org.gradle.api.tasks.TaskAction; -import org.gradle.process.ExecSpec; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; public class DVTTask extends DefaultTask { private RegularFileProperty argsFile; @@ -22,25 +22,14 @@ public RegularFileProperty getArgsFile() { } @TaskAction - public void generate() { - getProject().exec(new Action() { - @Override - public void execute(ExecSpec execSpec) { - execSpec.executable("dvt_cli.sh"); - execSpec.args("createProject"); - execSpec.args(getProject().getRootDir().getAbsolutePath()); - if (getProject().getPlugins().hasPlugin(SystemVerilogPlugin.class)) { - execSpec.args("-lang", "vlog"); - } - if (getProject().getPlugins().hasPlugin(CPlugin.class)) { - execSpec.args("-lang", "c"); - } - execSpec.args("-force"); - execSpec.args( - "-default.build", - "+dvt_init+ius.irun", - "-f", argsFile.getAsFile().get().getAbsolutePath()); - } - }); + public void generate() throws IOException { + File defaultBuild = getProject().file(".dvt/default.build"); + defaultBuild.getParentFile().mkdirs(); + defaultBuild.createNewFile(); + + FileWriter fw = new FileWriter(defaultBuild); + fw.write("+dvt_init+xcelium.xrun\n"); + fw.write("-f " + argsFile.getAsFile().get().getAbsolutePath() + "\n"); + fw.close(); } } From 51fa140e4662f0c71fc6aec21488ed172eaac0a9 Mon Sep 17 00:00:00 2001 From: Tudor Timi Date: Sun, 30 Jul 2023 19:14:48 +0300 Subject: [PATCH 2/3] Extract property for output file This way Gradle takes care of creating the file and outputs nice error messages in case it can't. --- .../gradle/hdvl/dvt/DVTTask.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/verificationgentleman/gradle/hdvl/dvt/DVTTask.java b/src/main/java/com/verificationgentleman/gradle/hdvl/dvt/DVTTask.java index f4891c0..5b2e49a 100644 --- a/src/main/java/com/verificationgentleman/gradle/hdvl/dvt/DVTTask.java +++ b/src/main/java/com/verificationgentleman/gradle/hdvl/dvt/DVTTask.java @@ -3,6 +3,7 @@ import org.gradle.api.DefaultTask; import org.gradle.api.file.RegularFileProperty; import org.gradle.api.tasks.InputFile; +import org.gradle.api.tasks.OutputFile; import org.gradle.api.tasks.TaskAction; import java.io.File; @@ -11,9 +12,12 @@ public class DVTTask extends DefaultTask { private RegularFileProperty argsFile; + private RegularFileProperty defaultBuild; public DVTTask() { argsFile = getProject().getObjects().fileProperty(); + defaultBuild = getProject().getObjects().fileProperty().convention( + getProject().getLayout().getProjectDirectory().dir(".dvt").file("default.build")); } @InputFile @@ -21,13 +25,14 @@ public RegularFileProperty getArgsFile() { return argsFile; } + @OutputFile + public RegularFileProperty getDefaultBuild() { + return defaultBuild; + } + @TaskAction public void generate() throws IOException { - File defaultBuild = getProject().file(".dvt/default.build"); - defaultBuild.getParentFile().mkdirs(); - defaultBuild.createNewFile(); - - FileWriter fw = new FileWriter(defaultBuild); + FileWriter fw = new FileWriter(defaultBuild.get().getAsFile()); fw.write("+dvt_init+xcelium.xrun\n"); fw.write("-f " + argsFile.getAsFile().get().getAbsolutePath() + "\n"); fw.close(); From da24154c873f566e8233aef82497f9145059c85a Mon Sep 17 00:00:00 2001 From: Tudor Timi Date: Sun, 30 Jul 2023 19:19:33 +0300 Subject: [PATCH 3/3] Add missing copyright notice --- .../gradle/hdvl/dvt/DVTTask.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/main/java/com/verificationgentleman/gradle/hdvl/dvt/DVTTask.java b/src/main/java/com/verificationgentleman/gradle/hdvl/dvt/DVTTask.java index 5b2e49a..7fb75fc 100644 --- a/src/main/java/com/verificationgentleman/gradle/hdvl/dvt/DVTTask.java +++ b/src/main/java/com/verificationgentleman/gradle/hdvl/dvt/DVTTask.java @@ -1,3 +1,18 @@ +/* + * Copyright 2021-2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.verificationgentleman.gradle.hdvl.dvt; import org.gradle.api.DefaultTask;