-
Notifications
You must be signed in to change notification settings - Fork 2
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
gomock_generator. Add --source-path option #930
base: master
Are you sure you want to change the base?
Changes from 1 commit
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 | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -28,6 +28,8 @@ type GenerationConfiguration struct { | |||||||||||
ConcurrentGoroutines int | ||||||||||||
// NoGoMod by default we'll consider go modules is enabled, mockgen will be called with -mod=mod to read interfaces in modules instead of default GOPATH | ||||||||||||
NoGoMod bool | ||||||||||||
// SourcePath override the output base path of the mocks | ||||||||||||
SourcePath string | ||||||||||||
} | ||||||||||||
|
||||||||||||
// MocksConfiguration contains the configuration of the mocks to generate. | ||||||||||||
|
@@ -67,7 +69,12 @@ func GenerateMocks(ctx context.Context, gcfg GenerationConfiguration, mocksCfg M | |||||||||||
if mocksCfg.BaseDirectory == "" { | ||||||||||||
mocksCfg.BaseDirectory = mocksCfg.BasePackage | ||||||||||||
} | ||||||||||||
err = os.Chdir(path.Join(os.Getenv("GOPATH"), "src", mocksCfg.BaseDirectory)) | ||||||||||||
|
||||||||||||
mocksPath := path.Join(path.Join(os.Getenv("GOPATH"), "src"), mocksCfg.BaseDirectory) | ||||||||||||
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. issue:
Suggested change
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. Yep. indeed. |
||||||||||||
if gcfg.SourcePath != "" { | ||||||||||||
mocksPath = gcfg.SourcePath | ||||||||||||
} | ||||||||||||
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. issue: IMO the check with the argument 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. I agree, I'll deal with this. |
||||||||||||
err = os.Chdir(mocksPath) | ||||||||||||
if err != nil { | ||||||||||||
return errors.Wrap(err, "fail to move to base package directory") | ||||||||||||
} | ||||||||||||
|
@@ -79,7 +86,10 @@ func GenerateMocks(ctx context.Context, gcfg GenerationConfiguration, mocksCfg M | |||||||||||
}).Infof("Generating %v mocks", len(mocksCfg.Mocks)) | ||||||||||||
|
||||||||||||
var mockSigs map[string]string | ||||||||||||
mockSigsPath := path.Join(os.Getenv("GOPATH"), "src", mocksCfg.BaseDirectory, gcfg.SignaturesFilename) | ||||||||||||
mockSigsPath := path.Join(gcfg.SourcePath, mocksCfg.BaseDirectory, gcfg.SignaturesFilename) | ||||||||||||
if gcfg.SourcePath != "" { | ||||||||||||
mockSigsPath = path.Join(gcfg.SourcePath, gcfg.SignaturesFilename) | ||||||||||||
} | ||||||||||||
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. issue: from what I understand, it shouldn't be needed at this point to still have a condition.
Suggested change
|
||||||||||||
|
||||||||||||
sigs, err := os.ReadFile(mockSigsPath) | ||||||||||||
if os.IsNotExist(err) { | ||||||||||||
|
@@ -168,7 +178,10 @@ func generateMock(ctx context.Context, gcfg GenerationConfiguration, baseDirecto | |||||||||||
mock.SrcPackage = path.Join(basePackage, mock.SrcPackage) | ||||||||||||
} | ||||||||||||
|
||||||||||||
mockPath := filepath.Join(os.Getenv("GOPATH"), "src", baseDirectory, mock.MockFile) | ||||||||||||
mockPath := filepath.Join(gcfg.SourcePath, baseDirectory, mock.MockFile) | ||||||||||||
if gcfg.SourcePath != "" { | ||||||||||||
mockPath = path.Join(gcfg.SourcePath, mock.MockFile) | ||||||||||||
} | ||||||||||||
log = log.WithFields(logrus.Fields{ | ||||||||||||
"mock_file": mock.MockFile, | ||||||||||||
"interface": mock.Interface, | ||||||||||||
|
@@ -198,7 +211,11 @@ func generateMock(ctx context.Context, gcfg GenerationConfiguration, baseDirecto | |||||||||||
mockSrcPath := strings.Replace(mock.SrcPackage, basePackage, baseDirectory, -1) | ||||||||||||
|
||||||||||||
hashKey := fmt.Sprintf("%s.%s", mockSrcPath, mock.Interface) | ||||||||||||
hash, err := interfaceHash(mockSrcPath, mock.Interface) | ||||||||||||
fullPath := path.Join(os.Getenv("GOPATH"), "src", mockSrcPath) | ||||||||||||
if gcfg.SourcePath != "" { | ||||||||||||
fullPath = path.Join(gcfg.SourcePath, strings.ReplaceAll(mock.SrcPackage, baseDirectory, "")) | ||||||||||||
} | ||||||||||||
hash, err := interfaceHash(fullPath, mockSrcPath, mock.Interface) | ||||||||||||
if err != nil { | ||||||||||||
return "", "", errors.Wrapf(err, "fail to get interface hash of %v:%v", mock.SrcPackage, mock.Interface) | ||||||||||||
} | ||||||||||||
|
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.
issue: I'm not sure I understand the choice of words here for the variable name. It mentions
Source
but it seems to be the location of what this program outputs. What do you think aboutMocksPath
orMocksRootPath
?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.
I'm not precious about the naming... but it is the location of your codebase. MocksRootPath works. I'll update it.