Skip to content

Commit

Permalink
Run clang-tidy against gpopt translator
Browse files Browse the repository at this point in the history
  • Loading branch information
d committed Jun 30, 2021
1 parent 438bbc8 commit feccc0a
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 8 deletions.
29 changes: 29 additions & 0 deletions .travis.yml
Expand Up @@ -99,6 +99,7 @@ matrix:
addons:
apt:
packages:
- bear
- ninja-build
- clang-11
- clang-tidy-11
Expand All @@ -109,6 +110,34 @@ matrix:
before_script: ~
after_script: ~
script:
- |
(
set -e
mkdir ../vpath.debug
cd ../vpath.debug
../gpdb/configure \
--enable-debug \
--enable-cassert \
--enable-orca \
--without-zstd --disable-gpfdist \
CC="ccache clang-11" CXX="ccache clang++-11" CFLAGS=-O0 CXXFLAGS=-O0
bear --append make -s -C src/backend/gpopt
)
CLANG_TIDY=clang-tidy-11 src/tools/tidy chk-gpopt ../vpath.debug
- |
(
set -e
mkdir ../vpath.release
cd ../vpath.release
../gpdb/configure \
--enable-debug \
--disable-cassert \
--enable-orca \
--without-zstd --disable-gpfdist \
CC="ccache clang-11" CXX="ccache clang++-11" CFLAGS=-O0 CXXFLAGS=-O0
bear --append make -s -C src/backend/gpopt
)
CLANG_TIDY=clang-tidy-11 src/tools/tidy chk-gpopt ../vpath.release
- CXX=clang++-11 cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -GNinja -DCMAKE_BUILD_TYPE=Debug -Hsrc/backend/gporca -Bbuild.debug
- CLANG_TIDY=clang-tidy-11 src/tools/tidy chk-orca build.debug
- CXX=clang++-11 cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -GNinja -DCMAKE_BUILD_TYPE=RelWithDebInfo -Hsrc/backend/gporca -Bbuild.relwithdebinfo
Expand Down
39 changes: 33 additions & 6 deletions concourse/tasks/clang_tidy.yml
Expand Up @@ -3,19 +3,46 @@ image_resource:
type: registry-image
source:
repository: gcr.io/data-orca/clang-toolchain
tag: 0.2
tag: 0.3

inputs:
- name: gpdb_src
path: .

run:
path: sh
args:
- -exc
- |
CXX=clang++-11 cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -GNinja -DCMAKE_BUILD_TYPE=Debug -Hsrc/backend/gporca -Bbuild.debug
src/tools/tidy chk-orca build.debug
CXX=clang++-11 cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -GNinja -DCMAKE_BUILD_TYPE=RelWithDebInfo -Hsrc/backend/gporca -Bbuild.relwithdebinfo
src/tools/tidy chk-orca build.relwithdebinfo
(
mkdir vpath.debug
cd vpath.debug
../gpdb_src/configure \
--enable-cassert \
--enable-orca \
--without-python --without-readline --without-zlib --without-zstd --without-libbz2 --disable-gpfdist --disable-gpcloud --disable-pxf --without-libcurl \
CC="ccache clang-11" CXX="ccache clang++-11" CFLAGS=-O0 CXXFLAGS=-O0
bear --append make -s -C src/backend/gpopt
)
(
mkdir vpath.release
cd vpath.release
../gpdb_src/configure \
--disable-cassert \
--enable-orca \
--without-python --without-readline --without-zlib --without-zstd --without-libbz2 --disable-gpfdist --disable-gpcloud --disable-pxf --without-libcurl \
CC="ccache clang-11" CXX="ccache clang++-11" CFLAGS=-O0 CXXFLAGS=-O0
bear --append make -s -C src/backend/gpopt
)
(
cd gpdb_src
src/tools/tidy chk-gpopt ../vpath.debug
src/tools/tidy chk-gpopt ../vpath.release
CXX=clang++-11 cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -GNinja -DCMAKE_BUILD_TYPE=Debug -Hsrc/backend/gporca -Bbuild.debug
src/tools/tidy chk-orca build.debug
CXX=clang++-11 cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -GNinja -DCMAKE_BUILD_TYPE=RelWithDebInfo -Hsrc/backend/gporca -Bbuild.relwithdebinfo
src/tools/tidy chk-orca build.relwithdebinfo
)
params:
CLANG_TIDY: clang-tidy-11
36 changes: 34 additions & 2 deletions src/backend/gporca/README.tidy.md
Expand Up @@ -40,7 +40,7 @@ apt-get install parallel clang-tidy-12

Alternatively `apt-get install clang-tidy` will give you a "default" version of `clang-tidy` from the distribution.

### Generating Build Directories With A Compilation Database
### Generating ORCA Build Directories With A Compilation Database

Here's an example of generating two build directories, `build.debug` and `build.release` at the root of Greenplum repository:

Expand All @@ -56,7 +56,7 @@ and release:
$ CXX=clang++ cmake -GNinja -Hsrc/backend/gporca -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_BUILD_TYPE=RelWithDebInfo -Bbuild.release
```

### Checking
### Checking ORCA code

To check (it's unsurprising if we pass the check in one configuration but not another)

Expand All @@ -76,3 +76,35 @@ So if you're (typically) using `clang-tidy` from Homebrew's LLVM package, you'll
```
$ CLANG_TIDY=/usr/local/opt/llvm/bin/clang-tidy src/tools/tidy chk-orca build.debug
```

### Generating VPATH builds With Compilation Databases

[bear]: https://github.com/rizsotto/Bear

The main Greenplum codebase, like upstream PostgreSQL, uses autoconf and GNU Make as the build system. This means that we'll need another tool, like [Bear][bear]. The following example assumes you start from the root of a check-out of our Git repository:

```
mkdir ../vpath.debug
(
cd ../vpath.debug
../gpdb/configure --config-cache -enable-depend --enable-orca --enable-cassert CC="ccache clang" CXX="ccache clang++" CFLAGS='-O0' CXXFLAGS='-O0'
bear --append make -s -C src/backend/gpopt
)
mkdir ../vpath.release
(
cd ../vpath.release
../gpdb/configure --config-cache -enable-depend --enable-orca --disable-cassert CC="ccache clang" CXX="ccache clang++" CFLAGS='-O0' CXXFLAGS='-O0'
bear --append make -s -C src/backend/gpopt
)
```

The steps above will create two VPATH build directories, one with assertions enabled, and another without assertions. Each directory has a compilation database (generated by `bear` intercepting the build commands) that understands the flags necessary to build the translator (`src/backend/gpopt`).

### Checking the Translator (`gpopt`)

If you have a compilation database (`compile_commands.json`) that records the commands used to build files in `src/backend/gpopt`, point the `tidy` script to that:

```
$ src/tools/tidy chk-gpopt ../vpath.debug
$ src/tools/tidy chk-gpopt ../vpath.release
```

0 comments on commit feccc0a

Please sign in to comment.