tools: Don't use Distribution class in helpers

This commit is contained in:
Ilya Matveev
2017-03-29 10:47:06 +07:00
committed by ilmat192
parent d4ced1ba9b
commit 6dea5e5c79
7 changed files with 46 additions and 54 deletions
@@ -117,11 +117,11 @@ private fun runCmd(command: Array<String>, workDir: File, verbose: Boolean = fal
.runExpectingSuccess()
}
private fun maybeExecuteHelper(dependenciesRoot: String, propertiesFile: String, dependencies: List<String>) {
private fun maybeExecuteHelper(dependenciesRoot: String, properties: Properties, dependencies: List<String>) {
try {
val kClass = Class.forName("org.jetbrains.kotlin.konan.InteropHelper0").kotlin
val kClass = Class.forName("org.jetbrains.kotlin.konan.Helper0").kotlin
val ctor = kClass.constructors.single() as KFunction<Runnable>
val result = ctor.call(dependenciesRoot, propertiesFile, dependencies)
val result = ctor.call(dependenciesRoot, properties, dependencies)
result.run()
} catch (notFound: ClassNotFoundException) {
// Just ignore, no helper.
@@ -130,7 +130,7 @@ private fun maybeExecuteHelper(dependenciesRoot: String, propertiesFile: String,
}
}
private fun Properties.defaultCompilerOpts(target: String, dependencies: String, konanFileName: String): List<String> {
private fun Properties.defaultCompilerOpts(target: String, dependencies: String): List<String> {
val hostSysRootDir = this.getOsSpecific("sysRoot", target)!!
val hostSysRoot = "$dependencies/$hostSysRootDir"
@@ -142,7 +142,7 @@ private fun Properties.defaultCompilerOpts(target: String, dependencies: String,
val llvmVersion = this.getProperty("llvmVersion")!!
val dependencyList = getOsSpecific("dependencies", target)?.split(' ') ?: listOf<String>()
maybeExecuteHelper(dependencies, konanFileName, dependencyList)
maybeExecuteHelper(dependencies, this, dependencyList)
// StubGenerator passes the arguments to libclang which
// works not exactly the same way as the clang binary and
@@ -259,7 +259,7 @@ private fun processLib(konanHome: String,
val generateShims = args["-shims"].isTrue()
val verbose = args["-verbose"].isTrue()
val defaultOpts = konanProperties.defaultCompilerOpts(target, dependencies, konanFileName)
val defaultOpts = konanProperties.defaultCompilerOpts(target, dependencies)
val headerFiles = config.getSpaceSeparated("headers") + additionalHeaders
val compilerOpts =
config.getSpaceSeparated("compilerOpts") +
@@ -13,13 +13,17 @@ import org.jetbrains.kotlin.config.addKotlinSourceRoots
import java.util.*
import kotlin.reflect.KFunction
// TODO: Don't use reflection?
private fun maybeExecuteHelper(configuration: CompilerConfiguration) {
try {
val kClass = Class.forName("org.jetbrains.kotlin.konan.CompilerHelper0").kotlin
val kClass = Class.forName("org.jetbrains.kotlin.konan.Helper0").kotlin
val ctor = kClass.constructors.single() as KFunction<Runnable>
val distribution = Distribution(configuration)
val result = ctor.call(distribution)
val result = ctor.call(
distribution.dependenciesDir,
distribution.properties.properties,
distribution.dependencies
)
result.run()
} catch (notFound: ClassNotFoundException) {
// Just ignore, no helper.
@@ -4,24 +4,13 @@
//
package org.jetbrains.kotlin.konan
import org.jetbrains.kotlin.backend.konan.Distribution
import org.jetbrains.kotlin.backend.konan.TargetManager
import java.util.*
// Name it CompilerHelper0 so that it get loaded.
class CompilerHelper0Disabled(val distribution: Distribution) : Runnable {
class Helper0Disabled(val dependenciesDir: String,
val properties: Properties,
val dependencies: List<String>) : Runnable {
override fun run() {
println("Running helper with ${distribution.konanHome} ${distribution.target} ${TargetManager.host}")
}
}
//
// Example startup helper for Kotlin N stub generator. Compile to JAR and add it to
// Kotlin N classpath - it will get loaded and executed automatically.
//
// Name it InteropHelper0 so that it get loaded.
class InteropHelper0Disabled(val dependenciesRoot: String, val dependencies: List<String>) : Runnable {
override fun run() {
println("Running helper with $dependenciesRoot $dependencies")
println("Running helper for $dependenciesDir, $properties, $dependencies")
}
}
+15 -1
View File
@@ -15,12 +15,24 @@ buildscript {
}
}
// Copied from backend.native project. =====
repositories {
maven {
url 'http://oss.sonatype.org/content/repositories/snapshots'
}
}
configurations.all {
// kotlin-compiler module includes Kotlin runtime bundled;
// make Gradle aware of this to avoid multiple Kotlin runtimes in classpath:
resolutionStrategy.dependencySubstitution {
substitute module('org.jetbrains.kotlin:kotlin-runtime') with module(kotlinCompilerModule)
substitute module('org.jetbrains.kotlin:kotlin-stdlib') with module(kotlinCompilerModule)
substitute module('org.jetbrains.kotlin:kotlin-reflect') with module(kotlinCompilerModule)
}
}
// =========================================
apply plugin: 'kotlin'
apply plugin: NativeInteropPlugin
@@ -29,8 +41,10 @@ configurations {
}
dependencies {
compile project(path: ':backend.native', configuration: 'cli_bc')
compile "org.jetbrains.kotlin:kotlin-runtime:$kotlin_version"
// We need this configuration to test the helpers.
cli_bc jar.outputs.files
cli_bc project(path: ':backend.native', configuration: 'cli_bc')
}
sourceSets {
@@ -1,11 +0,0 @@
package org.jetbrains.kotlin.konan
import org.jetbrains.kotlin.backend.konan.Distribution
import java.io.File
class CompilerHelper0(val dist: Distribution): Runnable {
override fun run() {
DependencyDownloader(File(dist.dependenciesDir), dist.properties.properties, dist.dependencies).run()
}
}
+13
View File
@@ -0,0 +1,13 @@
package org.jetbrains.kotlin.konan
import java.io.File
import java.util.*
class Helper0(val dependenciesDir: String,
val properties: Properties,
val dependencies: List<String>): Runnable {
override fun run() {
DependencyDownloader(File(dependenciesDir), properties, dependencies).run()
}
}
@@ -1,17 +0,0 @@
package org.jetbrains.kotlin.konan
import java.io.File
import java.util.*
class InteropHelper0(
val dependenciesRoot: String,
val propertiesFile: String,
val dependencies: List<String>): Runnable {
override fun run() =
DependencyDownloader(
File(dependenciesRoot),
Properties().apply { load(File(propertiesFile).inputStream()) },
dependencies
).run()
}