[Gradle, JS] Fix bridge between Gradle and Js IR CLI
This commit is contained in:
@@ -10,7 +10,6 @@ import java.io.BufferedReader
|
||||
import java.io.InputStream
|
||||
import java.io.InputStreamReader
|
||||
import java.io.RandomAccessFile
|
||||
import java.lang.Exception
|
||||
import java.nio.MappedByteBuffer
|
||||
import java.nio.channels.FileChannel
|
||||
import java.nio.file.*
|
||||
@@ -230,4 +229,4 @@ inline fun <T : AutoCloseable?, R> T.use(block: (T) -> R): R {
|
||||
this?.close()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,10 @@ import org.jetbrains.kotlin.konan.CompilerVersion
|
||||
import org.jetbrains.kotlin.konan.file.File
|
||||
import org.jetbrains.kotlin.library.impl.createKotlinLibraryComponents
|
||||
import org.jetbrains.kotlin.library.impl.isPre_1_4_Library
|
||||
import org.jetbrains.kotlin.util.*
|
||||
import org.jetbrains.kotlin.util.Logger
|
||||
import org.jetbrains.kotlin.util.WithLogger
|
||||
import org.jetbrains.kotlin.util.removeSuffixIfPresent
|
||||
import org.jetbrains.kotlin.util.suffixIfNot
|
||||
import java.nio.file.InvalidPathException
|
||||
import java.nio.file.Paths
|
||||
|
||||
@@ -145,7 +148,7 @@ abstract class KotlinLibrarySearchPathResolver<L : KotlinLibrary>(
|
||||
.filterNotNull()
|
||||
|
||||
matching.firstOrNull() ?: run {
|
||||
logger.fatal("Could not find \"$givenPath\" in ${searchRoots.map { it.absolutePath }}.")
|
||||
logger.fatal("Could not find \"$givenPath\" in ${searchRoots.map { it.absolutePath }}")
|
||||
}
|
||||
} catch (e: Throwable) {
|
||||
logger.error("Failed to resolve Kotlin library: $givenPath")
|
||||
@@ -154,7 +157,7 @@ abstract class KotlinLibrarySearchPathResolver<L : KotlinLibrary>(
|
||||
}
|
||||
}
|
||||
|
||||
override fun libraryMatch(candidate: L, unresolved: UnresolvedLibrary) = true
|
||||
override fun libraryMatch(candidate: L, unresolved: UnresolvedLibrary): Boolean = true
|
||||
|
||||
override fun resolve(givenPath: String) = resolve(UnresolvedLibrary(givenPath, null), false)
|
||||
|
||||
|
||||
@@ -17,9 +17,9 @@
|
||||
package org.jetbrains.kotlin.library.impl
|
||||
|
||||
import org.jetbrains.kotlin.konan.file.File
|
||||
import org.jetbrains.kotlin.library.*
|
||||
import org.jetbrains.kotlin.konan.properties.Properties
|
||||
import org.jetbrains.kotlin.konan.properties.loadProperties
|
||||
import org.jetbrains.kotlin.library.*
|
||||
|
||||
open class BaseKotlinLibraryImpl(
|
||||
val access: BaseLibraryAccess<KotlinLibraryLayout>,
|
||||
|
||||
@@ -20,12 +20,14 @@ open class KotlinLibraryLayoutForWriter(
|
||||
) : KotlinLibraryLayout, MetadataKotlinLibraryLayout, IrKotlinLibraryLayout {
|
||||
override val componentDir: File
|
||||
get() = File(unzippedDir, component)
|
||||
override val pre_1_4_manifest: File
|
||||
get() = File(unzippedDir, KLIB_MANIFEST_FILE_NAME)
|
||||
}
|
||||
|
||||
open class BaseWriterImpl(
|
||||
val libraryLayout: KotlinLibraryLayoutForWriter,
|
||||
moduleName: String,
|
||||
override val versions: KotlinLibraryVersioning,
|
||||
_versions: KotlinLibraryVersioning,
|
||||
builtInsPlatform: BuiltInsPlatform,
|
||||
nativeTargets: List<String> = emptyList(),
|
||||
val nopack: Boolean = false,
|
||||
@@ -34,14 +36,16 @@ open class BaseWriterImpl(
|
||||
|
||||
val klibFile = libraryLayout.libFile
|
||||
val manifestProperties = Properties()
|
||||
override val versions: KotlinLibraryVersioning = _versions
|
||||
|
||||
init {
|
||||
// TODO: figure out the proper policy here.
|
||||
klibFile.delete()
|
||||
klibFile.deleteRecursively()
|
||||
klibFile.parentFile.run { if (!exists) mkdirs() }
|
||||
libraryLayout.resourcesDir.mkdirs()
|
||||
// TODO: <name>:<hash> will go somewhere around here.
|
||||
manifestProperties.setProperty(KLIB_PROPERTY_UNIQUE_NAME, moduleName)
|
||||
manifestProperties.writeKonanLibraryVersioning(versions)
|
||||
manifestProperties.writeKonanLibraryVersioning(_versions)
|
||||
|
||||
if (builtInsPlatform != BuiltInsPlatform.COMMON) {
|
||||
manifestProperties.setProperty(KLIB_PROPERTY_BUILTINS_PLATFORM, builtInsPlatform.name)
|
||||
|
||||
+7
-5
@@ -39,9 +39,7 @@ import org.jetbrains.kotlin.gradle.model.builder.KotlinModelBuilder
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.*
|
||||
import org.jetbrains.kotlin.gradle.scripting.internal.ScriptingGradleSubplugin
|
||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsBinaryMode
|
||||
import org.jetbrains.kotlin.gradle.targets.js.ir.JsIrBinary
|
||||
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrCompilation
|
||||
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrLink
|
||||
import org.jetbrains.kotlin.gradle.targets.js.ir.*
|
||||
import org.jetbrains.kotlin.gradle.targets.js.jsPluginDeprecationMessage
|
||||
import org.jetbrains.kotlin.gradle.targets.jvm.KotlinJvmTarget
|
||||
import org.jetbrains.kotlin.gradle.tasks.*
|
||||
@@ -341,8 +339,12 @@ internal class KotlinJsIrSourceSetProcessor(
|
||||
// outputFile can be set later during the configuration phase, get it only after the phase:
|
||||
project.runOnceAfterEvaluated("KotlinJsIrSourceSetProcessor.doTargetSpecificProcessing", kotlinTask) {
|
||||
val kotlinTaskInstance = kotlinTask.get()
|
||||
kotlinTaskInstance.kotlinOptions.outputFile = kotlinTaskInstance.outputFile.absolutePath
|
||||
val outputDir = kotlinTaskInstance.outputFile.parentFile
|
||||
val kotlinOptions = kotlinTaskInstance.kotlinOptions
|
||||
kotlinOptions.outputFile = kotlinTaskInstance.outputFile.absolutePath
|
||||
val outputDir = if (kotlinOptions.isProduceUnzippedKlib())
|
||||
kotlinTaskInstance.outputFile
|
||||
else
|
||||
kotlinTaskInstance.outputFile.parentFile
|
||||
|
||||
if (outputDir.isParentOf(project.rootDir))
|
||||
throw InvalidUserDataException(
|
||||
|
||||
+7
-1
@@ -5,6 +5,8 @@
|
||||
|
||||
package org.jetbrains.kotlin.gradle.targets.js.ir
|
||||
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinJsOptions
|
||||
|
||||
/**
|
||||
* @see [compiler/testData/cli/js/jsExtraHelp.out]
|
||||
*/
|
||||
@@ -18,5 +20,9 @@ internal const val GENERATE_D_TS = "-Xgenerate-dts"
|
||||
|
||||
internal const val PRODUCE_JS = "-Xir-produce-js"
|
||||
internal const val PRODUCE_UNZIPPED_KLIB = "-Xir-produce-klib-dir"
|
||||
internal const val PRODUCE_ZIPPED_KLIB = "-Xir-produce-klib-file"
|
||||
|
||||
internal const val MODULE_NAME = "-Xir-module-name"
|
||||
internal const val MODULE_NAME = "-Xir-module-name"
|
||||
|
||||
fun KotlinJsOptions.isProduceUnzippedKlib() = PRODUCE_UNZIPPED_KLIB in freeCompilerArgs
|
||||
fun KotlinJsOptions.isProduceZippedKlib() = PRODUCE_ZIPPED_KLIB in freeCompilerArgs
|
||||
+22
-6
@@ -17,6 +17,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinTasksProvider
|
||||
import org.jetbrains.kotlin.gradle.testing.internal.kotlinTestRegistry
|
||||
import org.jetbrains.kotlin.gradle.testing.testTaskName
|
||||
import org.jetbrains.kotlin.gradle.utils.klibModuleName
|
||||
import java.io.File
|
||||
|
||||
open class KotlinJsIrTargetConfigurator(kotlinPluginVersion: String) :
|
||||
KotlinOnlyTargetConfigurator<KotlinJsIrCompilation, KotlinJsIrTarget>(true, true, kotlinPluginVersion),
|
||||
@@ -68,18 +69,33 @@ open class KotlinJsIrTargetConfigurator(kotlinPluginVersion: String) :
|
||||
compilation.kotlinOptions {
|
||||
configureOptions()
|
||||
|
||||
freeCompilerArgs += listOf(
|
||||
DISABLE_PRE_IR,
|
||||
PRODUCE_UNZIPPED_KLIB
|
||||
)
|
||||
var produceUnzippedKlib = isProduceUnzippedKlib()
|
||||
val produceZippedKlib = isProduceZippedKlib()
|
||||
|
||||
freeCompilerArgs = freeCompilerArgs + DISABLE_PRE_IR
|
||||
|
||||
val isMainCompilation = compilation.isMain()
|
||||
|
||||
if (!produceUnzippedKlib && !produceZippedKlib) {
|
||||
freeCompilerArgs = freeCompilerArgs + PRODUCE_UNZIPPED_KLIB
|
||||
produceUnzippedKlib = true
|
||||
}
|
||||
|
||||
// Configure FQ module name to avoid cyclic dependencies in klib manifests (see KT-36721).
|
||||
val baseName = if (compilation.isMain()) {
|
||||
val baseName = if (isMainCompilation) {
|
||||
target.project.name
|
||||
} else {
|
||||
"${target.project.name}_${compilation.name}"
|
||||
}
|
||||
freeCompilerArgs += listOf("$MODULE_NAME=${target.project.klibModuleName(baseName)}")
|
||||
|
||||
val destinationDir = compilation.compileKotlinTask.destinationDir
|
||||
outputFile = if (produceUnzippedKlib)
|
||||
destinationDir.absoluteFile.normalize().absolutePath
|
||||
else
|
||||
File(destinationDir, "$baseName.$KLIB_TYPE").absoluteFile.normalize().absolutePath
|
||||
|
||||
val klibModuleName = target.project.klibModuleName(baseName)
|
||||
freeCompilerArgs = freeCompilerArgs + "$MODULE_NAME=$klibModuleName"
|
||||
}
|
||||
|
||||
compilation.binaries
|
||||
|
||||
+26
-8
@@ -44,9 +44,6 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.associateWithTransitiveClosure
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.ownModuleName
|
||||
import org.jetbrains.kotlin.gradle.report.ReportingSettings
|
||||
import org.jetbrains.kotlin.gradle.utils.*
|
||||
import org.jetbrains.kotlin.gradle.utils.isParentOf
|
||||
import org.jetbrains.kotlin.gradle.utils.pathsAsStringRelativeTo
|
||||
import org.jetbrains.kotlin.gradle.utils.toSortedPathsArray
|
||||
import org.jetbrains.kotlin.incremental.ChangedFiles
|
||||
import org.jetbrains.kotlin.library.impl.isKotlinLibrary
|
||||
import org.jetbrains.kotlin.utils.JsLibraryUtils
|
||||
@@ -631,15 +628,29 @@ open class Kotlin2JsCompile : AbstractKotlinCompile<K2JSCompilerArguments>(), Ko
|
||||
override fun isIncrementalCompilationEnabled(): Boolean =
|
||||
when {
|
||||
"-Xir-produce-js" in kotlinOptions.freeCompilerArgs -> false
|
||||
"-Xir-produce-klib-dir" in kotlinOptions.freeCompilerArgs -> incrementalJsKlib
|
||||
"-Xir-produce-klib-dir" in kotlinOptions.freeCompilerArgs -> false // TODO: it's not supported yet
|
||||
"-Xir-produce-klib-file" in kotlinOptions.freeCompilerArgs -> incrementalJsKlib
|
||||
else -> incremental
|
||||
}
|
||||
|
||||
@Suppress("unused")
|
||||
@get:OutputFile
|
||||
@get:Internal
|
||||
val outputFile: File
|
||||
get() = kotlinOptions.outputFile?.let(::File) ?: defaultOutputFile
|
||||
get() = outputFilePath?.let(::File) ?: defaultOutputFile
|
||||
|
||||
@get:OutputFile
|
||||
@get:Optional
|
||||
val outputFileOrNull: File?
|
||||
get() = outputFile.let { file ->
|
||||
if (file.isFile) {
|
||||
file
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
@get:Input
|
||||
val outputFilePath: String?
|
||||
get() = kotlinOptions.outputFile
|
||||
|
||||
override fun findKotlinCompilerClasspath(project: Project): List<File> =
|
||||
findKotlinJsCompilerClasspath(project)
|
||||
@@ -651,7 +662,14 @@ open class Kotlin2JsCompile : AbstractKotlinCompile<K2JSCompilerArguments>(), Ko
|
||||
args.apply { fillDefaultValues() }
|
||||
super.setupCompilerArgs(args, defaultsOnly = defaultsOnly, ignoreClasspathResolutionErrors = ignoreClasspathResolutionErrors)
|
||||
|
||||
args.outputFile = outputFile.canonicalPath
|
||||
try {
|
||||
outputFile.canonicalPath
|
||||
} catch (ex: Throwable) {
|
||||
logger.warn("IO EXCEPTION: outputFile: ${outputFile.path}")
|
||||
throw ex
|
||||
}
|
||||
|
||||
args.outputFile = outputFile.absoluteFile.normalize().absolutePath
|
||||
|
||||
if (defaultsOnly) return
|
||||
|
||||
|
||||
Reference in New Issue
Block a user