Created
September 28, 2018 15:58
-
-
Save Shivam010/6a703f779b320c9fff649ec2464ee5c9 to your computer and use it in GitHub Desktop.
Bug recreation in lyft's protoc-gen-star | https://github.com/lyft/protoc-gen-star
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
syntax = "proto3"; | |
package bug; | |
import "helper.proto"; | |
message MsgOne { | |
HelperMessage helper_msg_1 = 1; | |
} | |
message MsgTwo { | |
HelperMessage helper_msg_2 = 1; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
syntax = "proto3"; | |
package bug; | |
message HelperMessage { | |
string txt = 1; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Bug Recreation file for Repo: https://github.com/lyft/protoc-gen-star | |
// Bug: Multiple imports of the same file | |
// There is a possibility that two different messages are importing the same file | |
// and hence, []File slice, 'i' will have multiple occurrences of the same file. | |
// Thus, a check is added to remove such occurrences in the pgs.File.Imports() | |
// Resolved in Repo: https://github.com/Shivam010/protoc-gen-star | |
package main | |
import ( | |
"fmt" | |
"github.com/lyft/protoc-gen-star" | |
) | |
func main() { | |
pgs.Init( | |
pgs.DebugMode(), | |
).RegisterModule( | |
NewModule(), | |
).Render() | |
} | |
// Module ... | |
type Module struct { | |
*pgs.ModuleBase | |
} | |
// NewModule ... | |
func NewModule() *Module { | |
return &Module{&pgs.ModuleBase{}} | |
} | |
// Name ... | |
func (m *Module) Name() string { | |
return "BugModule" | |
} | |
// Execute ... | |
func (m *Module) Execute(targets map[string]pgs.File, _ map[string]pgs.Package) []pgs.Artifact { | |
var output string | |
for _, file := range targets { | |
output = fmt.Sprintf("No. of imports: %v\n", len(file.Imports())) | |
for _, imp := range file.Imports() { | |
output += fmt.Sprintf("File: %v imported in File %v\n", imp.File().Name().String(), file.Name().String()) | |
} | |
m.AddGeneratorFile(file.Name().String()+".txt", output) | |
} | |
return m.Artifacts() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment