-
Notifications
You must be signed in to change notification settings - Fork 126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Kscript is broken on ArchLinux #371
Comments
Thanks for the report! Can you please execute in the console:
|
|
The second line is explaining why you get /usr/share/kotlin path for kotlin. (I am not exactly sure how this line work, but it is used to guess KOTLIN_HOME, if it is not set explicitly). |
It does not seem to fix the problem. # .zshrc
export KOTLIN_HOME=/usr $ echo $KOTLIN_HOME
/usr
$ kscript 'println("Hello world!")'
[kscript] [ERROR] Compilation of scriplet failed:
[kscript] [ERROR] Command : bash -c /usr/share/kotlin/bin/kotlinc -d '/home/ivan/.kscript/cache/jar_1075c8348f9943a25627037568233d8f/scriplet.jar' '/home/ivan/.kscript/cache/jar_1075c8348f9943a25627037568233d8f/Scriplet.kts' '/home/ivan/.kscript/cache/jar_1075c8348f9943a25627037568233d8f/Main_Scriplet.kt'
[kscript] [ERROR] Exit Code : 127
[kscript] [ERROR] Stdout :
[kscript] [ERROR] Stderr :
[kscript] [ERROR] bash: line 1: /usr/share/kotlin/bin/kotlinc: No such file or directory
[kscript] [ERROR] I'm not sure why the error message is visually different yet complains about the same thing. |
That's strange. Below you can see the code which is used to resolve kotlin home: As you can see KOTLIN_HOME env goes first while resolving kotlinc. Another relevant piece of code: https://github.com/holgerbrandl/kscript/blob/master/src/kscript But here also everything looks okay for me. |
It's not ok, since kscript makes wrong assumption about location of kotlin binaries, and doesn't check their actual location.
|
Is KOTLIN_HOME set by some installer e. g. SdkMan, or Kotlin installer? In other distros, KOTLIN_HOME is a separate directory that contains bin and lib. Here is a screenshot from Ubuntu: So if it is different in archlinux, I guess there will be needed a patch for KScript to correct that behavior on that specific platform. |
You can see the list of files here: https://archlinux.org/packages/community/any/kotlin/ (in the section ‘package contents’). Basically it is just another system package with binaries in |
Since it already assumes, that |
KScript is using KOTLIN_HOME in CommandResolver.kt in two places, so it is not enough to rely on PATH. I want to rework how scripting execution happens so that dependency on this environment variable might be relaxed. BTW. Has KScript worked previously on ArchLinux? |
4.0.0 is last version that works this succeed
but this failed
FROM archlinux
RUN pacman -Sy --noconfirm \
which \
jdk-openjdk \
unzip \
zip \
kotlin
RUN curl -s "https://get.sdkman.io" | bash
ARG VERSION=4.1.0
RUN . ~/.bashrc && sdk i kscript $VERSION
# Run test
RUN . ~/.bashrc; kscript 'println("Hi")'
ENTRYPOINT . ~/.bashrc; kscript 'println("Hi")' |
Thanks a lot for checking! I plan to do one more big rework in kscript so that refactoring might resolve this issue. However, I will keep this issue open as it is an important use case. |
Tried to fix problem of ignored KOTLIN_HOME=/usr variable value, that @sfesenko mentioned. Turns out The only way I found to bypass this behavior is to change the name of KOTLIN_HOME in bash launch script to this:
## run it using command substitution to have just the user process once kscript is done
- COMMAND=$("${KOTLIN_BIN}kotlin" -classpath "${JAR_PATH}" kscript.app.KscriptKt "$OSTYPE" "$@")
+ COMMAND=$(export KOTLIN_HOME_BYPASS=$KOTLIN_HOME; "${KOTLIN_BIN}kotlin" -classpath "${JAR_PATH}" kscript.app.KscriptKt "$OSTYPE" "$@")
And read its value from ConfigBuilder private fun resolveKotlinHome(osType: OsType): OsPath = path(
+ System.getenv("KOTLIN_HOME_BYPASS") ?:
System.getenv("KOTLIN_HOME") ?:
ShellUtils.guessKotlinHome(osType) ?:
throw IllegalStateException("KOTLIN_HOME is not set and could not be inferred from context.")
) This solved the problem with kscript finding
|
@DareFox - this is a nice workaround - thanks for bringing it here. Another workaround would be to install Kotlin using sdkman (alongside the system-installed one), as in kscript installation guide. That should also fix the problem, although I haven't tested it on ArchLinux. |
Is it first-party? Who should be contacted to do it?
ArchLinux users are blessed with a good quality package manager, we tend to avoid installing software by other means for security/stability reasons. |
@DareFox - I think those symbolic links should be added in the Kotlin package rather than in the KScript. This way, the behavior on the ArchLinux will be consistent with the Kotlin installation directory structure on other systems. And in fact, I think this is the best of all solutions discussed above. Can you try to push the change to the maintainer of the Kotlin package on ArchLinux? |
(at) HERE - let me discuss other solutions and why I don't think they are the best way to proceed. Let's assume we have the following structure on disk: Additional Kotlin versions:
In such a case, when we change 'KOTLIN_HOME' to one of the versions in '/opt', we will still have in 'PATH' binaries from the other version of Kotlin. So it may be wrong and will not work with libraries in 'KOTLIN_HOME'. We can, of course, change 'PATH' so that it will execute the correct version of 'kotlin' and 'kotlinc' scripts, but IMHO it's not really how "*_HOME" type variables work. They should direct to the whole, consistent environment connected with the Kotlin version.
This way, we can eliminate dependency on 'kotlin'/'kotlinc', but we do not have any guarantees that it will not break in new versions of Kotlin: calling jar files directly, without using scripts, is possible (and it works - I have tested it), but it is not a public API of Kotlin, and it can break at any time in a new version of Kotlin.
It's not a 'kscript' thing to provide those links. The best solution is to provide links in the Kotlin package. It is consistent with the way Kotlin is distributed. To summarize, I am reluctant to change 'kscript' to fix this problem because it seems that the issue should be resolved in the Kotlin package in ArchLinux. If anyone can contact the Kotlin package maintainer for ArchLinux, and ask to add symbolic links between 'KOTLIN_HOME/bin/' and '/usr/bin/', that would be the best solution. |
I have added information about the problem in the README file with a link to this ticket. |
@ here - I need some help with releasing to ArchLinux. Please have a look at: If you know how to solve that problem, please comment: |
Installed from the AUR.
Error message:
$ kscript 'println("Hello world")' /usr/bin/kscript: line 49: /usr/share/kotlin/bin/kotlin: No such file or directory
Correct path to the Kotlin binary:
$ command -v kotlin /usr/bin/kotlin
I don't really know what information could be of use, don't hesitate to ask for specific information you need.
The text was updated successfully, but these errors were encountered: