使用Java的Runtime.getRuntime().exec()运行时,从源代码构建Go会导致测试失败。

huangapple go评论96阅读模式
英文:

Building Go from source fails tests when run using Java's Runtime.getRuntime().exec()

问题

这个问题与之前的一个问题相关,链接在这里:https://stackoverflow.com/questions/40873863/java-runtime-getruntime-exec-appears-to-be-overwriting-path

我正在尝试在Java程序中从源代码构建Go。我可以在终端中正确构建它,但是Java的Runtime.getRuntime().exec()得到了有趣的结果。我尝试使用ProcessBuilder,但无法正确构建Go。使用当前的exec()设置,它可以正确构建,但是在两个测试中失败。代码片段:

String[] envp = new String[4];
envp[0] = "CC=/usr/bin/clang";
envp[1] = "GOROOT_BOOTSTRAP=/usr/local/go";
envp[2] = "CGO_ENABLED=0";
envp[3] = "PATH=" + System.getenv().get("PATH");
Runtime.getRuntime().exec("./all.bash", envp, "$HOME/Desktop/go/src");

它可以正常运行和编译,但是当运行测试套件时,我得到两个错误:

--- FAIL: TestCurrent (0.00s)
user_test.go:24: Current: user: Current not implemented on darwin/amd64 (got &user.User{Uid:"502", Gid:"20", Username:"", Name:"", HomeDir:""})
FAIL
FAIL    os/user    0.009s

还有一个更长的错误,由于长度太长,我就不在这里粘贴了,但归根结底是:

panic: test timed out after 3m0s
...
FAIL    runtime    180.056s

我不知道为什么前者会失败,但是对于从终端构建时的运行时,它显示:

ok    runtime    19.096s

所以某些原因导致它花费了很长时间。我搜索了一些资料,听说如果我将ARM=5作为环境变量使用,可能会解决这个问题,但是这并没有改变任何东西。有人知道为什么在从Java构建时这些测试失败,而在终端中构建时却没有问题吗?

英文:

This question is related to a previous question, here: https://stackoverflow.com/questions/40873863/java-runtime-getruntime-exec-appears-to-be-overwriting-path

I am trying to build Go from source from inside a Java program. I can build it properly using Terminal, but Java's Runtime.getRuntime().exec() gets interesting results. I tried using ProcessBuilder, but could not get it to properly make Go. Using my current setup with exec(), it makes properly, but then fails two tests. Code snippet:

String[] envp = new String[4];
envp[0] = "CC=/usr/bin/clang";
envp[1] = "GOROOT_BOOTSTRAP=/usr/local/go";
envp[2] = "CGO_ENABLED=0";
envp[3] = "PATH=" + System.getenv().get("PATH");
Runtime.getRuntime().exec("./all.bash", envp, "$HOME/Desktop/go/src");

It runs properly and compiles properly, but when it gets to running the test suite, I get two errors:

--- FAIL: TestCurrent (0.00s)
user_test.go:24: Current: user: Current not implemented on darwin/amd64 (got &user.User{Uid:"502", Gid:"20", Username:"", Name:"", HomeDir:""})
FAIL
FAIL	os/user	0.009s

and a much longer one that I won't paste here due to absurd length, but it comes down to:

panic: test timed out after 3m0s
...
FAIL	runtime	180.056s

I haven't any idea why the former is failing, but for the runtime when I build from the Terminal, it says:

ok  	runtime	19.096s

So something is causing that to take absurd amounts of time. I did some googling, and heard that it might be fixed if I use ARM=5 as an environment variable, but that didn't change anything. Does anyone have any idea why these tests are failing when I build from Java as opposed to the Terminal?

答案1

得分: 0

看起来,根据os/user包的源代码,本地用户处理似乎依赖于启用cgo。如果cgo=0(你的情况),它将回退到USERHOME环境变量。

相关源代码

尝试在执行环境中设置USER=whatever

恐怕我需要更多信息来诊断运行时问题。

英文:

Looking at the source code for the os/user package, it looks like the native user handling depends on having cgo enabled. If cgo=0 (your case), it will fall back to the USER and HOME environment variables.

source code in question

Try putting USER=whatever in your exec environment.

I'm afraid I'd need more information to diagnose the runtime issue.

huangapple
  • 本文由 发表于 2016年12月1日 03:09:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/40896293.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定