-
-
Notifications
You must be signed in to change notification settings - Fork 128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Only generate moq when interface file is newer than output file #179
base: main
Are you sure you want to change the base?
Changes from 2 commits
a030543
8cc0f14
895b4c5
8081411
51ae8e8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
module github.com/matryer/moq | ||
module github.com/djui/moq | ||
|
||
go 1.18 | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ import ( | |
"os" | ||
"path/filepath" | ||
|
||
"github.com/matryer/moq/pkg/moq" | ||
"github.com/djui/moq/pkg/moq" | ||
) | ||
|
||
// Version is the command version, injected at build time. | ||
|
@@ -23,6 +23,7 @@ type userFlags struct { | |
stubImpl bool | ||
skipEnsure bool | ||
remove bool | ||
force bool | ||
args []string | ||
} | ||
|
||
|
@@ -37,6 +38,7 @@ func main() { | |
flag.BoolVar(&flags.skipEnsure, "skip-ensure", false, | ||
"suppress mock implementation check, avoid import cycle if mocks generated outside of the tested package") | ||
flag.BoolVar(&flags.remove, "rm", false, "first remove output file, if it exists") | ||
flag.BoolVar(&flags.force, "force", false, "force generation, otherwise check if go generate file is newer than output file") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change is not backwards compatible. Maybe it is better to preserve the current mode of operation and add a flag to opt-in for the |
||
|
||
flag.Usage = func() { | ||
fmt.Println(`moq [flags] source-dir interface [interface2 [interface3 [...]]]`) | ||
|
@@ -65,6 +67,19 @@ func run(flags userFlags) error { | |
return errors.New("not enough arguments") | ||
} | ||
|
||
if !flags.force && flags.outFile != "" { | ||
inFile := os.Getenv("GOFILE") | ||
if inStat, err := os.Stat(inFile); err != nil { | ||
fmt.Fprintln(os.Stderr, err) | ||
} else if outStat, err := os.Stat(flags.outFile); err != nil { | ||
if !errors.Is(err, os.ErrNotExist) { | ||
fmt.Fprintln(os.Stderr, err) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the |
||
} else if !inStat.ModTime().After(outStat.ModTime()) { | ||
return nil // Assume no changes thus no need to regenerate. | ||
} | ||
} | ||
|
||
if flags.remove && flags.outFile != "" { | ||
if err := os.Remove(flags.outFile); err != nil { | ||
if !errors.Is(err, os.ErrNotExist) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change should not be part of the PR.
(see also all other files, where the import paths are changed)