Skip to content

Commit

Permalink
tools/check: adpot staged build to make ut a little bit faster (#51374)
Browse files Browse the repository at this point in the history
ref #31880
  • Loading branch information
tiancaiamao committed Feb 28, 2024
1 parent c23f0c9 commit 33d7a2c
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tools/check/go-compile-without-link.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash
# Copyright 2024 PingCAP, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# See https://gist.github.com/howardjohn/c0f5d0bc293ef7d7fada533a2c9ffaf4
# Usage: go test -exec=true -toolexec=go-compile-without-link -vet=off ./...
# Preferably as an alias like `alias go-test-compile='go test -exec=true -toolexec=go-compile-without-link -vet=off'`
# This will compile all tests, but not link them (which is the least cacheable part)

if [[ "${2}" == "-V=full" ]]; then
"$@"
exit 0
fi
case "$(basename ${1})" in
link)
# Output a dummy file
touch "${3}"
;;
# We could skip vet as well, but it can be done with -vet=off if desired
*)
"$@"
esac
18 changes: 18 additions & 0 deletions tools/check/ut.go
Original file line number Diff line number Diff line change
Expand Up @@ -869,8 +869,26 @@ func buildTestBinary(pkg string) error {
return nil
}

func generateBuildCache() error {
// cd cmd/tidb-server && go test -tags intest -exec true -vet off -toolexec=go-compile-without-link
cmd := exec.Command("go", "test", "-tags=intest", "-exec=true", "-vet=off")
goCompileWithoutLink := fmt.Sprintf("-toolexec=%s/tools/check/go-compile-without-link.sh", workDir)
cmd.Args = append(cmd.Args, goCompileWithoutLink)
cmd.Dir = path.Join(workDir, "cmd/tidb-server")
if err := cmd.Run(); err != nil {
return withTrace(err)
}
return nil
}

// buildTestBinaryMulti is much faster than build the test packages one by one.
func buildTestBinaryMulti(pkgs []string) error {
// staged build, generate the build cache for all the tests first, then generate the test binary.
// This way is faster than generating test binaries directly, because the cache can be used.
if err := generateBuildCache(); err != nil {
return withTrace(err)
}

// go test --exec=xprog -cover -vet=off --count=0 $(pkgs)
xprogPath := path.Join(workDir, "tools/bin/xprog")
packages := make([]string, 0, len(pkgs))
Expand Down

0 comments on commit 33d7a2c

Please sign in to comment.