Only generate moq when interface file is newer than output file#179
Only generate moq when interface file is newer than output file#179djui wants to merge 5 commits into
Conversation
breml
left a comment
There was a problem hiding this comment.
There are some more cases to be considered:
- It is possible to generate mocks from type aliases. In this case, the file where the type alias is located, does not change, when the signature of the mock it self changes.
- If the import path of the package, where the interface which is mocked is located, is changed (e.g. by moving a package to a an other folder), the generated mock would be needed to be regenerated, but the timestamp of the source file is not necessarily altered.
- The
go:generateline is not necessarily in the same file as the interface that is mocked, but changing this line would also potentially change the result of the generated mock. - Whenever
moqis updated, the resulting mock file might change as well.
| @@ -1,4 +1,4 @@ | |||
| module github.com/matryer/moq | |||
| module github.com/djui/moq | |||
There was a problem hiding this comment.
This change should not be part of the PR.
(see also all other files, where the import paths are changed)
| 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.
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 mtime behavior. Maybe the -mtime flag could be used to enable the mtime mode as well as contain the name of the source file as well. If the source file is the empty string, it would fall back to GOFILE env variable.
| 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.
If the mtime flag is used instead of force, I think failing to stat the source or the destination file would be an error, which is returned from run.
|
I like this, if it's opt-in @djui - the build is failing, but if you can patch it up, we can merge this. |
No description provided.