Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy JS stdlib as PY one (only for tests now) #121

Merged
merged 4 commits into from
Mar 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .idea/artifacts/kotlin_stdlib_py_js_1_6_255_SNAPSHOT.xml

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

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

140 changes: 140 additions & 0 deletions libraries/stdlib/py-minimal-for-test/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
import org.jetbrains.kotlin.gradle.dsl.KotlinCompile

plugins {
kotlin("multiplatform")
}

kotlin {
js(IR) {
nodejs()
}
}

val commonMainSources by task<Sync> {
dependsOn(":kotlin-stdlib-py:commonMainSources")
from {
val fullCommonMainSources = tasks.getByPath(":kotlin-stdlib-py:commonMainSources")
exclude(
listOf(
"libraries/stdlib/unsigned/src/kotlin/UByteArray.kt",
"libraries/stdlib/unsigned/src/kotlin/UIntArray.kt",
"libraries/stdlib/unsigned/src/kotlin/ULongArray.kt",
"libraries/stdlib/unsigned/src/kotlin/UMath.kt",
"libraries/stdlib/unsigned/src/kotlin/UNumbers.kt",
"libraries/stdlib/unsigned/src/kotlin/UShortArray.kt",
"libraries/stdlib/unsigned/src/kotlin/UStrings.kt",
"libraries/stdlib/common/src/generated/_Arrays.kt",
"libraries/stdlib/common/src/generated/_Collections.kt",
"libraries/stdlib/common/src/generated/_Comparisons.kt",
"libraries/stdlib/common/src/generated/_Maps.kt",
"libraries/stdlib/common/src/generated/_OneToManyTitlecaseMappings.kt",
"libraries/stdlib/common/src/generated/_Sequences.kt",
"libraries/stdlib/common/src/generated/_Sets.kt",
"libraries/stdlib/common/src/generated/_Strings.kt",
"libraries/stdlib/common/src/generated/_UArrays.kt",
"libraries/stdlib/common/src/generated/_URanges.kt",
"libraries/stdlib/common/src/generated/_UCollections.kt",
"libraries/stdlib/common/src/generated/_UComparisons.kt",
"libraries/stdlib/common/src/generated/_USequences.kt",
"libraries/stdlib/common/src/kotlin/SequencesH.kt",
"libraries/stdlib/common/src/kotlin/TextH.kt",
"libraries/stdlib/common/src/kotlin/UMath.kt",
"libraries/stdlib/common/src/kotlin/collections/**",
"libraries/stdlib/common/src/kotlin/ioH.kt",
"libraries/stdlib/src/kotlin/collections/**",
"libraries/stdlib/src/kotlin/properties/Delegates.kt",
"libraries/stdlib/src/kotlin/random/URandom.kt",
"libraries/stdlib/src/kotlin/text/**",
"libraries/stdlib/src/kotlin/time/**",
"libraries/stdlib/src/kotlin/util/KotlinVersion.kt",
"libraries/stdlib/src/kotlin/util/Tuples.kt"
)
)
fullCommonMainSources.outputs.files.singleFile
}

into("$buildDir/commonMainSources")
}

val jsMainSources by task<Sync> {
dependsOn(":kotlin-stdlib-py:jsMainSources")

from {
val fullJsMainSources = tasks.getByPath(":kotlin-stdlib-py:jsMainSources")
exclude(
listOf(
"libraries/stdlib/js/src/org.w3c/**",
"libraries/stdlib/js/src/kotlin/char.kt",
"libraries/stdlib/js/src/kotlin/collections.kt",
"libraries/stdlib/js/src/kotlin/collections/**",
"libraries/stdlib/js/src/kotlin/time/**",
"libraries/stdlib/js/src/kotlin/console.kt",
"libraries/stdlib/js/src/kotlin/coreDeprecated.kt",
"libraries/stdlib/js/src/kotlin/date.kt",
"libraries/stdlib/js/src/kotlin/grouping.kt",
"libraries/stdlib/js/src/kotlin/json.kt",
"libraries/stdlib/js/src/kotlin/promise.kt",
"libraries/stdlib/js/src/kotlin/regexp.kt",
"libraries/stdlib/js/src/kotlin/sequence.kt",
"libraries/stdlib/js/src/kotlin/throwableExtensions.kt",
"libraries/stdlib/js/src/kotlin/text/**",
"libraries/stdlib/js/src/kotlin/reflect/KTypeHelpers.kt",
"libraries/stdlib/js/src/kotlin/reflect/KTypeParameterImpl.kt",
"libraries/stdlib/js/src/kotlin/reflect/KTypeImpl.kt",
"libraries/stdlib/js/src/kotlin/dom/**",
"libraries/stdlib/js/src/kotlin/browser/**",
"libraries/stdlib/js/src/kotlinx/dom/**",
"libraries/stdlib/js/src/kotlinx/browser/**"
)
)
fullJsMainSources.outputs.files.singleFile
}

for (jsIrSrcDir in listOf("builtins", "runtime", "src")) {
from("$rootDir/libraries/stdlib/py/$jsIrSrcDir") {
exclude(
listOf(
"collectionsHacks.kt",
"generated/**",
"kotlin/text/**"
)
)
into("libraries/stdlib/py/$jsIrSrcDir")
}
}

from("$rootDir/libraries/stdlib/py-minimal-for-test/src")
into("$buildDir/jsMainSources")
}

kotlin {
sourceSets {
val commonMain by getting {
kotlin.srcDir(files(commonMainSources.map { it.destinationDir }))
}
val jsMain by getting {
kotlin.srcDir(files(jsMainSources.map { it.destinationDir }))
}
}
}

tasks.withType<KotlinCompile<*>> {
kotlinOptions.freeCompilerArgs += listOf(
"-Xallow-kotlin-package",
"-Xopt-in=kotlin.ExperimentalMultiplatform",
"-Xopt-in=kotlin.contracts.ExperimentalContracts",
"-Xopt-in=kotlin.RequiresOptIn",
"-Xopt-in=kotlin.ExperimentalUnsignedTypes",
"-Xopt-in=kotlin.ExperimentalStdlibApi"
)
}

tasks {
compileKotlinMetadata {
enabled = false
}

named("compileKotlinJs", KotlinCompile::class) {
kotlinOptions.freeCompilerArgs += "-Xir-module-name=kotlin"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* Copyright 2010-2021 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 kotlin.collections

@SinceKotlin("1.4")
@library("arrayEquals")
public infix fun <T> Array<out T>?.contentEquals(other: Array<out T>?): Boolean {
definedExternally
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* 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 kotlin

/**
* Returns `true` if this char sequence is empty (contains no characters).
*/
@kotlin.internal.InlineOnly
public inline fun CharSequence.isEmpty(): Boolean = length == 0

/**
* Accumulates value starting with [initial] value and applying [operation] from left to right to current accumulator value and each element.
*/
public inline fun <T, R> Array<out T>.fold(initial: R, operation: (acc: R, T) -> R): R {
var accumulator = initial
for (element in this) accumulator = operation(accumulator, element)
return accumulator
}


public actual fun Throwable.stackTraceToString(): String = toString()

public actual fun Throwable.printStackTrace() {
TODO("Not implemented in reduced runtime")
}

public actual fun Throwable.addSuppressed(exception: Throwable) {
TODO("Not implemented in reduced runtime")
}

public actual val Throwable.suppressedExceptions: List<Throwable>
get() = TODO("Not implemented in reduced runtime")

/**
* Returns a string representation of this [Long] value in the specified [radix].
*
* @throws IllegalArgumentException when [radix] is not a valid radix for number to string conversion.
*/
@SinceKotlin("1.2")
public fun Long.toString(radix: Int): String =
this.toStringImpl(checkRadix(radix))

/**
* Checks whether the given [radix] is valid radix for string to number and number to string conversion.
*/
internal fun checkRadix(radix: Int): Int {
if (radix !in 2..36) {
throw IllegalArgumentException("radix $radix was not in valid range 2..36")
}
return radix
}
27 changes: 27 additions & 0 deletions libraries/stdlib/py-minimal-for-test/src/tests.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2010-2018 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 kotlin.test

// This file plugs some declaration from "kotlin.test" library used in tests.

fun <T> assertEquals(a: T, b: T) {
if (a != b) throw Exception("")
}

fun assertTrue(x: Boolean) {
if (!x) throw Exception("")
}

fun assertFalse(x: Boolean) {
if (x) throw Exception("")
}

fun <T : Any> assertNotNull(actual: T?, message: String? = null): T {
if (actual == null) throw Exception("")
return actual
}


Loading