forked from UnitTestBot/UTBotJava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
151 lines (137 loc) · 4.45 KB
/
build.gradle.kts
File metadata and controls
151 lines (137 loc) · 4.45 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
val kotlinLoggingVersion: String? by rootProject
dependencies {
implementation("com.squareup.moshi:moshi:1.14.0")
implementation("com.squareup.moshi:moshi-kotlin:1.14.0")
implementation("com.squareup.moshi:moshi-adapters:1.14.0")
implementation(group = "io.github.microutils", name = "kotlin-logging", version = kotlinLoggingVersion)
}
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"
}
}