Skip to content

Commit

Permalink
JS: drop support of old library format
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexey Andreev authored and Alexey Andreev committed Feb 10, 2017
1 parent 82320bd commit 7192529
Show file tree
Hide file tree
Showing 37 changed files with 143 additions and 366 deletions.
44 changes: 44 additions & 0 deletions compiler/testData/cli/js/folderAsLib/LibraryExample.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
if (typeof kotlin === 'undefined') {
throw new Error("Error loading module 'LibraryExample'. Its dependency 'kotlin' was not found. Please, check whether 'kotlin' is loaded prior to 'LibraryExample'.");
}
var LibraryExample = function (_, Kotlin) {
'use strict';
function pairAdd(p) {
return p.first + p.second | 0;
}
function pairMul(p) {
return Kotlin.imul(p.first, p.second);
}
function IntHolder(value) {
this.value = value;
}
IntHolder.$metadata$ = {
kind: Kotlin.Kind.CLASS,
simpleName: 'IntHolder',
interfaces: []
};
IntHolder.prototype.component1 = function () {
return this.value;
};
IntHolder.prototype.copy_za3lpa$ = function (value) {
return new IntHolder(value === void 0 ? this.value : value);
};
IntHolder.prototype.toString = function () {
return 'IntHolder(value=' + Kotlin.toString(this.value) + ')';
};
IntHolder.prototype.hashCode = function () {
var result = 0;
result = result * 31 + Kotlin.hashCode(this.value) | 0;
return result;
};
IntHolder.prototype.equals = function (other) {
return this === other || (other !== null && (typeof other === 'object' && (Object.getPrototypeOf(this) === Object.getPrototypeOf(other) && Kotlin.equals(this.value, other.value))));
};
var package$library = _.library || (_.library = {});
var package$sample = package$library.sample || (package$library.sample = {});
package$sample.pairAdd_1fzo63$ = pairAdd;
package$sample.pairMul_1fzo63$ = pairMul;
package$sample.IntHolder = IntHolder;
Kotlin.defineModule('LibraryExample', _);
return _;
}(typeof LibraryExample === 'undefined' ? {} : LibraryExample, kotlin);

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Binary file added compiler/testData/cli/js/lib/LibraryExample.jar
Binary file not shown.
5 changes: 5 additions & 0 deletions compiler/testData/cli/js/lib/ReadMe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# jslib

Path to sources: `compiler/testData/cli/js/jslib`

`folderAsLib/LibraryExample.js`, `folderAsLib/LibraryExample.meta.js` and `LibraryExample.jar` should be updated after changing some files in source folder.
2 changes: 1 addition & 1 deletion compiler/testData/cli/js/notValidLibraryDir.args
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
$TESTDATA_DIR$/withLib.kt
-libraries
compiler/testData/integration/ant/js/simpleWithStdlibAndFolderAsAnotherLib
compiler/testData/integration/ant/js/simpleWithStdlibAndJsFileAsAnotherLib
-output
$TEMP_DIR$/out.js
2 changes: 1 addition & 1 deletion compiler/testData/cli/js/notValidLibraryDir.out
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
warning: 'compiler/testData/integration/ant/js/simpleWithStdlibAndFolderAsAnotherLib' is not a valid Kotlin Javascript library
warning: 'compiler/testData/integration/ant/js/simpleWithStdlibAndJsFileAsAnotherLib' is not a valid Kotlin Javascript library
compiler/testData/cli/js/withLib.kt:2:8: error: unresolved reference: library
import library.sample.*
^
Expand Down
2 changes: 1 addition & 1 deletion compiler/testData/cli/js/withFolderAsLib.args
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
$TESTDATA_DIR$/withLib.kt
-libraries
compiler/testData/integration/ant/js/simpleWithStdlibAndFolderAsAnotherLib/jslib-example
$TESTDATA_DIR$/folderAsLib
-output
$TEMP_DIR$/out.js
2 changes: 1 addition & 1 deletion compiler/testData/cli/js/withLib.args
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
$TESTDATA_DIR$/withLib.kt
-libraries
compiler/testData/integration/ant/js/simpleWithStdlibAndAnotherLib/jslib-example.jar
$TESTDATA_DIR$/lib/LibraryExample.jar
-output
$TEMP_DIR$/out.js

This file was deleted.

This file was deleted.

Binary file not shown.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

20 changes: 1 addition & 19 deletions compiler/util/src/org/jetbrains/kotlin/utils/LibraryUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,20 @@ import java.util.jar.Manifest
object LibraryUtils {
private val LOG = Logger.getInstance(LibraryUtils::class.java)

val KOTLIN_JS_MODULE_NAME: String = "Kotlin-JS-Module-Name"
private var TITLE_KOTLIN_JAVASCRIPT_STDLIB: String
private var TITLE_KOTLIN_JAVASCRIPT_LIB: String

val META_INF = "META-INF/"
private val MANIFEST_PATH = "${META_INF}MANIFEST.MF"
private val KOTLIN_JS_MODULE_ATTRIBUTE_NAME = Attributes.Name(KOTLIN_JS_MODULE_NAME)

init {
var jsStdLib = ""
var jsLib = ""

val manifestProperties = LibraryUtils::class.java.getResourceAsStream("/kotlinManifest.properties")
if (manifestProperties != null) {
try {
val properties = Properties()
properties.load(manifestProperties)
jsStdLib = properties.getPropertyOrFail("manifest.impl.title.kotlin.javascript.stdlib")
jsLib = properties.getPropertyOrFail("manifest.spec.title.kotlin.javascript.lib")
}
catch (e: IOException) {
LOG.error(e)
Expand All @@ -57,27 +52,14 @@ object LibraryUtils {
}

TITLE_KOTLIN_JAVASCRIPT_STDLIB = jsStdLib
TITLE_KOTLIN_JAVASCRIPT_LIB = jsLib
}

@JvmStatic fun getJarFile(classesRoots: List<VirtualFile>, jarName: String): VirtualFile? {
return classesRoots.firstOrNull { it.name == jarName }
}

@JvmStatic fun getKotlinJsModuleName(library: File): String? {
return getManifestMainAttributesFromJarOrDirectory(library)?.getValue(KOTLIN_JS_MODULE_ATTRIBUTE_NAME)
}

@JvmStatic fun isOldKotlinJavascriptLibrary(library: File): Boolean =
checkAttributeValue(library, TITLE_KOTLIN_JAVASCRIPT_LIB, Attributes.Name.SPECIFICATION_TITLE) &&
getKotlinJsModuleName(library) != null

@JvmStatic fun isKotlinJavascriptLibraryWithMetadata(library: File): Boolean =
KotlinJavascriptMetadataUtils.loadMetadata(library).isNotEmpty()

@Suppress("unused") // used in K2JSCompilerMojo
@JvmStatic fun isKotlinJavascriptLibrary(library: File): Boolean =
isOldKotlinJavascriptLibrary(library) || isKotlinJavascriptLibraryWithMetadata(library)
@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)
Expand Down
1 change: 0 additions & 1 deletion idea/src/META-INF/extensions/kotlin2js.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@
<suppressStringProvider implementation="org.jetbrains.kotlin.js.analyze.SuppressUnusedParameterForJsNative"/>
<suppressStringProvider implementation="org.jetbrains.kotlin.js.analyze.SuppressNoBodyErrorsForNativeDeclarations"/>
<diagnosticSuppressor implementation="org.jetbrains.kotlin.js.analyze.SuppressUninitializedErrorsForNativeDeclarations"/>
<diagnosticSuppressor implementation="org.jetbrains.kotlin.js.analyze.SuppressWarningsFromExternalModules"/>
</extensions>
</idea-plugin>
Original file line number Diff line number Diff line change
Expand Up @@ -98,36 +98,35 @@ class KotlinJpsBuildTest : AbstractKotlinJpsBuildTestCase() {
private val EXPECTED_JS_FILES_IN_OUTPUT_NO_COPY = hashSetOf(
"$PROJECT_NAME.js",
"$PROJECT_NAME.meta.js",
"$PROJECT_NAME/root-package.kjsm",
"$PROJECT_NAME/library/sample/sample.kjsm"
"$PROJECT_NAME/root-package.kjsm"
)
private val EXPECTED_JS_FILES_IN_OUTPUT_WITH_ADDITIONAL_LIB_AND_DEFAULT_DIR = hashSetOf(
"$PROJECT_NAME.js",
"$PROJECT_NAME.meta.js",
"lib/kotlin.js",
"lib/kotlin.meta.js",
"lib/jslib-example.js",
"lib/jslib-example.meta.js",
"lib/file0.js",
"lib/dir/file1.js",
"lib/META-INF-ex/file2.js",
"lib/res0.js",
"lib/resdir/res1.js",
"$PROJECT_NAME/root-package.kjsm",
"$PROJECT_NAME/library/sample/sample.kjsm"
"$PROJECT_NAME/root-package.kjsm"
)
private val EXPECTED_JS_FILES_IN_OUTPUT_WITH_ADDITIONAL_LIB_AND_CUSTOM_DIR = hashSetOf(
"$PROJECT_NAME.js",
"$PROJECT_NAME.meta.js",
"custom/kotlin.js",
"custom/kotlin.meta.js",
"custom/jslib-example.js",
"custom/jslib-example.meta.js",
"custom/file0.js",
"custom/dir/file1.js",
"custom/META-INF-ex/file2.js",
"custom/res0.js",
"custom/resdir/res1.js",
"$PROJECT_NAME/root-package.kjsm",
"$PROJECT_NAME/library/sample/sample.kjsm"
"$PROJECT_NAME/root-package.kjsm"
)

private fun k2jsOutput(vararg moduleNames: String): Array<String> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ Built-By: JetBrains
Implementation-Vendor: JetBrains
Implementation-Version: snapshot
Specification-Title: Kotlin JavaScript Lib
Kotlin-JS-Module-Name: jslib-example

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# jslib-example

Path to sources: compiler/integration-tests/testData/ant/js/simpleWithStdlibAndFolderAsAnotherLib/jslib-example
Path to sources: `compiler/testData/cli/js/jslib`

The archive compiler/integration-tests/testData/ant/js/simpleWithStdlibAndAnotherLib/jslib-example.jar should be updated after
changing some files in source folder.
Loading

0 comments on commit 7192529

Please sign in to comment.