Skip to content

Commit

Permalink
tools/pd-ut: accelarate build by compile-without-link (#8069)
Browse files Browse the repository at this point in the history
ref #7969

Signed-off-by: husharp <jinhao.hu@pingcap.com>

Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
  • Loading branch information
HuSharp and ti-chi-bot[bot] authored Apr 16, 2024
1 parent f5fd36f commit 22543a9
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tools/pd-ut/go-compile-without-link.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

# 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
20 changes: 20 additions & 0 deletions tools/pd-ut/ut.go
Original file line number Diff line number Diff line change
Expand Up @@ -589,8 +589,28 @@ func skipDIR(pkg string) bool {
return false
}

func generateBuildCache() error {
// cd cmd/pd-server && go test -tags=tso_function_test,deadlock -exec-=true -vet=off -toolexec=go-compile-without-link
cmd := exec.Command("go", "test", "-exec=true", "-vet", "off", "--tags=tso_function_test,deadlock")
goCompileWithoutLink := fmt.Sprintf("-toolexec=%s/tools/pd-ut/go-compile-without-link.sh", workDir)
cmd.Args = append(cmd.Args, goCompileWithoutLink)
cmd.Dir = fmt.Sprintf("%s/cmd/pd-server", workDir)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
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 --tags=tso_function_test,deadlock -vet=off --count=0 $(pkgs)
xprogPath := path.Join(workDir, "bin/xprog")
packages := make([]string, 0, len(pkgs))
Expand Down

0 comments on commit 22543a9

Please sign in to comment.