Skip to content

Commit

Permalink
cc: use raw path generation for C++ validation files. (#129)
Browse files Browse the repository at this point in the history
Decouples from the Go output path overrides.

Fixes #41.

Signed-off-by: Harvey Tuch <[email protected]>
  • Loading branch information
htuch authored and rodaine committed Dec 18, 2018
1 parent 37ac200 commit 7d810e6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
8 changes: 7 additions & 1 deletion templates/cc/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ func RegisterHeader(tpl *template.Template, params pgs.Parameters) {
// TODO(rodaine): break pgsgo dependency here (with equivalent pgscc subpackage)
type CCFuncs struct{ pgsgo.Context }

func CcFilePath(f pgs.File, ctx pgsgo.Context, tpl *template.Template) *pgs.FilePath {
out := pgs.FilePath(f.Name().String())
out = out.SetExt(".pb.validate." + tpl.Name())
return &out
}

func (fns CCFuncs) methodName(name interface{}) string {
nameStr := fmt.Sprintf("%s", name)
switch nameStr {
Expand Down Expand Up @@ -400,7 +406,7 @@ func (fns CCFuncs) staticVarName(msg pgs.Message) string {
}

func (fns CCFuncs) output(file pgs.File, ext string) string {
return fns.OutputPath(file).SetExt(ext).String()
return pgs.FilePath(file.Name().String()).SetExt(".pb" + ext).String()
}

func (fns CCFuncs) Type(f pgs.Field) pgsgo.TypeName {
Expand Down
4 changes: 4 additions & 0 deletions templates/pkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ func Template(params pgs.Parameters) map[string][]*template.Template {

func FilePathFor(tpl *template.Template) FilePathFn {
switch tpl.Name() {
case "h":
return cc.CcFilePath
case "cc":
return cc.CcFilePath
case "java":
return java.JavaFilePath
default:
Expand Down

0 comments on commit 7d810e6

Please sign in to comment.