1

我尝试在 Ubuntu Mate 15.10 上的 Raspberrypi2 中构建 kotlin 编译器

当我执行ant -f update_dependencies.xml和构建期间,出现以下错误。

override-version:
 [echo] Requested URL https://teamcity.jetbrains.com/guestAuth/app/rest/builds/?locator=buildType:IntelliJMarkdownParser_Build,status:SUCCESS,tag:forKotlin,count:1
 [echo] Build Number: 3174 - Kotlin 1.0.0-beta-5160 Build Id: 662124
  [get] Getting: https://teamcity.jetbrains.com/guestAuth/app/rest/builds/id:662124/artifacts/content/markdown_jar/markdown.jar
  [get] To: /home/kyungkoo/Downloads/kotlin-build-1.0.0-beta-4584/dependencies/markdown.jar
  [get] Not modified - so not downloaded
 [exec] Exception in thread "main" java.lang.reflect.InvocationTargetException
 [exec]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 [exec]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
 [exec]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 [exec]     at java.lang.reflect.Method.invoke(Method.java:497)
 [exec]     at org.jetbrains.kotlin.preloading.Preloader.run(Preloader.java:73)
 [exec]     at org.jetbrains.kotlin.preloading.Preloader.main(Preloader.java:35)
 [exec] Caused by: java.lang.UnsatisfiedLinkError: Could not load library. Reasons: [no jansi in java.library.path, /tmp/libjansi-32-2155791272664213050.so: /tmp/libjansi-32-2155791272664213050.so: cannot open shared object file: No such file or directory (Possible cause: can't load IA 32-bit .so on a ARM-bit platform)]
 [exec]     at org.fusesource.hawtjni.runtime.Library.doLoad(Library.java:182)
 [exec]     at org.fusesource.hawtjni.runtime.Library.load(Library.java:140)
 [exec]     at org.fusesource.jansi.internal.CLibrary.<clinit>(CLibrary.java:37)
 [exec]     at org.jetbrains.kotlin.cli.common.messages.PlainTextMessageRenderer.<clinit>(PlainTextMessageRenderer.java:35)
 [exec]     at org.jetbrains.kotlin.cli.common.messages.MessageRenderer.<clinit>(MessageRenderer.java:29)
 [exec]     at org.jetbrains.kotlin.cli.common.CLICompiler.exec(CLICompiler.java:57)
 [exec]     at org.jetbrains.kotlin.cli.common.CLICompiler.doMainNoExit(CLICompiler.java:240)
 [exec]     at org.jetbrains.kotlin.cli.common.CLICompiler.doMain(CLICompiler.java:231)
 [exec]     at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler$Companion.main(K2JVMCompiler.kt:246)
 [exec]     at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.main(K2JVMCompiler.kt)
 [exec]     ... 6 more

我安装了libjansi-javalibjansi-native-java但它不起作用。有什么想法可以解决这个问题吗?


我更新了源代码build-1.0.0-beta-5569并添加<arg value="-Dkotlin.colors.enabled=false"/>如下:

--- a/update_dependencies.xml
+++ b/update_dependencies.xml
@@ -368,6 +368,7 @@
     <macrodef name="build-protobuf-java-lite">
         <sequential>
             <exec executable="dependencies/bootstrap-compiler/Kotlin/kotlinc/bin/${kotlinc.executable.path}" failonerror="true">
+                <arg value="-Dkotlin.colors.enabled=false"/>
                 <arg value="-script"/>
                 <arg value="generators/infrastructure/build-protobuf-lite.kts"/>
                 <arg value="${basedir}/ideaSDK/lib/protobuf-2.5.0.jar"/>
@@ -419,6 +420,7 @@
                 <delete dir="${markdown.dir}" failonerror="false"/>
                 <unzip src="dependencies/download/markdown-sources.zip" dest="dependencies"/>
                 <exec executable="dependencies/bootstrap-compiler/Kotlin/kotlinc/bin/${kotlinc.executable.path}" failonerror="true">
+                    <arg value="-Dkotlin.colors.enabled=false"/>
                     <arg value="${markdown.dir}/src"/>
                     <arg value="-d"/>
                     <arg value="${markdown.dir}/out"/>
@@ -874,6 +876,7 @@
             <echo message="URL: ${override.version.url} Version: ${override.version.build.number}"/>

             <exec executable="dependencies/bootstrap-compiler/Kotlin/kotlinc/bin/${kotlinc.executable.path}" failonerror="false">
+                <arg value="-Dkotlin.colors.enbled=false"/>
                 <arg value="-cp"/>
                 <arg value="dependencies/bootstrap-compiler/Kotlin/kotlinc/lib/kotlin-compiler.jar"/>
                 <arg value="-script"/>

在 finsiehd 之后update_dependencies.xml,我执行ant -f build.xml并收到以下错误:

runner:
     [echo] Cleaning /home/kyungkoo/Downloads/kotlin-build-1.0.0-beta-5569/dist/classes/runner
    [mkdir] Created dir: /home/kyungkoo/Downloads/kotlin-build-1.0.0-beta-5569/dist/classes/runner
  [kotlinc] Compiling [/home/kyungkoo/Downloads/kotlin-build-1.0.0-beta-5569/compiler/cli/cli-runner/src] => [/home/kyungkoo/Downloads/kotlin-build-1.0.0-beta-5569/dist/classes/runner]

BUILD FAILED
/home/kyungkoo/Downloads/kotlin-build-1.0.0-beta-5569/build.xml:441: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.jetbrains.kotlin.ant.KotlinCompilerBaseTask.execute(KotlinCompilerBaseTask.kt:92)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:293)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.Target.execute(Target.java:435)
    at org.apache.tools.ant.Target.performTasks(Target.java:456)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1405)
    at org.apache.tools.ant.Project.executeTarget(Project.java:1376)
    at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
    at org.apache.tools.ant.Project.executeTargets(Project.java:1260)
    at org.apache.tools.ant.Main.runBuild(Main.java:853)
    at org.apache.tools.ant.Main.startAnt(Main.java:235)
    at org.apache.tools.ant.launch.Launcher.run(Launcher.java:285)
    at org.apache.tools.ant.launch.Launcher.main(Launcher.java:112)
Caused by: java.lang.UnsatisfiedLinkError: Could not load library. Reasons: [no jansi in java.library.path, /tmp/libjansi-32-7100610475620258495.so: /tmp/libjansi-32-7100610475620258495.so: cannot open shared object file: No such file or directory (Possible cause: can't load IA 32-bit .so on a ARM-bit platform)]
    at org.fusesource.hawtjni.runtime.Library.doLoad(Library.java:182)
    at org.fusesource.hawtjni.runtime.Library.load(Library.java:140)
    at org.fusesource.jansi.internal.CLibrary.<clinit>(CLibrary.java:37)
    at org.jetbrains.kotlin.cli.common.messages.PlainTextMessageRenderer.<clinit>(PlainTextMessageRenderer.java:35)
    at org.jetbrains.kotlin.cli.common.messages.MessageRenderer.<clinit>(MessageRenderer.java:29)
    at org.jetbrains.kotlin.cli.common.CLICompiler.execFullPathsInMessages(CLICompiler.java:69)
    ... 22 more

Total time: 1 minute 3 seconds

build.xml这样固定:

diff --git a/build.xml b/build.xml
index 38f751c..7bcfeb1 100644
--- a/build.xml
+++ b/build.xml
@@ -299,6 +299,7 @@

             <java classname="org.jetbrains.kotlin.preloading.Preloader" failonerror="true" fork="true"
                   maxmemory="${max.heap.size.for.forked.jvm}">
+                <sysproperty key="kotlin.colors.enabled" value="true"/>
                 <classpath>
                     <pathelement location="${kotlin-home}/lib/kotlin-preloader.jar"/>
                 </classpath>
@@ -468,6 +469,7 @@
               failonerror="true"
               fork="true"
               maxmemory="${max.heap.size.for.forked.jvm}">
+            <sysproperty key="kotlin.colors.enabled" value="true"/>
             <assertions>
                 <enable/>
             </assertions>
@@ -732,6 +734,7 @@
             <pathconvert property="src.line" refid="src.dirset" pathsep=" "/>

             <java classname="org.jetbrains.kotlin.preloading.Preloader" failonerror="true" fork="true" maxmemory="${max.heap.size.for.forked.jvm}">
+                <sysproperty key="kotlin.colors.enabled" value="true"/>
                 <classpath>
                     <pathelement location="${kotlin-home}/lib/kotlin-preloader.jar"/>
                 </classpath>
@@ -771,6 +774,7 @@

         <sequential>
             <java classname="org.jetbrains.kotlin.preloading.Preloader" failonerror="true" fork="true" maxmemory="${max.heap.size.for.forked.jvm}">
+                <sysproperty key="kotlin.colors.enabled" value="true"/>
                 <classpath>
                     <pathelement location="${kotlin-home}/lib/kotlin-preloader.jar"/>
                 </classpath>

然后,我执行 ant build。 ant -f build.xml -Dkotlin.colors.enabled=false. 我不擅长ant。所以,我不能确定这是正确的语法。但是构建已经开始,我得到了同样的错误。

BUILD FAILED
/home/kyungkoo/Downloads/kotlin-build-1.0.0-beta-5569/build.xml:442: java.lang.reflect.InvocationTargetException

...

Caused by: java.lang.UnsatisfiedLinkError: Could not load library. Reasons: [no jansi in java.library.path, /tmp/libjansi-32-7323034426853998701.so: /tmp/libjansi-32-7323034426853998701.so: cannot open shared object file: No such file or directory (Possible cause: can't load IA 32-bit .so on a ARM-bit platform)]
    at org.fusesource.hawtjni.runtime.Library.doLoad(Library.java:182)
    at org.fusesource.hawtjni.runtime.Library.load(Library.java:140)
    at org.fusesource.jansi.internal.CLibrary.<clinit>(CLibrary.java:37)
    at org.jetbrains.kotlin.cli.common.messages.PlainTextMessageRenderer.<clinit>(PlainTextMessageRenderer.java:35)
4

3 回答 3

3

看起来 Raspberry Pi 缺少 jansi 本机库。我不确定它们是否应该可用,但您可以在构建 Kotlin 时安全地禁用它们,因为 Kotlin 编译器仅使用 jansi 将彩色诊断消息输出到终端。要禁用颜色(以及因此 jansi),请尝试在 Kotlin 项目的根目录中应用此补丁:

diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/common/messages/PlainTextMessageRenderer.java b/compiler/cli/src/org/jetbrains/kotlin/cli/common/messages/PlainTextMessageRenderer.java
index e83309d..d4755e6 100644
--- a/compiler/cli/src/org/jetbrains/kotlin/cli/common/messages/PlainTextMessageRenderer.java
+++ b/compiler/cli/src/org/jetbrains/kotlin/cli/common/messages/PlainTextMessageRenderer.java
@@ -32,9 +32,7 @@ import static org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.*
 public abstract class PlainTextMessageRenderer implements MessageRenderer {
     // AnsiConsole doesn't check isatty() for stderr (see https://github.com/fusesource/jansi/pull/35).
     // TODO: investigate why ANSI escape codes on Windows only work in REPL for some reason
-    private static final boolean COLOR_ENABLED =
-            !SystemInfo.isWindows &&
-            CLibrary.isatty(CLibrary.STDERR_FILENO) != 0;
+    private static final boolean COLOR_ENABLED = false;

     private static final String LINE_SEPARATOR = LineSeparator.getSystemLineSeparator().getSeparatorString();
于 2016-01-08T14:03:19.563 回答
2

我只是想让 Kotlin 也能在我的 Raspberry Pi 上工作。我点击了上面的链接 - https://youtrack.jetbrains.com/issue/KT-10605 - 来自 IRus。从那我看到它确实检查了一个属性以禁用颜色,幸运的是。

因此,至少在传播更改之前,您可以执行以下操作:

kotlinc -Dkotlin.colors.enabled=false

然后它将跳过尝试加载非 ARM 共享库的部分。至少它对我来说可以让 REPL 运行。

我发现的另一种方法是像这样设置环境变量 JAVA_TOOL_OPTIONS :

export JAVA_TOOL_OPTIONS="-Dkotlin.colors.enabled=false"

这将被 java vm 拾取,然后你不需要在每个命令行上使用它(尽管它每次都会吐出令人讨厌的“拾取消息”。

于 2016-03-03T22:57:15.483 回答
0

由 jetbrains 开发的命令行 Kotlin 编译器可以作为 snap 包安装在所有当前支持的 Ubuntu 版本中。要安装它,请打开终端并键入:

sudo snap install kotlin --classic  

可用工具:

  • 科特林克
  • kotlinc-jvm
  • kotlinc-js
  • kotlin-dce-js
于 2018-03-10T06:31:54.153 回答