File tree Expand file tree Collapse file tree 3 files changed +34
-3
lines changed
src/main/kotlin/com/tschuchort/compiletesting Expand file tree Collapse file tree 3 files changed +34
-3
lines changed Original file line number Diff line number Diff line change 1+ import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
12
23plugins {
34 id " com.github.gmazzo.buildconfig" version " 3.1.0"
@@ -15,6 +16,18 @@ buildConfig {
1516 }
1617}
1718
19+ configurations. all {
20+ resolutionStrategy. dependencySubstitution {
21+ substitute(module(" org.jetbrains.kotlin:kotlin-dom-api-compat" ))
22+ .using variant(module(" org.jetbrains.kotlin:kotlin-dom-api-compat:$embedded_kotlin_version " )) {
23+ attributes {
24+ attribute(KotlinPlatformType . attribute, KotlinPlatformType . js)
25+ attribute(Usage . USAGE_ATTRIBUTE , project. objects. named(Usage , " kotlin-runtime" ))
26+ }
27+ }
28+ }
29+ }
30+
1831dependencies {
1932 compileOnly " com.google.auto.service:auto-service:1.0.1"
2033 kapt " com.google.auto.service:auto-service:1.0.1"
@@ -32,6 +45,7 @@ dependencies {
3245
3346 // Include Kotlin/JS standard library in test classpath for auto loading
3447 testRuntimeOnly " org.jetbrains.kotlin:kotlin-stdlib-js"
48+ testRuntimeOnly " org.jetbrains.kotlin:kotlin-dom-api-compat"
3549
3650 // The Kotlin compiler should be near the end of the list because its .jar file includes
3751 // an obsolete version of Guava
Original file line number Diff line number Diff line change @@ -27,6 +27,10 @@ internal object HostEnvironment {
2727 findInClasspath(kotlinDependencyRegex(" kotlin-stdlib-js" ))
2828 }
2929
30+ val kotlinDomApiCompatKlib: File ? by lazy {
31+ findInClasspath(kotlinDependencyRegex(" kotlin-dom-api-compat" ))
32+ }
33+
3034 val kotlinReflectJar: File ? by lazy {
3135 findInClasspath(kotlinDependencyRegex(" kotlin-reflect" ))
3236 }
@@ -40,7 +44,7 @@ internal object HostEnvironment {
4044 }
4145
4246 private fun kotlinDependencyRegex (prefix : String ): Regex {
43- return Regex (" $prefix (-[0-9]+\\ .[0-9]+(\\ .[0-9]+)?)([-0-9a-zA-Z]+)?\\ .jar" )
47+ return Regex (" $prefix (-[0-9]+\\ .[0-9]+(\\ .[0-9]+)?)([-0-9a-zA-Z]+)?( \\ .jar| \\ .klib) " )
4448 }
4549
4650 /* * Tries to find a file matching the given [regex] in the host process' classpath */
@@ -60,7 +64,11 @@ internal object HostEnvironment {
6064
6165 val classpaths = classGraph.classpathFiles
6266 val modules = classGraph.modules.mapNotNull { it.locationFile }
67+ val klibs = System .getProperty(" java.class.path" )
68+ .split(File .pathSeparator)
69+ .filter { it.endsWith(" .klib" ) }
70+ .map(::File )
6371
64- return (classpaths + modules).distinctBy(File ::getAbsolutePath)
72+ return (classpaths + modules + klibs ).distinctBy(File ::getAbsolutePath)
6573 }
6674}
Original file line number Diff line number Diff line change @@ -47,6 +47,15 @@ class KotlinJsCompilation : AbstractKotlinCompilation<K2JSCompilerArguments>() {
4747 HostEnvironment .kotlinStdLibJsJar
4848 }
4949
50+ /* *
51+ * Path to the kotlin-dom-api-compat.klib
52+ * If none is given, it will be searched for in the host
53+ * process' classpaths
54+ */
55+ var kotlinStdLibDomApi: File ? by default {
56+ HostEnvironment .kotlinDomApiCompatKlib
57+ }
58+
5059 /* *
5160 * Generate TypeScript declarations .d.ts file alongside JS file. Available in IR backend only
5261 */
@@ -84,7 +93,7 @@ class KotlinJsCompilation : AbstractKotlinCompilation<K2JSCompilerArguments>() {
8493 args.outputDir = outputDir.absolutePath // -ir-output-dir
8594 args.moduleName = Paths .get(outputFileName).nameWithoutExtension // -ir-output-name
8695 args.sourceMapBaseDirs = jsClasspath().joinToString(separator = File .pathSeparator)
87- args.libraries = listOfNotNull(kotlinStdLibJsJar).joinToString(separator = " : " )
96+ args.libraries = listOfNotNull(kotlinStdLibJsJar, kotlinStdLibDomApi ).joinToString(separator = File .pathSeparator )
8897
8998 args.irProduceKlibDir = irProduceKlibDir
9099 args.irProduceKlibFile = irProduceKlibFile
You can’t perform that action at this time.
0 commit comments