Build for CYGWIN

Summary:
Make it build for CYGWIN.
Need to define "-std=gnu++11" instead of "-std=c++11" and use some replacement functions.

Test Plan: Build it and run some unit tests in CYGWIN

Reviewers: yhchiang, rven, anthony, kradhakrishnan, igor

Reviewed By: igor

Subscribers: leveldb, dhruba

Differential Revision: https://reviews.facebook.net/D37605
main
sdong 10 years ago
parent d01bbb53ae
commit 98a44559d5
  1. 12
      build_tools/build_detect_platform
  2. 4
      db/column_family_test.cc
  3. 1
      include/rocksdb/slice.h
  4. 3
      port/stack_trace.cc
  5. 7
      table/block_based_filter_block.cc
  6. 2
      table/block_based_table_reader.cc
  7. 13
      table/format.cc
  8. 2
      util/autovector_test.cc
  9. 6
      util/env_posix.cc
  10. 16
      util/ldb_cmd.cc
  11. 18
      util/options_helper.cc
  12. 4
      util/string_util.h
  13. 13
      utilities/backupable/backupable_db.cc
  14. 4
      utilities/geodb/geodb_impl.cc

@ -90,7 +90,6 @@ fi
COMMON_FLAGS="$COMMON_FLAGS ${CFLAGS}"
CROSS_COMPILE=
PLATFORM_CCFLAGS=
PLATFORM_CXXFLAGS="$PLATFORM_CXXFLAGS ${CXXFLAGS}"
PLATFORM_LDFLAGS="$PLATFORM_LDFLAGS"
PLATFORM_SHARED_EXT="so"
PLATFORM_SHARED_LDFLAGS="-shared -Wl,-soname -Wl,"
@ -156,6 +155,16 @@ case "$TARGET_OS" in
PLATFORM_LDFLAGS="$PLATFORM_LDFLAGS -lpthread"
# PORT_FILES=port/dragonfly/dragonfly_specific.cc
;;
Cygwin)
PLATFORM=CYGWIN
PLATFORM_CXXFLAGS="-std=gnu++11"
COMMON_FLAGS="$COMMON_FLAGS -DCYGWIN"
if [ -z "$USE_CLANG" ]; then
COMMON_FLAGS="$COMMON_FLAGS -fno-builtin-memcmp"
fi
PLATFORM_LDFLAGS="$PLATFORM_LDFLAGS -lpthread -lrt"
# PORT_FILES=port/linux/linux_specific.cc
;;
OS_ANDROID_CROSSCOMPILE)
PLATFORM=OS_ANDROID
COMMON_FLAGS="$COMMON_FLAGS -fno-builtin-memcmp -D_REENTRANT -DOS_ANDROID -DLEVELDB_PLATFORM_POSIX"
@ -168,6 +177,7 @@ case "$TARGET_OS" in
exit 1
esac
PLATFORM_CXXFLAGS="$PLATFORM_CXXFLAGS ${CXXFLAGS}"
JAVA_LDFLAGS="$PLATFORM_LDFLAGS"
if [ "$CROSS_COMPILE" = "true" -o "$FBCODE_BUILD" = "true" ]; then

@ -118,7 +118,11 @@ class ColumnFamilyTest : public testing::Test {
int GetProperty(int cf, std::string property) {
std::string value;
EXPECT_TRUE(dbfull()->GetProperty(handles_[cf], property, &value));
#ifndef CYGWIN
return std::stoi(value);
#else
return std::strtol(value.c_str(), 0);
#endif
}
void Destroy() {

@ -20,6 +20,7 @@
#define STORAGE_ROCKSDB_INCLUDE_SLICE_H_
#include <assert.h>
#include <cstdio>
#include <stddef.h>
#include <string.h>
#include <string>

@ -5,7 +5,8 @@
//
#include "port/stack_trace.h"
#if defined(ROCKSDB_LITE) || !(defined(OS_LINUX) || defined(OS_MACOSX))
#if defined(ROCKSDB_LITE) || !(defined(OS_LINUX) || defined(OS_MACOSX)) || \
defined(CYGWIN)
// noop

@ -13,6 +13,7 @@
#include "db/dbformat.h"
#include "rocksdb/filter_policy.h"
#include "util/coding.h"
#include "util/string_util.h"
namespace rocksdb {
@ -59,7 +60,7 @@ void AppendItem(std::string* props, const std::string& key,
template <class TKey>
void AppendItem(std::string* props, const TKey& key, const std::string& value) {
std::string key_str = std::to_string(key);
std::string key_str = rocksdb::ToString(key);
AppendItem(props, key_str, value);
}
} // namespace
@ -236,7 +237,7 @@ std::string BlockBasedFilterBlockReader::ToString() const {
result.reserve(1024);
std::string s_bo("Block offset"), s_hd("Hex dump"), s_fb("# filter blocks");
AppendItem(&result, s_fb, std::to_string(num_));
AppendItem(&result, s_fb, rocksdb::ToString(num_));
AppendItem(&result, s_bo, s_hd);
for (size_t index = 0; index < num_; index++) {
@ -244,7 +245,7 @@ std::string BlockBasedFilterBlockReader::ToString() const {
uint32_t limit = DecodeFixed32(offset_ + index * 4 + 4);
if (start != limit) {
result.append(" filter block # " + std::to_string(index + 1) + "\n");
result.append(" filter block # " + rocksdb::ToString(index + 1) + "\n");
Slice filter = Slice(data_ + start, limit - start);
AppendItem(&result, start, filter.ToString(true));
}

@ -1586,7 +1586,7 @@ Status BlockBasedTable::DumpDataBlocks(WritableFile* out_file) {
}
out_file->Append("Data Block # ");
out_file->Append(std::to_string(block_id));
out_file->Append(rocksdb::ToString(block_id));
out_file->Append(" @ ");
out_file->Append(blockhandles_iter->value().ToString(true).c_str());
out_file->Append("\n");

@ -18,6 +18,7 @@
#include "util/compression.h"
#include "util/crc32c.h"
#include "util/perf_context_imp.h"
#include "util/string_util.h"
#include "util/xxhash.h"
namespace rocksdb {
@ -196,15 +197,15 @@ std::string Footer::ToString() const {
if (legacy) {
result.append("metaindex handle: " + metaindex_handle_.ToString() + "\n ");
result.append("index handle: " + index_handle_.ToString() + "\n ");
result.append("table_magic_number: " + std::to_string(table_magic_number_) +
"\n ");
result.append("table_magic_number: " +
rocksdb::ToString(table_magic_number_) + "\n ");
} else {
result.append("checksum: " + std::to_string(checksum_) + "\n ");
result.append("checksum: " + rocksdb::ToString(checksum_) + "\n ");
result.append("metaindex handle: " + metaindex_handle_.ToString() + "\n ");
result.append("index handle: " + index_handle_.ToString() + "\n ");
result.append("footer version: " + std::to_string(version_) + "\n ");
result.append("table_magic_number: " + std::to_string(table_magic_number_) +
"\n ");
result.append("footer version: " + rocksdb::ToString(version_) + "\n ");
result.append("table_magic_number: " +
rocksdb::ToString(table_magic_number_) + "\n ");
}
return result;
}

@ -192,7 +192,7 @@ vector<string> GetTestKeys(size_t size) {
int index = 0;
for (auto& key : keys) {
key = "item-" + to_string(index++);
key = "item-" + rocksdb::ToString(index++);
}
return keys;
}

@ -66,7 +66,7 @@
// For non linux platform, the following macros are used only as place
// holder.
#ifndef OS_LINUX
#if !(defined OS_LINUX) && !(defined CYGWIN)
#define POSIX_FADV_NORMAL 0 /* [MC1] no further special treatment */
#define POSIX_FADV_RANDOM 1 /* [MC1] expect random page refs */
#define POSIX_FADV_SEQUENTIAL 2 /* [MC1] expect sequential page refs */
@ -186,7 +186,11 @@ class PosixSequentialFile: public SequentialFile {
Status s;
size_t r = 0;
do {
#ifndef CYGWIN
r = fread_unlocked(scratch, 1, n, file_);
#else
r = fread(scratch, 1, n, file_);
#endif
} while (r == 0 && ferror(file_) && errno == EINTR);
IOSTATS_ADD(bytes_read, r);
*result = Slice(scratch, r);

@ -17,9 +17,11 @@
#include "rocksdb/table_properties.h"
#include "util/coding.h"
#include "util/sst_dump_tool_imp.h"
#include "util/string_util.h"
#include "util/scoped_arena_iterator.h"
#include "utilities/ttl/db_ttl_impl.h"
#include <cstdlib>
#include <ctime>
#include <dirent.h>
#include <limits>
@ -192,7 +194,11 @@ bool LDBCommand::ParseIntOption(const map<string, string>& options,
map<string, string>::const_iterator itr = option_map_.find(option);
if (itr != option_map_.end()) {
try {
#if defined(CYGWIN)
value = strtol(itr->second.c_str(), 0, 10);
#else
value = stoi(itr->second);
#endif
return true;
} catch(const invalid_argument&) {
exec_state =
@ -897,7 +903,11 @@ DBDumperCommand::DBDumperCommand(const vector<string>& params,
itr = options.find(ARG_MAX_KEYS);
if (itr != options.end()) {
try {
#if defined(CYGWIN)
max_keys_ = strtol(itr->second.c_str(), 0, 10);
#else
max_keys_ = stoi(itr->second);
#endif
} catch(const invalid_argument&) {
exec_state_ = LDBCommandExecuteResult::Failed(ARG_MAX_KEYS +
" has an invalid value");
@ -1104,7 +1114,7 @@ vector<string> ReduceDBLevelsCommand::PrepareArgs(const string& db_path,
vector<string> ret;
ret.push_back("reduce_levels");
ret.push_back("--" + ARG_DB + "=" + db_path);
ret.push_back("--" + ARG_NEW_LEVELS + "=" + to_string(new_levels));
ret.push_back("--" + ARG_NEW_LEVELS + "=" + rocksdb::ToString(new_levels));
if(print_old_level) {
ret.push_back("--" + ARG_PRINT_OLD_LEVELS);
}
@ -1656,7 +1666,11 @@ ScanCommand::ScanCommand(const vector<string>& params,
itr = options.find(ARG_MAX_KEYS);
if (itr != options.end()) {
try {
#if defined(CYGWIN)
max_keys_scanned_ = strtol(itr->second.c_str(), 0, 10);
#else
max_keys_scanned_ = stoi(itr->second);
#endif
} catch(const invalid_argument&) {
exec_state_ = LDBCommandExecuteResult::Failed(ARG_MAX_KEYS +
" has an invalid value");

@ -5,6 +5,7 @@
#include <cassert>
#include <cctype>
#include <cstdlib>
#include <unordered_set>
#include "rocksdb/cache.h"
#include "rocksdb/filter_policy.h"
@ -14,6 +15,7 @@
#include "rocksdb/table.h"
#include "rocksdb/utilities/convenience.h"
#include "table/block_based_table_factory.h"
#include "util/logging.h"
#include "util/options_helper.h"
namespace rocksdb {
@ -73,7 +75,13 @@ bool ParseBoolean(const std::string& type, const std::string& value) {
uint64_t ParseUint64(const std::string& value) {
size_t endchar;
#ifndef CYGWIN
uint64_t num = std::stoull(value.c_str(), &endchar);
#else
char* endptr;
uint64_t num = std::strtoul(value.c_str(), &endptr, 0);
endchar = endptr - value.c_str();
#endif
if (endchar < value.length()) {
char c = value[endchar];
@ -105,7 +113,13 @@ uint32_t ParseUint32(const std::string& value) {
int ParseInt(const std::string& value) {
size_t endchar;
#ifndef CYGWIN
int num = std::stoi(value.c_str(), &endchar);
#else
char* endptr;
int num = std::strtoul(value.c_str(), &endptr, 0);
endchar = endptr - value.c_str();
#endif
if (endchar < value.length()) {
char c = value[endchar];
@ -121,7 +135,11 @@ int ParseInt(const std::string& value) {
}
double ParseDouble(const std::string& value) {
#ifndef CYGWIN
return std::stod(value);
#else
return std::strtod(value.c_str(), 0);
#endif
}
CompactionStyle ParseCompactionStyle(const std::string& type) {

@ -14,10 +14,10 @@ extern std::vector<std::string> StringSplit(const std::string& arg, char delim);
template <typename T>
inline std::string ToString(T value) {
#ifndef OS_ANDROID
#if !(defined OS_ANDROID) && !(defined CYGWIN)
return std::to_string(value);
#else
// Andorid doesn't support all of C++11, std::to_string() being
// Andorid or cygwin doesn't support all of C++11, std::to_string() being
// one of the not supported features.
std::ostringstream os;
os << value;

@ -14,6 +14,7 @@
#include "util/coding.h"
#include "util/crc32c.h"
#include "util/logging.h"
#include "util/string_util.h"
#include "rocksdb/transaction_log.h"
#ifndef __STDC_FORMAT_MACROS
@ -251,7 +252,7 @@ class BackupEngineImpl : public BackupEngine {
bool tmp = false,
const std::string& file = "") const {
assert(file.size() == 0 || file[0] != '/');
return GetPrivateDirRel() + "/" + std::to_string(backup_id) +
return GetPrivateDirRel() + "/" + rocksdb::ToString(backup_id) +
(tmp ? ".tmp" : "") + "/" + file;
}
inline std::string GetSharedFileRel(const std::string& file = "",
@ -270,8 +271,8 @@ class BackupEngineImpl : public BackupEngine {
assert(file.size() == 0 || file[0] != '/');
std::string file_copy = file;
return file_copy.insert(file_copy.find_last_of('.'),
"_" + std::to_string(checksum_value)
+ "_" + std::to_string(file_size));
"_" + rocksdb::ToString(checksum_value) + "_" +
rocksdb::ToString(file_size));
}
inline std::string GetFileFromChecksumFile(const std::string& file) const {
assert(file.size() == 0 || file[0] != '/');
@ -287,7 +288,7 @@ class BackupEngineImpl : public BackupEngine {
return GetAbsolutePath("meta");
}
inline std::string GetBackupMetaFile(BackupID backup_id) const {
return GetBackupMetaDir() + "/" + std::to_string(backup_id);
return GetBackupMetaDir() + "/" + rocksdb::ToString(backup_id);
}
Status GetLatestBackupFileContents(uint32_t* latest_backup);
@ -402,7 +403,7 @@ BackupEngineImpl::BackupEngineImpl(Env* db_env,
Log(options_.info_log, "Detected backup %s", file.c_str());
BackupID backup_id = 0;
sscanf(file.c_str(), "%u", &backup_id);
if (backup_id == 0 || file != std::to_string(backup_id)) {
if (backup_id == 0 || file != rocksdb::ToString(backup_id)) {
if (!read_only_) {
Log(options_.info_log, "Unrecognized meta file %s, deleting",
file.c_str());
@ -1264,7 +1265,7 @@ Status BackupEngineImpl::BackupMeta::LoadFromFile(
line.remove_prefix(checksum_prefix.size());
checksum_value = static_cast<uint32_t>(
strtoul(line.data(), nullptr, 10));
if (line != std::to_string(checksum_value)) {
if (line != rocksdb::ToString(checksum_value)) {
return Status::Corruption("Invalid checksum value for " + filename +
" in " + meta_filename_);
}

@ -206,8 +206,8 @@ Status GeoDBImpl::SearchRadial(const GeoPosition& pos,
std::string GeoDBImpl::MakeKey1(const GeoPosition& pos, Slice id,
std::string quadkey) {
std::string lat = std::to_string(pos.latitude);
std::string lon = std::to_string(pos.longitude);
std::string lat = rocksdb::ToString(pos.latitude);
std::string lon = rocksdb::ToString(pos.longitude);
std::string key = "p:";
key.reserve(5 + quadkey.size() + id.size() + lat.size() + lon.size());
key.append(quadkey);

Loading…
Cancel
Save