From 98a44559d590a8cb63551393e275b57ed7e54504 Mon Sep 17 00:00:00 2001 From: sdong Date: Thu, 23 Apr 2015 19:17:57 -0700 Subject: [PATCH] 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 --- build_tools/build_detect_platform | 12 +++++++++++- db/column_family_test.cc | 4 ++++ include/rocksdb/slice.h | 1 + port/stack_trace.cc | 3 ++- table/block_based_filter_block.cc | 7 ++++--- table/block_based_table_reader.cc | 2 +- table/format.cc | 13 +++++++------ util/autovector_test.cc | 2 +- util/env_posix.cc | 6 +++++- util/ldb_cmd.cc | 16 +++++++++++++++- util/options_helper.cc | 18 ++++++++++++++++++ util/string_util.h | 4 ++-- utilities/backupable/backupable_db.cc | 13 +++++++------ utilities/geodb/geodb_impl.cc | 4 ++-- 14 files changed, 80 insertions(+), 25 deletions(-) diff --git a/build_tools/build_detect_platform b/build_tools/build_detect_platform index 0174d2244..98da12b06 100755 --- a/build_tools/build_detect_platform +++ b/build_tools/build_detect_platform @@ -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 diff --git a/db/column_family_test.cc b/db/column_family_test.cc index c48180367..a87294b8f 100644 --- a/db/column_family_test.cc +++ b/db/column_family_test.cc @@ -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() { diff --git a/include/rocksdb/slice.h b/include/rocksdb/slice.h index a67688c5d..7019c904c 100644 --- a/include/rocksdb/slice.h +++ b/include/rocksdb/slice.h @@ -20,6 +20,7 @@ #define STORAGE_ROCKSDB_INCLUDE_SLICE_H_ #include +#include #include #include #include diff --git a/port/stack_trace.cc b/port/stack_trace.cc index c7ddd3a1a..e2211e987 100644 --- a/port/stack_trace.cc +++ b/port/stack_trace.cc @@ -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 diff --git a/table/block_based_filter_block.cc b/table/block_based_filter_block.cc index 8cf3a855c..cd5602800 100644 --- a/table/block_based_filter_block.cc +++ b/table/block_based_filter_block.cc @@ -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 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)); } diff --git a/table/block_based_table_reader.cc b/table/block_based_table_reader.cc index bad3532e7..96e26b1c5 100644 --- a/table/block_based_table_reader.cc +++ b/table/block_based_table_reader.cc @@ -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"); diff --git a/table/format.cc b/table/format.cc index 6b3d4eead..ccc345f8e 100644 --- a/table/format.cc +++ b/table/format.cc @@ -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; } diff --git a/util/autovector_test.cc b/util/autovector_test.cc index 1c23c4335..c597e36f5 100644 --- a/util/autovector_test.cc +++ b/util/autovector_test.cc @@ -192,7 +192,7 @@ vector GetTestKeys(size_t size) { int index = 0; for (auto& key : keys) { - key = "item-" + to_string(index++); + key = "item-" + rocksdb::ToString(index++); } return keys; } diff --git a/util/env_posix.cc b/util/env_posix.cc index 329c48e95..891e4fbdf 100644 --- a/util/env_posix.cc +++ b/util/env_posix.cc @@ -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); diff --git a/util/ldb_cmd.cc b/util/ldb_cmd.cc index 0ea2fd4e0..e7b29d24f 100644 --- a/util/ldb_cmd.cc +++ b/util/ldb_cmd.cc @@ -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 #include #include #include @@ -192,7 +194,11 @@ bool LDBCommand::ParseIntOption(const map& options, map::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& 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 ReduceDBLevelsCommand::PrepareArgs(const string& db_path, vector 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& 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"); diff --git a/util/options_helper.cc b/util/options_helper.cc index 18e1f38b2..8f982c196 100644 --- a/util/options_helper.cc +++ b/util/options_helper.cc @@ -5,6 +5,7 @@ #include #include +#include #include #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) { diff --git a/util/string_util.h b/util/string_util.h index 2238a569b..dfbe50580 100644 --- a/util/string_util.h +++ b/util/string_util.h @@ -14,10 +14,10 @@ extern std::vector StringSplit(const std::string& arg, char delim); template 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; diff --git a/utilities/backupable/backupable_db.cc b/utilities/backupable/backupable_db.cc index d1d3b289c..1f86aeda0 100644 --- a/utilities/backupable/backupable_db.cc +++ b/utilities/backupable/backupable_db.cc @@ -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( 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_); } diff --git a/utilities/geodb/geodb_impl.cc b/utilities/geodb/geodb_impl.cc index 2cb9209e1..6f285fbbe 100644 --- a/utilities/geodb/geodb_impl.cc +++ b/utilities/geodb/geodb_impl.cc @@ -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);