4.X Regression: Windows support broken
While older versions were running e.g. on git-bash, this fails with 4.x
kscript "println(1+1)"
[kscript] [ERROR] compilation of scriplet failed
[kscript] [ERROR] Command : bash -c kotlinc -d 'C:\Users\brandl\.kscript\cache\jar_2ccd53e06b0355d3573a4ae8698398fe\scriplet.jar' C:\Users\brandl\.kscript\cache\jar_2ccd53e06b0355d3573a4ae8698398fe\Scriplet.kts C:\Users\brandl\.kscript\cache\jar_2ccd53e06b0355d3573a4ae8698398fe\Main_Scriplet.kt
[kscript] [ERROR] Exit Code : 1
[kscript] [ERROR] Stdout :
[kscript] [ERROR] Stderr :
[kscript] [ERROR] error: source file or directory not found: C:Usersbrandl.kscriptcachejar_2ccd53e06b0355d3573a4ae8698398feScriplet.kts
[kscript] [ERROR] error: source file or directory not found: C:Usersbrandl.kscriptcachejar_2ccd53e06b0355d3573a4ae8698398feMain_Scriplet.kt
[kscript] [ERROR] .stderr
Not sure why, because the preparation of the commands looks pretty mach the same as before
FYI @aartiPl
I have checked kscript 3.1.0 on Cygwin and I have problems configuring it on git-bash and on Cygwin:
... $ kscript kscript - Enhanced scripting support for Kotlin on *nix-based systems. <.......> Copyright : 2020 Holger Brandl License : MIT Version : v3.1.0 Website : https://github.com/holgerbrandl/kscript
Admin@Mars ~ $ kscript "println(1+1)" [kscript] [ERROR] kotlinc is not in PATH
Admin@Mars ~ $ which kotlinc /home/Admin/.sdkman/candidates/kotlin/current/bin/kotlinc ...
kotlin and kscript installed using sdkman and binaries visible in shell, but not for kscript.
Any hints how to configure it correctly?
I think the problem is that bash itself is not in the PATH
I found the WSL2 bash.exe in System32 folder kept getting in the way; easy workaround was to copy the msys bash.exe over the top of the one in System32.
@jayvdb - good point I was able to rename bash.exe from System32 folder using the following commands from win command line (as an admin):
.... takeown /F C:\Windows\System32\bash.exe icacls C:\Windows\System32\bash.exe /grant <SID>:F ren C:\Windows\System32\bash.exe wsl-bash.exe
SID - your windows user name ....
After renaming Windows 'bash.exe' to 'wsl-bash.exe' KScript has started to proceed with the execution. There are some other problems which I will look for, but for now the question: can we do anything to streamline Windows support in KScript in regards of bash.exe?
I always dreamed of removing the dependency on bash to improve windows support, but never managed to implement it.
Clearly kscript is mainly designed to be a scripting interpreter for bash, which somehow contradicts this idea. So even under windows, I'd assume the user to use a bash-environment to use kscript. But obviously, some users use it in other shells as well.
After @aartiPl 's workaround, getting a different error:
% kscript 'println("hello")'
[kscript] [ERROR] compilation of scriplet failed
[kscript] [ERROR] Command : bash -c kotlinc -d 'C:\Users\amynb\.kscript\cache\jar_b1fe1138a572056a6568211c6db7f553\scriplet.jar' C:\Users\amynb\.kscript\cache\jar_b1fe1138a572056a6568211c6db7f553\Scriplet.kts C:\Users\amynb\.kscript\cache\jar_b1fe1138a572056a6568211c6db7f553\Main_Scriplet.kt
[kscript] [ERROR] Exit Code : 1
[kscript] [ERROR] Stdout :
[kscript] [ERROR] Stderr :
[kscript] [ERROR] error: source file or directory not found: C:Usersamynb.kscriptcachejar_b1fe1138a572056a6568211c6db7f553Scriplet.kts
[kscript] [ERROR] error: source file or directory not found: C:Usersamynb.kscriptcachejar_b1fe1138a572056a6568211c6db7f553Main_Scriplet.kt
[kscript] [ERROR] .stderr
I have applied already some patches to improve Windows support. But first I have to solve #345 as it breaks kscript on my computer. Adding proper support for Cygwin/Mingw/Windows shouldn't be that difficult in new code. Only testing on different environments might require more work...
@aartiPl Just let me know how I can help/what parts I could focus on. :-)
I have merged to master the first part of the changes for multiplatform support. With kscript from master, I can execute simple scripts from linux/mingw/cygwin. There are still needed additional improvements and fixes though. https://github.com/holgerbrandl/kscript/commit/63b3f5ebe576c5885c3d23f87854f397a9263071
Shall we do a patch release then (to also include the dependency resolver downgrade workaround)>
Yes, that would be nice. I have just merged additional changes for better OS compatibility and reverted one incompatible change introduced by me previously.
Current status:
- I think that the resolver problem is fully sorted out (I have no more issues with dependency resolution).
- There are only some fixes for different OS-es but seems they improved the situation, so that simple scenarios work. I wouldn't consider it "solved", though.
- There is very initial support for Windows console. Simple kscript "println(1+1)" works in Windows console.
We still need (candidates for 4.1): (I have put the below points into TODO.md file)
-
Multiplatform tests for different OS-es
-
Windows console support requires @argfiles as kotlin/kotlinc command line is too long to execute from the console.
-
Fix for IntelliJ projects consisting of files with the same names + enable tests
-
Fix for packaging + enable tests
-
Cleanup of ENV variables (CUSTOM_KSCRIPT_PREAMBLE -> KSCRIPT_PREAMBLE, KSCRIPT_IDEA_COMMAND -> KSCRIPT_COMMAND_IDEA, KSCRIPT_GRADLE_COMMAND -> KSCRIPT_COMMAND_GRADLE)
-
Depreciation of @MavenRepository -> @Repository is Kotlin standard
-
Depreciation of some old features with WARN (comment based annotations, referencing script by $HOME and by '/' - those references won't work for web scripts)
-
Improve documentation
-
Improve Unit tests
@-here - there is a new version of kscript available: 4.0.2 - please retest with the new version.
Confirm fixed on 4.0.3
% kscript 'println("hello")'
hello
Fixed and tested in kscript 4.1 branch.