Skip to content

Commit

Permalink
This code change fixes issues when running gcassert under bazel by
Browse files Browse the repository at this point in the history
ensuring that we generate go and cgo files, and pass a path to C and
C++ compilers to the lint test process.

With these changes, `gcassert` can run as part of the `Lint` build
config and doesn't need its own build config so the gcassert build
config scripts are deleted.

Release note: None
Epic: CRDB-8349

Closes #65485
  • Loading branch information
healthy-pod committed Jun 8, 2023
1 parent 78dfbbc commit b8311b7
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 49 deletions.
6 changes: 3 additions & 3 deletions DEPS.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -5059,10 +5059,10 @@ def go_deps():
name = "com_github_jordanlewis_gcassert",
build_file_proto_mode = "disable_global",
importpath = "github.com/jordanlewis/gcassert",
sha256 = "4e6d2be78096ee4158d921af5d388f76bbf6d2638cee052ca628ba70da911704",
strip_prefix = "github.com/jordanlewis/[email protected]20221027203946-81f097ad35a0",
sha256 = "3919384e0288d9ce93da816ef227aec2c61b978eb761bd45a7fded957f792dcf",
strip_prefix = "github.com/jordanlewis/[email protected]20230505190637-fed79d91cd5f",
urls = [
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/jordanlewis/gcassert/com_github_jordanlewis_gcassert-v0.0.0-20221027203946-81f097ad35a0.zip",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/jordanlewis/gcassert/com_github_jordanlewis_gcassert-v0.0.0-20230505190637-fed79d91cd5f.zip",
],
)
go_repository(
Expand Down
2 changes: 1 addition & 1 deletion build/bazelutil/distdir_files.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ DISTDIR_FILES = {
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/joho/godotenv/com_github_joho_godotenv-v1.3.0.zip": "acef5a394fbd1193f52d0d19690b0bfe82728d18dd3bf67730dc5031c22d563f",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/jonboulle/clockwork/com_github_jonboulle_clockwork-v0.1.0.zip": "930d355d1ced60a668bcbca6154bb5671120ba11a34119505d1c0677f7bbbf97",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/jordan-wright/email/com_github_jordan_wright_email-v4.0.1-0.20210109023952-943e75fe5223+incompatible.zip": "6d35fa83ea02cfacd0e1ba9c9061381b963215cef84c8bf83ad5944cb304c390",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/jordanlewis/gcassert/com_github_jordanlewis_gcassert-v0.0.0-20221027203946-81f097ad35a0.zip": "4e6d2be78096ee4158d921af5d388f76bbf6d2638cee052ca628ba70da911704",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/jordanlewis/gcassert/com_github_jordanlewis_gcassert-v0.0.0-20230505190637-fed79d91cd5f.zip": "3919384e0288d9ce93da816ef227aec2c61b978eb761bd45a7fded957f792dcf",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/josharian/intern/com_github_josharian_intern-v1.0.0.zip": "5679bfd11c14adccdb45bd1a0f9cf4b445b95caeed6fb507ba96ecced11c248d",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/jpillora/backoff/com_github_jpillora_backoff-v1.0.0.zip": "f856692c725143c49b9cceabfbca8bc93d3dbde84a0aaa53fb26ed3774c220cc",
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/json-iterator/go/com_github_json_iterator_go-v1.1.12.zip": "d001ea57081afd0e378467c8f4a9b6a51259996bb8bb763f78107eaf12f99501",
Expand Down
12 changes: 0 additions & 12 deletions build/teamcity/cockroach/ci/tests/gcassert.sh

This file was deleted.

15 changes: 0 additions & 15 deletions build/teamcity/cockroach/ci/tests/gcassert_impl.sh

This file was deleted.

8 changes: 7 additions & 1 deletion build/teamcity/cockroach/ci/tests/lint_impl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@

set -xeuo pipefail

# GCAssert requirements -- start
export PATH="$(dirname $(bazel run @go_sdk//:bin/go --run_under=realpath)):$PATH"
bazel run //pkg/gen:code
bazel run //pkg/cmd/generate-cgo:generate-cgo --run_under="cd $(bazel info workspace) && "
# GCAssert requirements -- end

bazel build //pkg/cmd/bazci --config=ci
XML_OUTPUT_FILE=/artifacts/test.xml GO_TEST_WRAP_TESTV=1 GO_TEST_WRAP=1 bazel \
XML_OUTPUT_FILE=/artifacts/test.xml GO_TEST_WRAP_TESTV=1 GO_TEST_WRAP=1 CC=$(which gcc) CXX=$(which gcc) bazel \
run --config=ci --config=test //build/bazelutil:lint
# The schema of the output test.xml will be slightly wrong -- ask `bazci` to fix
# it up.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ require (
github.com/jackc/pgx/v5 v5.3.1
github.com/jaegertracing/jaeger v1.18.1
github.com/jordan-wright/email v4.0.1-0.20210109023952-943e75fe5223+incompatible
github.com/jordanlewis/gcassert v0.0.0-20221027203946-81f097ad35a0
github.com/jordanlewis/gcassert v0.0.0-20230505190637-fed79d91cd5f
github.com/kevinburke/go-bindata v3.13.0+incompatible
github.com/kisielk/errcheck v1.6.1-0.20210625163953-8ddee489636a
github.com/kisielk/gotool v1.0.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1441,8 +1441,8 @@ github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqx
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
github.com/jordan-wright/email v4.0.1-0.20210109023952-943e75fe5223+incompatible h1:jdpOPRN1zP63Td1hDQbZW73xKmzDvZHzVdNYxhnTMDA=
github.com/jordan-wright/email v4.0.1-0.20210109023952-943e75fe5223+incompatible/go.mod h1:1c7szIrayyPPB/987hsnvNzLushdWf4o/79s3P08L8A=
github.com/jordanlewis/gcassert v0.0.0-20221027203946-81f097ad35a0 h1:y9VRjxb2hZlTElaaUH50QkZnPKrvQR5NhPza66vh+9w=
github.com/jordanlewis/gcassert v0.0.0-20221027203946-81f097ad35a0/go.mod h1:FsDIOYX6N9TFyHD602Yu/Zp04+KySTH00okDq+9IPqo=
github.com/jordanlewis/gcassert v0.0.0-20230505190637-fed79d91cd5f h1:GoV80Ggs5ZeF6uDv/lYDGJAv2Wz3Mp/brqRbjvEm6mI=
github.com/jordanlewis/gcassert v0.0.0-20230505190637-fed79d91cd5f/go.mod h1:FsDIOYX6N9TFyHD602Yu/Zp04+KySTH00okDq+9IPqo=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/jpillora/backoff v1.0.0 h1:uvFg412JmmHBHw7iwprIxkPMI+sGQ4kzOWsMeHnm2EA=
Expand Down
43 changes: 39 additions & 4 deletions pkg/cmd/generate-cgo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,19 @@ import "C"
krbDir = filepath.Join(bazelBin, "c-deps/libkrb5_foreign")
}
}
cppFlags := fmt.Sprintf("-I%s", filepath.Join(jemallocDir, "include"))
ldFlags := fmt.Sprintf("-L%s -L%s", filepath.Join(jemallocDir, "lib"), filepath.Join(projDir, "lib"))

srcToPersistentDirs := make(map[string]string, 3)
srcToPersistentDirs[jemallocDir] = filepath.Join(workspace, "bin", "c-deps", filepath.Base(jemallocDir))
srcToPersistentDirs[projDir] = filepath.Join(workspace, "bin", "c-deps", filepath.Base(projDir))
if krbDir != "" {
srcToPersistentDirs[krbDir] = filepath.Join(workspace, "bin", "c-deps", filepath.Base(krbDir))
}

cppFlags := fmt.Sprintf("-I%s", filepath.Join(srcToPersistentDirs[jemallocDir], "include"))
ldFlags := fmt.Sprintf("-L%s -L%s", filepath.Join(srcToPersistentDirs[jemallocDir], "lib"), filepath.Join(srcToPersistentDirs[projDir], "lib"))
if krbDir != "" {
cppFlags += fmt.Sprintf(" -I%s", filepath.Join(krbDir, "include"))
ldFlags += fmt.Sprintf(" -L%s", filepath.Join(krbDir, "lib"))
cppFlags += fmt.Sprintf(" -I%s", filepath.Join(srcToPersistentDirs[krbDir], "include"))
ldFlags += fmt.Sprintf(" -L%s", filepath.Join(srcToPersistentDirs[krbDir], "lib"))
}

cgoPkgs := []string{
Expand All @@ -177,6 +185,33 @@ import "C"
return err
}
}

// Copy jemallocDir, projDir, and krbDir to a persistent location (//bin/c-deps).
if err := os.MkdirAll(filepath.Join(workspace, "bin", "c-deps"), 0755); err != nil {
return err
}
// Ensure that overwriting existing ones is possible to prevent permissions errors.
chmodCmd := exec.Command("chmod", "-R", "755", filepath.Join(workspace, "bin", "c-deps"))
var chmodOutBuf, chmodErrBuf strings.Builder
chmodCmd.Stderr = &chmodErrBuf
chmodCmd.Stdout = &chmodOutBuf
if err := chmodCmd.Run(); err != nil {
return errors.Wrapf(err, "Output: %s - %s", chmodOutBuf.String(), chmodErrBuf.String())
}
for dirToCopy := range srcToPersistentDirs {
if dirToCopy != "" {
copyCmdArgs := []string{"-r", dirToCopy, filepath.Dir(srcToPersistentDirs[dirToCopy])}
logCommand("cp", copyCmdArgs...)
cmd := exec.Command("cp", copyCmdArgs...)
var outBuf, errBuf strings.Builder
cmd.Stdout = &outBuf
cmd.Stderr = &errBuf
cmd.Dir = workspace
if err := cmd.Run(); err != nil {
return errors.Wrapf(err, "Output: %s - %s", outBuf.String(), errBuf.String())
}
}
}
return nil
}

Expand Down
18 changes: 8 additions & 10 deletions pkg/testutils/lint/lint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1430,7 +1430,7 @@ func TestLint(t *testing.T) {
if pkgSpecified {
skip.IgnoreLint(t, "PKG specified")
}
ignore := `\.(pb(\.gw)?)|(\.[eo]g)\.go|/testdata/|^sql/parser/sql\.go$|(_)?generated(_test)?\.go$`
ignore := `zcgo*|\.(pb(\.gw)?)|(\.[eo]g)\.go|/testdata/|^sql/parser/sql\.go$|(_)?generated(_test)?\.go$`
cmd, stderr, filter, err := dirCmd(pkgDir, "crlfmt", "-fast", "-ignore", ignore, "-tab", "2", ".")
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -2110,15 +2110,13 @@ func TestLint(t *testing.T) {
}
})

if !bazel.BuiltWithBazel() {
var buf strings.Builder
if err := gcassert.GCAssert(&buf, gcassertPaths...); err != nil {
t.Fatal(err)
}
output := buf.String()
if len(output) > 0 {
t.Fatalf("failed gcassert:\n%s", output)
}
var buf strings.Builder
if err := gcassert.GCAssert(&buf, gcassertPaths...); err != nil {
t.Fatal(err)
}
output := buf.String()
if len(output) > 0 {
t.Fatalf("failed gcassert:\n%s", output)
}
})

Expand Down

0 comments on commit b8311b7

Please sign in to comment.