jenkins: use -race for check-imports and fix dbx check (#1873)

What: Use -race for check-imports, this means it will use the cached build files.

Why:
This commit is contained in:
Egon Elbre 2019-05-01 18:44:12 +03:00 committed by JT Olio
parent 6ece4f11ad
commit ecde1bd251
4 changed files with 61 additions and 7 deletions

View File

@ -29,7 +29,7 @@ pipeline {
stage('Lint') {
steps {
sh 'go run ./scripts/check-copyright.go'
sh 'go run ./scripts/check-imports.go ./...'
sh 'go run ./scripts/check-imports.go -race ./...'
sh 'go run ./scripts/protobuf.go --protoc=$HOME/protoc/bin/protoc lint'
sh 'protolock status'
sh 'bash ./scripts/check-dbx-version.sh'

View File

@ -10,7 +10,6 @@ import (
"errors"
"fmt"
"reflect"
"regexp"
"strconv"
"strings"
"sync"
@ -3641,10 +3640,54 @@ func __sqlbundle_Render(dialect __sqlbundle_Dialect, sql __sqlbundle_SQL, ops ..
return dialect.Rebind(out)
}
var __sqlbundle_reSpace = regexp.MustCompile(`\s+`)
func __sqlbundle_flattenSQL(x string) string {
// trim whitespace from beginning and end
s, e := 0, len(x)-1
for s < len(x) && (x[s] == ' ' || x[s] == '\t' || x[s] == '\n') {
s++
}
for s <= e && (x[e] == ' ' || x[e] == '\t' || x[e] == '\n') {
e--
}
if s > e {
return ""
}
x = x[s : e+1]
func __sqlbundle_flattenSQL(s string) string {
return strings.TrimSpace(__sqlbundle_reSpace.ReplaceAllString(s, " "))
// check for whitespace that needs fixing
wasSpace := false
for i := 0; i < len(x); i++ {
r := x[i]
justSpace := r == ' '
if (wasSpace && justSpace) || r == '\t' || r == '\n' {
// whitespace detected, start writing a new string
var result strings.Builder
result.Grow(len(x))
if wasSpace {
result.WriteString(x[:i-1])
} else {
result.WriteString(x[:i])
}
for p := i; p < len(x); p++ {
for p < len(x) && (x[p] == ' ' || x[p] == '\t' || x[p] == '\n') {
p++
}
result.WriteByte(' ')
start := p
for p < len(x) && !(x[p] == ' ' || x[p] == '\t' || x[p] == '\n') {
p++
}
result.WriteString(x[start:p])
}
return result.String()
}
wasSpace = justSpace
}
// no problematic whitespace found
return x
}
// this type is specially named to match up with the name returned by the
@ -3723,6 +3766,8 @@ type __sqlbundle_Condition struct {
func (*__sqlbundle_Condition) private() {}
func (c *__sqlbundle_Condition) Render() string {
// TODO(jeff): maybe check if we can use placeholders instead of the
// literal null: this would make the templates easier.
switch {
case c.Equal && c.Null:

View File

@ -7,4 +7,5 @@ then
echo "dbx version ok"
else
echo "please use latest dbx tool to generate code"
exit 1
fi

View File

@ -30,6 +30,8 @@ check-imports verifies whether imports are divided into three blocks:
*/
var race = flag.Bool("race", false, "load with race tag")
func main() {
flag.Parse()
@ -38,9 +40,15 @@ func main() {
pkgNames = []string{"."}
}
var buildFlags []string
if *race {
buildFlags = append(buildFlags, "-race")
}
roots, err := packages.Load(&packages.Config{
Mode: packages.LoadAllSyntax,
Env: os.Environ(),
Mode: packages.LoadAllSyntax,
Env: os.Environ(),
BuildFlags: buildFlags,
}, pkgNames...)
if err != nil {