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

Commit fbf1acb

Browse files
author
Filip Nguyen
committed
Reflect in Current Directory First
1 parent 3dcdcb6 commit fbf1acb

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

mockgen/reflect.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,11 @@ func runInDir(program []byte, dir string) (*model.Package, error) {
129129
if err := cmd.Run(); err != nil {
130130
return nil, err
131131
}
132-
return run(filepath.Join(tmpDir, progBinary))
132+
p, err := run(filepath.Join(tmpDir, progBinary))
133+
if err == nil {
134+
log.Printf("Successfully reflected in directory: %v\n", err)
135+
}
136+
return p, err
133137
}
134138

135139
// reflectMode generates mocks via reflection on an interface.
@@ -152,6 +156,11 @@ func reflectMode(importPath string, symbols []string) (*model.Package, error) {
152156

153157
wd, _ := os.Getwd()
154158

159+
// Try to run it in the current working directory.
160+
if p, err := runInDir(program, wd); err == nil {
161+
return p, nil
162+
}
163+
155164
// Try to run the program in the same directory as the input package.
156165
if p, err := build.Import(importPath, wd, build.FindOnly); err == nil {
157166
dir := p.Dir
@@ -160,11 +169,7 @@ func reflectMode(importPath string, symbols []string) (*model.Package, error) {
160169
}
161170
}
162171

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.
172+
// Try to run it in a standard temp directory.
168173
return runInDir(program, "")
169174
}
170175

0 commit comments

Comments
 (0)