-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from tudortimi/create-hdvl-base-plugin
Create HDVL base plugin
- Loading branch information
Showing
22 changed files
with
576 additions
and
232 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env sh | ||
|
||
exec "$(dirname "$0")/../../gradlew" "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
includeBuild("../..") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// Some file that should be excluded | ||
|
||
void some_c_function() { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// Some file that should be built | ||
|
||
void some_c_function() { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
package dummy; | ||
endpackage |
162 changes: 162 additions & 0 deletions
162
src/functTest/groovy/com/verificationgentleman/gradle/hdvl/c/CPluginSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(' ') | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...radle/hdvl/systemverilog/GenArgsFile.java → ...iongentleman/gradle/hdvl/GenArgsFile.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.