Skip to content

Commit

Permalink
Merge pull request simelo#22 from simelotech/stdevHan_t21_support_mai…
Browse files Browse the repository at this point in the history
…npackage_parameter

[cmd] Fixes simelo#21 Added new parameter to define mainPackage
  • Loading branch information
olemis authored Feb 3, 2020
2 parents 2a55fec + 3e0c8c4 commit 291e1e4
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions src/cmd/cgogen.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type Config struct {
FullTranspile bool //Full conversion to c code
FullTranspileDir string
FullTranspileOut string
MainPackagePath string
PrefixLib string
}

Expand All @@ -51,6 +52,7 @@ func (c *Config) register() {
flag.BoolVar(&c.IgnoreDependants, "id", false, "Ignore dependants")
flag.StringVar(&c.FullTranspileDir, "transdir", "", "Directory to get source code for full transpile")
flag.StringVar(&c.FullTranspileOut, "transout", "", "Directory to put c files of full transpile")
flag.StringVar(&c.MainPackagePath, "main", "", "Define main package path the functions")
flag.StringVar(&c.PrefixLib, "prefix", "SKY", "Define prefix the function and type error export")
}

Expand All @@ -77,7 +79,10 @@ var inplaceConvertTypesPackages = map[string]string{
"BalanceResult": "cli",
}

var mainPackagePath = string("github.com/SkycoinProject/skycoin/src/")
var (
mainPackagePath = ""
packagePath = ""
)

var arrayTypes = map[string]string{
"PubKey": "cipher",
Expand All @@ -102,6 +107,11 @@ func main() {
handleTypes = make(map[string]string)
cfg.register()
flag.Parse()
if cfg.MainPackagePath == "" {
fmt.Println("The main package path is required")
return
}
packagePath, mainPackagePath = getPathPackage(cfg.MainPackagePath)
functionPrefix = strings.ToUpper(string(cfg.PrefixLib))
includePrefix = strings.ToLower(cfg.PrefixLib)
log.Println("Load prefix " + functionPrefix)
Expand Down Expand Up @@ -322,7 +332,7 @@ func findImportPath(importName string) (string, bool) {
func isLibName(importName string) bool {
path, result := findImportPath(importName)
if result {
return strings.HasPrefix(path, "github.com/SkycoinProject")
return strings.HasPrefix(path, packagePath)
} else {
return false
}
Expand Down Expand Up @@ -1329,3 +1339,18 @@ var basicTypesMap = map[string]string{
}

var packageSeparator = "__"

func getPathPackage(path string) (packagePath_ string, mainPackagePath_ string) {

index := strings.LastIndex(path, "/")
if index == -1 {
mainPackagePath_ = path
} else {
mainPackagePath_ = string(path[:index])
}
index = strings.LastIndex(mainPackagePath_, "/")
packagePath_ = string(mainPackagePath_[:index+1])
mainPackagePath_ = mainPackagePath_ + "/src/"

return
}

0 comments on commit 291e1e4

Please sign in to comment.