Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tcwalther committed Mar 11, 2023
1 parent 208d82c commit 7eae85e
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 4 deletions.
14 changes: 10 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ let package = Package(
name: "librocksdb",
path: "Sources/librocksdb",
exclude: [
// this list was generated via `ls -1 upstream/**/*{bench,mock,test}*.cc` in `Sources/librocksdb/`.
// this list was generated via `ls -1 upstream/**/*{bench,test}*.cc` in `Sources/librocksdb/`.
"upstream/cache/cache_bench.cc",
"upstream/cache/cache_bench_tool.cc",
"upstream/cache/cache_reservation_manager_test.cc",
Expand Down Expand Up @@ -129,7 +129,6 @@ let package = Package(
"upstream/env/env_basic_test.cc",
"upstream/env/env_test.cc",
"upstream/env/io_posix_test.cc",
"upstream/env/mock_env.cc",
"upstream/env/mock_env_test.cc",
"upstream/env/mock_env_test.cc",
"upstream/file/delete_scheduler_test.cc",
Expand Down Expand Up @@ -169,11 +168,9 @@ let package = Package(
"upstream/table/cuckoo/cuckoo_table_builder_test.cc",
"upstream/table/cuckoo/cuckoo_table_reader_test.cc",
"upstream/table/merger_test.cc",
"upstream/table/mock_table.cc",
"upstream/table/sst_file_reader_test.cc",
"upstream/table/table_reader_bench.cc",
"upstream/table/table_test.cc",
"upstream/test_util/mock_time_env.cc",
"upstream/test_util/testharness.cc",
"upstream/test_util/testutil.cc",
"upstream/test_util/testutil_test.cc",
Expand Down Expand Up @@ -254,6 +251,9 @@ let package = Package(

// PowerPC assembly
"upstream/util/crc32c_ppc_asm.S",

// This relies on gtest, and it doesn't seem like we need it. We do need mock_env, though.
"upstream/table/mock_table.cc",
],
sources: [
"upstream/cache",
Expand All @@ -264,20 +264,26 @@ let package = Package(
"upstream/logging",
"upstream/memory",
"upstream/memtable",
"upstream/monitoring",
"upstream/options",
"upstream/port",
"upstream/table",
"upstream/test_util",
"upstream/trace_replay",
"upstream/util",
"upstream/utilities",

// workaround for the cmake-configured build_version.cc.in
"patches",
],
publicHeadersPath: "public_headers",
cxxSettings: [
.headerSearchPath("upstream"),
.headerSearchPath("upstream/include"),
.define("ROCKSDB_PLATFORM_POSIX"),
.define("ROCKSDB_LIB_IO_POSIX"),
.define("NPERF_CONTEXT"),
.define("NIOSTATS_CONTEXT"),
.define("PORTABLE"),
.define(osEnvRocks),
]),
Expand Down
71 changes: 71 additions & 0 deletions Sources/librocksdb/patches/build_version.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.

#include <memory>

#include "rocksdb/version.h"
#include "util/string_util.h"

// The build script may replace these values with real values based
// on whether or not GIT is available and the platform settings
static const std::string rocksdb_build_git_sha = "rocksdb_build_git_sha:da11a59034584ea2d0911268b8136e5249d6b692";
static const std::string rocksdb_build_git_tag = "rocksdb_build_git_tag:v6.29.5";
#define HAS_GIT_CHANGES 0
#if HAS_GIT_CHANGES == 0
// If HAS_GIT_CHANGES is 0, the GIT date is used.
// Use the time the branch/tag was last modified
static const std::string rocksdb_build_date = "rocksdb_build_date:2022-03-02 17:41:02";
#else
// If HAS_GIT_CHANGES is > 0, the branch/tag has modifications.
// Use the time the build was created.
static const std::string rocksdb_build_date = "rocksdb_build_date:@BUILD_DATE@";
#endif

namespace ROCKSDB_NAMESPACE {
static void AddProperty(std::unordered_map<std::string, std::string> *props, const std::string& name) {
size_t colon = name.find(":");
if (colon != std::string::npos && colon > 0 && colon < name.length() - 1) {
// If we found a "@:", then this property was a build-time substitution that failed. Skip it
size_t at = name.find("@", colon);
if (at != colon + 1) {
// Everything before the colon is the name, after is the value
(*props)[name.substr(0, colon)] = name.substr(colon + 1);
}
}
}

static std::unordered_map<std::string, std::string>* LoadPropertiesSet() {
auto * properties = new std::unordered_map<std::string, std::string>();
AddProperty(properties, rocksdb_build_git_sha);
AddProperty(properties, rocksdb_build_git_tag);
AddProperty(properties, rocksdb_build_date);
return properties;
}

const std::unordered_map<std::string, std::string>& GetRocksBuildProperties() {
static std::unique_ptr<std::unordered_map<std::string, std::string>> props(LoadPropertiesSet());
return *props;
}

std::string GetRocksVersionAsString(bool with_patch) {
std::string version = ToString(ROCKSDB_MAJOR) + "." + ToString(ROCKSDB_MINOR);
if (with_patch) {
return version + "." + ToString(ROCKSDB_PATCH);
} else {
return version;
}
}

std::string GetRocksBuildInfoAsString(const std::string& program, bool verbose) {
std::string info = program + " (RocksDB) " + GetRocksVersionAsString(true);
if (verbose) {
for (const auto& it : GetRocksBuildProperties()) {
info.append("\n ");
info.append(it.first);
info.append(": ");
info.append(it.second);
}
}
return info;
}
} // namespace ROCKSDB_NAMESPACE

0 comments on commit 7eae85e

Please sign in to comment.