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

Reflect in Current Directory First #390

Merged
merged 1 commit into from
Feb 3, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions mockgen/reflect.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ func runInDir(program []byte, dir string) (*model.Package, error) {
if err := cmd.Run(); err != nil {
return nil, err
}

return run(filepath.Join(tmpDir, progBinary))
}

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

wd, _ := os.Getwd()

// Try to run the reflection program in the current working directory.
if p, err := runInDir(program, wd); err == nil {
return p, nil
}

// Try to run the program in the same directory as the input package.
if p, err := build.Import(importPath, wd, build.FindOnly); err == nil {
dir := p.Dir
Expand All @@ -160,11 +166,7 @@ func reflectMode(importPath string, symbols []string) (*model.Package, error) {
}
}

// Since that didn't work, try to run it in the current working directory.
if p, err := runInDir(program, wd); err == nil {
return p, nil
}
// Since that didn't work, try to run it in a standard temp directory.
// Try to run it in a standard temp directory.
return runInDir(program, "")
}

Expand Down