Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tools/check: adpot staged build to make ut a little bit faster #51374

Merged
merged 4 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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