Skip to content

Commit

Permalink
Add clang-format script and CI job (#9)
Browse files Browse the repository at this point in the history
Adding scripts/format-diff.sh to use clang-format to format code changes since diverge from master. Also adding travis CI job to check if the code needs to format. Also format all existing code.

Signed-off-by: Yi Wu <yiwu@pingcap.com>
  • Loading branch information
yiwu-arbug committed May 15, 2019
1 parent 05a3755 commit 73b2918
Show file tree
Hide file tree
Showing 43 changed files with 838 additions and 819 deletions.
21 changes: 13 additions & 8 deletions .travis.yml
Expand Up @@ -9,10 +9,12 @@ addons:
apt:
sources:
- ubuntu-toolchain-r-test
- llvm-toolchain-xenial-7
packages:
- g++-7
- libgflags-dev
- lcov
- clang-format-7

# For GCC build, we also report code coverage to codecov.
matrix:
Expand All @@ -26,28 +28,31 @@ matrix:
- compiler: clang
env: SANITIZER="UBSAN"
- env: COMPILER=gcc7
- env: FORMATTER=ON

install:
- git clone --depth=1 --branch=tikv-3.0 https://github.com/pingcap/rocksdb.git
- if [ "${COMPILER}" == gcc7 ]; then
CC=gcc-7;
CXX=g++-7;
COVERAGE_OPT="-DCODE_COVERAGE=ON";
export COVERAGE_OPT="-DCODE_COVERAGE=ON";
fi
- if [ ! -z "${BUILD_TYPE}" ]; then
BUILD_OPT="-DCMAKE_BUILD_TYPE=${BUILD_TYPE}";
export BUILD_OPT="-DCMAKE_BUILD_TYPE=${BUILD_TYPE}";
else
BUILD_OPT="-DCMAKE_BUILD_TYPE=Debug";
export BUILD_OPT="-DCMAKE_BUILD_TYPE=Debug";
fi
- if [ ! -z "${SANITIZER}" ]; then
SANITIZER_OPT="-DWITH_${SANITIZER}=ON";
TOOLS_OPT="-DWITH_TITAN_TOOLS=OFF";
export SANITIZER_OPT="-DWITH_${SANITIZER}=ON";
export TOOLS_OPT="-DWITH_TITAN_TOOLS=OFF";
fi

script:
- cmake . -L -DROCKSDB_DIR=./rocksdb -DTRAVIS=ON ${BUILD_OPT} ${SANITIZER_OPT} ${TOOLS_OPT} ${COVERAGE_OPT}
- make -j4
- ctest -R titan
- if [ -z "${FORMATTER}" ]; then
bash scripts/travis-make.sh;
else
bash scripts/travis-format.sh;
fi

after_success:
- if [ "${COMPILER}" == gcc7 ]; then
Expand Down
3 changes: 3 additions & 0 deletions README.md
Expand Up @@ -32,4 +32,7 @@ cmake .. -DROCKSDB_DIR=<rocksdb_source_dir> -DWITH_SNAPPY=ON
# Run tests after build. You need to filter tests by "titan" prefix.
ctest -R titan
# To format code, install clang-format and run the script.
bash scripts/format-diff.sh
```
10 changes: 5 additions & 5 deletions include/titan/db.h
Expand Up @@ -46,8 +46,7 @@ class TitanDB : public StackableDB {

using StackableDB::CreateColumnFamilies;
Status CreateColumnFamilies(
const ColumnFamilyOptions& options,
const std::vector<std::string>& names,
const ColumnFamilyOptions& options, const std::vector<std::string>& names,
std::vector<ColumnFamilyHandle*>* handles) override {
std::vector<TitanCFDescriptor> descs;
for (auto& name : names) {
Expand Down Expand Up @@ -75,7 +74,8 @@ class TitanDB : public StackableDB {
Status DropColumnFamilies(
const std::vector<ColumnFamilyHandle*>& handles) override = 0;

Status DestroyColumnFamilyHandle(ColumnFamilyHandle* column_family) override = 0;
Status DestroyColumnFamilyHandle(ColumnFamilyHandle* column_family) override =
0;

using StackableDB::Merge;
Status Merge(const WriteOptions&, ColumnFamilyHandle*, const Slice& /*key*/,
Expand All @@ -85,8 +85,8 @@ class TitanDB : public StackableDB {

using rocksdb::StackableDB::SingleDelete;
Status SingleDelete(const WriteOptions& /*wopts*/,
ColumnFamilyHandle* /*column_family*/,
const Slice& /*key*/) override {
ColumnFamilyHandle* /*column_family*/,
const Slice& /*key*/) override {
return Status::NotSupported("Not supported operation in titan db.");
}

Expand Down
3 changes: 3 additions & 0 deletions scripts/format-diff.sh
@@ -0,0 +1,3 @@
#!/bin/bash

git diff `git merge-base master HEAD` | clang-format-diff -style=google -p1 -i
11 changes: 11 additions & 0 deletions scripts/travis-format.sh
@@ -0,0 +1,11 @@
#!/bin/bash

set -ev
git fetch --depth=1 origin master:master;
git diff $(git merge-base master HEAD) HEAD > diff;
cat diff | clang-format-diff-7 -style=google -p1 > formatted;
if [ -s formatted ]; then
cat formatted;
echo "Run scripts/format-diff.sh to format your code.";
exit 1;
fi;
7 changes: 7 additions & 0 deletions scripts/travis-make.sh
@@ -0,0 +1,7 @@
#!/bin/bash

set -ev
cmake . -L -DROCKSDB_DIR=./rocksdb -DTRAVIS=ON ${BUILD_OPT} ${SANITIZER_OPT} ${TOOLS_OPT} ${COVERAGE_OPT}
make -j4
ctest -R titan

2 changes: 1 addition & 1 deletion src/base_db_listener.h
@@ -1,7 +1,7 @@
#pragma once

#include "rocksdb/listener.h"
#include "db_impl.h"
#include "rocksdb/listener.h"

namespace rocksdb {

Expand Down
2 changes: 1 addition & 1 deletion src/blob_file_builder.h
@@ -1,8 +1,8 @@
#pragma once

#include "util/file_reader_writer.h"
#include "blob_format.h"
#include "titan/options.h"
#include "util/file_reader_writer.h"

namespace rocksdb {
namespace titandb {
Expand Down
2 changes: 1 addition & 1 deletion src/blob_file_cache.cc
@@ -1,7 +1,7 @@
#include "blob_file_cache.h"

#include "util/filename.h"
#include "util.h"
#include "util/filename.h"

namespace rocksdb {
namespace titandb {
Expand Down
2 changes: 1 addition & 1 deletion src/blob_file_cache.h
@@ -1,8 +1,8 @@
#pragma once

#include "rocksdb/options.h"
#include "blob_file_reader.h"
#include "blob_format.h"
#include "rocksdb/options.h"
#include "titan/options.h"

namespace rocksdb {
Expand Down
2 changes: 1 addition & 1 deletion src/blob_file_iterator.cc
@@ -1,7 +1,7 @@
#include "blob_file_iterator.h"

#include "util/crc32c.h"
#include "util.h"
#include "util/crc32c.h"

namespace rocksdb {
namespace titandb {
Expand Down
4 changes: 2 additions & 2 deletions src/blob_file_iterator.h
Expand Up @@ -3,13 +3,13 @@
#include <cstdint>
#include <queue>

#include "blob_format.h"
#include "rocksdb/slice.h"
#include "rocksdb/status.h"
#include "table/internal_iterator.h"
#include "util/file_reader_writer.h"
#include "blob_format.h"
#include "titan/options.h"
#include "util.h"
#include "util/file_reader_writer.h"

namespace rocksdb {
namespace titandb {
Expand Down
7 changes: 4 additions & 3 deletions src/blob_file_iterator_test.cc
Expand Up @@ -2,11 +2,11 @@

#include <cinttypes>

#include "util/filename.h"
#include "util/testharness.h"
#include "blob_file_builder.h"
#include "blob_file_cache.h"
#include "blob_file_reader.h"
#include "util/filename.h"
#include "util/testharness.h"

namespace rocksdb {
namespace titandb {
Expand Down Expand Up @@ -57,7 +57,8 @@ class BlobFileIteratorTest : public testing::Test {
{
std::unique_ptr<WritableFile> f;
ASSERT_OK(env_->NewWritableFile(file_name_, &f, env_options_));
writable_file_.reset(new WritableFileWriter(std::move(f), file_name_, env_options_));
writable_file_.reset(
new WritableFileWriter(std::move(f), file_name_, env_options_));
}
builder_.reset(new BlobFileBuilder(cf_options, writable_file_.get()));
}
Expand Down
2 changes: 1 addition & 1 deletion src/blob_file_manager.h
@@ -1,7 +1,7 @@
#pragma once

#include "util/file_reader_writer.h"
#include "blob_format.h"
#include "util/file_reader_writer.h"

namespace rocksdb {
namespace titandb {
Expand Down
2 changes: 1 addition & 1 deletion src/blob_file_reader.h
@@ -1,8 +1,8 @@
#pragma once

#include "util/file_reader_writer.h"
#include "blob_format.h"
#include "titan/options.h"
#include "util/file_reader_writer.h"

namespace rocksdb {
namespace titandb {
Expand Down
2 changes: 1 addition & 1 deletion src/blob_file_size_collector.h
@@ -1,9 +1,9 @@
#pragma once

#include "db_impl.h"
#include "rocksdb/listener.h"
#include "rocksdb/table_properties.h"
#include "util/coding.h"
#include "db_impl.h"
#include "version_set.h"

namespace rocksdb {
Expand Down
4 changes: 2 additions & 2 deletions src/blob_file_size_collector_test.cc
Expand Up @@ -40,8 +40,8 @@ class BlobFileSizeCollectorTest : public testing::Test {
void NewFileWriter(std::unique_ptr<WritableFileWriter>* result) {
std::unique_ptr<WritableFile> writable_file;
ASSERT_OK(env_->NewWritableFile(file_name_, &writable_file, env_options_));
result->reset(
new WritableFileWriter(std::move(writable_file), file_name_, env_options_));
result->reset(new WritableFileWriter(std::move(writable_file), file_name_,
env_options_));
ASSERT_TRUE(*result);
}

Expand Down
10 changes: 6 additions & 4 deletions src/blob_file_test.cc
@@ -1,8 +1,8 @@
#include "util/filename.h"
#include "util/testharness.h"
#include "blob_file_builder.h"
#include "blob_file_cache.h"
#include "blob_file_reader.h"
#include "util/filename.h"
#include "util/testharness.h"

namespace rocksdb {
namespace titandb {
Expand Down Expand Up @@ -31,7 +31,8 @@ class BlobFileTest : public testing::Test {
{
std::unique_ptr<WritableFile> f;
ASSERT_OK(env_->NewWritableFile(file_name_, &f, env_options_));
file.reset(new WritableFileWriter(std::move(f), file_name_, env_options_));
file.reset(
new WritableFileWriter(std::move(f), file_name_, env_options_));
}
std::unique_ptr<BlobFileBuilder> builder(
new BlobFileBuilder(cf_options, file.get()));
Expand Down Expand Up @@ -91,7 +92,8 @@ class BlobFileTest : public testing::Test {
{
std::unique_ptr<WritableFile> f;
ASSERT_OK(env_->NewWritableFile(file_name_, &f, env_options_));
file.reset(new WritableFileWriter(std::move(f), file_name_, env_options_));
file.reset(
new WritableFileWriter(std::move(f), file_name_, env_options_));
}
std::unique_ptr<BlobFileBuilder> builder(
new BlobFileBuilder(cf_options, file.get()));
Expand Down
2 changes: 1 addition & 1 deletion src/blob_format_test.cc
@@ -1,7 +1,7 @@
#include "blob_format.h"
#include "util/testharness.h"
#include "testutil.h"
#include "util.h"
#include "util/testharness.h"

namespace rocksdb {
namespace titandb {
Expand Down
4 changes: 1 addition & 3 deletions src/blob_gc.cc
Expand Up @@ -12,9 +12,7 @@ BlobGC::BlobGC(std::vector<BlobFileMeta*>&& blob_files,

BlobGC::~BlobGC() {}

void BlobGC::SetColumnFamily(ColumnFamilyHandle* cfh) {
cfh_ = cfh;
}
void BlobGC::SetColumnFamily(ColumnFamilyHandle* cfh) { cfh_ = cfh; }

ColumnFamilyData* BlobGC::GetColumnFamilyData() {
auto* cfhi = reinterpret_cast<ColumnFamilyHandleImpl*>(cfh_);
Expand Down
2 changes: 1 addition & 1 deletion src/blob_gc.h
Expand Up @@ -2,8 +2,8 @@

#include <memory>

#include "db/column_family.h"
#include "blob_format.h"
#include "db/column_family.h"
#include "titan/options.h"

namespace rocksdb {
Expand Down
4 changes: 2 additions & 2 deletions src/blob_gc_job.h
@@ -1,11 +1,11 @@
#pragma once

#include "db/db_impl.h"
#include "rocksdb/status.h"
#include "blob_file_builder.h"
#include "blob_file_iterator.h"
#include "blob_file_manager.h"
#include "blob_gc.h"
#include "db/db_impl.h"
#include "rocksdb/status.h"
#include "titan/options.h"
#include "version_set.h"

Expand Down

0 comments on commit 73b2918

Please sign in to comment.