diff --git a/backend.native/konan.properties b/backend.native/konan.properties index f52c495fd00..eb9e75acb0a 100644 --- a/backend.native/konan.properties +++ b/backend.native/konan.properties @@ -50,35 +50,24 @@ osVersionMinFlagLd.osx = -macosx_version_min osVersionMinFlagClang.osx = -mmacosx-version-min osVersionMin.osx = 10.11 entrySelector.osx = -alias _Konan_main _main -dependencies.osx = target-sysroot-2-darwin-macos \ +dependencies.osx = \ libffi-3.2.1-2-darwin-macos \ - clang-llvm-5.0.0-darwin-macos \ - target-toolchain-1-osx + clang-llvm-5.0.0-darwin-macos target-sysroot-2-darwin-macos.default = \ - remote:internal \ - /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk - -target-sysroot-2-darwin-macos.alt = \ - /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk + remote:internal target-toolchain-1-osx.default = \ - remote:internal \ - /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain + remote:internal # Apple iOS. targetToolchain.osx-ios = target-toolchain-1-osx -dependencies.osx-ios = target-toolchain-1-osx \ +dependencies.osx-ios = \ libffi-3.2.1-2-darwin-ios \ - clang-llvm-5.0.0-darwin-macos \ - target-sysroot-3-darwin-ios + clang-llvm-5.0.0-darwin-macos target-sysroot-3-darwin-ios.default = \ - remote:internal \ - /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.2.sdk - -target-sysroot-3-darwin-ios.alt = \ - /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk + remote:internal arch.ios = arm64 entrySelector.ios = -alias _Konan_main _main @@ -98,17 +87,12 @@ osVersionMin.ios = 8.0 # Apple iOS simulator. targetToolchain.osx-ios_sim = target-toolchain-1-osx -dependencies.osx-ios_sim = target-toolchain-1-osx \ +dependencies.osx-ios_sim = \ libffi-3.2.1-1-darwin-ios_sim \ - clang-llvm-5.0.0-darwin-macos \ - target-sysroot-2-darwin-ios_sim + clang-llvm-5.0.0-darwin-macos target-sysroot-2-darwin-ios_sim.default = \ - remote:internal \ - /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator11.2.sdk - -target-sysroot-2-darwin-ios_sim.alt = \ - /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk + remote:internal arch.ios_sim = x86_64 entrySelector.ios_sim = -alias _Konan_main _main diff --git a/build.gradle b/build.gradle index a60513d3e77..dcb725d7629 100644 --- a/build.gradle +++ b/build.gradle @@ -34,6 +34,8 @@ ext { // Force build to use only 'default' profile: konanProperties.setProperty(DEPENDENCY_PROFILES_KEY, "default") + // Force build to use fixed Xcode version: + konanProperties.setProperty("useFixedXcodeVersion", "9.2") // TODO: it actually affects only resolution made in :dependencies, // that's why we assume that 'default' profile comes first (and check this above). diff --git a/dependencies/build.gradle b/dependencies/build.gradle index 6b3f8c71b70..5ee941fc914 100644 --- a/dependencies/build.gradle +++ b/dependencies/build.gradle @@ -210,10 +210,7 @@ class HelperNativeDep extends TgzNativeDep { enum DependencyKind { LLVM( "llvm", { it.llvmHome }, { "llvmDir" } ), - GCC_TOOLCHAIN( "gccToolchain", { (it instanceof LinuxBasedConfigurables) ? it.gccToolchain : null }, { "gccToolchainDir" }), - SYSROOT( "sysroot", { it.targetSysRoot } ), - LIBFFI( "libffi", { it.libffiDir } ), - TARGET_TOOLCHAIN("targetToolchain", { it.targetToolchain } ) + LIBFFI( "libffi", { it.libffiDir } ) DependencyKind(String name, @@ -241,7 +238,8 @@ enum DependencyKind { } TargetManager.enabled.each { target -> - def konanProperties = new KonanPropertiesLoader(target, + def konanProperties = ConfigurablesImplKt.loadConfigurables( + target, rootProject.ext.konanProperties, rootProject.ext.dependenciesDir.canonicalPath ) diff --git a/shared/src/main/kotlin/org/jetbrains/kotlin/konan/exec/ExecuteCommand.kt b/shared/src/main/kotlin/org/jetbrains/kotlin/konan/exec/ExecuteCommand.kt index 9f5c8465a9d..29dd7d5b6b6 100644 --- a/shared/src/main/kotlin/org/jetbrains/kotlin/konan/exec/ExecuteCommand.kt +++ b/shared/src/main/kotlin/org/jetbrains/kotlin/konan/exec/ExecuteCommand.kt @@ -60,9 +60,43 @@ open class Command(initialCommand: List) { } open fun execute() { - if (logger != null) logger!! { command.toList().joinToString(" ") } + log() val code = runProcess() + handleExitCode(code) + } + + fun getOutputLines(): List { + log() + + val outputFile = createTempFile() + outputFile.deleteOnExit() + + try { + val builder = ProcessBuilder(command) + + builder.redirectInput(Redirect.INHERIT) + builder.redirectError(Redirect.INHERIT) + builder.redirectOutput(ProcessBuilder.Redirect.to(outputFile)) + // Note: getting process output could be done without redirecting to temporary file, + // however this would require managing a thread to read `process.inputStream` because + // it may have limited capacity. + + val process = builder.start() + val code = process.waitFor() + handleExitCode(code) + + return outputFile.readLines() + } finally { + outputFile.delete() + } + } + + private fun handleExitCode(code: Int) { if (code != 0) throw KonanExternalToolFailure("The ${command[0]} command returned non-zero exit code: $code.", command[0]) } + + private fun log() { + if (logger != null) logger!! { command.toList().joinToString(" ") } + } } diff --git a/shared/src/main/kotlin/org/jetbrains/kotlin/konan/target/Apple.kt b/shared/src/main/kotlin/org/jetbrains/kotlin/konan/target/Apple.kt new file mode 100644 index 00000000000..73df9843884 --- /dev/null +++ b/shared/src/main/kotlin/org/jetbrains/kotlin/konan/target/Apple.kt @@ -0,0 +1,71 @@ +/* + * Copyright 2010-2018 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed -> in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin.konan.target + +import org.jetbrains.kotlin.konan.properties.KonanPropertiesLoader +import org.jetbrains.kotlin.konan.properties.Properties +import org.jetbrains.kotlin.konan.util.InternalServer + +class AppleConfigurablesImpl( + target: KonanTarget, + properties: Properties, + baseDir: String? +) : AppleConfigurables, KonanPropertiesLoader(target, properties, baseDir) { + + private val sdkDependency = this.targetSysRoot!! + private val toolchainDependency = this.targetToolchain!! + + override val absoluteTargetSysRoot: String get() = when (xcodePartsProvider) { + is XcodePartsProvider.Local -> when (target) { + KonanTarget.MACBOOK -> xcodePartsProvider.xcode.macosxSdk + KonanTarget.IPHONE -> xcodePartsProvider.xcode.iphoneosSdk + KonanTarget.IPHONE_SIM -> xcodePartsProvider.xcode.iphonesimulatorSdk + else -> error(target) + } + XcodePartsProvider.InternalServer -> absolute(sdkDependency) + } + + override val absoluteTargetToolchain: String get() = when (xcodePartsProvider) { + is XcodePartsProvider.Local -> xcodePartsProvider.xcode.toolchain + XcodePartsProvider.InternalServer -> absolute(toolchainDependency) + } + + override val dependencies get() = super.dependencies + when (xcodePartsProvider) { + is XcodePartsProvider.Local -> emptyList() + XcodePartsProvider.InternalServer -> listOf(sdkDependency, toolchainDependency) + } + + private val xcodePartsProvider = if (InternalServer.isAvailable) { + XcodePartsProvider.InternalServer + } else { + val xcode = Xcode.current + properties.getProperty("useFixedXcodeVersion")?.let { requiredXcodeVersion -> + val currentXcodeVersion = xcode.version + + if (currentXcodeVersion != requiredXcodeVersion) { + error("expected Xcode version $requiredXcodeVersion, got $currentXcodeVersion") + } + } + + XcodePartsProvider.Local(xcode) + } + + private sealed class XcodePartsProvider { + class Local(val xcode: Xcode) : XcodePartsProvider() + object InternalServer : XcodePartsProvider() + } +} diff --git a/shared/src/main/kotlin/org/jetbrains/kotlin/konan/target/ConfigurablesImpl.kt b/shared/src/main/kotlin/org/jetbrains/kotlin/konan/target/ConfigurablesImpl.kt index fc3d7e2cf5b..6b1d5d9071e 100644 --- a/shared/src/main/kotlin/org/jetbrains/kotlin/konan/target/ConfigurablesImpl.kt +++ b/shared/src/main/kotlin/org/jetbrains/kotlin/konan/target/ConfigurablesImpl.kt @@ -27,9 +27,6 @@ class LinuxMIPSConfigurablesImpl(target: KonanTarget, properties: Properties, ba class AndroidConfigurablesImpl(target: KonanTarget, properties: Properties, baseDir: String?) : AndroidConfigurables, KonanPropertiesLoader(target, properties, baseDir) -class AppleConfigurablesImpl(target: KonanTarget, properties: Properties, baseDir: String?) - : AppleConfigurables, KonanPropertiesLoader(target, properties, baseDir) - class MingwConfigurablesImpl(target: KonanTarget, properties: Properties, baseDir: String?) : MingwConfigurables, KonanPropertiesLoader(target, properties, baseDir) diff --git a/shared/src/main/kotlin/org/jetbrains/kotlin/konan/target/KonanProperties.kt b/shared/src/main/kotlin/org/jetbrains/kotlin/konan/target/KonanProperties.kt index bbdca9e3e9d..e04ef9178da 100644 --- a/shared/src/main/kotlin/org/jetbrains/kotlin/konan/target/KonanProperties.kt +++ b/shared/src/main/kotlin/org/jetbrains/kotlin/konan/target/KonanProperties.kt @@ -31,8 +31,8 @@ interface TargetableExternalStorage { fun downloadDependencies() } -open class KonanPropertiesLoader(override val target: KonanTarget, val properties: Properties, val baseDir: String? = null) : Configurables { - val dependencies get() = hostTargetList("dependencies") +abstract class KonanPropertiesLoader(override val target: KonanTarget, val properties: Properties, val baseDir: String? = null) : Configurables { + open val dependencies get() = hostTargetList("dependencies") override fun downloadDependencies() { dependencyProcessor!!.run() diff --git a/shared/src/main/kotlin/org/jetbrains/kotlin/konan/target/Xcode.kt b/shared/src/main/kotlin/org/jetbrains/kotlin/konan/target/Xcode.kt new file mode 100644 index 00000000000..ff1d581de0c --- /dev/null +++ b/shared/src/main/kotlin/org/jetbrains/kotlin/konan/target/Xcode.kt @@ -0,0 +1,57 @@ +/* + * Copyright 2010-2018 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin.konan.target + +import org.jetbrains.kotlin.konan.KonanExternalToolFailure +import org.jetbrains.kotlin.konan.exec.Command +import org.jetbrains.kotlin.konan.file.File + +interface Xcode { + val toolchain: String + val macosxSdk: String + val iphoneosSdk: String + val iphonesimulatorSdk: String + val version: String + + companion object { + val current: Xcode by lazy { + CurrentXcode + } + } +} + +private object CurrentXcode : Xcode { + + override val toolchain by lazy { + val ldPath = xcrun("-f", "ld") // = $toolchain/usr/bin/ld + File(ldPath).parentFile.parentFile.parentFile.absolutePath + } + + override val macosxSdk by lazy { getSdkPath("macosx") } + override val iphoneosSdk by lazy { getSdkPath("iphoneos") } + override val iphonesimulatorSdk by lazy { getSdkPath("iphonesimulator") } + + override val version by lazy { + xcrun("xcodebuild", "-version") + .removePrefix("Xcode ") + } + + private fun xcrun(vararg args: String): String = + Command("/usr/bin/xcrun", *args).getOutputLines().first() // TODO: handle execution error + + private fun getSdkPath(sdk: String) = xcrun("--sdk", sdk, "--show-sdk-path") +} diff --git a/shared/src/main/kotlin/org/jetbrains/kotlin/konan/util/DependencyProcessor.kt b/shared/src/main/kotlin/org/jetbrains/kotlin/konan/util/DependencyProcessor.kt index 76efb5bc3b1..19a31ad8ed0 100644 --- a/shared/src/main/kotlin/org/jetbrains/kotlin/konan/util/DependencyProcessor.kt +++ b/shared/src/main/kotlin/org/jetbrains/kotlin/konan/util/DependencyProcessor.kt @@ -273,7 +273,7 @@ class DependencyProcessor(dependenciesRoot: File, } } -private object InternalServer { +internal object InternalServer { private val host = "repo.labs.intellij.net" val url = "http://$host/kotlin-native" diff --git a/utilities/env_blacklist b/utilities/env_blacklist index f8677816a2b..d2a5e54501e 100644 --- a/utilities/env_blacklist +++ b/utilities/env_blacklist @@ -29,7 +29,6 @@ CLANG_WARN__DUPLICATE_METHOD_MATCH CURRENT_ARCH DEVELOPER_APPLICATIONS_DIR DEVELOPER_BIN_DIR -DEVELOPER_DIR DEVELOPER_FRAMEWORKS_DIR DEVELOPER_FRAMEWORKS_DIR_QUOTED DEVELOPER_LIBRARY_DIR