3db1613167
Produce special stdlib artifact with annotations for dist. Put js outputs to dist, they're required for JS backend tests. Use kotlin-compiler for maven, which has all required dependencies bundled. Clean local directory repository on clean. Change paths in tests to compiled artifacts.
270 lines
6.8 KiB
Groovy
270 lines
6.8 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 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"
|
|
|
|
sourceSets {
|
|
builtinsFiles {
|
|
kotlin {
|
|
srcDir "${builtinsDir}/native/kotlin/"
|
|
include "Comparable.kt"
|
|
}
|
|
}
|
|
builtins {
|
|
kotlin {
|
|
source builtinsFiles.kotlin
|
|
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 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 {
|
|
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
|
|
}
|
|
|
|
|
|
dist {
|
|
[mergedJar, sourcesJar].forEach {
|
|
from(it)
|
|
// legacy
|
|
from(it) {
|
|
rename("kotlin-stdlib-js", 'kotlin-jslib')
|
|
}
|
|
}
|
|
from(compileJs) {
|
|
into '../../js'
|
|
}
|
|
}
|
|
|
|
|
|
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]
|
|
}
|
|
}
|
|
|
|
karmaGenerateConfig.outputs.upToDateWhen { false }
|
|
karmaRun.dependsOn testClasses
|
|
clean.dependsOn karmaClean
|