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 {
|
||||
compile project(":utilities:basic-utils")
|
||||
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
|
||||
compile "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion"
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package kotlinx.cinterop
|
||||
|
||||
import org.jetbrains.kotlin.konan.util.KonanHomeProvider
|
||||
import java.io.File
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Paths
|
||||
@@ -93,7 +94,7 @@ fun loadKonanLibrary(name: String) {
|
||||
System.loadLibrary(name)
|
||||
} catch (e: UnsatisfiedLinkError) {
|
||||
val fullLibraryName = System.mapLibraryName(name)
|
||||
val dir = "${System.getProperty("konan.home")}/konan/nativelib"
|
||||
val dir = "${KonanHomeProvider.determineKonanHome()}/konan/nativelib"
|
||||
try {
|
||||
System.load("$dir/$fullLibraryName")
|
||||
} catch (e: UnsatisfiedLinkError) {
|
||||
|
||||
@@ -30,16 +30,18 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
|
||||
compile "org.jetbrains.kotlin:kotlin-compiler:$kotlinVersion"
|
||||
compile project(':Interop:Indexer')
|
||||
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"
|
||||
implementation project(":Interop:Indexer")
|
||||
implementation project(":utilities:basic-utils")
|
||||
api project(path: ":endorsedLibraries:kotlinx.cli", configuration: "jvmRuntimeElements")
|
||||
|
||||
testCompile "junit:junit:4.12"
|
||||
testCompile "org.jetbrains.kotlin:kotlin-test-junit:$buildKotlinVersion"
|
||||
testCompile "org.jetbrains.kotlin:kotlin-test:$buildKotlinVersion"
|
||||
api "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
|
||||
api "org.jetbrains.kotlin:kotlin-compiler:$kotlinVersion"
|
||||
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 {
|
||||
|
||||
+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.PlatformManager
|
||||
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.native.interop.gen.jvm.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 platformManager = PlatformManager(distribution)
|
||||
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.Distribution
|
||||
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.packageFqName
|
||||
import org.jetbrains.kotlin.library.resolver.impl.KotlinLibraryResolverImpl
|
||||
@@ -406,7 +407,7 @@ private fun getLibraryResolver(
|
||||
repos,
|
||||
libraries.filter { it.contains(org.jetbrains.kotlin.konan.file.File.separator) },
|
||||
target,
|
||||
Distribution()
|
||||
Distribution(KonanHomeProvider.determineKonanHome())
|
||||
).libraryResolver()
|
||||
}
|
||||
|
||||
|
||||
@@ -153,6 +153,8 @@ dependencies {
|
||||
kotlinCommonSources(it) { transitive = false }
|
||||
}
|
||||
|
||||
compilerCompile project(":utilities:basic-utils")
|
||||
|
||||
compilerCompile "com.google.protobuf:protobuf-java:${protobufVersion}"
|
||||
|
||||
compilerCompile kotlinCompilerModule
|
||||
@@ -192,12 +194,10 @@ final List<File> stdLibSrc = [
|
||||
]
|
||||
|
||||
// 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 ->
|
||||
def konanJvmArgs = [*HostManager.regularJvmArgs,
|
||||
"-Dkonan.home=${rootProject.projectDir}/dist"
|
||||
]
|
||||
def konanJvmArgs = [*HostManager.regularJvmArgs]
|
||||
|
||||
def defaultArgs = ['-nopack', '-nostdlib', '-no-default-libs', '-no-endorsed-libs']
|
||||
if (target != "wasm32") defaultArgs += '-g'
|
||||
@@ -208,7 +208,10 @@ targetList.each { target ->
|
||||
|
||||
task("${target}Stdlib", type: JavaExec) {
|
||||
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
|
||||
args = [*konanArgs,
|
||||
'-output', project(':runtime').file("build/${target}Stdlib"),
|
||||
|
||||
@@ -113,6 +113,7 @@ class K2Native : CLICompiler<K2NativeCompilerArguments>() {
|
||||
|
||||
with(KonanConfigKeys) {
|
||||
with(configuration) {
|
||||
arguments.kotlinHome?.let { put(KONAN_HOME, it) }
|
||||
|
||||
put(NODEFAULTLIBS, arguments.nodefaultlibs || !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.properties.loadProperties
|
||||
import org.jetbrains.kotlin.konan.target.*
|
||||
import org.jetbrains.kotlin.konan.util.KonanHomeProvider
|
||||
import org.jetbrains.kotlin.library.KotlinLibrary
|
||||
import org.jetbrains.kotlin.library.resolver.TopologicalLibraryOrder
|
||||
|
||||
class KonanConfig(val project: Project, val configuration: CompilerConfiguration) {
|
||||
|
||||
internal val distribution = Distribution(
|
||||
false,
|
||||
null,
|
||||
configuration.get(KonanConfigKeys.RUNTIME_FILE))
|
||||
configuration.get(KonanConfigKeys.KONAN_HOME) ?: KonanHomeProvider.determineKonanHome(),
|
||||
false,
|
||||
configuration.get(KonanConfigKeys.RUNTIME_FILE)
|
||||
)
|
||||
|
||||
internal val platformManager = PlatformManager(distribution)
|
||||
internal val targetManager = platformManager.targetManager(configuration.get(KonanConfigKeys.TARGET))
|
||||
|
||||
+2
@@ -48,6 +48,8 @@ class KonanConfigKeys {
|
||||
= CompilerConfigurationKey.create("generate test runner")
|
||||
val INCLUDED_BINARY_FILES: CompilerConfigurationKey<List<String>>
|
||||
= CompilerConfigurationKey.create("included binary file paths")
|
||||
val KONAN_HOME: CompilerConfigurationKey<String>
|
||||
= CompilerConfigurationKey.create("overridden compiler distribution path")
|
||||
val LIBRARY_FILES: CompilerConfigurationKey<List<String>>
|
||||
= CompilerConfigurationKey.create("library file paths")
|
||||
val LIBRARY_VERSION: CompilerConfigurationKey<String?>
|
||||
|
||||
@@ -79,7 +79,7 @@ class RunExternalTestGroup extends JavaExec {
|
||||
classpath = project.fileTree("$dist.canonicalPath/konan/lib/") {
|
||||
include '*.jar'
|
||||
}
|
||||
jvmArgs "-Dkonan.home=${dist.canonicalPath}", "-Xmx4G"
|
||||
jvmArgs "-Xmx4G"
|
||||
enableAssertions = true
|
||||
def sources = File.createTempFile(name,".lst")
|
||||
sources.deleteOnExit()
|
||||
|
||||
@@ -204,6 +204,8 @@ class NamedNativeInteropConfig implements Named {
|
||||
new File(project.findProject(":Interop:Indexer").buildDir, "nativelibs"),
|
||||
new File(project.findProject(":Interop:Runtime").buildDir, "nativelibs")
|
||||
).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
|
||||
environment "LIBCLANG_DISABLE_CRASH_RECOVERY": "1"
|
||||
|
||||
|
||||
@@ -62,12 +62,9 @@ findHome() {
|
||||
}
|
||||
KONAN_HOME="$(findHome)"
|
||||
|
||||
NATIVE_LIB="${KONAN_HOME}/konan/nativelib"
|
||||
|
||||
java_opts=(-ea \
|
||||
-Xmx3G \
|
||||
-XX:TieredStopAtLevel=1 \
|
||||
"-Dkonan.home=${KONAN_HOME}" \
|
||||
-Dfile.encoding=UTF-8 \
|
||||
${JAVA_OPTS})
|
||||
|
||||
|
||||
@@ -51,7 +51,6 @@ if not "!ARG!" == "" (
|
||||
goto again
|
||||
)
|
||||
|
||||
set "NATIVE_LIB=%_KONAN_HOME%\konan\nativelib"
|
||||
set "KONAN_LIB=%_KONAN_HOME%\konan\lib"
|
||||
|
||||
set "KONAN_JAR=%KONAN_LIB%\kotlin-native.jar"
|
||||
@@ -62,7 +61,6 @@ set "KONAN_CLASSPATH=%KONAN_JAR%;%TROVE_JAR%"
|
||||
set JAVA_OPTS=-ea ^
|
||||
-Xmx3G ^
|
||||
-XX:TieredStopAtLevel=1 ^
|
||||
"-Dkonan.home=%_KONAN_HOME%" ^
|
||||
-Dfile.encoding=UTF-8 ^
|
||||
%JAVA_OPTS%
|
||||
|
||||
|
||||
@@ -20,9 +20,7 @@ inline fun <reified T: AbstractArchiveTask> createLlvmPackingTask(
|
||||
blacklist: File?,
|
||||
crossinline additionalConfiguration: T.() -> Unit
|
||||
) {
|
||||
val distribution = Distribution(
|
||||
konanHomeOverride = rootProject.projectDir.absolutePath
|
||||
)
|
||||
val distribution = Distribution(rootProject.projectDir.absolutePath)
|
||||
val reducedLlvmAppendix = distribution.properties
|
||||
.getProperty("reducedLlvmAppendix")
|
||||
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")
|
||||
|
||||
targetList.each { target ->
|
||||
def konanJvmArgs = [*HostManager.regularJvmArgs,
|
||||
"-Dkonan.home=${rootProject.projectDir}/dist",
|
||||
]
|
||||
def konanJvmArgs = [*HostManager.regularJvmArgs]
|
||||
|
||||
def defaultArgs = ['-nopack', '-no-default-libs', '-no-endorsed-libs']
|
||||
if (target != "wasm32") defaultArgs += '-g'
|
||||
@@ -88,10 +86,14 @@ targetList.each { target ->
|
||||
// See :endorsedLibraries.ext for full endorsedLibraries list.
|
||||
def moduleName = endorsedLibraries[project].name
|
||||
|
||||
dependsOn ":distCompiler"
|
||||
dependsOn ":${target}CrossDistRuntime"
|
||||
|
||||
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
|
||||
args = [*konanArgs,
|
||||
'-output', outputFile,
|
||||
|
||||
+7
-5
@@ -41,15 +41,17 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
|
||||
compile project(path: ':backend.native', configuration: 'cli_bc')
|
||||
testCompile "junit:junit:4.12"
|
||||
testCompile "org.jetbrains.kotlin:kotlin-test-junit:$buildKotlinVersion"
|
||||
testCompile "org.jetbrains.kotlin:kotlin-test:$buildKotlinVersion"
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
|
||||
implementation project(path: ':backend.native', configuration: 'cli_bc')
|
||||
implementation project(":utilities:basic-utils")
|
||||
testImplementation "junit:junit:4.12"
|
||||
testImplementation "org.jetbrains.kotlin:kotlin-test-junit:$buildKotlinVersion"
|
||||
testImplementation "org.jetbrains.kotlin:kotlin-test:$buildKotlinVersion"
|
||||
}
|
||||
|
||||
test {
|
||||
dependsOn 'cleanTest'
|
||||
// Specify a path to the distribution that is used in the tests.
|
||||
systemProperty('konan.home', getProperty("org.jetbrains.kotlin.native.home"))
|
||||
dependsOn konanArtifacts.collect { it.getByTarget('host') }
|
||||
if (useCustomDist) {
|
||||
|
||||
@@ -25,6 +25,7 @@ import org.jetbrains.kotlin.util.Logger
|
||||
import org.jetbrains.kotlin.library.metadata.KlibMetadataProtoBuf
|
||||
import org.jetbrains.kotlin.konan.library.KonanLibrary
|
||||
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.storage.LockBasedStorageManager
|
||||
import java.lang.System.out
|
||||
@@ -170,7 +171,7 @@ class Library(val name: String, val requestedRepository: String?, val target: St
|
||||
if (!module.isNativeStdlib()) {
|
||||
val resolver = resolverByName(
|
||||
emptyList(),
|
||||
distributionKlib = Distribution().klib,
|
||||
distributionKlib = Distribution(KonanHomeProvider.determineKonanHome()).klib,
|
||||
skipCurrentDir = true,
|
||||
logger = KlibToolLogger)
|
||||
resolver.defaultLinks(false, true, true)
|
||||
@@ -202,7 +203,8 @@ fun libraryInRepoOrCurrentDir(repository: File, name: String) =
|
||||
fun main(args: Array<String>) {
|
||||
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 repository = command.options["-repository"]?.last()
|
||||
|
||||
@@ -33,7 +33,8 @@ class ContentsTest {
|
||||
@Test
|
||||
fun `Stdlib content should be printed without exceptions`() {
|
||||
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
|
||||
@@ -357,6 +358,6 @@ class ContentsTest {
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
# 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
|
||||
# if true, ignores Xcode version check.
|
||||
ignoreXcodeVersionCheck = false
|
||||
|
||||
@@ -18,7 +18,7 @@ interface SearchPathResolverWithTarget<L: KotlinLibrary>: SearchPathResolverWith
|
||||
fun defaultResolver(
|
||||
repositories: List<String>,
|
||||
target: KonanTarget,
|
||||
distribution: Distribution = Distribution(),
|
||||
distribution: Distribution,
|
||||
compatibleCompilerVersions: List<CompilerVersion> = emptyList()
|
||||
): 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) {
|
||||
|
||||
constructor(konanHome: String, experimental: Boolean = false): this(Distribution(konanHome), experimental)
|
||||
|
||||
private val loaders = filteredOutEnabledButNotSupported.map {
|
||||
it to loadConfigurables(it, distribution.properties, DependencyProcessor.defaultDependenciesRoot.absolutePath)
|
||||
}.toMap()
|
||||
|
||||
+1
-1
@@ -155,7 +155,7 @@ open class KonanLibrariesSpec(
|
||||
defaultResolver(
|
||||
repos.map { it.absolutePath },
|
||||
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)
|
||||
|
||||
// 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)) {
|
||||
project.setProperty(ProjectProperty.KONAN_HOME, project.konanCompilerDownloadDir())
|
||||
project.setProperty(ProjectProperty.DOWNLOAD_COMPILER, true)
|
||||
|
||||
-6
@@ -30,7 +30,6 @@ internal interface KonanToolRunner: Named {
|
||||
val classpath: FileCollection
|
||||
val jvmArgs: List<String>
|
||||
val environment: Map<String, Any>
|
||||
val additionalSystemProperties: Map<String, String>
|
||||
|
||||
fun run(args: List<String>)
|
||||
fun run(vararg args: String) = run(args.toList())
|
||||
@@ -70,10 +69,6 @@ internal abstract class KonanCliRunner(
|
||||
addAll(project.jvmArgs)
|
||||
}
|
||||
|
||||
override val additionalSystemProperties = mutableMapOf(
|
||||
"konan.home" to konanHome
|
||||
)
|
||||
|
||||
override val environment = mutableMapOf("LIBCLANG_DISABLE_CRASH_RECOVERY" to "1")
|
||||
|
||||
private fun String.escapeQuotes() = replace("\"", "\\\"")
|
||||
@@ -106,7 +101,6 @@ internal abstract class KonanCliRunner(
|
||||
.escapeQuotesForWindows()
|
||||
.toMap()
|
||||
)
|
||||
spec.systemProperties(additionalSystemProperties)
|
||||
spec.args(listOf(toolName) + transformArgs(args))
|
||||
blacklistEnvironment.forEach { spec.environment.remove(it) }
|
||||
spec.environment(environment)
|
||||
|
||||
+1
@@ -4,6 +4,7 @@ import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.provider.Property
|
||||
import org.gradle.api.tasks.*
|
||||
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.konan.target.CompilerOutputKind
|
||||
import org.jetbrains.kotlin.konan.target.HostManager
|
||||
|
||||
+1
-1
@@ -329,7 +329,7 @@ abstract class KonanCompileTask: KonanBuildingTask(), KonanCompileSpec {
|
||||
val resolver = defaultResolver(
|
||||
repos.map { it.absolutePath },
|
||||
konanTarget,
|
||||
Distribution(konanHomeOverride = project.konanHome)
|
||||
Distribution(project.konanHome)
|
||||
)
|
||||
|
||||
return KonanModelArtifactImpl(
|
||||
|
||||
+1
-1
@@ -176,7 +176,7 @@ open class KonanInteropTask @Inject constructor(@Internal val workerExecutor: Wo
|
||||
val resolver = defaultResolver(
|
||||
repos.map { it.absolutePath },
|
||||
konanTarget,
|
||||
Distribution(konanHomeOverride = project.konanHome)
|
||||
Distribution(project.konanHome)
|
||||
)
|
||||
|
||||
return KonanModelArtifactImpl(
|
||||
|
||||
+9
-5
@@ -87,11 +87,7 @@ class KonanProject {
|
||||
this.targets = targets
|
||||
projectPath = projectDir.toPath()
|
||||
konanBuildDir = projectPath.resolve('build/konan').toFile()
|
||||
def konanHome = System.getProperty("konan.home") ?: System.getProperty("org.jetbrains.kotlin.native.home")
|
||||
if (konanHome == null) {
|
||||
throw new IllegalStateException("konan.home isn't specified")
|
||||
}
|
||||
def konanHomeDir = new File(konanHome)
|
||||
def konanHomeDir = new File(getKonanHome())
|
||||
if (!konanHomeDir.exists() || !konanHomeDir.directory) {
|
||||
throw new IllegalStateException("konan.home doesn't exist or is not a directory: $konanHomeDir.canonicalPath")
|
||||
}
|
||||
@@ -370,4 +366,12 @@ class KonanProject {
|
||||
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()
|
||||
}
|
||||
|
||||
def platformManager = new PlatformManager()
|
||||
def platformManager = new PlatformManager(KonanProject.konanHome)
|
||||
|
||||
def 'Plugin should provide a correct path to the artifacts created'() {
|
||||
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 {
|
||||
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
|
||||
compile project(':backend.native')
|
||||
compile project(':Interop:StubGenerator')
|
||||
compile project(':klib')
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
|
||||
implementation project(':backend.native')
|
||||
implementation project(':Interop:StubGenerator')
|
||||
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.KonanTarget
|
||||
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.visibleName
|
||||
import org.jetbrains.kotlin.native.interop.tool.CommonInteropArguments.Companion.DEFAULT_MODE
|
||||
@@ -120,7 +121,7 @@ fun generatePlatformLibraries(args: Array<String>) {
|
||||
|
||||
argParser.parse(args)
|
||||
|
||||
val distribution = customerDistribution()
|
||||
val distribution = customerDistribution(KonanHomeProvider.determineKonanHome())
|
||||
val target = HostManager(distribution).targetByName(targetName)
|
||||
|
||||
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.konan.file.File
|
||||
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.interop
|
||||
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 targetRequest = if (arguments is CInteropArguments) arguments.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,
|
||||
InternalInteropOptions(generatedDir.absolutePath,
|
||||
|
||||
Reference in New Issue
Block a user