Skip to content

Commit 5da336a

Browse files
committed
Multiplatform support and fixes - part II.
1 parent 63b3f5e commit 5da336a

File tree

5 files changed

+38
-8
lines changed

5 files changed

+38
-8
lines changed

TODO.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# kscript 4.1 features:
2+
3+
* Multiplatform tests for different OS-es
4+
* Windows console support requires @argfiles as kotlin/kotlinc command line is too long to execute it from console.
5+
6+
* Fix for IntelliJ projects consisting of files with the same names + re-enable tests
7+
* Fix for packaging + re-enable tests
8+
* Cleanup of ENV variables (CUSTOM_KSCRIPT_PREAMBLE -> KSCRIPT_PREAMBLE, KSCRIPT_IDEA_COMMAND -> KSCRIPT_COMMAND_IDEA, KSCRIPT_GRADLE_COMMAND -> KSCRIPT_COMMAND_GRADLE)
9+
* Depreciation of @MavenRepository -> @Repository is Kotlin standard
10+
* Depreciation of some old features with WARN (comment based annotations, referencing script by $HOME and by '/' - those references won't work for web scripts)
11+
* Improve Unit tests

src/kscript.bat

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@echo off
2+
3+
for /f %%i in ('where kscript.bat') do set ABS_KSCRIPT_PATH=%%i
4+
set JAR_PATH=%ABS_KSCRIPT_PATH:~0,-4%.jar
5+
6+
rem kotlin -classpath %JAR_PATH% kscript.app.KscriptKt "windows" %*
7+
FOR /F "tokens=* USEBACKQ" %%O IN (`kotlin -classpath %JAR_PATH% kscript.app.KscriptKt "windows" %*`) DO (SET RESULT=%%O)
8+
%RESULT%

src/main/kotlin/kscript/app/model/ConfigBuilder.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,18 @@ class ConfigBuilder internal constructor() {
2424
var repositoryPasswordEnvVariable: String? = null
2525

2626
fun build(): Config {
27-
//Java resolved env variables paths are always in native format; All paths should be stored in Config as native.
27+
//Java resolved env variables paths are always in native format; All paths should be stored in Config as native,
28+
//and then converted as needed to shell format.
2829

29-
//TODO: can it be read from: System.getProperty("os.name"); what about cygwin and msys?
3030
val osType = OsType.findOrThrow(requireNotNull(osType))
3131
val classPathSeparator = classPathSeparator ?: if (osType.isWindowsLike() || osType.isUnixHostedOnWindows()) ';' else ':'
3232
val hostPathSeparatorChar = hostPathSeparatorChar ?: File.separatorChar
3333
val shellPathSeparatorChar = shellPathSeparatorChar ?: if (osType.isUnixHostedOnWindows()) '/' else hostPathSeparatorChar
3434
val selfName = selfName ?: System.getenv("KSCRIPT_NAME") ?: "kscript"
3535
val kscriptDir = kscriptDir ?: Paths.get(System.getenv("KSCRIPT_DIR") ?: (System.getProperty("user.home")!! + "/.kscript"))
36-
val customPreamble = customPreamble ?: System.getenv("KSCRIPT_PREAMBLE") ?: ""
37-
val intellijCommand = intellijCommand ?: System.getenv("KSCRIPT_COMMAND_IDEA") ?: "idea"
38-
val gradleCommand = gradleCommand ?: System.getenv("KSCRIPT_COMMAND_GRADLE") ?: "gradle"
36+
val customPreamble = customPreamble ?: System.getenv("CUSTOM_KSCRIPT_PREAMBLE") ?: ""
37+
val intellijCommand = intellijCommand ?: System.getenv("KSCRIPT_IDEA_COMMAND") ?: "idea"
38+
val gradleCommand = gradleCommand ?: System.getenv("KSCRIPT_GRADLE_COMMAND") ?: "gradle"
3939
val kotlinHome = kotlinHome ?: (System.getenv("KOTLIN_HOME") ?: ShellUtils.guessKotlinHome(osType))?.let { Paths.get(it).absolute() }
4040
val homeDir = homeDir ?: Paths.get(System.getProperty("user.home")!!)
4141
val kotlinOptsEnvVariable = kotlinOptsEnvVariable ?: System.getenv("KSCRIPT_KOTLIN_OPTS") ?: ""

src/main/kotlin/kscript/app/resolver/CommandResolver.kt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,28 @@ class CommandResolver(private val config: Config, private val script: Script) {
1919
//WINDOWS: C:\Users\Admin\.sdkman\candidates\kotlin\current\bin\kotlin -classpath "C:\Users\Admin;C:\Users\Admin\.kscript\cache\jar_2ccd53e06b0355d3573a4ae8698398fe\scriplet.jar;C:\Users\Admin\.sdkman\candidates\kotlin\current\lib\kotlin-script-runtime.jar" Main_Scriplet
2020
//MACOS:
2121

22+
23+
//<command_path>kotlinc -classpath "p1:p2"
24+
//OS Conversion matrix
25+
// command_path command_quoting classpath_path classpath_separator classpath_quoting files_path files_quoting main_class_quoting
26+
//LINUX native no native : " ?
27+
//GIT-BASH shell no native ; " ?
28+
//CYGWIN shell no native ; "
29+
//WINDOWS native no native ; "
30+
//MACOS ? ? ? ? ?
31+
32+
2233
//Path conversion (Cygwin/mingw): cygpath -u "c:\Users\Admin"; /cygdrive/c/ - Cygwin; /c/ - Mingw
2334
//uname --> CYGWIN_NT-10.0 or MINGW64_NT-10.0-19043
2435
//How to find if mingw/cyg/win (second part): https://stackoverflow.com/questions/40877323/quickly-find-if-java-was-launched-from-windows-cmd-or-cygwin-terminal
2536

2637
fun compileKotlin(jar: Path, dependencies: Set<Path>, filePaths: Set<Path>): String {
2738
val compilerOptsStr = resolveCompilerOpts(script.compilerOpts)
2839
val classpath = resolveClasspath(dependencies)
29-
val files = filePaths.joinToString(" ") { "'${it.absolutePathString()}'" }
40+
val files = filePaths.joinToString(" ") { "\"${it.absolutePathString()}\"" }
3041
val kotlinc = resolveKotlinBinary("kotlinc")
3142

32-
return "'$kotlinc' $compilerOptsStr $classpath -d '${jar.absolutePathString()}' $files"
43+
return "$kotlinc $compilerOptsStr $classpath -d \"${jar.absolutePathString()}\" $files"
3344
}
3445

3546
fun executeKotlin(jarArtifact: JarArtifact, dependencies: Set<Path>, userArgs: List<String>): String {

test/resources/custom_dsl/mydsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22

3-
export KSCRIPT_PREAMBLE='
3+
export CUSTOM_KSCRIPT_PREAMBLE='
44
// declare dependencies
55
@file:DependsOn("com.github.holgerbrandl:kutils:0.12")
66

0 commit comments

Comments
 (0)