This repository has been archived by the owner on Aug 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 569
/
build.gradle
306 lines (270 loc) · 9.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
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
import org.jetbrains.kotlin.RegressionsReporter
import org.jetbrains.kotlin.RegressionsSummaryReporter
import org.jetbrains.kotlin.BuildRegister
import org.jetbrains.kotlin.MPPTools
buildscript {
ext.rootBuildDirectory = file('..')
apply from: "$rootBuildDirectory/gradle/loadRootProperties.gradle"
apply from: "$rootBuildDirectory/gradle/kotlinGradlePlugin.gradle"
repositories {
maven { url 'https://cache-redirector.jetbrains.com/jcenter'}
maven { url 'https://cache-redirector.jetbrains.com/maven-central' }
mavenCentral()
maven { url buildKotlinCompilerRepo }
maven { url kotlinCompilerRepo }
jcenter()
maven { url "https://kotlin.bintray.com/kotlinx" }
maven { url "https://dl.bintray.com/kotlin/kotlin-dev" }
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-native-build-tools:$konanVersion"
}
}
def rootBuildDirectory = projectDir.parentFile
task konanRun {
subprojects.each {
dependsOn "${it.path}:konanRun"
}
}
task jvmRun {
subprojects.each {
dependsOn "${it.path}:jvmRun"
}
}
task clean {
subprojects.each {
dependsOn "${it.path}:clean"
}
doLast {
delete "${buildDir.absolutePath}"
}
}
defaultTasks 'konanRun'
private static String getAnalyzerTargetName() {
// Copy-pasted from tools/benchmarksAnalyzer/build.gradle.
String target = System.getProperty("os.name")
if (target == 'Linux') return 'linux'
if (target.startsWith('Windows')) return 'windows'
if (target.startsWith('Mac')) return 'macos'
return 'unknown'
}
private String findAnalyzerBinary() {
String result = "${projectDir}/../${analyzerToolDirectory}/${getAnalyzerTargetName()}/" +
"${analyzerTool}ReleaseExecutable/${analyzerTool}${MPPTools.getNativeProgramExtension()}"
if (file(result).exists()) return result
else return null
}
// Produce and send slack report.
task slackReport(type: RegressionsReporter) {
def analyzerBinary = MPPTools.findFile("${analyzerTool}${MPPTools.getNativeProgramExtension()}",
"${rootBuildDirectory}/${analyzerToolDirectory}")
def teamcityConfig = System.getenv("TEAMCITY_BUILD_PROPERTIES_FILE")
if (teamcityConfig && analyzerBinary != null) {
// Create folder for report (root Kotlin project settings make create report in separate folder).
def reportDirectory = new File(outputReport).parentFile
mkdir reportDirectory
def targetsResults = new File(new File("${rootBuildDirectory}"), "targetsResults").toString()
mkdir targetsResults
currentBenchmarksReportFile = "${buildDir.absolutePath}/${nativeJson}"
analyzer = analyzerBinary
htmlReport = outputReport
defaultBranch = project.findProperty('kotlin.native.default.branch') ?: "master"
def target = System.getProperty("os.name")
summaryFile = "${targetsResults}/${target}.txt"
bundleBuild = project.findProperty('kotlin.bundleBuild') == null ? false : true
}
}
task slackSummary(type: RegressionsSummaryReporter) {
targetsResultFiles = ['Linux': "${rootBuildDirectory}/targetsResults/Linux.txt".toString(),
'MacOSX': "${rootBuildDirectory}/targetsResults/Mac OS X.txt".toString(),
'Windows': "${rootBuildDirectory}/targetsResults/Windows 10.txt".toString()]
}
private String getUploadedFile(String fileName) {
def teamcityConfig = System.getenv("TEAMCITY_BUILD_PROPERTIES_FILE")
if (teamcityConfig) {
def buildProperties = new Properties()
buildProperties.load(new FileInputStream(teamcityConfig))
def buildNumber = buildProperties.getProperty("build.number")
def target = System.getProperty("os.name").replaceAll("\\s", "")
return "${target}/${buildNumber}/${fileName}"
}
return null
}
private def uploadBenchmarkResultToArtifactory(String fileName) {
def teamcityConfig = System.getenv("TEAMCITY_BUILD_PROPERTIES_FILE")
if (teamcityConfig) {
def uploadedFile = getUploadedFile(fileName)
def buildProperties = new Properties()
buildProperties.load(new FileInputStream(teamcityConfig))
def password = buildProperties.getProperty("artifactory.apikey")
MPPTools.uploadFileToArtifactory("${artifactoryUrl}", "${artifactoryRepo}",
uploadedFile, "${buildDir.absolutePath}/${fileName}", password)
}
}
// Register external benchmarks reports (e.g. results of libraries benchmarks)
task registerExternalBenchmarks {
doLast {
def reports = externalReports.split(';')
def jsonReports = []
reports.each {
def reportFile = new File(buildDir, it)
if (!reportFile.exists())
return
def lines = reportFile.readLines()
if (lines.size < 4) {
project.logger.warn("Couldn't use report to register benchmarks. Wrong format.")
return
}
def name = lines[0]
def options = lines[1]
if (!options.startsWith("OPTIONS")) {
project.logger.warn("Couldn't use report to register benchmarks. Wrong format in options description.")
return
}
def optionsList = options.replace("OPTIONS ", "").replaceAll("\\[|\\]", "").split(",\\s*").toList()
def status = lines[2]
def compileTime = null
def codeSize = null
lines.drop(3).each {
if (it.startsWith("COMPILE_TIME")) {
compileTime = it
}
if (it.startsWith("CODE_SIZE")) {
codeSize = it
}
}
// Create benchmarks report.
def properties = [
"cpu": System.getProperty("os.arch"),
"os": System.getProperty("os.name"),
"jdkVersion": System.getProperty("java.version"),
"jdkVendor": System.getProperty("java.vendor"),
"kotlinVersion": kotlinVersion,
"type": "native",
"compilerVersion": konanVersion,
"flags": optionsList,
"benchmarks": "[]"]
if (compileTime != null) {
def compileBenchmark = MPPTools.toCompileBenchmark(compileTime, status, name)
properties += ["compileTime": [compileBenchmark]]
}
if (codeSize != null) {
properties += ["codeSize": MPPTools.toCodeSizeBenchmark(codeSize, status, name)]
}
def output = MPPTools.createJsonReport(properties)
def jsonFile = new File(buildDir, it.replace(".txt", ".json"))
jsonFile.write(output)
jsonReports.add(jsonFile)
}
def merged = MPPTools.mergeReports(jsonReports)
if (!merged.isEmpty()) {
mkdir buildDir.absolutePath
new File(buildDir, externalBenchmarksReport).write(merged)
uploadBenchmarkResultToArtifactory(externalBenchmarksReport)
}
}
}
task registerBuild(type: BuildRegister) {
onlyBranch = project.findProperty('kotlin.register.branch')
def uploadedFile = getUploadedFile(nativeJson)
if (uploadedFile != null) {
println("Use file from Artifacrory $uploadedFile")
fileWithResult = uploadedFile
}
// Get bundle size.
bundleSize = null
if (project.findProperty('kotlin.bundleBuild') != null) {
def dist = findProperty('kotlin.native.home') ?: 'dist'
dist = (new File(dist)).isAbsolute() ? dist : "${project.getProjectDir()}/$dist"
bundleSize = (new File(dist)).directorySize()
}
}
task registerExternalBuild(type: BuildRegister) {
onlyBranch = project.findProperty('kotlin.register.branch')
def uploadedFile = getUploadedFile(externalBenchmarksReport)
if (uploadedFile != null) {
println("Use file from Artifacrory $uploadedFile")
fileWithResult = uploadedFile
} else {
fileWithResult = externalBenchmarksReport
}
}
registerExternalBenchmarks.finalizedBy registerExternalBuild
def mergeReports(String fileName) {
def reports = []
subprojects.each {
def reportFile = new File("${it.buildDir.absolutePath}/${fileName}")
if (reportFile.exists()) {
reports.add(reportFile)
}
}
def output = MPPTools.mergeReports(reports)
mkdir buildDir.absolutePath
new File("${buildDir.absolutePath}/${fileName}").write(output)
}
task mergeNativeReports {
doLast {
mergeReports(nativeJson)
uploadBenchmarkResultToArtifactory(nativeJson)
}
}
task mergeJvmReports {
doLast {
mergeReports(jvmJson)
uploadBenchmarkResultToArtifactory(jvmJson)
}
}
subprojects.each {
it.afterEvaluate {
it.jvmJsonReport.finalizedBy mergeJvmReports
it.konanJsonReport.finalizedBy mergeNativeReports
}
}
task teamCityStat(type:Exec) {
def analyzer = findAnalyzerBinary()
if (analyzer != null) {
commandLine "${analyzer}", "-r", "teamcity", "${buildDir.absolutePath}/${nativeJson}"
} else {
println("No analyzer $analyzerTool found in subdirectories of ${rootBuildDirectory}/${analyzerToolDirectory}")
}
}
task cinterop {
dependsOn 'clean'
dependsOn 'cinterop:konanRun'
}
task framework {
dependsOn 'clean'
dependsOn 'framework:konanRun'
}
task helloworld {
dependsOn 'clean'
dependsOn 'helloworld:konanRun'
}
task objcinterop {
dependsOn 'clean'
dependsOn 'objcinterop:konanRun'
}
task ring {
dependsOn 'clean'
dependsOn 'ring:konanRun'
}
task numerical {
dependsOn 'clean'
dependsOn 'numerical:konanRun'
}
task startup {
dependsOn 'clean'
dependsOn 'startup:konanRun'
}
task swiftinterop {
dependsOn 'clean'
dependsOn 'swiftinterop:konanRun'
}
task videoplayer {
dependsOn 'clean'
dependsOn 'videoplayer:konanRun'
}
task KotlinVsSwift {
dependsOn 'clean'
dependsOn 'KotlinVsSwift:konanRun'
}