Move JS binary version utilities to 'js.config'
This allows to replace dependency of 'util' on 'deserialization' with dependency on 'descriptors'.
This commit is contained in:
committed by
Alexander Udalov
parent
fe5104b865
commit
7bb77e5672
@@ -4,7 +4,7 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
api(project(":core:descriptors"))
|
api(project(":core:deserialization"))
|
||||||
api(project(":compiler:util"))
|
api(project(":compiler:util"))
|
||||||
compileOnly(intellijCoreDep()) { includeJars("intellij-core") }
|
compileOnly(intellijCoreDep()) { includeJars("intellij-core") }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
kotlin("jvm")
|
kotlin("jvm")
|
||||||
id("jps-compatible")
|
id("jps-compatible")
|
||||||
@@ -6,7 +5,7 @@ plugins {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile(project(":compiler:util"))
|
compile(project(":compiler:util"))
|
||||||
compile(project(":core:descriptors"))
|
compile(project(":core:deserialization"))
|
||||||
compileOnly(intellijDep()) { includeJars("trove4j") }
|
compileOnly(intellijDep()) { includeJars("trove4j") }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ plugins {
|
|||||||
dependencies {
|
dependencies {
|
||||||
api(kotlinStdlib())
|
api(kotlinStdlib())
|
||||||
api(project(":compiler:compiler.version"))
|
api(project(":compiler:compiler.version"))
|
||||||
api(project(":core:deserialization"))
|
api(project(":core:descriptors"))
|
||||||
|
|
||||||
compileOnly(project(":kotlin-reflect-api"))
|
compileOnly(project(":kotlin-reflect-api"))
|
||||||
compileOnly(intellijCoreDep()) { includeJars("intellij-core") }
|
compileOnly(intellijCoreDep()) { includeJars("intellij-core") }
|
||||||
|
|||||||
@@ -17,14 +17,12 @@
|
|||||||
package org.jetbrains.kotlin.utils
|
package org.jetbrains.kotlin.utils
|
||||||
|
|
||||||
import com.intellij.openapi.diagnostic.Logger
|
import com.intellij.openapi.diagnostic.Logger
|
||||||
import com.intellij.openapi.util.io.FileUtil
|
|
||||||
import com.intellij.openapi.vfs.VirtualFile
|
import com.intellij.openapi.vfs.VirtualFile
|
||||||
import java.io.*
|
import java.io.*
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import java.util.jar.Attributes
|
import java.util.jar.Attributes
|
||||||
import java.util.jar.JarFile
|
import java.util.jar.JarFile
|
||||||
import java.util.jar.Manifest
|
import java.util.jar.Manifest
|
||||||
import java.util.zip.ZipFile
|
|
||||||
|
|
||||||
object LibraryUtils {
|
object LibraryUtils {
|
||||||
private val LOG = Logger.getInstance(LibraryUtils::class.java)
|
private val LOG = Logger.getInstance(LibraryUtils::class.java)
|
||||||
@@ -60,38 +58,10 @@ object LibraryUtils {
|
|||||||
return classesRoots.firstOrNull { it.name == jarName }
|
return classesRoots.firstOrNull { it.name == jarName }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("unused") // used in K2JSCompilerMojo
|
|
||||||
@JvmStatic fun isKotlinJavascriptLibrary(library: File): Boolean = KotlinJavascriptMetadataUtils.loadMetadata(library).isNotEmpty()
|
|
||||||
|
|
||||||
@JvmStatic fun isKotlinJavascriptStdLibrary(library: File): Boolean {
|
@JvmStatic fun isKotlinJavascriptStdLibrary(library: File): Boolean {
|
||||||
return checkAttributeValue(library, TITLE_KOTLIN_JAVASCRIPT_STDLIB, Attributes.Name.IMPLEMENTATION_TITLE)
|
return checkAttributeValue(library, TITLE_KOTLIN_JAVASCRIPT_STDLIB, Attributes.Name.IMPLEMENTATION_TITLE)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun isZippedKlibInZip(candidate: File): Boolean {
|
|
||||||
var manifestFound = false
|
|
||||||
var irFound = false
|
|
||||||
for (entry in ZipFile(candidate).entries()) {
|
|
||||||
if (entry.name == "manifest") manifestFound = true
|
|
||||||
if (entry.name == "ir/") irFound = true
|
|
||||||
}
|
|
||||||
return manifestFound && irFound
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun isZippedKlib(candidate: File): Boolean {
|
|
||||||
return candidate.extension == "klib"
|
|
||||||
}
|
|
||||||
|
|
||||||
@JvmStatic
|
|
||||||
fun isKotlinJavascriptIrLibrary(candidate: File): Boolean {
|
|
||||||
return when {
|
|
||||||
isZippedKlib(candidate) -> true
|
|
||||||
FileUtil.isJarOrZip(candidate) -> isZippedKlibInZip(candidate)
|
|
||||||
!File(candidate, "manifest").isFile -> false
|
|
||||||
!File(candidate, "ir").isDirectory -> false
|
|
||||||
else -> true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getManifestFromJar(library: File): Manifest? {
|
private fun getManifestFromJar(library: File): Manifest? {
|
||||||
if (!library.canRead()) return null
|
if (!library.canRead()) return null
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,9 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
api(project(":core:deserialization"))
|
||||||
api(project(":compiler:config"))
|
api(project(":compiler:config"))
|
||||||
|
compileOnly(intellijCoreDep()) { includeJars("intellij-core") }
|
||||||
}
|
}
|
||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
|
|||||||
+34
-14
@@ -1,17 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
*
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
* 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.utils
|
package org.jetbrains.kotlin.utils
|
||||||
@@ -27,10 +16,28 @@ import java.util.zip.ZipException
|
|||||||
import java.util.zip.ZipFile
|
import java.util.zip.ZipFile
|
||||||
|
|
||||||
object JsLibraryUtils {
|
object JsLibraryUtils {
|
||||||
private val LOG = Logger.getInstance(LibraryUtils::class.java)
|
private val LOG = Logger.getInstance(JsLibraryUtils::class.java)
|
||||||
|
|
||||||
private val META_INF_RESOURCES = "${LibraryUtils.META_INF}resources/"
|
private val META_INF_RESOURCES = "${LibraryUtils.META_INF}resources/"
|
||||||
|
|
||||||
|
// Also used in K2JSCompilerMojo
|
||||||
|
@JvmStatic
|
||||||
|
fun isKotlinJavascriptLibrary(library: File): Boolean =
|
||||||
|
KotlinJavascriptMetadataUtils.loadMetadata(library).isNotEmpty()
|
||||||
|
|
||||||
|
// Also used in K2JSCompilerMojo
|
||||||
|
@Suppress("unused")
|
||||||
|
@JvmStatic
|
||||||
|
fun isKotlinJavascriptIrLibrary(candidate: File): Boolean {
|
||||||
|
return when {
|
||||||
|
isZippedKlib(candidate) -> true
|
||||||
|
FileUtil.isJarOrZip(candidate) -> isZippedKlibInZip(candidate)
|
||||||
|
!File(candidate, "manifest").isFile -> false
|
||||||
|
!File(candidate, "ir").isDirectory -> false
|
||||||
|
else -> true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@JvmStatic fun copyJsFilesFromLibraries(libraries: List<String>, outputLibraryJsPath: String, copySourceMap: Boolean = false) {
|
@JvmStatic fun copyJsFilesFromLibraries(libraries: List<String>, outputLibraryJsPath: String, copySourceMap: Boolean = false) {
|
||||||
for (library in libraries) {
|
for (library in libraries) {
|
||||||
val file = File(library)
|
val file = File(library)
|
||||||
@@ -63,6 +70,19 @@ object JsLibraryUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun isZippedKlibInZip(candidate: File): Boolean {
|
||||||
|
var manifestFound = false
|
||||||
|
var irFound = false
|
||||||
|
for (entry in ZipFile(candidate).entries()) {
|
||||||
|
if (entry.name == "manifest") manifestFound = true
|
||||||
|
if (entry.name == "ir/") irFound = true
|
||||||
|
}
|
||||||
|
return manifestFound && irFound
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun isZippedKlib(candidate: File): Boolean =
|
||||||
|
candidate.extension == "klib"
|
||||||
|
|
||||||
private fun File.runIfFileExists(relativePath: String, action: (JsLibrary) -> Unit) {
|
private fun File.runIfFileExists(relativePath: String, action: (JsLibrary) -> Unit) {
|
||||||
if (isFile) {
|
if (isFile) {
|
||||||
action(JsLibrary(readText(), relativePath, correspondingSourceMapFile().contentIfExists(), this))
|
action(JsLibrary(readText(), relativePath, correspondingSourceMapFile().contentIfExists(), this))
|
||||||
+2
-14
@@ -1,17 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
*
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
* 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.utils
|
package org.jetbrains.kotlin.utils
|
||||||
@@ -24,7 +13,6 @@ import java.util.*
|
|||||||
|
|
||||||
class KotlinJavascriptMetadata(val version: JsMetadataVersion, val moduleName: String, val body: ByteArray)
|
class KotlinJavascriptMetadata(val version: JsMetadataVersion, val moduleName: String, val body: ByteArray)
|
||||||
|
|
||||||
// TODO: move to JS modules
|
|
||||||
class JsMetadataVersion(vararg numbers: Int) : BinaryVersion(*numbers) {
|
class JsMetadataVersion(vararg numbers: Int) : BinaryVersion(*numbers) {
|
||||||
override fun isCompatible(): Boolean =
|
override fun isCompatible(): Boolean =
|
||||||
this.isCompatibleTo(INSTANCE)
|
this.isCompatibleTo(INSTANCE)
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
kotlin("jvm")
|
kotlin("jvm")
|
||||||
id("jps-compatible")
|
id("jps-compatible")
|
||||||
@@ -9,6 +8,7 @@ dependencies {
|
|||||||
compile(project(":compiler:frontend"))
|
compile(project(":compiler:frontend"))
|
||||||
compile(project(":compiler:serialization"))
|
compile(project(":compiler:serialization"))
|
||||||
compile(project(":js:js.ast"))
|
compile(project(":js:js.ast"))
|
||||||
|
compile(project(":js:js.config"))
|
||||||
compileOnly(intellijCoreDep()) { includeJars("intellij-core") }
|
compileOnly(intellijCoreDep()) { includeJars("intellij-core") }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -16,4 +16,3 @@ sourceSets {
|
|||||||
"main" { projectDefault() }
|
"main" { projectDefault() }
|
||||||
"test" {}
|
"test" {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -37,7 +37,7 @@ import org.jetbrains.kotlin.gradle.report.BuildReportMode
|
|||||||
import org.jetbrains.kotlin.gradle.utils.*
|
import org.jetbrains.kotlin.gradle.utils.*
|
||||||
import org.jetbrains.kotlin.incremental.ChangedFiles
|
import org.jetbrains.kotlin.incremental.ChangedFiles
|
||||||
import org.jetbrains.kotlin.library.impl.isKotlinLibrary
|
import org.jetbrains.kotlin.library.impl.isKotlinLibrary
|
||||||
import org.jetbrains.kotlin.utils.LibraryUtils
|
import org.jetbrains.kotlin.utils.JsLibraryUtils
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@@ -562,7 +562,7 @@ open class Kotlin2JsCompile : AbstractKotlinCompile<K2JSCompilerArguments>(), Ko
|
|||||||
get() = kotlinOptionsImpl.sourceMapBaseDirs
|
get() = kotlinOptionsImpl.sourceMapBaseDirs
|
||||||
|
|
||||||
private fun isHybridKotlinJsLibrary(file: File): Boolean =
|
private fun isHybridKotlinJsLibrary(file: File): Boolean =
|
||||||
LibraryUtils.isKotlinJavascriptLibrary(file) && isKotlinLibrary(file)
|
JsLibraryUtils.isKotlinJavascriptLibrary(file) && isKotlinLibrary(file)
|
||||||
|
|
||||||
private fun KotlinJsOptions.isPreIrBackendDisabled(): Boolean =
|
private fun KotlinJsOptions.isPreIrBackendDisabled(): Boolean =
|
||||||
listOf(
|
listOf(
|
||||||
@@ -590,7 +590,7 @@ open class Kotlin2JsCompile : AbstractKotlinCompile<K2JSCompilerArguments>(), Ko
|
|||||||
::isHybridKotlinJsLibrary
|
::isHybridKotlinJsLibrary
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
LibraryUtils::isKotlinJavascriptLibrary
|
JsLibraryUtils::isKotlinJavascriptLibrary
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun callCompilerAsync(args: K2JSCompilerArguments, sourceRoots: SourceRoots, changedFiles: ChangedFiles) {
|
override fun callCompilerAsync(args: K2JSCompilerArguments, sourceRoots: SourceRoots, changedFiles: ChangedFiles) {
|
||||||
|
|||||||
+2
-2
@@ -28,7 +28,7 @@ import org.apache.maven.project.MavenProject;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments;
|
import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments;
|
||||||
import org.jetbrains.kotlin.cli.js.K2JSCompiler;
|
import org.jetbrains.kotlin.cli.js.K2JSCompiler;
|
||||||
import org.jetbrains.kotlin.utils.LibraryUtils;
|
import org.jetbrains.kotlin.utils.JsLibraryUtils;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -146,7 +146,7 @@ public class K2JSCompilerMojo extends KotlinCompileMojoBase<K2JSCompilerArgument
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean checkIsKotlinJavascriptLibrary(File file) {
|
private boolean checkIsKotlinJavascriptLibrary(File file) {
|
||||||
return useIrBackend ? LibraryUtils.isKotlinJavascriptIrLibrary(file) : LibraryUtils.isKotlinJavascriptLibrary(file);
|
return useIrBackend ? JsLibraryUtils.isKotlinJavascriptIrLibrary(file) : JsLibraryUtils.isKotlinJavascriptLibrary(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ val projectsToShadow = listOf(
|
|||||||
":compiler:util",
|
":compiler:util",
|
||||||
":compiler:config",
|
":compiler:config",
|
||||||
":compiler:config.jvm",
|
":compiler:config.jvm",
|
||||||
|
":js:js.config",
|
||||||
":core:util.runtime",
|
":core:util.runtime",
|
||||||
":compiler:compiler.version"
|
":compiler:compiler.version"
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user