Improve compatibility with newer GCC+Clang, resolve some warnings

This commit is contained in:
Campbell Jones
2020-10-26 15:33:02 -04:00
committed by Stanislav Erokhin
parent 58855b9eff
commit 4c9bbe54d4
22 changed files with 112 additions and 106 deletions
@@ -39,8 +39,8 @@ class ExecClang(private val project: Project) {
return konanArgs(target)
}
fun resolveExecutable(executable: String?): String {
val executable = executable ?: "clang"
fun resolveExecutable(executableOrNull: String?): String {
val executable = executableOrNull ?: "clang"
if (listOf("clang", "clang++").contains(executable)) {
val llvmDir = project.findProperty("llvmDir")
@@ -179,10 +179,10 @@ val Project.executor: ExecutorService
*/
fun ExecutorService.add(actionParameter: Action<in ExecSpec>) = object : ExecutorService {
override fun execute(action: Action<in ExecSpec>): ExecResult? =
this@add.execute(Action {
this@add.execute {
action.execute(it)
actionParameter.execute(it)
})
}
}
/**
@@ -221,6 +221,7 @@ fun localExecutorService(project: Project): ExecutorService = object : ExecutorS
* @param iosDevice an optional project property used to control simulator's device type
* Specify -PiosDevice=iPhone X to set it
*/
@Suppress("KDocUnresolvedReference")
private fun simulator(project: Project): ExecutorService = object : ExecutorService {
private val target = project.testTarget
@@ -269,6 +270,7 @@ private fun simulator(project: Project): ExecutorService = object : ExecutorServ
* @param remote makes binaries be executed on a remote host
* Specify it as -Premote=user@host
*/
@Suppress("KDocUnresolvedReference")
private fun sshExecutor(project: Project): ExecutorService = object : ExecutorService {
private val remote: String = project.property("remote").toString()
@@ -332,14 +334,15 @@ private fun deviceLauncher(project: Project) = object : ExecutorService {
private val deviceName = project.findProperty("device_name") as? String
private val bundleID = "org.jetbrains.kotlin.KonanTestLauncher"
override fun execute(action: Action<in ExecSpec>): ExecResult? {
var result: ExecResult? = null
val result: ExecResult?
try {
val udid = targetUDID()
println("Found device UDID: $udid")
install(udid, xcProject.resolve("build/KonanTestLauncher.ipa").toString())
val bundleId = "org.jetbrains.kotlin.KonanTestLauncher"
val commands = startDebugServer(udid, bundleId)
val commands = startDebugServer(udid)
.split("\n")
.filter { it.isNotBlank() }
.flatMap { listOf("-o", it) }
@@ -377,7 +380,7 @@ private fun deviceLauncher(project: Project) = object : ExecutorService {
savedOut?.write(it.toByteArray())
}
uninstall(udid, bundleId)
uninstall(udid)
} catch (exc: Exception) {
throw RuntimeException("iOS-device execution failed", exc)
} finally {
@@ -463,12 +466,12 @@ private fun deviceLauncher(project: Project) = object : ExecutorService {
check(result.exitValue == 0) { "Installation of $bundlePath failed: $out" }
}
private fun uninstall(udid: String, bundleId: String) {
private fun uninstall(udid: String) {
val out = ByteArrayOutputStream()
project.exec {
it.workingDir = xcProject.toFile()
it.commandLine = listOf(idb, "uninstall", "--udid", udid, bundleId)
it.commandLine = listOf(idb, "uninstall", "--udid", udid, bundleID)
it.standardOutput = out
it.errorOutput = out
it.isIgnoreExitValue = true
@@ -476,12 +479,12 @@ private fun deviceLauncher(project: Project) = object : ExecutorService {
println(out.toString())
}
private fun startDebugServer(udid: String, bundleId: String): String {
private fun startDebugServer(udid: String): String {
val out = ByteArrayOutputStream()
val result = project.exec {
it.workingDir = xcProject.toFile()
it.commandLine = listOf(idb, "debugserver", "start", "--udid", udid, bundleId)
it.commandLine = listOf(idb, "debugserver", "start", "--udid", udid, bundleID)
it.standardOutput = out
it.errorOutput = out
it.isIgnoreExitValue = true
@@ -98,14 +98,14 @@ fun createJsonReport(projectProperties: Map<String, Any>): String {
val machine = Environment.Machine(getValue("cpu"), getValue("os"))
val jdk = Environment.JDKInstance(getValue("jdkVersion"), getValue("jdkVendor"))
val env = Environment(machine, jdk)
val flags = (projectProperties["flags"] ?: emptyList<String>()) as List<String>
val flags: List<String> = (projectProperties["flags"] as? List<*>)?.filterIsInstance<String>() ?: emptyList()
val backend = Compiler.Backend(Compiler.backendTypeFromString(getValue("type"))!! ,
getValue("compilerVersion"), flags)
val kotlin = Compiler(backend, getValue("kotlinVersion"))
val benchDesc = getValue("benchmarks")
val benchmarksArray = JsonTreeParser.parse(benchDesc)
val benchmarks = parseBenchmarksArray(benchmarksArray)
.union(projectProperties["compileTime"] as List<BenchmarkResult>).union(
.union((projectProperties["compileTime"] as? List<*>)?.filterIsInstance<BenchmarkResult>() ?: emptyList()).union(
listOf(projectProperties["codeSize"] as? BenchmarkResult).filterNotNull()).toList()
val report = BenchmarksReport(env, benchmarks, kotlin)
return report.toJson()
@@ -184,7 +184,6 @@ fun sendUploadRequest(url: String, fileName: String, username: String? = null, p
}
// A short-cut to add a Kotlin/Native run task.
@JvmOverloads
fun createRunTask(
subproject: Project,
name: String,
@@ -100,8 +100,7 @@ open class RegressionsReporter : DefaultTask() {
val teamcityConfig = System.getenv("TEAMCITY_BUILD_PROPERTIES_FILE") ?:
error("Can't load teamcity config!")
val buildProperties = Properties()
buildProperties.load(FileInputStream(teamcityConfig))
val buildProperties = Properties().apply { load(FileInputStream(teamcityConfig)) }
val buildId = buildProperties.getProperty("teamcity.build.id")
val buildTypeId = buildProperties.getProperty("teamcity.buildType.id")
val buildNumber = buildProperties.getProperty("build.number")
@@ -115,7 +114,7 @@ open class RegressionsReporter : DefaultTask() {
val testReportUrl = testReportUrl(buildId, buildTypeId)
// Get previous build on branch.
val builds = getBuild(previousBuildLocator(buildTypeId,branch), user, password)
getBuild(previousBuildLocator(buildTypeId,branch), user, password)
// Get changes description.
val changesList = getCommits("id:$buildId", user, password)
@@ -135,7 +134,7 @@ open class RegressionsReporter : DefaultTask() {
val target = System.getProperty("os.name").replace("\\s".toRegex(), "")
// Generate comparison report.
val output = arrayOf("$analyzer", "-r", "html", "$currentBenchmarksReportFile", "artifactory:$compareToBuildNumber:$target:$artifactoryFileName", "-o", "$htmlReport")
val output = arrayOf(analyzer, "-r", "html", currentBenchmarksReportFile, "artifactory:$compareToBuildNumber:$target:$artifactoryFileName", "-o", htmlReport)
.runCommand()
if (output.contains("Uncaught exception")) {
@@ -170,4 +169,4 @@ open class RegressionsReporter : DefaultTask() {
}
session.disconnect()
}
}
}
@@ -10,14 +10,14 @@ import kotlin.math.min
* Examples of numeric version strings: "12.4.1.2", "9", "0.5".
*/
private fun compareStringsAsVersions(version1: String, version2: String): Int {
val version1 = version1.split('.').map { it.toInt() }
val version2 = version2.split('.').map { it.toInt() }
val minimalLength = min(version1.size, version2.size)
val splitVersion1 = version1.split('.').map { it.toInt() }
val splitVersion2 = version2.split('.').map { it.toInt() }
val minimalLength = min(splitVersion1.size, splitVersion2.size)
for (index in 0 until minimalLength) {
if (version1[index] < version2[index]) return -1
if (version1[index] > version2[index]) return 1
if (splitVersion1[index] < splitVersion2[index]) return -1
if (splitVersion1[index] > splitVersion2[index]) return 1
}
return version1.size.compareTo(version2.size)
return splitVersion1.size.compareTo(splitVersion2.size)
}
/**
@@ -110,9 +110,7 @@ open class CompileBenchmarkingPlugin : Plugin<Project> {
private fun getCompilerFlags(benchmarkExtension: CompileBenchmarkExtension) =
benchmarkExtension.compilerOpts
private fun Project.configureJvmRun(
benchmarkExtension: CompileBenchmarkExtension
) {
private fun Project.configureJvmRun() {
val jvmRun = tasks.create("jvmRun") {
it.group = BenchmarkingPlugin.BENCHMARKING_GROUP
it.description = "Runs the compile only benchmark for Kotlin/JVM."
@@ -139,7 +137,7 @@ open class CompileBenchmarkingPlugin : Plugin<Project> {
// Create tasks.
configureUtilityTasks()
configureKonanRun(benchmarkExtension)
configureJvmRun(benchmarkExtension)
configureJvmRun()
}
companion object {
@@ -79,7 +79,7 @@ open class SwiftBenchmarkingPlugin : BenchmarkingPlugin() {
val nativeTarget = kotlin.targets.getByName(NATIVE_TARGET_NAME) as KotlinNativeTarget
// Build executable from swift code.
framework = nativeTarget.binaries.getFramework(nativeFrameworkName, benchmark.buildType)
val buildSwift = tasks.create("buildSwift") { task ->
tasks.create("buildSwift") { task ->
task.dependsOn(framework.linkTaskName)
task.doLast {
val frameworkParentDirPath = framework.outputDirectory.absolutePath
@@ -104,4 +104,4 @@ open class SwiftBenchmarkingPlugin : BenchmarkingPlugin() {
} else {
listOf("-O", "-wmo")
}
}
}
@@ -35,7 +35,7 @@ open class CompileToBitcodePlugin: Plugin<Project> {
open class CompileToBitcodeExtension @Inject constructor(val project: Project) {
private val targetList = with(project) {
provider { rootProject.property("targetList") as List<String> } // TODO: Can we make it better?
provider { (rootProject.property("targetList") as? List<*>)?.filterIsInstance<String>() ?: emptyList() } // TODO: Can we make it better?
}
fun create(