diff options
Diffstat (limited to 'compiler_wrapper/errors.go')
-rw-r--r-- | compiler_wrapper/errors.go | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/compiler_wrapper/errors.go b/compiler_wrapper/errors.go index 525b986e..7095e37d 100644 --- a/compiler_wrapper/errors.go +++ b/compiler_wrapper/errors.go @@ -30,6 +30,20 @@ func wrapErrorwithSourceLocf(err error, format string, v ...interface{}) error { return newErrorwithSourceLocfInternal(2, "%s: %s", fmt.Sprintf(format, v...), err.Error()) } +func wrapSubprocessErrorWithSourceLoc(cmd *command, subprocessErr error) (exitCode int, err error) { + if subprocessErr == nil { + return 0, nil + } + if userErr, ok := getCCacheError(cmd, subprocessErr); ok { + return 0, userErr + } + if exitCode, ok := getExitCode(subprocessErr); ok { + return exitCode, nil + } + err = newErrorwithSourceLocfInternal(2, "failed to execute %#v: %s", cmd, subprocessErr) + return 0, err +} + // Based on the implementation of log.Output func newErrorwithSourceLocfInternal(skip int, format string, v ...interface{}) error { _, file, line, ok := runtime.Caller(skip) @@ -55,3 +69,14 @@ func getExitCode(err error) (exitCode int, ok bool) { } return 0, false } + +func getCCacheError(compilerCmd *command, compilerCmdErr error) (ccacheErr userError, ok bool) { + if en, ok := compilerCmdErr.(syscall.Errno); ok && en == syscall.ENOENT && + strings.Contains(compilerCmd.path, "ccache") { + ccacheErr = + newUserErrorf("ccache not found under %s. Please install it", + compilerCmd.path) + return ccacheErr, true + } + return ccacheErr, false +} |