Commit cd33254c authored by Hugo Moreau's avatar Hugo Moreau

Global var detection blocking compile

 * main.go : Here.
parent f2340640
Pipeline #26343 failed with stage
in 1 minute and 49 seconds
......@@ -417,7 +417,7 @@ func duplicateGoroutines(filepath string) (string, []*cspinfo.Goroutine) {
return tmpFile.Name(), goroutines
}
func treatGlobal(src []byte) []byte {
func treatGlobal(src []byte) ([]byte, bool) {
info := &types.Info{
Uses: make(map[*ast.Ident]types.Object),
Selections: make(map[*ast.SelectorExpr]*types.Selection),
......@@ -450,7 +450,7 @@ func treatGlobal(src []byte) []byte {
fmt.Println(err)
os.Exit(1)
}
return src
return src, len(global2.FuncsGetter) > 0 || len(global.FuncsSetter) > 0
}
type packageTemplate struct {
......@@ -551,8 +551,9 @@ func main() {
os.Exit(1)
}
src, global := treatGlobal(src)
if len(toIgnore) != 0 {
src = treatGlobal(src)
a, bb := tools.RewriteBlackbox(string(src), toIgnore, *output)
if err = os.MkdirAll(*output+"/blackbox", 0777); err != nil {
......@@ -571,6 +572,13 @@ func main() {
fmt.Println(err)
os.Exit(1)
}
}
if global {
fmt.Println("Global detected, file has been rewrotre in", path.Join(*output, basePackagePath))
if err = ioutil.WriteFile(path.Join(*output, basePackagePath), []byte(src), 0666); err != nil {
fmt.Println(err)
os.Exit(1)
}
os.Exit(2)
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment