diff options
author | Tobias Bosch <tbosch@google.com> | 2019-08-13 12:45:50 -0700 |
---|---|---|
committer | Tobias Bosch <tbosch@google.com> | 2019-08-13 20:35:26 +0000 |
commit | d5ce3d74eb5c9b66291a9a22014d7468df9879e3 (patch) | |
tree | 2286cf8950d9211593d0e9e2b05f5bdd3aa1ee53 /compiler_wrapper | |
parent | 1b336f8d1c5ddb9a977fd182cc32ddbfec68d1d2 (diff) | |
download | toolchain-utils-d5ce3d74eb5c9b66291a9a22014d7468df9879e3.tar.gz |
Allow wrapper to build with cros sdk.
Cros sdk uses go version 1.11.
BUG=chromium:773875
TEST=unit test
Change-Id: Ib76cb21b47f24263e3c0f9fad6321192ad4cf801
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/1752535
Tested-by: Tobias Bosch <tbosch@google.com>
Reviewed-by: George Burgess <gbiv@chromium.org>
Diffstat (limited to 'compiler_wrapper')
-rw-r--r-- | compiler_wrapper/goldenutil_test.go | 3 | ||||
-rw-r--r-- | compiler_wrapper/oldwrapper.go | 14 | ||||
-rw-r--r-- | compiler_wrapper/testutil_test.go | 2 |
3 files changed, 11 insertions, 8 deletions
diff --git a/compiler_wrapper/goldenutil_test.go b/compiler_wrapper/goldenutil_test.go index 2b6463df..99d45bb8 100644 --- a/compiler_wrapper/goldenutil_test.go +++ b/compiler_wrapper/goldenutil_test.go @@ -194,6 +194,7 @@ type replacingWriter struct { } func (writer *replacingWriter) Write(p []byte) (n int, err error) { - p = bytes.ReplaceAll(p, writer.old, writer.new) + // TODO: Use bytes.ReplaceAll once cros sdk uses golang >= 1.12 + p = bytes.Replace(p, writer.old, writer.new, -1) return writer.Writer.Write(p) } diff --git a/compiler_wrapper/oldwrapper.go b/compiler_wrapper/oldwrapper.go index 6c4ee0ec..5db47257 100644 --- a/compiler_wrapper/oldwrapper.go +++ b/compiler_wrapper/oldwrapper.go @@ -203,7 +203,8 @@ func callOldShellWrapper(env env, cfg *oldWrapperConfig, inputCmd *command, file oldWrapperContent := cfg.OldWrapperContent oldWrapperContent = regexp.MustCompile(`(?m)^exec\b`).ReplaceAllString(oldWrapperContent, "exec_mock") oldWrapperContent = regexp.MustCompile(`\$EXEC`).ReplaceAllString(oldWrapperContent, "exec_mock") - oldWrapperContent = strings.ReplaceAll(oldWrapperContent, "$0", cfg.CmdPath) + // TODO: Use strings.ReplaceAll once cros sdk uses golang >= 1.12 + oldWrapperContent = strings.Replace(oldWrapperContent, "$0", cfg.CmdPath, -1) cfg.OldWrapperContent = oldWrapperContent mockFile, err := ioutil.TempFile("", filepattern) if err != nil { @@ -241,7 +242,7 @@ function exec_mock { // Note: Using a self executable wrapper does not work due to a race condition // on unix systems. See https://github.com/golang/go/issues/22315 oldWrapperCmd := &command{ - Path: "/usr/bin/sh", + Path: "/bin/sh", Args: append([]string{mockFile.Name()}, inputCmd.Args...), EnvUpdates: inputCmd.EnvUpdates, } @@ -250,11 +251,12 @@ function exec_mock { func callOldPythonWrapper(env env, cfg *oldWrapperConfig, inputCmd *command, filepattern string, stdout io.Writer, stderr io.Writer) (exitCode int, err error) { oldWrapperContent := cfg.OldWrapperContent - oldWrapperContent = strings.ReplaceAll(oldWrapperContent, "from __future__ import print_function", "") + // TODO: Use strings.ReplaceAll once cros sdk uses golang >= 1.12 + oldWrapperContent = strings.Replace(oldWrapperContent, "from __future__ import print_function", "", -1) // Replace sets with lists to make our comparisons deterministic - oldWrapperContent = strings.ReplaceAll(oldWrapperContent, "set(", "ListSet(") - oldWrapperContent = strings.ReplaceAll(oldWrapperContent, "if __name__ == '__main__':", "def runMain():") - oldWrapperContent = strings.ReplaceAll(oldWrapperContent, "__file__", "'"+cfg.WrapperPath+"'") + oldWrapperContent = strings.Replace(oldWrapperContent, "set(", "ListSet(", -1) + oldWrapperContent = strings.Replace(oldWrapperContent, "if __name__ == '__main__':", "def runMain():", -1) + oldWrapperContent = strings.Replace(oldWrapperContent, "__file__", "'"+cfg.WrapperPath+"'", -1) cfg.OldWrapperContent = oldWrapperContent mockFile, err := ioutil.TempFile("", filepattern) diff --git a/compiler_wrapper/testutil_test.go b/compiler_wrapper/testutil_test.go index da014ac9..fa321a07 100644 --- a/compiler_wrapper/testutil_test.go +++ b/compiler_wrapper/testutil_test.go @@ -288,7 +288,7 @@ func matchFullString(regex string) string { func newExitCodeError(exitCode int) error { // It's actually hard to create an error that represents a command // with exit code. Using a real command instead. - tmpCmd := exec.Command("/usr/bin/sh", "-c", fmt.Sprintf("exit %d", exitCode)) + tmpCmd := exec.Command("/bin/sh", "-c", fmt.Sprintf("exit %d", exitCode)) return tmpCmd.Run() } |