Skip to content

Commit

Permalink
Merge pull request #121 from tudortimi/implement-more-streamlined-cre…
Browse files Browse the repository at this point in the history
…ation-of-dvt-project

Implement more streamlined creation of DVT project
  • Loading branch information
tudortimi authored Jul 30, 2023
2 parents 8f9f92b + da24154 commit aea9c64
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 174 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,185 +60,46 @@ 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'
}
"""

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')
.build()

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'
}
"""

when:
def result = newGradleRunnerWithFakeDvtCli()
def result = GradleRunner.create()
.withProjectDir(testProjectDir.root)
.withPluginClasspath()
.withArguments(':dvt')
.build()

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')
}
}
Original file line number Diff line number Diff line change
@@ -1,46 +1,55 @@
/*
* 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 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.OutputFile;
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;
private RegularFileProperty defaultBuild;

public DVTTask() {
argsFile = getProject().getObjects().fileProperty();
defaultBuild = getProject().getObjects().fileProperty().convention(
getProject().getLayout().getProjectDirectory().dir(".dvt").file("default.build"));
}

@InputFile
public RegularFileProperty getArgsFile() {
return argsFile;
}

@OutputFile
public RegularFileProperty getDefaultBuild() {
return defaultBuild;
}

@TaskAction
public void generate() {
getProject().exec(new Action<ExecSpec>() {
@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 {
FileWriter fw = new FileWriter(defaultBuild.get().getAsFile());
fw.write("+dvt_init+xcelium.xrun\n");
fw.write("-f " + argsFile.getAsFile().get().getAbsolutePath() + "\n");
fw.close();
}
}

0 comments on commit aea9c64

Please sign in to comment.