Skip to content

Commit

Permalink
chore: wrap precompile filename and tags logic
Browse files Browse the repository at this point in the history
Make precompile targetFilename and tags logic reusable by
wrapping it in a function.

Signed-off-by: Hariom Verma <hariom.verma@tendermint.com>
  • Loading branch information
harry-hov committed Jan 26, 2023
1 parent 3998197 commit 291845e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
16 changes: 1 addition & 15 deletions cmd/gnodev/precompile.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"log"
"os"
"path/filepath"
"strings"

"github.com/gnolang/gno/pkgs/command"
"github.com/gnolang/gno/pkgs/errors"
Expand Down Expand Up @@ -125,20 +124,7 @@ func precompileFile(srcPath string, opts *precompileOptions) error {
}

// compute attributes based on filename.
var targetFilename string
var tags string
nameNoExtension := strings.TrimSuffix(filepath.Base(srcPath), ".gno")
switch {
case strings.HasSuffix(srcPath, "_filetest.gno"):
tags = "gno,filetest"
targetFilename = "." + nameNoExtension + ".gno.gen.go"
case strings.HasSuffix(srcPath, "_test.gno"):
tags = "gno,test"
targetFilename = "." + nameNoExtension + ".gno.gen_test.go"
default:
tags = "gno"
targetFilename = nameNoExtension + ".gno.gen.go"
}
targetFilename, tags := gno.GetPrecompileFilenameAndTags(srcPath)

// preprocess.
precompileRes, err := gno.Precompile(string(source), tags, srcPath)
Expand Down
17 changes: 17 additions & 0 deletions pkgs/gnolang/precompile.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,23 @@ func guessRootDir(fileOrPkg string, goBinary string) (string, error) {
return rootDir, nil
}

// GetPrecompileFilenameAndTags returns the filename and tags for precompiled files.
func GetPrecompileFilenameAndTags(gnoFilePath string) (targetFilename, tags string) {
nameNoExtension := strings.TrimSuffix(filepath.Base(gnoFilePath), ".gno")
switch {
case strings.HasSuffix(gnoFilePath, "_filetest.gno"):
tags = "gno,filetest"
targetFilename = "." + nameNoExtension + ".gno.gen.go"
case strings.HasSuffix(gnoFilePath, "_test.gno"):
tags = "gno,test"
targetFilename = "." + nameNoExtension + ".gno.gen_test.go"
default:
tags = "gno"
targetFilename = nameNoExtension + ".gno.gen.go"
}
return
}

func PrecompileAndCheckMempkg(mempkg *std.MemPackage) error {
gofmt := "gofmt"

Expand Down

0 comments on commit 291845e

Please sign in to comment.