-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
195 lines (174 loc) · 5.48 KB
/
build.gradle.kts
File metadata and controls
195 lines (174 loc) · 5.48 KB
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm") version "1.8.22"
`maven-publish`
}
publishing {
publications {
create<MavenPublication>("jar") {
from(components["java"])
groupId = "org.utpython.types"
artifactId = project.name
}
}
}
tasks.test {
useJUnitPlatform()
}
repositories {
mavenCentral()
}
tasks {
withType<JavaCompile> {
sourceCompatibility = JavaVersion.VERSION_1_8.toString()
targetCompatibility = JavaVersion.VERSION_1_8.toString()
options.encoding = "UTF-8"
options.compilerArgs = options.compilerArgs + "-Xlint:all" + "-Werror"
}
withType<KotlinCompile> {
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
freeCompilerArgs = freeCompilerArgs + "-Xallow-result-return-type" + "-Xsam-conversions=class"
allWarningsAsErrors = true
}
}
}
val kotlinLoggingVersion = "1.8.3"
val moshiVersion = "1.15.1"
dependencies {
implementation("com.squareup.moshi:moshi:$moshiVersion")
implementation("com.squareup.moshi:moshi-kotlin:$moshiVersion")
implementation("com.squareup.moshi:moshi-adapters:$moshiVersion")
implementation(group = "io.github.microutils", name = "kotlin-logging", version = kotlinLoggingVersion)
testImplementation(kotlin("test-junit5"))
}
val utbotMypyRunnerVersion = File(project.projectDir, "src/main/resources/utbot_mypy_runner_version").readText()
// these two properties --- from GRADLE_USER_HOME/gradle.properties
val pypiToken: String? by project
val pythonInterpreter: String? by project
val utbotMypyRunnerPath = File(project.projectDir, "src/main/python/utbot_mypy_runner")
val localMypyPath = File(utbotMypyRunnerPath, "dist")
tasks.register("cleanDist") {
group = "python"
delete(localMypyPath.canonicalPath)
}
val installPoetry =
if (pythonInterpreter != null) {
tasks.register<Exec>("installPoetry") {
group = "python"
workingDir = utbotMypyRunnerPath
commandLine(pythonInterpreter, "-m", "pip", "install", "poetry")
}
} else {
null
}
val setMypyRunnerVersion =
if (pythonInterpreter != null) {
tasks.register<Exec>("setVersion") {
dependsOn(installPoetry!!)
group = "python"
workingDir = utbotMypyRunnerPath
commandLine(pythonInterpreter, "-m", "poetry", "version", utbotMypyRunnerVersion)
}
} else {
null
}
val buildMypyRunner =
if (pythonInterpreter != null) {
tasks.register<Exec>("buildUtbotMypyRunner") {
dependsOn(setMypyRunnerVersion!!)
group = "python"
workingDir = utbotMypyRunnerPath
commandLine(pythonInterpreter, "-m", "poetry", "build")
}
} else {
null
}
if (pythonInterpreter != null && pypiToken != null) {
tasks.register<Exec>("publishUtbotMypyRunner") {
dependsOn(buildMypyRunner!!)
group = "python"
workingDir = utbotMypyRunnerPath
commandLine(
pythonInterpreter,
"-m",
"poetry",
"publish",
"-u",
"__token__",
"-p",
pypiToken
)
}
}
val uninstallMypyRunner =
if (pythonInterpreter != null) {
tasks.register<Exec>("uninstallMypyRunner") {
group = "python"
commandLine(
pythonInterpreter,
"-m",
"pip",
"uninstall",
"utbot_mypy_runner"
)
commandLine(
pythonInterpreter,
"-m",
"pip",
"cache",
"purge"
)
}
} else {
null
}
val installMypyRunner =
if (pythonInterpreter != null) {
tasks.register<Exec>("installUtbotMypyRunner") {
dependsOn(buildMypyRunner!!)
group = "python"
environment("PIP_FIND_LINKS" to localMypyPath.canonicalPath)
commandLine(
pythonInterpreter,
"-m",
"pip",
"install",
"utbot_mypy_runner==$utbotMypyRunnerVersion"
)
}
} else {
null
}
val samplesDir = File(project.projectDir, "src/test/resources/samples")
val buildDir = File(project.buildDir, "samples_builds")
val jsonDir = File(project.projectDir, "src/test/resources")
fun getParamsForSample(sampleName: String): List<String> =
listOf(
sampleName,
File(samplesDir, "$sampleName.py").canonicalPath,
sampleName,
buildDir.canonicalPath,
File(jsonDir, "$sampleName.json").canonicalPath
)
val samplesInfo = listOf(
getParamsForSample("annotation_tests"),
getParamsForSample("boruvka"),
getParamsForSample("import_test"),
getParamsForSample("subtypes"),
)
if (pythonInterpreter != null) {
val subtasks = samplesInfo.map { params ->
tasks.register<JavaExec>("regenerateJsonForTests_${params.first()}") {
dependsOn(installMypyRunner!!)
group = "python_subtasks"
classpath = sourceSets.test.get().runtimeClasspath
args = listOf(pythonInterpreter) + params.drop(1)
mainClass.set("org.utbot.python.newtyping.samples.GenerateMypyInfoBuildKt")
}
}
tasks.register("regenerateJsonForTests") {
subtasks.forEach { dependsOn(it) }
group = "python"
}
}