From ecde1bd251b6e0815767330a2aa59dd5d9700122 Mon Sep 17 00:00:00 2001 From: Egon Elbre Date: Wed, 1 May 2019 18:44:12 +0300 Subject: [PATCH] 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: --- Jenkinsfile.public | 2 +- satellite/satellitedb/dbx/satellitedb.dbx.go | 53 ++++++++++++++++++-- scripts/check-dbx-version.sh | 1 + scripts/check-imports.go | 12 ++++- 4 files changed, 61 insertions(+), 7 deletions(-) diff --git a/Jenkinsfile.public b/Jenkinsfile.public index fbb2e9d59..47f45eece 100644 --- a/Jenkinsfile.public +++ b/Jenkinsfile.public @@ -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' diff --git a/satellite/satellitedb/dbx/satellitedb.dbx.go b/satellite/satellitedb/dbx/satellitedb.dbx.go index 1f03464d8..eeae32ac5 100644 --- a/satellite/satellitedb/dbx/satellitedb.dbx.go +++ b/satellite/satellitedb/dbx/satellitedb.dbx.go @@ -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: diff --git a/scripts/check-dbx-version.sh b/scripts/check-dbx-version.sh index d640bde90..b35b00d7c 100755 --- a/scripts/check-dbx-version.sh +++ b/scripts/check-dbx-version.sh @@ -7,4 +7,5 @@ then echo "dbx version ok" else echo "please use latest dbx tool to generate code" + exit 1 fi \ No newline at end of file diff --git a/scripts/check-imports.go b/scripts/check-imports.go index b9d79ac99..bda7fb664 100644 --- a/scripts/check-imports.go +++ b/scripts/check-imports.go @@ -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 {