ec8ead754f
Rework kotlin-test common tests to make them runnable with qunit. Change the way how asserter is overridden in js box tests. Minor: remove unneeded test configs
283 lines
7.2 KiB
Groovy
283 lines
7.2 KiB
Groovy
plugins {
|
|
id 'com.craigburke.karma' version '1.4.4'
|
|
}
|
|
|
|
description = 'Kotlin Standard Library for JS'
|
|
|
|
apply plugin: 'kotlin2js'
|
|
|
|
configurePublishing(project)
|
|
|
|
|
|
def builtinsSrcDir = "${buildDir}/builtin-sources"
|
|
def builtinsSrcDir2 = "${buildDir}/builtin-sources-for-builtins"
|
|
def commonSrcDir = "${buildDir}/common-sources"
|
|
def commonTestSrcDir = "${buildDir}/common-test-sources"
|
|
def builtinsDir = "${rootDir}/../core/builtins"
|
|
def jsLibrariesDir = "${rootDir}/../js/js.libraries"
|
|
def jsSrcDir = "${jsLibrariesDir}/src"
|
|
def jsTestSrcDir = "${jsLibrariesDir}/test"
|
|
def jsSrcJsDir = "${jsSrcDir}/js"
|
|
def jsOutputFile = "${buildDir}/classes/kotlin.js"
|
|
def jsTestOutputFile = "${buildDir}/classes/test/kotlin-stdlib-js_test.js"
|
|
def kotlinTestJsOutputFile = "${project(':kotlin-test:kotlin-test-js').buildDir}/classes/main/kotlin-test.js"
|
|
def kotlinTestJsTestOutputFile = "${project(':kotlin-test:kotlin-test-js').buildDir}/classes/test/kotlin-test-js_test.js"
|
|
|
|
|
|
sourceSets {
|
|
builtins {
|
|
kotlin {
|
|
srcDir builtinsSrcDir2
|
|
srcDir "${jsSrcDir}/builtins"
|
|
}
|
|
}
|
|
|
|
main {
|
|
kotlin {
|
|
srcDir builtinsSrcDir
|
|
srcDir jsSrcDir
|
|
exclude "builtins"
|
|
srcDir commonSrcDir
|
|
}
|
|
}
|
|
|
|
test {
|
|
kotlin {
|
|
srcDir commonTestSrcDir
|
|
srcDir jsTestSrcDir
|
|
}
|
|
}
|
|
}
|
|
|
|
dependencies {
|
|
testCompile project(':kotlin-test:kotlin-test-js')
|
|
}
|
|
|
|
createPreprocessorTask(project, "Main", "${projectDir}/../src/kotlin", commonSrcDir)
|
|
createPreprocessorTask(project, "Test", "${projectDir}/../test", commonTestSrcDir)
|
|
|
|
task prepareComparableSource(type: Copy) {
|
|
doFirst {
|
|
delete builtinsSrcDir2
|
|
}
|
|
from("${builtinsDir}/native/kotlin") {
|
|
include "Comparable.kt"
|
|
}
|
|
into builtinsSrcDir2
|
|
}
|
|
|
|
task prepareBuiltinsSources(type: Copy) {
|
|
doFirst {
|
|
delete builtinsSrcDir
|
|
}
|
|
from("${builtinsDir}/native/kotlin") {
|
|
include "Iterator.kt"
|
|
include "Collections.kt"
|
|
include "CharSequence.kt"
|
|
include "Annotation.kt"
|
|
}
|
|
from("${builtinsDir}/src/kotlin/") {
|
|
include "annotation/Annotations.kt"
|
|
include "Function.kt"
|
|
include "Iterators.kt"
|
|
include "Range.kt"
|
|
include "Progressions.kt"
|
|
include "ProgressionIterators.kt"
|
|
include "Ranges.kt"
|
|
include "internal/InternalAnnotations.kt"
|
|
include "internal/progressionUtil.kt"
|
|
include "reflect/**/*.kt"
|
|
include "Unit.kt"
|
|
}
|
|
into builtinsSrcDir
|
|
}
|
|
|
|
kotlin.experimental.coroutines "enable"
|
|
|
|
tasks.withType(org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile) {
|
|
kotlinOptions {
|
|
main = "noCall"
|
|
moduleKind = "commonjs"
|
|
freeCompilerArgs = [
|
|
"-version",
|
|
"-Xallow-kotlin-package",
|
|
]
|
|
}
|
|
}
|
|
|
|
compileBuiltinsKotlin2Js {
|
|
dependsOn prepareComparableSource
|
|
kotlinOptions {
|
|
metaInfo = false
|
|
outputFile = "${buildDir}/classes/builtins/kotlin.js"
|
|
}
|
|
}
|
|
|
|
compileKotlin2Js {
|
|
dependsOn preprocessSourcesMain, prepareBuiltinsSources
|
|
kotlinOptions {
|
|
outputFile = "${buildDir}/classes/main/kotlin.js"
|
|
}
|
|
}
|
|
|
|
compileTestKotlin2Js {
|
|
dependsOn preprocessSourcesTest
|
|
kotlinOptions {
|
|
moduleKind = "plain"
|
|
}
|
|
}
|
|
|
|
configurations {
|
|
closureCompiler
|
|
}
|
|
dependencies {
|
|
closureCompiler "com.google.javascript:closure-compiler:v20160315"
|
|
}
|
|
|
|
task compileJs {
|
|
dependsOn compileBuiltinsKotlin2Js, compileKotlin2Js
|
|
inputs.files(compileBuiltinsKotlin2Js.outputs.files)
|
|
inputs.files(compileKotlin2Js.outputs.files)
|
|
inputs.dir(jsSrcDir)
|
|
outputs.file(jsOutputFile)
|
|
|
|
|
|
doLast {
|
|
ant.taskdef(
|
|
name: 'closureCompiler',
|
|
classname: 'com.google.javascript.jscomp.ant.CompileTask',
|
|
classpath: configurations.closureCompiler.asPath)
|
|
|
|
ant.closureCompiler(
|
|
compilationLevel: 'whitespace',
|
|
prettyprint: 'true',
|
|
languagein: 'ECMASCRIPT5_STRICT',
|
|
warning: 'default',
|
|
output: jsOutputFile,
|
|
outputWrapperFile: "${jsSrcJsDir}/closure-wrapper.txt"
|
|
) {
|
|
ant.path {
|
|
fileset(dir: "${jsSrcJsDir}") {
|
|
include(name: '**/*.js')
|
|
exclude(name: 'externs.js')
|
|
}
|
|
fileset(dir: "${buildDir}/classes") {
|
|
include(name: 'builtins/kotlin.js')
|
|
include(name: 'main/kotlin.js')
|
|
}
|
|
}
|
|
|
|
externs(dir: "${jsSrcJsDir}") {
|
|
ant.file(name: 'externs.js')
|
|
}
|
|
}
|
|
|
|
ant.replaceregexp(
|
|
file: jsOutputFile,
|
|
match: "module.exports,\\s*require\\([^)]+\\)",
|
|
replace: "",
|
|
byline: "true", encoding: "UTF-8")
|
|
ant.replaceregexp(
|
|
file: jsOutputFile,
|
|
match: "function\\s*\\(_,\\s*Kotlin\\)",
|
|
replace: "function()",
|
|
byline: "true", encoding: "UTF-8")
|
|
ant.replaceregexp(
|
|
file: jsOutputFile,
|
|
match: "return\\s+_;",
|
|
replace: "",
|
|
byline: "true", encoding: "UTF-8")
|
|
}
|
|
}
|
|
|
|
classes.dependsOn compileJs
|
|
|
|
|
|
jar {
|
|
enabled false
|
|
}
|
|
|
|
task mergedJar(type: Jar, dependsOn: classes) {
|
|
classifier = null
|
|
manifestAttributes(manifest, project, 'Main')
|
|
|
|
// TODO: Use standard implementation title after js stdlib detector becomes more flexible
|
|
Properties properties = new Properties()
|
|
new File("${rootDir}/../resources/kotlinManifest.properties").withInputStream {
|
|
properties.load(it)
|
|
}
|
|
manifest.attributes 'Implementation-Title' : properties."manifest.impl.title.kotlin.javascript.stdlib"
|
|
|
|
includeEmptyDirs false
|
|
duplicatesStrategy DuplicatesStrategy.EXCLUDE
|
|
from jsOutputFile
|
|
from sourceSets.main.output
|
|
}
|
|
|
|
task sourcesJar(type: Jar, dependsOn: classes) {
|
|
classifier = 'sources'
|
|
includeEmptyDirs false
|
|
from (sourceSets.builtins.allSource) {
|
|
into 'kotlin'
|
|
}
|
|
from (sourceSets.main.allSource) {
|
|
into 'kotlin'
|
|
exclude '**/*.java'
|
|
exclude 'js/**'
|
|
}
|
|
}
|
|
|
|
|
|
artifacts {
|
|
runtime mergedJar
|
|
archives mergedJar
|
|
archives sourcesJar
|
|
archives javadocJar
|
|
}
|
|
|
|
task distJs(type: Copy) {
|
|
from(compileJs)
|
|
into "$distDir/js"
|
|
}
|
|
|
|
dist {
|
|
dependsOn distJs
|
|
[mergedJar, sourcesJar].forEach {
|
|
from(it)
|
|
// legacy
|
|
from(it) {
|
|
rename("kotlin-stdlib-js", 'kotlin-jslib')
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
karma {
|
|
dependencies(['qunitjs@1.23.1', 'karma-teamcity-reporter@0.1.2'])
|
|
|
|
frameworks = ['qunit']
|
|
browsers = ['PhantomJS']
|
|
|
|
if (project.hasProperty("teamcity")) {
|
|
reporters = ['teamcity']
|
|
}
|
|
|
|
profile('default') {
|
|
libraryBases = ['']
|
|
libraryFiles = [jsOutputFile, kotlinTestJsOutputFile]
|
|
|
|
sourceBases = []
|
|
sourceFiles = []
|
|
|
|
testBases = ['']
|
|
testFiles = [jsTestOutputFile, kotlinTestJsTestOutputFile]
|
|
}
|
|
}
|
|
|
|
karmaGenerateConfig.outputs.upToDateWhen { false }
|
|
karmaRun {
|
|
dependsOn testClasses
|
|
dependsOn tasks.getByPath(':kotlin-test:kotlin-test-js:testClasses')
|
|
}
|
|
clean.dependsOn karmaClean
|