Skip to content

Commit

Permalink
Merge pull request #43 from tudortimi/create-hdvl-base-plugin
Browse files Browse the repository at this point in the history
Create HDVL base plugin
  • Loading branch information
tudortimi authored Jan 15, 2021
2 parents 9154cf0 + 57f9816 commit a220830
Show file tree
Hide file tree
Showing 22 changed files with 576 additions and 232 deletions.
4 changes: 4 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ gradlePlugin {
id = "com.verificationgentleman.gradle.hdvl.systemverilog"
implementationClass = "com.verificationgentleman.gradle.hdvl.systemverilog.SystemVerilogPlugin"
}
create("c") {
id = "com.verificationgentleman.gradle.hdvl.c"
implementationClass = "com.verificationgentleman.gradle.hdvl.c.CPlugin"
}
create("svunit") {
id = "com.verificationgentleman.gradle.hdvl.svunit"
implementationClass = "com.verificationgentleman.gradle.hdvl.svunit.SVUnitPlugin"
Expand Down
12 changes: 12 additions & 0 deletions examples/sv-with-c/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
plugins {
id("com.verificationgentleman.gradle.hdvl.systemverilog")
id("com.verificationgentleman.gradle.hdvl.c")
}

sourceSets {
main {
c {
exclude("**/bad.c")
}
}
}
3 changes: 3 additions & 0 deletions examples/sv-with-c/gradlew
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env sh

exec "$(dirname "$0")/../../gradlew" "$@"
1 change: 1 addition & 0 deletions examples/sv-with-c/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
includeBuild("../..")
4 changes: 4 additions & 0 deletions examples/sv-with-c/src/main/c/bad.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Some file that should be excluded

void some_c_function() {
}
4 changes: 4 additions & 0 deletions examples/sv-with-c/src/main/c/good.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Some file that should be built

void some_c_function() {
}
2 changes: 2 additions & 0 deletions examples/sv-with-c/src/main/sv/dummy.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
package dummy;
endpackage
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
/*
* Copyright 2021 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.c

import org.gradle.testkit.runner.GradleRunner
import org.junit.Rule
import org.junit.rules.TemporaryFolder
import spock.lang.Ignore
import spock.lang.Specification

import static org.gradle.testkit.runner.TaskOutcome.NO_SOURCE
import static org.gradle.testkit.runner.TaskOutcome.SUCCESS

class CPluginSpec extends Specification {
@Rule TemporaryFolder testProjectDir = new TemporaryFolder()
File buildFile

def setup() {
buildFile = testProjectDir.newFile('build.gradle')
buildFile << """
plugins {
id 'com.verificationgentleman.gradle.hdvl.c'
}
"""
}

def "can successfully import the plugin"() {
when:
def result = GradleRunner.create()
.withProjectDir(testProjectDir.root)
.withPluginClasspath()
.build()

then:
result.task(":help").outcome == SUCCESS
}

def "can specify a source set C source directory using a closure"() {
File sv = testProjectDir.newFolder('c')
new File(sv, 'dummy.c').createNewFile()

buildFile << """
sourceSets {
main {
c {
srcDirs = ['c']
}
}
}
task copy(type: Copy) {
from sourceSets.main.c.files
into 'build'
}
"""

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

then:
result.task(":copy").outcome == SUCCESS
new File(testProjectDir.root, 'build/dummy.c').exists()
}

@Ignore("Complains that the source set doesn't support conventions")
def "can specify a source set C source exclude using an action"() {
// XXX Most tests use 'build.gradle', but in this test we want to use a Kotlin build script. It seems like
// overkill to create a new test class just fo this.
setup:
new File(testProjectDir.root, 'build.gradle').delete()

File sv = testProjectDir.newFolder('src', 'main', 'c')
new File(sv, 'dummy.c').createNewFile()

File buildFile = testProjectDir.newFile('build.gradle.kts')
buildFile << """
import com.verificationgentleman.gradle.hdvl.c.CSourceSet
plugins {
id("com.verificationgentleman.gradle.hdvl.c")
}
sourceSets {
main {
withConvention(CSourceSet::class) {
c.exclude("**/dummy.c")
}
}
}
tasks.register<Copy>("copy") {
// XXX Not clear why we can't just do 'sourceSets.main.sv'.
// 'sourceSets.main' doesn't return an object of type 'SourceSet', but a
// 'NamedDomainObjectProvider<SourceSet'. The Java plugin has the same issue.
from(sourceSets.main.withConvention(CSourceSet::class) { c })
include("*")
into("build")
}
"""

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

then:
result.task(":copy").outcome == NO_SOURCE
}

def "'genArgsFile' task writes C files to args file"() {
File c = testProjectDir.newFolder('src', 'main', 'c')
new File(c, 'dummy.c').createNewFile()

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

then:
new File(testProjectDir.root, 'build/args.f').text.contains('src/main/c/dummy.c')
}

def "'genArgsFile' task indents entries in makelib block"() {
File c = testProjectDir.newFolder('src', 'main', 'c')
new File(c, 'dummy.c').createNewFile()

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

then:
def lines = new File(testProjectDir.root, 'build/args.f').text.split('\n')
lines.findAll { !it.contains('-makelib') && !it.contains('-endlib') }.each {
assert it.startsWith(' ')
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package com.verificationgentleman.gradle.hdvl.systemverilog
import org.gradle.testkit.runner.GradleRunner
import org.junit.Rule
import org.junit.rules.TemporaryFolder
import spock.lang.Ignore
import spock.lang.Specification

import static org.gradle.testkit.runner.TaskOutcome.NO_SOURCE
Expand Down Expand Up @@ -206,37 +207,6 @@ class SystemVerilogPluginSpec extends Specification {
new File(testProjectDir.root, 'build/dummy.svh').exists()
}

def "can specify a source set C source directory using a closure"() {
File sv = testProjectDir.newFolder('c')
new File(sv, 'dummy.c').createNewFile()

buildFile << """
sourceSets {
main {
c {
srcDirs = ['c']
}
}
}
task copy(type: Copy) {
from sourceSets.main.c.files
into 'build'
}
"""

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

then:
result.task(":copy").outcome == SUCCESS
new File(testProjectDir.root, 'build/dummy.c').exists()
}

def "'main' source set is added by the plugin"() {
File sv = testProjectDir.newFolder('src', 'main', 'sv')
new File(sv, 'dummy.sv').createNewFile()
Expand All @@ -260,6 +230,7 @@ class SystemVerilogPluginSpec extends Specification {
new File(testProjectDir.root, 'build/dummy.sv').exists()
}

@Ignore("Complains that the source set doesn't support conventions")
def "can specify a source set source exclude using an action"() {
// XXX Most tests use 'build.gradle', but in this test we want to use a Kotlin build script. It seems like
// overkill to create a new test class just fo this.
Expand All @@ -271,14 +242,16 @@ class SystemVerilogPluginSpec extends Specification {

File buildFile = testProjectDir.newFile('build.gradle.kts')
buildFile << """
import com.verificationgentleman.gradle.hdvl.systemverilog.SystemVerilogSourceSet
plugins {
id("com.verificationgentleman.gradle.hdvl.systemverilog")
}
sourceSets {
main {
sv {
exclude("**/dummy.sv")
withConvention(SystemVerilogSourceSet::class) {
sv.exclude("**/dummy.sv")
}
}
}
Expand All @@ -287,7 +260,7 @@ class SystemVerilogPluginSpec extends Specification {
// XXX Not clear why we can't just do 'sourceSets.main.sv'.
// 'sourceSets.main' doesn't return an object of type 'SourceSet', but a
// 'NamedDomainObjectProvider<SourceSet'. The Java plugin has the same issue.
from(sourceSets.main.get().sv.files)
from(sourceSets.main.withConvention(SystemVerilogSourceSet::class) { sv }.files)
include("*")
into("build")
}
Expand All @@ -304,6 +277,7 @@ class SystemVerilogPluginSpec extends Specification {
result.task(":copy").outcome == NO_SOURCE
}

@Ignore("Complains that the source set doesn't support conventions")
def "can specify a source set exported header source exclude using an action"() {
// XXX Most tests use 'build.gradle', but in this test we want to use a Kotlin build script. It seems like
// overkill to create a new test class just fo this.
Expand All @@ -315,58 +289,16 @@ class SystemVerilogPluginSpec extends Specification {

File buildFile = testProjectDir.newFile('build.gradle.kts')
buildFile << """
plugins {
id("com.verificationgentleman.gradle.hdvl.systemverilog")
}
import com.verificationgentleman.gradle.hdvl.systemverilog.SystemVerilogSourceSet
sourceSets {
main {
svHeaders {
exclude("**/dummy.svh")
}
}
}
tasks.register<Copy>("copy") {
// XXX Not clear why we can't just do 'sourceSets.main.sv'.
// 'sourceSets.main' doesn't return an object of type 'SourceSet', but a
// 'NamedDomainObjectProvider<SourceSet'. The Java plugin has the same issue.
from(sourceSets.main.get().svHeaders.files)
include("*")
into("build")
}
"""

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

then:
result.task(":copy").outcome == NO_SOURCE
}

def "can specify a source set C source exclude using an action"() {
// XXX Most tests use 'build.gradle', but in this test we want to use a Kotlin build script. It seems like
// overkill to create a new test class just fo this.
setup:
new File(testProjectDir.root, 'build.gradle').delete()

File sv = testProjectDir.newFolder('src', 'main', 'c')
new File(sv, 'dummy.c').createNewFile()

File buildFile = testProjectDir.newFile('build.gradle.kts')
buildFile << """
plugins {
id("com.verificationgentleman.gradle.hdvl.systemverilog")
}
sourceSets {
main {
c {
exclude("**/dummy.c")
withConvention(SystemVerilogSourceSet::class) {
svHeaders.exclude("**/dummy.svh")
}
}
}
Expand All @@ -375,7 +307,7 @@ class SystemVerilogPluginSpec extends Specification {
// XXX Not clear why we can't just do 'sourceSets.main.sv'.
// 'sourceSets.main' doesn't return an object of type 'SourceSet', but a
// 'NamedDomainObjectProvider<SourceSet'. The Java plugin has the same issue.
from(sourceSets.main.get().c.files)
from(sourceSets.main.withConvention(SystemVerilogSourceSet::class) { svHeaders }.files)
include("*")
into("build")
}
Expand Down Expand Up @@ -505,26 +437,9 @@ class SystemVerilogPluginSpec extends Specification {
linesWithIncdir.each { assert !it.endsWith("src/main/sv_headers") }
}

def "'genArgsFile' task writes C files to args file"() {
File c = testProjectDir.newFolder('src', 'main', 'c')
new File(c, 'dummy.c').createNewFile()

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

then:
new File(testProjectDir.root, 'build/args.f').text.contains('src/main/c/dummy.c')
}

def "'genArgsFile' task indents entries in makelib block"() {
File sv = testProjectDir.newFolder('src', 'main', 'sv')
new File(sv, 'dummy.sv').createNewFile()
File c = testProjectDir.newFolder('src', 'main', 'c')
new File(c, 'dummy.c').createNewFile()

when:
def result = GradleRunner.create()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.verificationgentleman.gradle.hdvl.systemverilog;
package com.verificationgentleman.gradle.hdvl;

import org.gradle.api.file.FileCollection;
import org.gradle.api.file.FileTree;
Expand Down
Loading

0 comments on commit a220830

Please sign in to comment.