Get rid of konan.home in the compiler
This patch uses a path to a jar containing compiler classes to determine the distribution path instead of relying on the konan.home system property. However this property still may be used to specify the distribution path e.g. when the distribution isn't fully built and the compiler is executed from classes located in a build directory.
This commit is contained in:
committed by
Ilya Matveev
parent
f959f275e8
commit
cc631f1f99
@@ -66,6 +66,7 @@ repositories {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
compile project(":utilities:basic-utils")
|
||||||
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
|
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
|
||||||
compile "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion"
|
compile "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package kotlinx.cinterop
|
package kotlinx.cinterop
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.konan.util.KonanHomeProvider
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.nio.file.Files
|
import java.nio.file.Files
|
||||||
import java.nio.file.Paths
|
import java.nio.file.Paths
|
||||||
@@ -93,7 +94,7 @@ fun loadKonanLibrary(name: String) {
|
|||||||
System.loadLibrary(name)
|
System.loadLibrary(name)
|
||||||
} catch (e: UnsatisfiedLinkError) {
|
} catch (e: UnsatisfiedLinkError) {
|
||||||
val fullLibraryName = System.mapLibraryName(name)
|
val fullLibraryName = System.mapLibraryName(name)
|
||||||
val dir = "${System.getProperty("konan.home")}/konan/nativelib"
|
val dir = "${KonanHomeProvider.determineKonanHome()}/konan/nativelib"
|
||||||
try {
|
try {
|
||||||
System.load("$dir/$fullLibraryName")
|
System.load("$dir/$fullLibraryName")
|
||||||
} catch (e: UnsatisfiedLinkError) {
|
} catch (e: UnsatisfiedLinkError) {
|
||||||
|
|||||||
@@ -30,16 +30,18 @@ repositories {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
|
implementation project(":Interop:Indexer")
|
||||||
compile "org.jetbrains.kotlin:kotlin-compiler:$kotlinVersion"
|
implementation project(":utilities:basic-utils")
|
||||||
compile project(':Interop:Indexer')
|
api project(path: ":endorsedLibraries:kotlinx.cli", configuration: "jvmRuntimeElements")
|
||||||
compile "org.jetbrains.kotlin:kotlin-native-shared:$konanVersion"
|
|
||||||
compile project(path: ":endorsedLibraries:kotlinx.cli", configuration: "jvmRuntimeElements")
|
|
||||||
compile "org.jetbrains.kotlinx:kotlinx-metadata-klib:0.0.1-dev-5"
|
|
||||||
|
|
||||||
testCompile "junit:junit:4.12"
|
api "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
|
||||||
testCompile "org.jetbrains.kotlin:kotlin-test-junit:$buildKotlinVersion"
|
api "org.jetbrains.kotlin:kotlin-compiler:$kotlinVersion"
|
||||||
testCompile "org.jetbrains.kotlin:kotlin-test:$buildKotlinVersion"
|
api "org.jetbrains.kotlin:kotlin-native-shared:$konanVersion"
|
||||||
|
api "org.jetbrains.kotlinx:kotlinx-metadata-klib:0.0.1-dev-5"
|
||||||
|
|
||||||
|
testImplementation "junit:junit:4.12"
|
||||||
|
testImplementation "org.jetbrains.kotlin:kotlin-test-junit:$buildKotlinVersion"
|
||||||
|
testImplementation "org.jetbrains.kotlin:kotlin-test:$buildKotlinVersion"
|
||||||
}
|
}
|
||||||
|
|
||||||
compileKotlin {
|
compileKotlin {
|
||||||
|
|||||||
+2
-1
@@ -20,12 +20,13 @@ import org.jetbrains.kotlin.konan.target.HostManager
|
|||||||
import org.jetbrains.kotlin.konan.target.KonanTarget
|
import org.jetbrains.kotlin.konan.target.KonanTarget
|
||||||
import org.jetbrains.kotlin.konan.target.PlatformManager
|
import org.jetbrains.kotlin.konan.target.PlatformManager
|
||||||
import org.jetbrains.kotlin.konan.target.customerDistribution
|
import org.jetbrains.kotlin.konan.target.customerDistribution
|
||||||
|
import org.jetbrains.kotlin.konan.util.KonanHomeProvider
|
||||||
import org.jetbrains.kotlin.konan.util.defaultTargetSubstitutions
|
import org.jetbrains.kotlin.konan.util.defaultTargetSubstitutions
|
||||||
import org.jetbrains.kotlin.native.interop.gen.jvm.KotlinPlatform
|
import org.jetbrains.kotlin.native.interop.gen.jvm.KotlinPlatform
|
||||||
|
|
||||||
class ToolConfig(userProvidedTargetName: String?, flavor: KotlinPlatform) {
|
class ToolConfig(userProvidedTargetName: String?, flavor: KotlinPlatform) {
|
||||||
|
|
||||||
private val konanHome = System.getProperty("konan.home")
|
private val konanHome = KonanHomeProvider.determineKonanHome()
|
||||||
private val distribution = customerDistribution(konanHome)
|
private val distribution = customerDistribution(konanHome)
|
||||||
private val platformManager = PlatformManager(distribution)
|
private val platformManager = PlatformManager(distribution)
|
||||||
private val targetManager = platformManager.targetManager(userProvidedTargetName)
|
private val targetManager = platformManager.targetManager(userProvidedTargetName)
|
||||||
|
|||||||
+2
-1
@@ -31,6 +31,7 @@ import org.jetbrains.kotlin.konan.library.*
|
|||||||
import org.jetbrains.kotlin.konan.target.CompilerOutputKind
|
import org.jetbrains.kotlin.konan.target.CompilerOutputKind
|
||||||
import org.jetbrains.kotlin.konan.target.Distribution
|
import org.jetbrains.kotlin.konan.target.Distribution
|
||||||
import org.jetbrains.kotlin.konan.target.KonanTarget
|
import org.jetbrains.kotlin.konan.target.KonanTarget
|
||||||
|
import org.jetbrains.kotlin.konan.util.KonanHomeProvider
|
||||||
import org.jetbrains.kotlin.library.KotlinLibrary
|
import org.jetbrains.kotlin.library.KotlinLibrary
|
||||||
import org.jetbrains.kotlin.library.packageFqName
|
import org.jetbrains.kotlin.library.packageFqName
|
||||||
import org.jetbrains.kotlin.library.resolver.impl.KotlinLibraryResolverImpl
|
import org.jetbrains.kotlin.library.resolver.impl.KotlinLibraryResolverImpl
|
||||||
@@ -406,7 +407,7 @@ private fun getLibraryResolver(
|
|||||||
repos,
|
repos,
|
||||||
libraries.filter { it.contains(org.jetbrains.kotlin.konan.file.File.separator) },
|
libraries.filter { it.contains(org.jetbrains.kotlin.konan.file.File.separator) },
|
||||||
target,
|
target,
|
||||||
Distribution()
|
Distribution(KonanHomeProvider.determineKonanHome())
|
||||||
).libraryResolver()
|
).libraryResolver()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -153,6 +153,8 @@ dependencies {
|
|||||||
kotlinCommonSources(it) { transitive = false }
|
kotlinCommonSources(it) { transitive = false }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
compilerCompile project(":utilities:basic-utils")
|
||||||
|
|
||||||
compilerCompile "com.google.protobuf:protobuf-java:${protobufVersion}"
|
compilerCompile "com.google.protobuf:protobuf-java:${protobufVersion}"
|
||||||
|
|
||||||
compilerCompile kotlinCompilerModule
|
compilerCompile kotlinCompilerModule
|
||||||
@@ -192,12 +194,10 @@ final List<File> stdLibSrc = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
// These files are built before the 'dist' is complete,
|
// These files are built before the 'dist' is complete,
|
||||||
// so we provide custom values for konan.home, --runtime etc
|
// so we provide a custom value for --runtime
|
||||||
|
|
||||||
targetList.each { target ->
|
targetList.each { target ->
|
||||||
def konanJvmArgs = [*HostManager.regularJvmArgs,
|
def konanJvmArgs = [*HostManager.regularJvmArgs]
|
||||||
"-Dkonan.home=${rootProject.projectDir}/dist"
|
|
||||||
]
|
|
||||||
|
|
||||||
def defaultArgs = ['-nopack', '-nostdlib', '-no-default-libs', '-no-endorsed-libs']
|
def defaultArgs = ['-nopack', '-nostdlib', '-no-default-libs', '-no-endorsed-libs']
|
||||||
if (target != "wasm32") defaultArgs += '-g'
|
if (target != "wasm32") defaultArgs += '-g'
|
||||||
@@ -208,7 +208,10 @@ targetList.each { target ->
|
|||||||
|
|
||||||
task("${target}Stdlib", type: JavaExec) {
|
task("${target}Stdlib", type: JavaExec) {
|
||||||
main = 'org.jetbrains.kotlin.cli.bc.K2NativeKt'
|
main = 'org.jetbrains.kotlin.cli.bc.K2NativeKt'
|
||||||
classpath = project.configurations.cli_bc
|
// This task depends on distCompiler, so the compiler jar is already in the dist directory.
|
||||||
|
classpath = fileTree("${rootProject.projectDir}/dist/konan/lib") {
|
||||||
|
include "*.jar"
|
||||||
|
}
|
||||||
jvmArgs = konanJvmArgs
|
jvmArgs = konanJvmArgs
|
||||||
args = [*konanArgs,
|
args = [*konanArgs,
|
||||||
'-output', project(':runtime').file("build/${target}Stdlib"),
|
'-output', project(':runtime').file("build/${target}Stdlib"),
|
||||||
|
|||||||
@@ -113,6 +113,7 @@ class K2Native : CLICompiler<K2NativeCompilerArguments>() {
|
|||||||
|
|
||||||
with(KonanConfigKeys) {
|
with(KonanConfigKeys) {
|
||||||
with(configuration) {
|
with(configuration) {
|
||||||
|
arguments.kotlinHome?.let { put(KONAN_HOME, it) }
|
||||||
|
|
||||||
put(NODEFAULTLIBS, arguments.nodefaultlibs || !arguments.libraryToAddToCache.isNullOrEmpty())
|
put(NODEFAULTLIBS, arguments.nodefaultlibs || !arguments.libraryToAddToCache.isNullOrEmpty())
|
||||||
put(NOENDORSEDLIBS, arguments.noendorsedlibs || !arguments.libraryToAddToCache.isNullOrEmpty())
|
put(NOENDORSEDLIBS, arguments.noendorsedlibs || !arguments.libraryToAddToCache.isNullOrEmpty())
|
||||||
|
|||||||
+5
-3
@@ -20,15 +20,17 @@ import org.jetbrains.kotlin.konan.file.File
|
|||||||
import org.jetbrains.kotlin.konan.library.KonanLibrary
|
import org.jetbrains.kotlin.konan.library.KonanLibrary
|
||||||
import org.jetbrains.kotlin.konan.properties.loadProperties
|
import org.jetbrains.kotlin.konan.properties.loadProperties
|
||||||
import org.jetbrains.kotlin.konan.target.*
|
import org.jetbrains.kotlin.konan.target.*
|
||||||
|
import org.jetbrains.kotlin.konan.util.KonanHomeProvider
|
||||||
import org.jetbrains.kotlin.library.KotlinLibrary
|
import org.jetbrains.kotlin.library.KotlinLibrary
|
||||||
import org.jetbrains.kotlin.library.resolver.TopologicalLibraryOrder
|
import org.jetbrains.kotlin.library.resolver.TopologicalLibraryOrder
|
||||||
|
|
||||||
class KonanConfig(val project: Project, val configuration: CompilerConfiguration) {
|
class KonanConfig(val project: Project, val configuration: CompilerConfiguration) {
|
||||||
|
|
||||||
internal val distribution = Distribution(
|
internal val distribution = Distribution(
|
||||||
false,
|
configuration.get(KonanConfigKeys.KONAN_HOME) ?: KonanHomeProvider.determineKonanHome(),
|
||||||
null,
|
false,
|
||||||
configuration.get(KonanConfigKeys.RUNTIME_FILE))
|
configuration.get(KonanConfigKeys.RUNTIME_FILE)
|
||||||
|
)
|
||||||
|
|
||||||
internal val platformManager = PlatformManager(distribution)
|
internal val platformManager = PlatformManager(distribution)
|
||||||
internal val targetManager = platformManager.targetManager(configuration.get(KonanConfigKeys.TARGET))
|
internal val targetManager = platformManager.targetManager(configuration.get(KonanConfigKeys.TARGET))
|
||||||
|
|||||||
+2
@@ -48,6 +48,8 @@ class KonanConfigKeys {
|
|||||||
= CompilerConfigurationKey.create("generate test runner")
|
= CompilerConfigurationKey.create("generate test runner")
|
||||||
val INCLUDED_BINARY_FILES: CompilerConfigurationKey<List<String>>
|
val INCLUDED_BINARY_FILES: CompilerConfigurationKey<List<String>>
|
||||||
= CompilerConfigurationKey.create("included binary file paths")
|
= CompilerConfigurationKey.create("included binary file paths")
|
||||||
|
val KONAN_HOME: CompilerConfigurationKey<String>
|
||||||
|
= CompilerConfigurationKey.create("overridden compiler distribution path")
|
||||||
val LIBRARY_FILES: CompilerConfigurationKey<List<String>>
|
val LIBRARY_FILES: CompilerConfigurationKey<List<String>>
|
||||||
= CompilerConfigurationKey.create("library file paths")
|
= CompilerConfigurationKey.create("library file paths")
|
||||||
val LIBRARY_VERSION: CompilerConfigurationKey<String?>
|
val LIBRARY_VERSION: CompilerConfigurationKey<String?>
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ class RunExternalTestGroup extends JavaExec {
|
|||||||
classpath = project.fileTree("$dist.canonicalPath/konan/lib/") {
|
classpath = project.fileTree("$dist.canonicalPath/konan/lib/") {
|
||||||
include '*.jar'
|
include '*.jar'
|
||||||
}
|
}
|
||||||
jvmArgs "-Dkonan.home=${dist.canonicalPath}", "-Xmx4G"
|
jvmArgs "-Xmx4G"
|
||||||
enableAssertions = true
|
enableAssertions = true
|
||||||
def sources = File.createTempFile(name,".lst")
|
def sources = File.createTempFile(name,".lst")
|
||||||
sources.deleteOnExit()
|
sources.deleteOnExit()
|
||||||
|
|||||||
@@ -204,6 +204,8 @@ class NamedNativeInteropConfig implements Named {
|
|||||||
new File(project.findProject(":Interop:Indexer").buildDir, "nativelibs"),
|
new File(project.findProject(":Interop:Indexer").buildDir, "nativelibs"),
|
||||||
new File(project.findProject(":Interop:Runtime").buildDir, "nativelibs")
|
new File(project.findProject(":Interop:Runtime").buildDir, "nativelibs")
|
||||||
).asPath
|
).asPath
|
||||||
|
// Set the konan.home property because we run the cinterop tool not from a distribution jar
|
||||||
|
// so it will not be able to determine this path by itself.
|
||||||
systemProperties "konan.home": project.rootProject.projectDir
|
systemProperties "konan.home": project.rootProject.projectDir
|
||||||
environment "LIBCLANG_DISABLE_CRASH_RECOVERY": "1"
|
environment "LIBCLANG_DISABLE_CRASH_RECOVERY": "1"
|
||||||
|
|
||||||
|
|||||||
@@ -62,12 +62,9 @@ findHome() {
|
|||||||
}
|
}
|
||||||
KONAN_HOME="$(findHome)"
|
KONAN_HOME="$(findHome)"
|
||||||
|
|
||||||
NATIVE_LIB="${KONAN_HOME}/konan/nativelib"
|
|
||||||
|
|
||||||
java_opts=(-ea \
|
java_opts=(-ea \
|
||||||
-Xmx3G \
|
-Xmx3G \
|
||||||
-XX:TieredStopAtLevel=1 \
|
-XX:TieredStopAtLevel=1 \
|
||||||
"-Dkonan.home=${KONAN_HOME}" \
|
|
||||||
-Dfile.encoding=UTF-8 \
|
-Dfile.encoding=UTF-8 \
|
||||||
${JAVA_OPTS})
|
${JAVA_OPTS})
|
||||||
|
|
||||||
|
|||||||
@@ -51,7 +51,6 @@ if not "!ARG!" == "" (
|
|||||||
goto again
|
goto again
|
||||||
)
|
)
|
||||||
|
|
||||||
set "NATIVE_LIB=%_KONAN_HOME%\konan\nativelib"
|
|
||||||
set "KONAN_LIB=%_KONAN_HOME%\konan\lib"
|
set "KONAN_LIB=%_KONAN_HOME%\konan\lib"
|
||||||
|
|
||||||
set "KONAN_JAR=%KONAN_LIB%\kotlin-native.jar"
|
set "KONAN_JAR=%KONAN_LIB%\kotlin-native.jar"
|
||||||
@@ -62,7 +61,6 @@ set "KONAN_CLASSPATH=%KONAN_JAR%;%TROVE_JAR%"
|
|||||||
set JAVA_OPTS=-ea ^
|
set JAVA_OPTS=-ea ^
|
||||||
-Xmx3G ^
|
-Xmx3G ^
|
||||||
-XX:TieredStopAtLevel=1 ^
|
-XX:TieredStopAtLevel=1 ^
|
||||||
"-Dkonan.home=%_KONAN_HOME%" ^
|
|
||||||
-Dfile.encoding=UTF-8 ^
|
-Dfile.encoding=UTF-8 ^
|
||||||
%JAVA_OPTS%
|
%JAVA_OPTS%
|
||||||
|
|
||||||
|
|||||||
@@ -20,9 +20,7 @@ inline fun <reified T: AbstractArchiveTask> createLlvmPackingTask(
|
|||||||
blacklist: File?,
|
blacklist: File?,
|
||||||
crossinline additionalConfiguration: T.() -> Unit
|
crossinline additionalConfiguration: T.() -> Unit
|
||||||
) {
|
) {
|
||||||
val distribution = Distribution(
|
val distribution = Distribution(rootProject.projectDir.absolutePath)
|
||||||
konanHomeOverride = rootProject.projectDir.absolutePath
|
|
||||||
)
|
|
||||||
val reducedLlvmAppendix = distribution.properties
|
val reducedLlvmAppendix = distribution.properties
|
||||||
.getProperty("reducedLlvmAppendix")
|
.getProperty("reducedLlvmAppendix")
|
||||||
val propertiesLoader = object : KonanPropertiesLoader(
|
val propertiesLoader = object : KonanPropertiesLoader(
|
||||||
|
|||||||
@@ -72,9 +72,7 @@ def commonSrc = new File("$projectDir/src/main/kotlin")
|
|||||||
def nativeSrc = new File("$projectDir/src/main/kotlin-native")
|
def nativeSrc = new File("$projectDir/src/main/kotlin-native")
|
||||||
|
|
||||||
targetList.each { target ->
|
targetList.each { target ->
|
||||||
def konanJvmArgs = [*HostManager.regularJvmArgs,
|
def konanJvmArgs = [*HostManager.regularJvmArgs]
|
||||||
"-Dkonan.home=${rootProject.projectDir}/dist",
|
|
||||||
]
|
|
||||||
|
|
||||||
def defaultArgs = ['-nopack', '-no-default-libs', '-no-endorsed-libs']
|
def defaultArgs = ['-nopack', '-no-default-libs', '-no-endorsed-libs']
|
||||||
if (target != "wasm32") defaultArgs += '-g'
|
if (target != "wasm32") defaultArgs += '-g'
|
||||||
@@ -88,10 +86,14 @@ targetList.each { target ->
|
|||||||
// See :endorsedLibraries.ext for full endorsedLibraries list.
|
// See :endorsedLibraries.ext for full endorsedLibraries list.
|
||||||
def moduleName = endorsedLibraries[project].name
|
def moduleName = endorsedLibraries[project].name
|
||||||
|
|
||||||
|
dependsOn ":distCompiler"
|
||||||
dependsOn ":${target}CrossDistRuntime"
|
dependsOn ":${target}CrossDistRuntime"
|
||||||
|
|
||||||
main = 'org.jetbrains.kotlin.cli.bc.K2NativeKt'
|
main = 'org.jetbrains.kotlin.cli.bc.K2NativeKt'
|
||||||
classpath = project(":backend.native").configurations.cli_bc
|
// This task depends on distCompiler, so the compiler jar is already in the dist directory.
|
||||||
|
classpath = fileTree("${rootProject.projectDir}/dist/konan/lib") {
|
||||||
|
include "*.jar"
|
||||||
|
}
|
||||||
jvmArgs = konanJvmArgs
|
jvmArgs = konanJvmArgs
|
||||||
args = [*konanArgs,
|
args = [*konanArgs,
|
||||||
'-output', outputFile,
|
'-output', outputFile,
|
||||||
|
|||||||
+7
-5
@@ -41,15 +41,17 @@ repositories {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
|
||||||
compile project(path: ':backend.native', configuration: 'cli_bc')
|
implementation project(path: ':backend.native', configuration: 'cli_bc')
|
||||||
testCompile "junit:junit:4.12"
|
implementation project(":utilities:basic-utils")
|
||||||
testCompile "org.jetbrains.kotlin:kotlin-test-junit:$buildKotlinVersion"
|
testImplementation "junit:junit:4.12"
|
||||||
testCompile "org.jetbrains.kotlin:kotlin-test:$buildKotlinVersion"
|
testImplementation "org.jetbrains.kotlin:kotlin-test-junit:$buildKotlinVersion"
|
||||||
|
testImplementation "org.jetbrains.kotlin:kotlin-test:$buildKotlinVersion"
|
||||||
}
|
}
|
||||||
|
|
||||||
test {
|
test {
|
||||||
dependsOn 'cleanTest'
|
dependsOn 'cleanTest'
|
||||||
|
// Specify a path to the distribution that is used in the tests.
|
||||||
systemProperty('konan.home', getProperty("org.jetbrains.kotlin.native.home"))
|
systemProperty('konan.home', getProperty("org.jetbrains.kotlin.native.home"))
|
||||||
dependsOn konanArtifacts.collect { it.getByTarget('host') }
|
dependsOn konanArtifacts.collect { it.getByTarget('host') }
|
||||||
if (useCustomDist) {
|
if (useCustomDist) {
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import org.jetbrains.kotlin.util.Logger
|
|||||||
import org.jetbrains.kotlin.library.metadata.KlibMetadataProtoBuf
|
import org.jetbrains.kotlin.library.metadata.KlibMetadataProtoBuf
|
||||||
import org.jetbrains.kotlin.konan.library.KonanLibrary
|
import org.jetbrains.kotlin.konan.library.KonanLibrary
|
||||||
import org.jetbrains.kotlin.konan.library.resolverByName
|
import org.jetbrains.kotlin.konan.library.resolverByName
|
||||||
|
import org.jetbrains.kotlin.konan.util.KonanHomeProvider
|
||||||
import org.jetbrains.kotlin.library.metadata.parseModuleHeader
|
import org.jetbrains.kotlin.library.metadata.parseModuleHeader
|
||||||
import org.jetbrains.kotlin.storage.LockBasedStorageManager
|
import org.jetbrains.kotlin.storage.LockBasedStorageManager
|
||||||
import java.lang.System.out
|
import java.lang.System.out
|
||||||
@@ -170,7 +171,7 @@ class Library(val name: String, val requestedRepository: String?, val target: St
|
|||||||
if (!module.isNativeStdlib()) {
|
if (!module.isNativeStdlib()) {
|
||||||
val resolver = resolverByName(
|
val resolver = resolverByName(
|
||||||
emptyList(),
|
emptyList(),
|
||||||
distributionKlib = Distribution().klib,
|
distributionKlib = Distribution(KonanHomeProvider.determineKonanHome()).klib,
|
||||||
skipCurrentDir = true,
|
skipCurrentDir = true,
|
||||||
logger = KlibToolLogger)
|
logger = KlibToolLogger)
|
||||||
resolver.defaultLinks(false, true, true)
|
resolver.defaultLinks(false, true, true)
|
||||||
@@ -202,7 +203,8 @@ fun libraryInRepoOrCurrentDir(repository: File, name: String) =
|
|||||||
fun main(args: Array<String>) {
|
fun main(args: Array<String>) {
|
||||||
val command = Command(args)
|
val command = Command(args)
|
||||||
|
|
||||||
val targetManager = PlatformManager().targetManager(command.options["-target"]?.last())
|
val targetManager = PlatformManager(KonanHomeProvider.determineKonanHome())
|
||||||
|
.targetManager(command.options["-target"]?.last())
|
||||||
val target = targetManager.targetName
|
val target = targetManager.targetName
|
||||||
|
|
||||||
val repository = command.options["-repository"]?.last()
|
val repository = command.options["-repository"]?.last()
|
||||||
|
|||||||
@@ -33,7 +33,8 @@ class ContentsTest {
|
|||||||
@Test
|
@Test
|
||||||
fun `Stdlib content should be printed without exceptions`() {
|
fun `Stdlib content should be printed without exceptions`() {
|
||||||
val output = StringBuilder()
|
val output = StringBuilder()
|
||||||
Library(Distribution().stdlib, null, "host").contents(output)
|
val distributionPath = System.getProperty("konan.home")
|
||||||
|
Library(Distribution(distributionPath).stdlib, null, "host").contents(output)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -357,6 +358,6 @@ class ContentsTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val LIBRARY_DIRECTORY = Paths.get("build/konan/libs").resolve( HostManager.hostName)
|
val LIBRARY_DIRECTORY = Paths.get("build/konan/libs").resolve(HostManager.hostName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -21,7 +21,7 @@ dependenciesUrl = https://download.jetbrains.com/kotlin/native
|
|||||||
dependencyProfiles = default alt
|
dependencyProfiles = default alt
|
||||||
|
|
||||||
# Don't check dependencies on a server.
|
# Don't check dependencies on a server.
|
||||||
# If true, dependency downloader will throw an exception if a dependency isn't found in konan.home.
|
# If true, dependency downloader will throw an exception if a dependency isn't found in $KONAN_DATA_DIR/dependencies
|
||||||
airplaneMode = false
|
airplaneMode = false
|
||||||
# if true, ignores Xcode version check.
|
# if true, ignores Xcode version check.
|
||||||
ignoreXcodeVersionCheck = false
|
ignoreXcodeVersionCheck = false
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ interface SearchPathResolverWithTarget<L: KotlinLibrary>: SearchPathResolverWith
|
|||||||
fun defaultResolver(
|
fun defaultResolver(
|
||||||
repositories: List<String>,
|
repositories: List<String>,
|
||||||
target: KonanTarget,
|
target: KonanTarget,
|
||||||
distribution: Distribution = Distribution(),
|
distribution: Distribution,
|
||||||
compatibleCompilerVersions: List<CompilerVersion> = emptyList()
|
compatibleCompilerVersions: List<CompilerVersion> = emptyList()
|
||||||
): SearchPathResolverWithTarget<KonanLibrary> = defaultResolver(repositories, emptyList(), target, distribution, compatibleCompilerVersions)
|
): SearchPathResolverWithTarget<KonanLibrary> = defaultResolver(repositories, emptyList(), target, distribution, compatibleCompilerVersions)
|
||||||
|
|
||||||
|
|||||||
@@ -29,9 +29,11 @@ class Platform(val configurables: Configurables)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class PlatformManager(distribution: Distribution = Distribution(), experimental: Boolean = false) :
|
class PlatformManager(private val distribution: Distribution, experimental: Boolean = false) :
|
||||||
HostManager(distribution, experimental) {
|
HostManager(distribution, experimental) {
|
||||||
|
|
||||||
|
constructor(konanHome: String, experimental: Boolean = false): this(Distribution(konanHome), experimental)
|
||||||
|
|
||||||
private val loaders = filteredOutEnabledButNotSupported.map {
|
private val loaders = filteredOutEnabledButNotSupported.map {
|
||||||
it to loadConfigurables(it, distribution.properties, DependencyProcessor.defaultDependenciesRoot.absolutePath)
|
it to loadConfigurables(it, distribution.properties, DependencyProcessor.defaultDependenciesRoot.absolutePath)
|
||||||
}.toMap()
|
}.toMap()
|
||||||
|
|||||||
+1
-1
@@ -155,7 +155,7 @@ open class KonanLibrariesSpec(
|
|||||||
defaultResolver(
|
defaultResolver(
|
||||||
repos.map { it.absolutePath },
|
repos.map { it.absolutePath },
|
||||||
task.konanTarget,
|
task.konanTarget,
|
||||||
Distribution(konanHomeOverride = project.konanHome)
|
Distribution(project.konanHome)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -345,7 +345,7 @@ class KonanPlugin @Inject constructor(private val registry: ToolingModelBuilderR
|
|||||||
|
|
||||||
project.warnAboutDeprecatedProperty(ProjectProperty.KONAN_HOME)
|
project.warnAboutDeprecatedProperty(ProjectProperty.KONAN_HOME)
|
||||||
|
|
||||||
// Set additional project properties like konan.home, konan.build.targets etc.
|
// Set additional project properties like org.jetbrains.kotlin.native.home, konan.build.targets etc.
|
||||||
if (!project.hasProperty(ProjectProperty.KONAN_HOME)) {
|
if (!project.hasProperty(ProjectProperty.KONAN_HOME)) {
|
||||||
project.setProperty(ProjectProperty.KONAN_HOME, project.konanCompilerDownloadDir())
|
project.setProperty(ProjectProperty.KONAN_HOME, project.konanCompilerDownloadDir())
|
||||||
project.setProperty(ProjectProperty.DOWNLOAD_COMPILER, true)
|
project.setProperty(ProjectProperty.DOWNLOAD_COMPILER, true)
|
||||||
|
|||||||
-6
@@ -30,7 +30,6 @@ internal interface KonanToolRunner: Named {
|
|||||||
val classpath: FileCollection
|
val classpath: FileCollection
|
||||||
val jvmArgs: List<String>
|
val jvmArgs: List<String>
|
||||||
val environment: Map<String, Any>
|
val environment: Map<String, Any>
|
||||||
val additionalSystemProperties: Map<String, String>
|
|
||||||
|
|
||||||
fun run(args: List<String>)
|
fun run(args: List<String>)
|
||||||
fun run(vararg args: String) = run(args.toList())
|
fun run(vararg args: String) = run(args.toList())
|
||||||
@@ -70,10 +69,6 @@ internal abstract class KonanCliRunner(
|
|||||||
addAll(project.jvmArgs)
|
addAll(project.jvmArgs)
|
||||||
}
|
}
|
||||||
|
|
||||||
override val additionalSystemProperties = mutableMapOf(
|
|
||||||
"konan.home" to konanHome
|
|
||||||
)
|
|
||||||
|
|
||||||
override val environment = mutableMapOf("LIBCLANG_DISABLE_CRASH_RECOVERY" to "1")
|
override val environment = mutableMapOf("LIBCLANG_DISABLE_CRASH_RECOVERY" to "1")
|
||||||
|
|
||||||
private fun String.escapeQuotes() = replace("\"", "\\\"")
|
private fun String.escapeQuotes() = replace("\"", "\\\"")
|
||||||
@@ -106,7 +101,6 @@ internal abstract class KonanCliRunner(
|
|||||||
.escapeQuotesForWindows()
|
.escapeQuotesForWindows()
|
||||||
.toMap()
|
.toMap()
|
||||||
)
|
)
|
||||||
spec.systemProperties(additionalSystemProperties)
|
|
||||||
spec.args(listOf(toolName) + transformArgs(args))
|
spec.args(listOf(toolName) + transformArgs(args))
|
||||||
blacklistEnvironment.forEach { spec.environment.remove(it) }
|
blacklistEnvironment.forEach { spec.environment.remove(it) }
|
||||||
spec.environment(environment)
|
spec.environment(environment)
|
||||||
|
|||||||
+1
@@ -4,6 +4,7 @@ import org.gradle.api.DefaultTask
|
|||||||
import org.gradle.api.provider.Property
|
import org.gradle.api.provider.Property
|
||||||
import org.gradle.api.tasks.*
|
import org.gradle.api.tasks.*
|
||||||
import org.jetbrains.kotlin.gradle.plugin.konan.KonanCompilerRunner
|
import org.jetbrains.kotlin.gradle.plugin.konan.KonanCompilerRunner
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.konan.hostManager
|
||||||
import org.jetbrains.kotlin.gradle.plugin.konan.konanHome
|
import org.jetbrains.kotlin.gradle.plugin.konan.konanHome
|
||||||
import org.jetbrains.kotlin.konan.target.CompilerOutputKind
|
import org.jetbrains.kotlin.konan.target.CompilerOutputKind
|
||||||
import org.jetbrains.kotlin.konan.target.HostManager
|
import org.jetbrains.kotlin.konan.target.HostManager
|
||||||
|
|||||||
+1
-1
@@ -329,7 +329,7 @@ abstract class KonanCompileTask: KonanBuildingTask(), KonanCompileSpec {
|
|||||||
val resolver = defaultResolver(
|
val resolver = defaultResolver(
|
||||||
repos.map { it.absolutePath },
|
repos.map { it.absolutePath },
|
||||||
konanTarget,
|
konanTarget,
|
||||||
Distribution(konanHomeOverride = project.konanHome)
|
Distribution(project.konanHome)
|
||||||
)
|
)
|
||||||
|
|
||||||
return KonanModelArtifactImpl(
|
return KonanModelArtifactImpl(
|
||||||
|
|||||||
+1
-1
@@ -176,7 +176,7 @@ open class KonanInteropTask @Inject constructor(@Internal val workerExecutor: Wo
|
|||||||
val resolver = defaultResolver(
|
val resolver = defaultResolver(
|
||||||
repos.map { it.absolutePath },
|
repos.map { it.absolutePath },
|
||||||
konanTarget,
|
konanTarget,
|
||||||
Distribution(konanHomeOverride = project.konanHome)
|
Distribution(project.konanHome)
|
||||||
)
|
)
|
||||||
|
|
||||||
return KonanModelArtifactImpl(
|
return KonanModelArtifactImpl(
|
||||||
|
|||||||
+9
-5
@@ -87,11 +87,7 @@ class KonanProject {
|
|||||||
this.targets = targets
|
this.targets = targets
|
||||||
projectPath = projectDir.toPath()
|
projectPath = projectDir.toPath()
|
||||||
konanBuildDir = projectPath.resolve('build/konan').toFile()
|
konanBuildDir = projectPath.resolve('build/konan').toFile()
|
||||||
def konanHome = System.getProperty("konan.home") ?: System.getProperty("org.jetbrains.kotlin.native.home")
|
def konanHomeDir = new File(getKonanHome())
|
||||||
if (konanHome == null) {
|
|
||||||
throw new IllegalStateException("konan.home isn't specified")
|
|
||||||
}
|
|
||||||
def konanHomeDir = new File(konanHome)
|
|
||||||
if (!konanHomeDir.exists() || !konanHomeDir.directory) {
|
if (!konanHomeDir.exists() || !konanHomeDir.directory) {
|
||||||
throw new IllegalStateException("konan.home doesn't exist or is not a directory: $konanHomeDir.canonicalPath")
|
throw new IllegalStateException("konan.home doesn't exist or is not a directory: $konanHomeDir.canonicalPath")
|
||||||
}
|
}
|
||||||
@@ -370,4 +366,12 @@ class KonanProject {
|
|||||||
return value.replace('\\', '\\\\')
|
return value.replace('\\', '\\\\')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static String getKonanHome() {
|
||||||
|
def konanHome = System.getProperty("konan.home") ?: System.getProperty("org.jetbrains.kotlin.native.home")
|
||||||
|
if (konanHome == null) {
|
||||||
|
throw new IllegalStateException("konan.home isn't specified")
|
||||||
|
}
|
||||||
|
return konanHome
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -26,7 +26,7 @@ class PathSpecification extends BaseKonanSpecification {
|
|||||||
project.konanBuildDir.toPath().resolve(path).toFile().exists()
|
project.konanBuildDir.toPath().resolve(path).toFile().exists()
|
||||||
}
|
}
|
||||||
|
|
||||||
def platformManager = new PlatformManager()
|
def platformManager = new PlatformManager(KonanProject.konanHome)
|
||||||
|
|
||||||
def 'Plugin should provide a correct path to the artifacts created'() {
|
def 'Plugin should provide a correct path to the artifacts created'() {
|
||||||
expect:
|
expect:
|
||||||
|
|||||||
@@ -19,6 +19,11 @@ tasks.named<KotlinCompile>("compileKotlin") {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
// Convert to normal strings since originally these properties contain GStrings.
|
||||||
|
val kotlinCompilerModule = rootProject.ext["kotlinCompilerModule"].toString()
|
||||||
|
val kotlinStdLibModule = rootProject.ext["kotlinStdLibModule"].toString()
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
api(kotlinStdLibModule)
|
||||||
|
implementation(kotlinCompilerModule)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package org.jetbrains.kotlin.konan.util
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.utils.PathUtil
|
||||||
|
import java.io.File
|
||||||
|
import java.nio.file.Paths
|
||||||
|
|
||||||
|
object KonanHomeProvider {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines a path to the current Kotlin/Native distribution.
|
||||||
|
*
|
||||||
|
* - If the system property "konan.home" is set, the method returns its value.
|
||||||
|
* - Otherwise, it determines a path to a jar containing this class. If this path corresponds to the jar path
|
||||||
|
* inside a distribution, the method calculates the path to the distribution on the basis of this jar path.
|
||||||
|
* Otherwise an IllegalStateException is thrown.
|
||||||
|
*/
|
||||||
|
fun determineKonanHome(): String {
|
||||||
|
val propertyValue = System.getProperty("konan.home")
|
||||||
|
return if (propertyValue != null) {
|
||||||
|
File(propertyValue).absolutePath
|
||||||
|
} else {
|
||||||
|
val jarPath = PathUtil.getResourcePathForClass(this::class.java)
|
||||||
|
|
||||||
|
// Check that the path obtained really points to the distribution.
|
||||||
|
val expectedRelativeJarPath = Paths.get("konan/lib/kotlin-native.jar")
|
||||||
|
check(jarPath.toPath().endsWith(expectedRelativeJarPath)) {
|
||||||
|
val classesPath = if (jarPath.extension == "jar") jarPath else jarPath.parentFile
|
||||||
|
"""
|
||||||
|
Cannot determine a compiler distribution directory.
|
||||||
|
A path to compiler classes is not a part of a distribution: ${classesPath.absolutePath}.
|
||||||
|
Please set the konan.home system property to specify the distribution path manually.
|
||||||
|
""".trimIndent()
|
||||||
|
}
|
||||||
|
|
||||||
|
// The compiler jar is located in <dist>/konan/lib.
|
||||||
|
jarPath.parentFile.parentFile.parentFile.absolutePath
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -22,8 +22,9 @@ compileKotlin {
|
|||||||
|
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
|
||||||
compile project(':backend.native')
|
implementation project(':backend.native')
|
||||||
compile project(':Interop:StubGenerator')
|
implementation project(':Interop:StubGenerator')
|
||||||
compile project(':klib')
|
implementation project(':klib')
|
||||||
|
implementation project(":utilities:basic-utils")
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -16,6 +16,7 @@ import org.jetbrains.kotlin.konan.target.CompilerOutputKind
|
|||||||
import org.jetbrains.kotlin.konan.target.HostManager
|
import org.jetbrains.kotlin.konan.target.HostManager
|
||||||
import org.jetbrains.kotlin.konan.target.KonanTarget
|
import org.jetbrains.kotlin.konan.target.KonanTarget
|
||||||
import org.jetbrains.kotlin.konan.target.customerDistribution
|
import org.jetbrains.kotlin.konan.target.customerDistribution
|
||||||
|
import org.jetbrains.kotlin.konan.util.KonanHomeProvider
|
||||||
import org.jetbrains.kotlin.konan.util.PlatformLibsInfo
|
import org.jetbrains.kotlin.konan.util.PlatformLibsInfo
|
||||||
import org.jetbrains.kotlin.konan.util.visibleName
|
import org.jetbrains.kotlin.konan.util.visibleName
|
||||||
import org.jetbrains.kotlin.native.interop.tool.CommonInteropArguments.Companion.DEFAULT_MODE
|
import org.jetbrains.kotlin.native.interop.tool.CommonInteropArguments.Companion.DEFAULT_MODE
|
||||||
@@ -120,7 +121,7 @@ fun generatePlatformLibraries(args: Array<String>) {
|
|||||||
|
|
||||||
argParser.parse(args)
|
argParser.parse(args)
|
||||||
|
|
||||||
val distribution = customerDistribution()
|
val distribution = customerDistribution(KonanHomeProvider.determineKonanHome())
|
||||||
val target = HostManager(distribution).targetByName(targetName)
|
val target = HostManager(distribution).targetByName(targetName)
|
||||||
|
|
||||||
val inputDirectory = inputDirectoryPath?.File()
|
val inputDirectory = inputDirectoryPath?.File()
|
||||||
|
|||||||
+2
-1
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.cli.utilities
|
|||||||
import org.jetbrains.kotlin.cli.bc.SHORT_MODULE_NAME_ARG
|
import org.jetbrains.kotlin.cli.bc.SHORT_MODULE_NAME_ARG
|
||||||
import org.jetbrains.kotlin.konan.file.File
|
import org.jetbrains.kotlin.konan.file.File
|
||||||
import org.jetbrains.kotlin.konan.target.PlatformManager
|
import org.jetbrains.kotlin.konan.target.PlatformManager
|
||||||
|
import org.jetbrains.kotlin.konan.util.KonanHomeProvider
|
||||||
import org.jetbrains.kotlin.native.interop.gen.jvm.InternalInteropOptions
|
import org.jetbrains.kotlin.native.interop.gen.jvm.InternalInteropOptions
|
||||||
import org.jetbrains.kotlin.native.interop.gen.jvm.interop
|
import org.jetbrains.kotlin.native.interop.gen.jvm.interop
|
||||||
import org.jetbrains.kotlin.native.interop.tool.*
|
import org.jetbrains.kotlin.native.interop.tool.*
|
||||||
@@ -39,7 +40,7 @@ fun invokeInterop(flavor: String, args: Array<String>): Array<String>? {
|
|||||||
val repos = arguments.repo
|
val repos = arguments.repo
|
||||||
val targetRequest = if (arguments is CInteropArguments) arguments.target
|
val targetRequest = if (arguments is CInteropArguments) arguments.target
|
||||||
else (arguments as JSInteropArguments).target
|
else (arguments as JSInteropArguments).target
|
||||||
val target = PlatformManager().targetManager(targetRequest).target
|
val target = PlatformManager(KonanHomeProvider.determineKonanHome()).targetManager(targetRequest).target
|
||||||
|
|
||||||
val cinteropArgsToCompiler = interop(flavor, args,
|
val cinteropArgsToCompiler = interop(flavor, args,
|
||||||
InternalInteropOptions(generatedDir.absolutePath,
|
InternalInteropOptions(generatedDir.absolutePath,
|
||||||
|
|||||||
Reference in New Issue
Block a user