v.io/jiri/runutil: move code out of jiri/util to better locations...
- move TranslateExitCode to runutil
- move NoSnapshotExitCode to devtools/vbinary/exitcode
MultiPart: 1/2
Change-Id: Ic8224b3687931edf05779f0b41a6032caaa162d5
diff --git a/runutil/.api b/runutil/.api
index 9969ef5..31e5676 100644
--- a/runutil/.api
+++ b/runutil/.api
@@ -8,6 +8,7 @@
pkg runutil, func NewRun(map[string]string, io.Reader, io.Writer, io.Writer, bool, bool, bool) *Run
pkg runutil, func NewSequence(map[string]string, io.Reader, io.Writer, io.Writer, bool, bool, bool) *Sequence
pkg runutil, func NewStart(map[string]string, io.Reader, io.Writer, io.Writer, bool, bool, bool) *Start
+pkg runutil, func TranslateExitCode(error) error
pkg runutil, method (*Run) Chdir(string) error
pkg runutil, method (*Run) Chmod(string, os.FileMode) error
pkg runutil, method (*Run) Command(string, ...string) error
diff --git a/runutil/sequence.go b/runutil/sequence.go
index 01f6941..ec35908 100644
--- a/runutil/sequence.go
+++ b/runutil/sequence.go
@@ -10,10 +10,14 @@
"io"
"io/ioutil"
"os"
+ "os/exec"
"path/filepath"
"runtime"
"sync"
+ "syscall"
"time"
+
+ "v.io/x/lib/cmdline"
)
// Sequence provides for convenient chaining of multiple calls to its
@@ -55,9 +59,19 @@
// Note that terminating functions, even those that take an action, may
// return an error generated by a previous method.
//
-// In addtion to Run which will always run a command as a subprocess,
+// In addition to Run which will always run a command as a subprocess,
// the Call method will invoke a function. Note that Capture and Timeout
// do not affect such calls.
+//
+// Errors returned by Sequence augment those returned by the underlying
+// packages with details of the exact call that generated those errors.
+// This means that it is not possible to test directly for errors from
+// those packages. The GetOriginalError function can be used to obtain
+// the error from the underlying package, or the IsTimeout, IsNotExists etc
+// functions can be used on the wrapped error. The ExitCode method
+// is also provided to convert to the exit codes expected by the
+// v.io/x/lib/cmdline package which is often used in conjunction with
+// Sequence.
type Sequence struct {
r *Run
err error
@@ -175,8 +189,26 @@
return s.err
}
-// GetOriginalError gets the original error wrapped in the given err.
-// If the given err is not a wrappedError, just return itself.
+// TranslateExitCode translates errors from the "os/exec" package that
+// contain exit codes into cmdline.ErrExitCode errors.
+func TranslateExitCode(err error) error {
+ return translateExitCode(GetOriginalError(err))
+}
+
+func translateExitCode(err error) error {
+ if exit, ok := err.(*exec.ExitError); ok {
+ if wait, ok := exit.Sys().(syscall.WaitStatus); ok {
+ if status := wait.ExitStatus(); wait.Exited() && status != 0 {
+ return cmdline.ErrExitCode(status)
+ }
+ }
+ }
+ return err
+}
+
+// GetOriginalError gets the original error wrapped in the supplied err.
+// If the given err has not been wrapped by Sequence, then the supplied error
+// is returned.
func GetOriginalError(err error) error {
if we, ok := err.(*wrappedError); ok {
return we.oe
diff --git a/util/.api b/util/.api
new file mode 100644
index 0000000..019f596
--- /dev/null
+++ b/util/.api
@@ -0,0 +1,52 @@
+pkg util, const Black Color
+pkg util, const Blue Color
+pkg util, const Cyan Color
+pkg util, const Green Color
+pkg util, const Magenta Color
+pkg util, const Red Color
+pkg util, const White Color
+pkg util, const Yellow Color
+pkg util, func ColorString(string, Color) string
+pkg util, func ConfigFilePath(*jiri.X) (string, error)
+pkg util, func LoadConfig(*jiri.X) (*Config, error)
+pkg util, func LoadOncallRotation(*jiri.X) (*OncallRotation, error)
+pkg util, func NewConfig(...ConfigOpt) *Config
+pkg util, func Oncall(*jiri.X, time.Time) (*OncallShift, error)
+pkg util, func OncallRotationPath(*jiri.X) (string, error)
+pkg util, func SaveConfig(*jiri.X, *Config) error
+pkg util, func ThirdPartyBinPath(*jiri.X, string) (string, error)
+pkg util, method (Config) APICheckProjects() map[string]struct{}
+pkg util, method (Config) CopyrightCheckProjects() map[string]struct{}
+pkg util, method (Config) GoWorkspaces() []string
+pkg util, method (Config) GroupTests([]string) []string
+pkg util, method (Config) JenkinsMatrixJobs() map[string]JenkinsMatrixJobInfo
+pkg util, method (Config) ProjectTests([]string) []string
+pkg util, method (Config) Projects() []string
+pkg util, method (Config) TestDependencies(string) []string
+pkg util, method (Config) TestParts(string) []string
+pkg util, method (Config) VDLWorkspaces() []string
+pkg util, type APICheckProjectsOpt map[string]struct{}
+pkg util, type Color int
+pkg util, type Config struct
+pkg util, type ConfigOpt interface, unexported methods
+pkg util, type CopyrightCheckProjectsOpt map[string]struct{}
+pkg util, type GoWorkspacesOpt []string
+pkg util, type JenkinsMatrixJobInfo struct
+pkg util, type JenkinsMatrixJobInfo struct, HasArch bool
+pkg util, type JenkinsMatrixJobInfo struct, HasOS bool
+pkg util, type JenkinsMatrixJobInfo struct, HasParts bool
+pkg util, type JenkinsMatrixJobInfo struct, Name string
+pkg util, type JenkinsMatrixJobInfo struct, ShowOS bool
+pkg util, type JenkinsMatrixJobsOpt map[string]JenkinsMatrixJobInfo
+pkg util, type OncallRotation struct
+pkg util, type OncallRotation struct, Shifts []OncallShift
+pkg util, type OncallRotation struct, XMLName xml.Name
+pkg util, type OncallShift struct
+pkg util, type OncallShift struct, Date string
+pkg util, type OncallShift struct, Primary string
+pkg util, type OncallShift struct, Secondary string
+pkg util, type ProjectTestsOpt map[string][]string
+pkg util, type TestDependenciesOpt map[string][]string
+pkg util, type TestGroupsOpt map[string][]string
+pkg util, type TestPartsOpt map[string][]string
+pkg util, type VDLWorkspacesOpt []string
diff --git a/util/exit.go b/util/exit.go
deleted file mode 100644
index 6b403b0..0000000
--- a/util/exit.go
+++ /dev/null
@@ -1,31 +0,0 @@
-// Copyright 2015 The Vanadium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package util
-
-import (
- "os/exec"
- "syscall"
-
- "v.io/x/lib/cmdline"
-)
-
-const (
- // NoSnapshotExitCode is returned when the vbinary tool fails to
- // find a snapshot for the given date.
- NoSnapshotExitCode = 3
-)
-
-// TranslateExitCode translates errors from the "os/exec" package that
-// contain exit codes into cmdline.ErrExitCode errors.
-func TranslateExitCode(err error) error {
- if exit, ok := err.(*exec.ExitError); ok {
- if wait, ok := exit.Sys().(syscall.WaitStatus); ok {
- if status := wait.ExitStatus(); wait.Exited() && status != 0 {
- return cmdline.ErrExitCode(status)
- }
- }
- }
- return err
-}