OLD | NEW |
1 // Copyright 2017 The LUCI Authors. All rights reserved. | 1 // Copyright 2017 The LUCI Authors. All rights reserved. |
2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
4 | 4 |
5 package application | 5 package application |
6 | 6 |
7 import ( | 7 import ( |
8 "fmt" | 8 "fmt" |
9 "os" | 9 "os" |
10 "os/exec" | 10 "os/exec" |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 // the LookPathResult. | 97 // the LookPathResult. |
98 func (lp *lookPath) checkWrapper(c context.Context, path string, env environ.Env
) (isWrapper bool, err error) { | 98 func (lp *lookPath) checkWrapper(c context.Context, path string, env environ.Env
) (isWrapper bool, err error) { |
99 env.Set(checkWrapperENV, "1") | 99 env.Set(checkWrapperENV, "1") |
100 | 100 |
101 cmd := exec.CommandContext(c, path, "--version") | 101 cmd := exec.CommandContext(c, path, "--version") |
102 cmd.Env = env.Sorted() | 102 cmd.Env = env.Sorted() |
103 | 103 |
104 output, err := cmd.CombinedOutput() | 104 output, err := cmd.CombinedOutput() |
105 rc, ok := exitcode.Get(err) | 105 rc, ok := exitcode.Get(err) |
106 if !ok { | 106 if !ok { |
107 » » err = errors.Annotate(err).Reason("failed to check if %(path)q i
s a wrapper"). | 107 » » err = errors.Annotate(err, "failed to check if %q is a wrapper",
path).Err() |
108 » » » D("path", path). | |
109 » » » Err() | |
110 return | 108 return |
111 } | 109 } |
112 | 110 |
113 // Retain the last output, so our "look" can reference it to extract the | 111 // Retain the last output, so our "look" can reference it to extract the |
114 // version string. | 112 // version string. |
115 lp.lastPath = path | 113 lp.lastPath = path |
116 lp.lastOutput = string(output) | 114 lp.lastOutput = string(output) |
117 | 115 |
118 if rc != 0 { | 116 if rc != 0 { |
119 // The target exited with a non-zero error code. It is a wrapper
if it | 117 // The target exited with a non-zero error code. It is a wrapper
if it |
120 // printed the sentinel text. | 118 // printed the sentinel text. |
121 isWrapper = strings.TrimSpace(lp.lastOutput) == checkWrapperSent
inel | 119 isWrapper = strings.TrimSpace(lp.lastOutput) == checkWrapperSent
inel |
122 if isWrapper { | 120 if isWrapper { |
123 // The target was successfully identified as a wrapper.
Clear "err", which | 121 // The target was successfully identified as a wrapper.
Clear "err", which |
124 // is non-nil b/c of the non-zero exit code, to indicate
a successful | 122 // is non-nil b/c of the non-zero exit code, to indicate
a successful |
125 // wrapper check. | 123 // wrapper check. |
126 err = nil | 124 err = nil |
127 return | 125 return |
128 } | 126 } |
129 | 127 |
130 // The target returned non-zero, but didn't identify as a wrappe
r. It is | 128 // The target returned non-zero, but didn't identify as a wrappe
r. It is |
131 // likely something that happens to be named the same thing as t
he target, | 129 // likely something that happens to be named the same thing as t
he target, |
132 // which is an error. | 130 // which is an error. |
133 » » err = errors.Annotate(err).Reason("wrapper check returned non-ze
ro").Err() | 131 » » err = errors.Annotate(err, "wrapper check returned non-zero").Er
r() |
134 } | 132 } |
135 | 133 |
136 return | 134 return |
137 } | 135 } |
OLD | NEW |