| 49 | } |
| 50 | |
| 51 | func checkPkg(pkg *ast.Package) error { |
| 52 | var violations []string |
| 53 | ast.Inspect(pkg, func(node ast.Node) bool { |
| 54 | switch node := node.(type) { |
| 55 | case *ast.FuncDecl: |
| 56 | var b bytes.Buffer |
| 57 | if err := printer.Fprint(&b, fset, node); err != nil { |
| 58 | log.Fatal(err) |
| 59 | } |
| 60 | src := b.String() |
| 61 | |
| 62 | if strings.Contains(src, "MakeGitError") && !strings.Contains(src, "runtime.LockOSThread()") && !strings.Contains(src, "defer runtime.UnlockOSThread()") && !ignoreViolationsInFunc[node.Name.Name] { |
| 63 | pos := fset.Position(node.Pos()) |
| 64 | violations = append(violations, fmt.Sprintf("%s at %s:%d", node.Name.Name, pos.Filename, pos.Line)) |
| 65 | } |
| 66 | } |
| 67 | return true |
| 68 | }) |
| 69 | if len(violations) > 0 { |
| 70 | return fmt.Errorf("%d non-thread-locked calls to MakeGitError found. To fix, add the following to each func below that calls MakeGitError, before the cgo call that might produce the error:\n\n\truntime.LockOSThread()\n\tdefer runtime.UnlockOSThread()\n\n%s", len(violations), strings.Join(violations, "\n")) |
| 71 | } |
| 72 | return nil |
| 73 | } |