Skip to content
This repository was archived by the owner on Jun 27, 2023. It is now read-only.

Commit 41fe4f7

Browse files
author
Filip Nguyen
authoredFeb 3, 2020
Reflect in Current Directory First (#390)
Some users have intention to run mockgen in a module aware directory with version pinned to those in `go.mod`. Always try to run reflect program in current working directory first.
1 parent 5c85495 commit 41fe4f7

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed
 

‎mockgen/reflect.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ func runInDir(program []byte, dir string) (*model.Package, error) {
129129
if err := cmd.Run(); err != nil {
130130
return nil, err
131131
}
132+
132133
return run(filepath.Join(tmpDir, progBinary))
133134
}
134135

@@ -152,6 +153,11 @@ func reflectMode(importPath string, symbols []string) (*model.Package, error) {
152153

153154
wd, _ := os.Getwd()
154155

156+
// Try to run the reflection program in the current working directory.
157+
if p, err := runInDir(program, wd); err == nil {
158+
return p, nil
159+
}
160+
155161
// Try to run the program in the same directory as the input package.
156162
if p, err := build.Import(importPath, wd, build.FindOnly); err == nil {
157163
dir := p.Dir
@@ -160,11 +166,7 @@ func reflectMode(importPath string, symbols []string) (*model.Package, error) {
160166
}
161167
}
162168

163-
// Since that didn't work, try to run it in the current working directory.
164-
if p, err := runInDir(program, wd); err == nil {
165-
return p, nil
166-
}
167-
// Since that didn't work, try to run it in a standard temp directory.
169+
// Try to run it in a standard temp directory.
168170
return runInDir(program, "")
169171
}
170172

0 commit comments

Comments
 (0)
This repository has been archived.