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:
Alexander Udalov
2020-03-15 17:38:02 +01:00
committed by Alexander Udalov
parent fe5104b865
commit 7bb77e5672
11 changed files with 48 additions and 69 deletions
+1 -1
View File
@@ -4,7 +4,7 @@ plugins {
}
dependencies {
api(project(":core:descriptors"))
api(project(":core:deserialization"))
api(project(":compiler:util"))
compileOnly(intellijCoreDep()) { includeJars("intellij-core") }
}
+1 -2
View File
@@ -1,4 +1,3 @@
plugins {
kotlin("jvm")
id("jps-compatible")
@@ -6,7 +5,7 @@ plugins {
dependencies {
compile(project(":compiler:util"))
compile(project(":core:descriptors"))
compile(project(":core:deserialization"))
compileOnly(intellijDep()) { includeJars("trove4j") }
}
+1 -1
View File
@@ -7,7 +7,7 @@ plugins {
dependencies {
api(kotlinStdlib())
api(project(":compiler:compiler.version"))
api(project(":core:deserialization"))
api(project(":core:descriptors"))
compileOnly(project(":kotlin-reflect-api"))
compileOnly(intellijCoreDep()) { includeJars("intellij-core") }
@@ -17,14 +17,12 @@
package org.jetbrains.kotlin.utils
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.util.io.FileUtil
import com.intellij.openapi.vfs.VirtualFile
import java.io.*
import java.util.*
import java.util.jar.Attributes
import java.util.jar.JarFile
import java.util.jar.Manifest
import java.util.zip.ZipFile
object LibraryUtils {
private val LOG = Logger.getInstance(LibraryUtils::class.java)
@@ -60,38 +58,10 @@ object LibraryUtils {
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 {
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? {
if (!library.canRead()) return null
+2
View File
@@ -4,7 +4,9 @@ plugins {
}
dependencies {
api(project(":core:deserialization"))
api(project(":compiler:config"))
compileOnly(intellijCoreDep()) { includeJars("intellij-core") }
}
sourceSets {
@@ -1,17 +1,6 @@
/*
* Copyright 2010-2015 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.
* 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.
*/
package org.jetbrains.kotlin.utils
@@ -27,10 +16,28 @@ import java.util.zip.ZipException
import java.util.zip.ZipFile
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/"
// 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) {
for (library in libraries) {
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) {
if (isFile) {
action(JsLibrary(readText(), relativePath, correspondingSourceMapFile().contentIfExists(), this))
@@ -1,17 +1,6 @@
/*
* Copyright 2010-2015 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.
* 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.
*/
package org.jetbrains.kotlin.utils
@@ -24,7 +13,6 @@ import java.util.*
class KotlinJavascriptMetadata(val version: JsMetadataVersion, val moduleName: String, val body: ByteArray)
// TODO: move to JS modules
class JsMetadataVersion(vararg numbers: Int) : BinaryVersion(*numbers) {
override fun isCompatible(): Boolean =
this.isCompatibleTo(INSTANCE)
+1 -2
View File
@@ -1,4 +1,3 @@
plugins {
kotlin("jvm")
id("jps-compatible")
@@ -9,6 +8,7 @@ dependencies {
compile(project(":compiler:frontend"))
compile(project(":compiler:serialization"))
compile(project(":js:js.ast"))
compile(project(":js:js.config"))
compileOnly(intellijCoreDep()) { includeJars("intellij-core") }
}
@@ -16,4 +16,3 @@ sourceSets {
"main" { projectDefault() }
"test" {}
}
@@ -37,7 +37,7 @@ import org.jetbrains.kotlin.gradle.report.BuildReportMode
import org.jetbrains.kotlin.gradle.utils.*
import org.jetbrains.kotlin.incremental.ChangedFiles
import org.jetbrains.kotlin.library.impl.isKotlinLibrary
import org.jetbrains.kotlin.utils.LibraryUtils
import org.jetbrains.kotlin.utils.JsLibraryUtils
import java.io.File
import javax.inject.Inject
@@ -562,7 +562,7 @@ open class Kotlin2JsCompile : AbstractKotlinCompile<K2JSCompilerArguments>(), Ko
get() = kotlinOptionsImpl.sourceMapBaseDirs
private fun isHybridKotlinJsLibrary(file: File): Boolean =
LibraryUtils.isKotlinJavascriptLibrary(file) && isKotlinLibrary(file)
JsLibraryUtils.isKotlinJavascriptLibrary(file) && isKotlinLibrary(file)
private fun KotlinJsOptions.isPreIrBackendDisabled(): Boolean =
listOf(
@@ -590,7 +590,7 @@ open class Kotlin2JsCompile : AbstractKotlinCompile<K2JSCompilerArguments>(), Ko
::isHybridKotlinJsLibrary
}
} else {
LibraryUtils::isKotlinJavascriptLibrary
JsLibraryUtils::isKotlinJavascriptLibrary
}
override fun callCompilerAsync(args: K2JSCompilerArguments, sourceRoots: SourceRoots, changedFiles: ChangedFiles) {
@@ -28,7 +28,7 @@ import org.apache.maven.project.MavenProject;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments;
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.util.ArrayList;
@@ -146,7 +146,7 @@ public class K2JSCompilerMojo extends KotlinCompileMojoBase<K2JSCompilerArgument
}
private boolean checkIsKotlinJavascriptLibrary(File file) {
return useIrBackend ? LibraryUtils.isKotlinJavascriptIrLibrary(file) : LibraryUtils.isKotlinJavascriptLibrary(file);
return useIrBackend ? JsLibraryUtils.isKotlinJavascriptIrLibrary(file) : JsLibraryUtils.isKotlinJavascriptLibrary(file);
}
/**
+1
View File
@@ -22,6 +22,7 @@ val projectsToShadow = listOf(
":compiler:util",
":compiler:config",
":compiler:config.jvm",
":js:js.config",
":core:util.runtime",
":compiler:compiler.version"
)