forked from Xilinx/RapidWright
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
139 lines (120 loc) · 3.97 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import java.util.stream.Collectors
apply plugin: 'application'
apply plugin: 'java-library'
mainClassName = "com.xilinx.rapidwright.MainEntrypoint"
sourceSets {
main {
java.destinationDirectory.fileValue(file('bin'))
java {
srcDirs = ['src']
}
}
test {
java {
srcDirs = ['test']
}
}
}
//Kryo needs to access sun.nio.ch.DirectBuffer. This is forbidden by default in Java 16 and up. Check if we need to add a jvm arg.
if (org.gradle.api.JavaVersion.current().isJava10Compatible()) {
applicationDefaultJvmArgs = ["--add-exports=java.base/sun.nio.ch=ALL-UNNAMED"]
}
tasks.withType(Test) {
maxHeapSize = "5G"
//Propagate JVM settings to test JVM
jvmArgs applicationDefaultJvmArgs
environment 'RAPIDWRIGHT_PATH',file('.')
//We need to rerun tests when the data files change
if (file('data').exists()) {
inputs.dir file('data')
}
}
sourceCompatibility = 8
targetCompatibility = 8
dependencies {
api fileTree(dir: 'jars', include: ['*.jar'], exclude: ['junit*.jar', '*-javadoc.jar'])
testImplementation fileTree(dir: 'jars', include: ['junit-jupiter-*.jar', 'junit-platform-*.jar'])
}
task updateJars {
group = "build setup"
description = "Download Jar Dependencies."
doLast {
def f = new File('rapidwright-installer.jar')
if (!f.exists()) {
println 'Downloading...'
new URL('https://www.rapidwright.io/docs/_downloads/rapidwright-installer.jar').withInputStream{ i -> f.withOutputStream{ it << i }}
}
def stdout = new StringBuilder(), stderr = new StringBuilder()
def proc = 'java -jar rapidwright-installer.jar -u'.execute()
proc.consumeProcessOutput(stdout,stderr)
proc.waitForOrKill(1100000)
println "$stdout\n$stderr"
f.delete()
}
}
task update_jars {
group = "build setup"
description = "Alias for 'updateJars'."
dependsOn updateJars
}
task testJava(type:Test) {
group = "verification"
description = "Runs the Java unit tests."
useJUnitPlatform()
}
task testPython(type:Test) {
group = "verification"
description = "Runs the Python unit tests."
doFirst {
// Necessary because gradle will try and match against Java tests
filter.setFailOnNoMatchingTests(false)
}
doLast {
exec {
environment 'CLASSPATH', sourceSets.main.runtimeClasspath.getAsPath()
executable = 'python3'
args = ['-m', 'pytest', '--junitxml', "$buildDir/test-results/testPython/testPython.xml", '--rootdir', 'python/test']
// Prevent python/tests/... with the same namespace as in Java from clobbering
args += ['--import-mode=importlib']
// Workaround from https://github.com/jpype-project/jpype/issues/842#issuecomment-847027355
args += ['-p', 'no:faulthandler']
if (!filter.commandLineIncludePatterns.isEmpty()) {
args += ['--pyargs'] + filter.commandLineIncludePatterns.stream().map((p) -> 'python.test.' + p).collect(Collectors.toList())
}
}
}
}
test {
dependsOn testJava
dependsOn testPython
}
gradle.taskGraph.whenReady {
if (!project.test.filter.commandLineIncludePatterns.isEmpty()) {
throw new InvalidUserDataException("'test' task does not support filters (i.e. '--tests' option); please apply filters directly to 'testJava'/'testPython' tasks instead.")
}
}
task updateSubmodules(type:Exec) {
group = "build setup"
description = "Update Git submodules"
executable = 'git'
args = ['submodule', 'update', '--init', '--recursive']
}
task initSubmodules {
group = "build setup"
description = "Init Git submodules (first time only)"
if (!file("test/RapidWrightDCP/.git").exists()) {
dependsOn updateSubmodules
}
}
task remindSubmodules {
onlyIf {
testJava.state.failure != null || testPython.state.failure != null
}
doLast {
logger.warn('Failed tests detected. Some tests depend on DCPs from the git submodule at test/RapidWrightDCP, consider checking its status and updating with \'gradlew updateSubmodules\'')
}
}
tasks.withType(Test) {
dependsOn initSubmodules
finalizedBy remindSubmodules
}