Skip to content

Commit

Permalink
Changes to support unity build:
Browse files Browse the repository at this point in the history
* Script for building the unity.cc file via Makefile
* Unity executable Makefile target for testing builds
* Source code changes to fix compilation of unity build
  • Loading branch information
miguelportilla committed Aug 11, 2014
1 parent 54153ab commit 93e6b5e
Show file tree
Hide file tree
Showing 19 changed files with 131 additions and 79 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ coverage/COVERAGE_REPORT
tags
java/*.log
java/include/org_rocksdb_*.h
unity.cc
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,14 @@ valgrind_check: all $(PROGRAMS) $(TESTS)
echo $$t $$((etime - stime)) >> $(VALGRIND_DIR)/valgrind_tests_times; \
done

unity.cc:
$(shell (export ROCKSDB_ROOT="$(CURDIR)"; "$(CURDIR)/build_tools/unity" "$(CURDIR)/unity.cc"))

unity: unity.cc unity.o
$(CXX) unity.o $(EXEC_LDFLAGS) -o $@ $(LDFLAGS) $(COVERAGEFLAGS)

clean:
-rm -f $(PROGRAMS) $(TESTS) $(LIBRARY) $(SHARED) $(MEMENVLIBRARY) build_config.mk
-rm -f $(PROGRAMS) $(TESTS) $(LIBRARY) $(SHARED) $(MEMENVLIBRARY) build_config.mk unity.cc
-rm -rf ios-x86/* ios-arm/*
-find . -name "*.[od]" -exec rm {} \;
-find . -type f -regex ".*\.\(\(gcda\)\|\(gcno\)\)" -exec rm {} \;
Expand Down
78 changes: 78 additions & 0 deletions build_tools/unity
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/bin/sh
#
# Create the unity file
#

OUTPUT=$1
if test -z "$OUTPUT"; then
echo "usage: $0 <output-filename>" >&2
exit 1
fi

# Delete existing file, if it exists
rm -f "$OUTPUT"
touch "$OUTPUT"

# Detect OS
if test -z "$TARGET_OS"; then
TARGET_OS=`uname -s`
fi

# generic port files (working on all platform by #ifdef) go directly in /port
GENERIC_PORT_FILES=`cd "$ROCKSDB_ROOT"; find port -name '*.cc' | tr "\n" " "`

# On GCC, we pick libc's memcmp over GCC's memcmp via -fno-builtin-memcmp
case "$TARGET_OS" in
Darwin)
# PORT_FILES=port/darwin/darwin_specific.cc
;;
IOS)
;;
Linux)
# PORT_FILES=port/linux/linux_specific.cc
;;
SunOS)
# PORT_FILES=port/sunos/sunos_specific.cc
;;
FreeBSD)
# PORT_FILES=port/freebsd/freebsd_specific.cc
;;
NetBSD)
# PORT_FILES=port/netbsd/netbsd_specific.cc
;;
OpenBSD)
# PORT_FILES=port/openbsd/openbsd_specific.cc
;;
DragonFly)
# PORT_FILES=port/dragonfly/dragonfly_specific.cc
;;
OS_ANDROID_CROSSCOMPILE)
# PORT_FILES=port/android/android.cc
;;
*)
echo "Unknown platform!" >&2
exit 1
esac

# We want to make a list of all cc files within util, db, table, and helpers
# except for the test and benchmark files. By default, find will output a list
# of all files matching either rule, so we need to append -print to make the
# prune take effect.
DIRS="util db table utilities"

set -f # temporarily disable globbing so that our patterns arent expanded
PRUNE_TEST="-name *test*.cc -prune"
PRUNE_BENCH="-name *bench*.cc -prune"
PORTABLE_FILES=`cd "$ROCKSDB_ROOT"; find $DIRS $PRUNE_TEST -o $PRUNE_BENCH -o -name '*.cc' -print | sort`
PORTABLE_CPP=`cd "$ROCKSDB_ROOT"; find $DIRS $PRUNE_TEST -o $PRUNE_BENCH -o -name '*.cpp' -print | sort`
set +f # re-enable globbing

# The sources consist of the portable files, plus the platform-specific port
# file.
for SOURCE_FILE in $PORTABLE_FILES $GENERIC_PORT_FILES $PORT_FILES $PORTABLE_CPP
do
echo "#include <$SOURCE_FILE>" >> "$OUTPUT"
done

echo "int main(int argc, char** argv){ return 0; }" >> "$OUTPUT"

9 changes: 0 additions & 9 deletions db/column_family.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,6 @@ ColumnFamilyHandleImpl::~ColumnFamilyHandleImpl() {

uint32_t ColumnFamilyHandleImpl::GetID() const { return cfd()->GetID(); }

namespace {
// Fix user-supplied options to be reasonable
template <class T, class V>
static void ClipToRange(T* ptr, V minvalue, V maxvalue) {
if (static_cast<V>(*ptr) > maxvalue) *ptr = maxvalue;
if (static_cast<V>(*ptr) < minvalue) *ptr = minvalue;
}
} // anonymous namespace

ColumnFamilyOptions SanitizeOptions(const InternalKeyComparator* icmp,
const InternalFilterPolicy* ipolicy,
const ColumnFamilyOptions& src) {
Expand Down
2 changes: 1 addition & 1 deletion db/compaction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

namespace rocksdb {

static uint64_t TotalFileSize(const std::vector<FileMetaData*>& files) {
uint64_t TotalFileSize(const std::vector<FileMetaData*>& files) {
uint64_t sum = 0;
for (size_t i = 0; i < files.size() && files[i]; i++) {
sum += files[i]->fd.GetFileSize();
Expand Down
3 changes: 3 additions & 0 deletions db/compaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,7 @@ class Compaction {
void ResetNextCompactionIndex();
};

// Utility function
extern uint64_t TotalFileSize(const std::vector<FileMetaData*>& files);

} // namespace rocksdb
16 changes: 8 additions & 8 deletions db/compaction_picker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@

namespace rocksdb {

uint64_t TotalCompensatedFileSize(const std::vector<FileMetaData*>& files) {
uint64_t sum = 0;
for (size_t i = 0; i < files.size() && files[i]; i++) {
sum += files[i]->compensated_file_size;
}
return sum;
}

namespace {
// Determine compression type, based on user options, level of the output
// file and whether compression is disabled.
Expand Down Expand Up @@ -45,14 +53,6 @@ CompressionType GetCompressionType(const Options& options, int level,
}
}

uint64_t TotalCompensatedFileSize(const std::vector<FileMetaData*>& files) {
uint64_t sum = 0;
for (size_t i = 0; i < files.size() && files[i]; i++) {
sum += files[i]->compensated_file_size;
}
return sum;
}

// Multiple two operands. If they overflow, return op1.
uint64_t MultiplyCheckOverflow(uint64_t op1, int op2) {
if (op1 == 0) {
Expand Down
3 changes: 3 additions & 0 deletions db/compaction_picker.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,7 @@ class FIFOCompactionPicker : public CompactionPicker {
}
};

// Utility function
extern uint64_t TotalCompensatedFileSize(const std::vector<FileMetaData*>& files);

} // namespace rocksdb
9 changes: 0 additions & 9 deletions db/db_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -231,15 +231,6 @@ struct DBImpl::CompactionState {
}
};

namespace {
// Fix user-supplied options to be reasonable
template <class T, class V>
static void ClipToRange(T* ptr, V minvalue, V maxvalue) {
if (static_cast<V>(*ptr) > maxvalue) *ptr = maxvalue;
if (static_cast<V>(*ptr) < minvalue) *ptr = minvalue;
}
} // anonymous namespace

Options SanitizeOptions(const std::string& dbname,
const InternalKeyComparator* icmp,
const InternalFilterPolicy* ipolicy,
Expand Down
7 changes: 7 additions & 0 deletions db/db_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -647,4 +647,11 @@ extern Options SanitizeOptions(const std::string& db,
const Options& src);
extern DBOptions SanitizeOptions(const std::string& db, const DBOptions& src);

// Fix user-supplied options to be reasonable
template <class T, class V>
static void ClipToRange(T* ptr, V minvalue, V maxvalue) {
if (static_cast<V>(*ptr) > maxvalue) *ptr = maxvalue;
if (static_cast<V>(*ptr) < minvalue) *ptr = minvalue;
}

} // namespace rocksdb
28 changes: 6 additions & 22 deletions db/version_set.cc
Original file line number Diff line number Diff line change
Expand Up @@ -301,23 +301,6 @@ class FilePicker {
};
} // anonymous namespace

static uint64_t TotalFileSize(const std::vector<FileMetaData*>& files) {
uint64_t sum = 0;
for (size_t i = 0; i < files.size() && files[i]; i++) {
sum += files[i]->fd.GetFileSize();
}
return sum;
}

static uint64_t TotalCompensatedFileSize(
const std::vector<FileMetaData*>& files) {
uint64_t sum = 0;
for (size_t i = 0; i < files.size() && files[i]; i++) {
sum += files[i]->compensated_file_size;
}
return sum;
}

Version::~Version() {
assert(refs_ == 0);

Expand Down Expand Up @@ -666,14 +649,15 @@ void Version::AddIterators(const ReadOptions& read_options,
}

// Callback from TableCache::Get()
namespace {
enum SaverState {
kNotFound,
kFound,
kDeleted,
kCorrupt,
kMerge // saver contains the current merge result (the operands)
};

namespace version_set {
struct Saver {
SaverState state;
const Comparator* ucmp;
Expand All @@ -686,15 +670,15 @@ struct Saver {
Logger* logger;
Statistics* statistics;
};
}
} // namespace version_set

// Called from TableCache::Get and Table::Get when file/block in which
// key may exist are not there in TableCache/BlockCache respectively. In this
// case we can't guarantee that key does not exist and are not permitted to do
// IO to be certain.Set the status=kFound and value_found=false to let the
// caller know that key may exist but is not there in memory
static void MarkKeyMayExist(void* arg) {
Saver* s = reinterpret_cast<Saver*>(arg);
version_set::Saver* s = reinterpret_cast<version_set::Saver*>(arg);
s->state = kFound;
if (s->value_found != nullptr) {
*(s->value_found) = false;
Expand All @@ -703,7 +687,7 @@ static void MarkKeyMayExist(void* arg) {

static bool SaveValue(void* arg, const ParsedInternalKey& parsed_key,
const Slice& v) {
Saver* s = reinterpret_cast<Saver*>(arg);
version_set::Saver* s = reinterpret_cast<version_set::Saver*>(arg);
MergeContext* merge_contex = s->merge_context;
std::string merge_result; // temporary area for merge results later

Expand Down Expand Up @@ -817,7 +801,7 @@ void Version::Get(const ReadOptions& options,
Slice user_key = k.user_key();

assert(status->ok() || status->IsMergeInProgress());
Saver saver;
version_set::Saver saver;
saver.state = status->ok()? kNotFound : kMerge;
saver.ucmp = user_comparator_;
saver.user_key = user_key;
Expand Down
3 changes: 0 additions & 3 deletions table/block_based_table_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ namespace rocksdb {

extern const std::string kHashIndexPrefixesBlock;
extern const std::string kHashIndexPrefixesMetadataBlock;
namespace {

typedef BlockBasedTableOptions::IndexType IndexType;

Expand Down Expand Up @@ -335,8 +334,6 @@ Slice CompressBlock(const Slice& raw,
return raw;
}

} // anonymous namespace

// kBlockBasedTableMagicNumber was picked by running
// echo rocksdb.table.block_based | sha1sum
// and taking the leading 64 bits.
Expand Down
7 changes: 0 additions & 7 deletions table/block_prefix_index.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

namespace rocksdb {

namespace {

inline uint32_t Hash(const Slice& s) {
return rocksdb::Hash(s.data(), s.size(), 0);
}
Expand All @@ -26,8 +24,6 @@ inline uint32_t PrefixToBucket(const Slice& prefix, uint32_t num_buckets) {
return Hash(prefix) % num_buckets;
}



// The prefix block index is simply a bucket array, with each entry pointing to
// the blocks that span the prefixes hashed to this bucket.
//
Expand Down Expand Up @@ -64,7 +60,6 @@ inline uint32_t EncodeIndex(uint32_t index) {
return index | kBlockArrayMask;
}


// temporary storage for prefix information during index building
struct PrefixRecord {
Slice prefix;
Expand All @@ -74,8 +69,6 @@ struct PrefixRecord {
PrefixRecord* next;
};

} // anonymous namespace

class BlockPrefixIndex::Builder {
public:
explicit Builder(const SliceTransform* internal_prefix_extractor)
Expand Down
16 changes: 8 additions & 8 deletions table/merger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include "util/autovector.h"

namespace rocksdb {
namespace {
namespace merger {
typedef std::priority_queue<
IteratorWrapper*,
std::vector<IteratorWrapper*>,
Expand All @@ -43,7 +43,7 @@ MaxIterHeap NewMaxIterHeap(const Comparator* comparator) {
MinIterHeap NewMinIterHeap(const Comparator* comparator) {
return MinIterHeap(MinIteratorComparator(comparator));
}
} // namespace
} // namespace merger

const size_t kNumIterReserve = 4;

Expand All @@ -56,8 +56,8 @@ class MergingIterator : public Iterator {
current_(nullptr),
use_heap_(true),
direction_(kForward),
maxHeap_(NewMaxIterHeap(comparator_)),
minHeap_(NewMinIterHeap(comparator_)) {
maxHeap_(merger::NewMaxIterHeap(comparator_)),
minHeap_(merger::NewMinIterHeap(comparator_)) {
children_.resize(n);
for (int i = 0; i < n; i++) {
children_[i].Set(children[i]);
Expand Down Expand Up @@ -274,8 +274,8 @@ class MergingIterator : public Iterator {
kReverse
};
Direction direction_;
MaxIterHeap maxHeap_;
MinIterHeap minHeap_;
merger::MaxIterHeap maxHeap_;
merger::MinIterHeap minHeap_;
};

void MergingIterator::FindSmallest() {
Expand All @@ -302,8 +302,8 @@ void MergingIterator::FindLargest() {

void MergingIterator::ClearHeaps() {
use_heap_ = true;
maxHeap_ = NewMaxIterHeap(comparator_);
minHeap_ = NewMinIterHeap(comparator_);
maxHeap_ = merger::NewMaxIterHeap(comparator_);
minHeap_ = merger::NewMinIterHeap(comparator_);
}

Iterator* NewMergingIterator(const Comparator* cmp, Iterator** list, int n,
Expand Down
3 changes: 0 additions & 3 deletions util/bloom.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
namespace rocksdb {

namespace {
static uint32_t BloomHash(const Slice& key) {
return Hash(key.data(), key.size(), 0xbc9f1d34);
}

class BloomFilterPolicy : public FilterPolicy {
private:
Expand Down
3 changes: 0 additions & 3 deletions util/dynamic_bloom.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
namespace rocksdb {

namespace {
static uint32_t BloomHash(const Slice& key) {
return Hash(key.data(), key.size(), 0xbc9f1d34);
}

uint32_t GetTotalBitsForLocality(uint32_t total_bits) {
uint32_t num_blocks =
Expand Down
Loading

0 comments on commit 93e6b5e

Please sign in to comment.