Skip to content

Commit c2d1e47

Browse files
committed
Fixed issues with @file:CompilerOpts in combination with @file:Include (fixes #173)
1 parent dbb16d9 commit c2d1e47

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

src/main/kotlin/kscript/app/Script.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package kscript.app
22

33
import java.io.File
4-
import java.lang.IllegalArgumentException
54

65
/* Immutable script class */
76
data class Script(val lines: List<String>, val extension: String = "kts") : Iterable<String> {
@@ -71,7 +70,7 @@ data class Script(val lines: List<String>, val extension: String = "kts") : Iter
7170
}
7271

7372

74-
private val KSCRIPT_DIRECTIVE_ANNO: List<Regex> = listOf("DependsOn", "KotlinOpts", "Include", "EntryPoint", "MavenRepository", "DependsOnMaven")
73+
private val KSCRIPT_DIRECTIVE_ANNO: List<Regex> = listOf("DependsOn", "KotlinOpts", "Include", "EntryPoint", "MavenRepository", "DependsOnMaven", "CompilerOpts")
7574
.map { "^@file:$it[(]".toRegex() }
7675

7776
private fun isKscriptAnnotation(line: String) =
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
## Prevent regressions of https://github.com/holgerbrandl/kscript/issues/173
2+
3+
echo "fun foo() = 42" > compiler_opts_with_includes_dep.kts
4+
5+
cat <<"EOF" >> compiler_opts_with_includes_master.kt
6+
@file:CompilerOpts("-jvm-target 1.8")
7+
@file:Include("compiler_opts_with_includes_dep.kts")
8+
@file:DependsOnMaven("log4j:log4j:1.2.14")
9+
10+
import java.io.File
11+
12+
fun main(args: Array<String>) {
13+
println("hello"+foo())
14+
}
15+
EOF
16+
17+
kscript compiler_opts_with_includes_master.kt
18+

test/test_suite.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,9 @@ assert 'echo "println(123)" > 123foo.kts; kscript 123foo.kts' "123"
253253
## prevent regression of #185
254254
assert "source ${KSCRIPT_HOME}/test/resources/home_dir_include.sh" "42"
255255

256+
## prevent regression of #173
257+
assert "source ${KSCRIPT_HOME}/test/resources/compiler_opts_with_includes.sh" "hello42"
258+
256259

257260
kscript_nocall() { kotlin -classpath ${KSCRIPT_HOME}/build/libs/kscript.jar kscript.app.KscriptKt "$@";}
258261
export -f kscript_nocall

0 commit comments

Comments
 (0)