From 43cbea8a67ddf9a9ef1d816e665a9cf33388afd1 Mon Sep 17 00:00:00 2001 From: alexander-gorshenev Date: Mon, 12 Feb 2018 18:59:54 +0300 Subject: [PATCH] Fixed a little issue in how we call ExecClang plugin. (#1317) Moved ExecClang plugin to Kotlin. --- backend.native/tests/build.gradle | 4 +- .../org/jetbrains/kotlin/ExecClang.groovy | 109 ------------------ .../org/jetbrains/kotlin/KonanTest.groovy | 2 +- .../kotlin/org/jetbrains/kotlin/ExecClang.kt | 105 +++++++++++++++++ 4 files changed, 109 insertions(+), 111 deletions(-) delete mode 100644 buildSrc/plugins/src/main/groovy/org/jetbrains/kotlin/ExecClang.groovy create mode 100644 buildSrc/plugins/src/main/kotlin/org/jetbrains/kotlin/ExecClang.kt diff --git a/backend.native/tests/build.gradle b/backend.native/tests/build.gradle index 02a7a20d4fb..d62efacda65 100644 --- a/backend.native/tests/build.gradle +++ b/backend.native/tests/build.gradle @@ -64,6 +64,8 @@ ext.externalTestsDir = project.file("external") ext.externalStdlibTestsDir = project.file("stdlib_external") externalTestsDir.mkdirs() +ext.platformManager = project.rootProject.platformManager +ext.target = platformManager.targetManager(project.testTarget).target project.convention.plugins.remoteExec = new org.jetbrains.kotlin.ExecRemote(project) allprojects { @@ -2424,7 +2426,7 @@ if (isMac()) { interop = 'objcSmoke' doFirst { - execKonanClang(project.testTarget) { + execKonanClang(project.target) { args "$projectDir/interop/objc/smoke.m" args "-lobjc", '-fobjc-arc' args '-fPIC', '-shared', '-o', "$buildDir/libobjcsmoke.dylib" diff --git a/buildSrc/plugins/src/main/groovy/org/jetbrains/kotlin/ExecClang.groovy b/buildSrc/plugins/src/main/groovy/org/jetbrains/kotlin/ExecClang.groovy deleted file mode 100644 index bcb334f4bbc..00000000000 --- a/buildSrc/plugins/src/main/groovy/org/jetbrains/kotlin/ExecClang.groovy +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright 2010-2017 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 - -import org.gradle.api.Action -import org.gradle.api.GradleException -import org.gradle.api.Project -import org.gradle.process.ExecResult -import org.gradle.process.ExecSpec -import org.gradle.util.ConfigureUtil -import org.jetbrains.kotlin.konan.target.* - -class ExecClang { - - private final Project project - - ExecClang(Project project) { - this.project = project - } - - private def platformManager = project.rootProject.platformManager - - private List konanArgs(KonanTarget target) { - return platformManager.platform(target).clang.clangArgsForKonanSources - } - - private List konanArgs(String targetName) { - def target = platformManager.targetManager(targetName).target - return konanArgs(target) - } - - // The bare ones invoke clang with system default sysroot. - - public ExecResult execBareClang(Action action) { - return this.execClang([], action) - } - - public ExecResult execBareClang(Closure closure) { - return this.execClang([], closure) - } - - // The konan ones invoke clang with konan provided sysroots. - // So they require a target or assume it to be the host. - // The target can be specified as KonanTarget or as a - // (nullable, which means host) target name. - - public ExecResult execKonanClang(String target, Action action) { - return this.execClang(konanArgs(target), action) - } - - public ExecResult execKonanClang(KonanTarget target, Action action) { - return this.execClang(konanArgs(target), action) - } - - public ExecResult execKonanClang(String target, Closure closure) { - return this.execClang(konanArgs(target), closure) - } - - public ExecResult execKonanClang(KonanTarget target, Closure closure) { - return this.execClang(konanArgs(target), closure) - } - - // These ones are private, so one has to choose either Bare or Konan. - - private ExecResult execClang(List defaultArgs, Closure closure) { - return this.execClang(defaultArgs, ConfigureUtil.configureUsing(closure)) - } - - private ExecResult execClang(List defaultArgs, Action action) { - Action extendedAction = new Action() { - @Override - void execute(ExecSpec execSpec) { - action.execute(execSpec) - - execSpec.with { - - if (executable == null) { - executable = 'clang' - } - - if (executable in ['clang', 'clang++']) { - executable = "${project.llvmDir}/bin/$executable" - } else { - throw new GradleException("unsupported clang executable: $executable") - } - - environment["PATH"] = project.files(project.hostPlatform.clang.clangPaths).asPath + - File.pathSeparator + environment["PATH"] - args defaultArgs - } - } - } - return project.exec(extendedAction) - } -} diff --git a/buildSrc/plugins/src/main/groovy/org/jetbrains/kotlin/KonanTest.groovy b/buildSrc/plugins/src/main/groovy/org/jetbrains/kotlin/KonanTest.groovy index 2e47ed27250..7539e45e675 100644 --- a/buildSrc/plugins/src/main/groovy/org/jetbrains/kotlin/KonanTest.groovy +++ b/buildSrc/plugins/src/main/groovy/org/jetbrains/kotlin/KonanTest.groovy @@ -551,7 +551,7 @@ class DynamicKonanTest extends KonanTest { void runClang(List cSources, String output, List moreArgs) { def log = new ByteArrayOutputStream() - project.execKonanClang(project.testTarget) { + project.execKonanClang(project.target) { workingDir outputDirectory executable "clang" diff --git a/buildSrc/plugins/src/main/kotlin/org/jetbrains/kotlin/ExecClang.kt b/buildSrc/plugins/src/main/kotlin/org/jetbrains/kotlin/ExecClang.kt new file mode 100644 index 00000000000..9950e710302 --- /dev/null +++ b/buildSrc/plugins/src/main/kotlin/org/jetbrains/kotlin/ExecClang.kt @@ -0,0 +1,105 @@ +/* + * Copyright 2010-2017 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 + +import org.gradle.api.Action +import groovy.lang.Closure +import org.gradle.api.GradleException +import org.gradle.api.Project +import org.gradle.process.ExecResult +import org.gradle.process.ExecSpec +import org.gradle.util.ConfigureUtil +import org.jetbrains.kotlin.konan.target.* +import org.jetbrains.kotlin.konan.file.* + +internal class ExecClang(private val project: Project) { + + private val platformManager = project.rootProject.findProperty("platformManager") as PlatformManager + + private fun konanArgs(target: KonanTarget): List { + return platformManager.platform(target).clang.clangArgsForKonanSources.asList() + } + + private fun konanArgs(targetName: String?): List { + val target = platformManager.targetManager(targetName).target + return konanArgs(target) + } + + // The bare ones invoke clang with system default sysroot. + + fun execBareClang(action: Action): ExecResult { + return this.execClang(emptyList(), action) + } + + fun execBareClang(closure: Closure): ExecResult { + return this.execClang(emptyList(), closure) + } + + // The konan ones invoke clang with konan provided sysroots. + // So they require a target or assume it to be the host. + // The target can be specified as KonanTarget or as a + // (nullable, which means host) target name. + + fun execKonanClang(target: String?, action: Action): ExecResult { + return this.execClang(konanArgs(target), action) + } + + fun execKonanClang(target: KonanTarget, action: Action): ExecResult { + return this.execClang(konanArgs(target), action) + } + + fun execKonanClang(target: String?, closure: Closure): ExecResult { + return this.execClang(konanArgs(target), closure) + } + + fun execKonanClang(target: KonanTarget, closure: Closure): ExecResult { + return this.execClang(konanArgs(target), closure) + } + + // These ones are private, so one has to choose either Bare or Konan. + + private fun execClang(defaultArgs: List, closure: Closure): ExecResult { + return this.execClang(defaultArgs, ConfigureUtil.configureUsing(closure)) + } + + private fun execClang(defaultArgs: List, action: Action): ExecResult { + val extendedAction = object : Action { + override fun execute(execSpec: ExecSpec) { + action.execute(execSpec) + + execSpec.apply { + if (executable == null) { + executable = "clang" + } + + if (listOf("clang", "clang++").contains(executable)) { + val llvmDir = project.findProperty("llvmDir") + executable = "${llvmDir}/bin/$executable" } + else { + throw GradleException("unsupported clang executable: $executable") + } + + val hostPlatform = project.findProperty("hostPlatform") as Platform + environment["PATH"] = project.files(hostPlatform.clang.clangPaths).asPath + + java.io.File.pathSeparator + environment["PATH"] + args(defaultArgs) + } + } + } + return project.exec(extendedAction) + } +}