Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tools build #6475

Merged
merged 12 commits into from
Sep 8, 2023
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

### Internals
* Add a CI job to validate that the headers in the installation package all build ([PR #6954](https://github.com/realm/realm-core/pull/6954)).
* Fix build of most internal tools, also build them by default. ([PR #6475](https://github.com/realm/realm-core/pull/6475))

----------------------------------------------

Expand Down
5 changes: 4 additions & 1 deletion src/external/IntelRDFPMathLib20U2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ LIBRARY/src/bid_round.c

add_library(Bid OBJECT ${BID_SOURCES})
if(MSVC)
target_compile_options(Bid PUBLIC /W1 /sdl-)
get_target_property(comp_opts Bid COMPILE_OPTIONS)
string(REGEX REPLACE "/W[1234]" "/W1" comp_opts "${comp_opts}")
set_target_properties(Bid PROPERTIES COMPILE_OPTIONS "${comp_opts}")
target_compile_options(Bid PUBLIC /sdl-)
endif()

# Note: checking for -Wfoo since unknown -Wno-foo flags are ignored.
Expand Down
4 changes: 4 additions & 0 deletions src/external/s2/util/math/mathutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,13 @@ template<typename T> struct MathLimits {
#endif //UTIL_MATH_MATHLIMITS_H
// ========================================================================= //

#if defined(__clang__)
// Disable error about fabs causing truncation of value because
// it takes a double instead of a long double (Clang 3.5)
// See SERVER-15183
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wabsolute-value"
#endif

class MathUtil {
public:
Expand Down Expand Up @@ -695,6 +697,8 @@ bool MathUtil::WithinFractionOrMargin(const T x, const T y,
}
}

#if defined(__clang__)
#pragma clang diagnostic pop
#endif

#endif // UTIL_MATH_MATHUTIL_H__
35 changes: 22 additions & 13 deletions src/realm/exec/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,49 +1,58 @@
add_executable(RealmImporter importer_tool.cpp importer.cpp importer.hpp)
set_target_properties(RealmImporter PROPERTIES
OUTPUT_NAME "realm-importer"
DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX}
)
target_link_libraries(RealmImporter Storage)

if(NOT APPLE AND NOT ANDROID AND NOT CMAKE_SYSTEM_NAME MATCHES "^Windows")
# FIXME add_executable(RealmImporter importer_tool.cpp importer.cpp importer.hpp)
# set_target_properties(RealmImporter PROPERTIES
# OUTPUT_NAME "realm-importer"
# DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX})
# target_link_libraries(RealmImporter realm)

add_executable(RealmDaemon realmd.cpp)
set_target_properties(RealmDaemon PROPERTIES
OUTPUT_NAME "realmd"
DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX})
target_link_libraries(RealmDaemon Storage)
list(APPEND ExecTargetsToInstall RealmDaemon)

endif()

add_executable(RealmTrawler EXCLUDE_FROM_ALL realm_trawler.cpp )
add_executable(RealmTrawler realm_trawler.cpp)
set_target_properties(RealmTrawler PROPERTIES
OUTPUT_NAME "realm-trawler"
DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX}
)
target_link_libraries(RealmTrawler Storage)
if (EMSCRIPTEN)
set_target_properties(RealmTrawler PROPERTIES EXCLUDE_FROM_ALL TRUE)
endif()

add_executable(RealmEnumerate EXCLUDE_FROM_ALL realm_enumerate.cpp )
add_executable(RealmEnumerate realm_enumerate.cpp)
set_target_properties(RealmEnumerate PROPERTIES
OUTPUT_NAME "realm-enumerate"
DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX}
)
target_link_libraries(RealmEnumerate ObjectStore)
# FIXME can be fixed for others, but requires link and install fixes for libuv target
if (NOT APPLE)
set_target_properties(RealmEnumerate PROPERTIES EXCLUDE_FROM_ALL TRUE)
endif()

add_executable(RealmDecrypt EXCLUDE_FROM_ALL realm_decrypt.cpp )
add_executable(RealmDecrypt realm_decrypt.cpp)
set_target_properties(RealmDecrypt PROPERTIES
OUTPUT_NAME "realm-decrypt"
DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX}
)
target_link_libraries(RealmDecrypt Storage)
if (NOT REALM_ENABLE_ENCRYPTION)
set_target_properties(RealmDecrypt PROPERTIES EXCLUDE_FROM_ALL TRUE)
endif()

add_executable(RealmEncrypt EXCLUDE_FROM_ALL realm_encrypt.cpp )
add_executable(RealmEncrypt realm_encrypt.cpp)
set_target_properties(RealmEncrypt PROPERTIES
OUTPUT_NAME "realm-encrypt"
DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX}
)
target_link_libraries(RealmEncrypt Storage)

add_executable(RealmBrowser EXCLUDE_FROM_ALL realm_browser.cpp )
add_executable(RealmBrowser realm_browser.cpp)
set_target_properties(RealmBrowser PROPERTIES
OUTPUT_NAME "realm-browser-10"
DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX}
Expand All @@ -60,7 +69,7 @@ target_link_libraries(Realm2JSON Storage QueryParser Sync)
list(APPEND ExecTargetsToInstall Realm2JSON)
endif()

add_executable(RealmDump EXCLUDE_FROM_ALL realm_dump.c)
add_executable(RealmDump realm_dump.c)
set_target_properties(RealmDump PROPERTIES
OUTPUT_NAME "realm-dump"
DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX}
Expand Down
100 changes: 59 additions & 41 deletions src/realm/exec/importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ const char* DataTypeToText(DataType t)
void print_col_names(Table& table)
{
std::cout << "\n";
for (size_t t = 0; t < table.get_column_count(); t++) {
for (auto t : table.get_column_keys()) {
std::string s = std::string(table.get_column_name(t).data());
s = set_width(s, print_width);
std::cout << s.c_str() << " ";
}
std::cout << "\n";
for (size_t t = 0; t < table.get_column_count(); t++) {
for (auto t : table.get_column_keys()) {
std::string s = "Type: " + std::string(DataTypeToText(table.get_column_type(t)));
s = set_width(s, print_width);
std::cout << s.c_str() << " ";
Expand All @@ -83,23 +83,33 @@ void print_col_names(Table& table)
// Prints row 'r' of a Realm table
void print_row(Table& table, size_t r)
{
for (size_t c = 0; c < table.get_column_count(); c++) {
auto&& obj = table.get_object(r);
for (auto k : table.get_column_keys()) {
char buf[print_width];

if (table.get_column_type(c) == type_Bool)
sprintf(buf, "%s", table.get_bool(c, r) ? "true" : "false");
if (table.get_column_type(c) == type_Double)
sprintf(buf, "%f", table.get_double(c, r));
if (table.get_column_type(c) == type_Float)
sprintf(buf, "%f", table.get_float(c, r));
if (table.get_column_type(c) == type_Int)
sprintf(buf, "%lld", static_cast<long long>(table.get_int(c, r)));
if (table.get_column_type(c) == type_String) {
auto type = table.get_column_type(k);

switch (type) {
case type_Bool:
snprintf(buf, print_width, "%s", obj.get<bool>(k) ? "true" : "false");
break;
case type_Double:
snprintf(buf, print_width, "%f", obj.get<double>(k));
break;
case type_Float:
snprintf(buf, print_width, "%f", obj.get<float>(k));
break;
case type_Int:
snprintf(buf, print_width, "%lld", static_cast<long long>(obj.get<int64_t>(k)));
break;
case type_String:
#if defined(_MSC_VER) && _MSC_VER
_snprintf(buf, sizeof(buf), "%s", table.get_string(c, r).data());
_snprintf(buf, sizeof(buf), "%s", obj.get<StringData>(k).data());
#else
snprintf(buf, sizeof(buf), "%s", table.get_string(c, r).data());
snprintf(buf, sizeof(buf), "%s", obj.get<StringData>(k).data());
#endif
break;
default:
break;
}
std::string s = std::string(buf);
s = set_width(s, print_width);
Expand Down Expand Up @@ -528,10 +538,10 @@ size_t Importer::tokenize(std::vector<std::vector<std::string>>& payload, size_t
std::string s = payload[payload.size() - 1][0];
if (s.length() > 100)
s = s.substr(0, 100);
sprintf(buf,
"Wrong number of delimitors around line %lld (+|- 3) in csv file. First few characters "
"of line: %s",
static_cast<unsigned long long>(m_row - 1), s.c_str());
snprintf(buf, 500,
"Wrong number of delimitors around line %lld (+|- 3) in csv file. First few characters "
"of line: %s",
static_cast<unsigned long long>(m_row - 1), s.c_str());
throw std::runtime_error(buf);
}
}
Expand Down Expand Up @@ -615,7 +625,7 @@ size_t Importer::import_csv(FILE* file, Table& table, std::vector<DataType>* imp
// occurences by a string
if (header[t] == "") {
char buf[10];
sprintf(buf, "Column%d", static_cast<int>(t));
snprintf(buf, 10, "Column%d", static_cast<int>(t));
header[t] = buf;
}
}
Expand All @@ -624,7 +634,7 @@ size_t Importer::import_csv(FILE* file, Table& table, std::vector<DataType>* imp
// Use "1", "2", "3", ... for column names
for (size_t i = 0; i < scheme1.size(); i++) {
char buf[10];
sprintf(buf, "%d", static_cast<int>(i));
snprintf(buf, 10, "%d", static_cast<int>(i));
header.push_back(buf);
}
}
Expand Down Expand Up @@ -663,33 +673,40 @@ size_t Importer::import_csv(FILE* file, Table& table, std::vector<DataType>* imp
if (!Quiet && imported_rows % 123 == 0)
std::cout << imported_rows << " rows\r";

// Add empty row to Realm
REALM_ASSERT(false); // unimplemented
// table.add_empty_row();

// Add all fields to new row
for (size_t col = 0; col < scheme.size(); col++) {
FieldValues values;
auto keys = table.get_column_keys();
size_t col = 0;
for (auto key = keys.begin(); key != keys.end(); ++key, ++col) {
bool success = true;

if (scheme[col] == type_String)
table.set_string(col, imported_rows, StringData(payload[row][col]));
else if (scheme[col] == type_Int)
table.set_int(col, imported_rows, parse_integer<true>(payload[row][col].c_str(), &success));
else if (scheme[col] == type_Double)
table.set_double(col, imported_rows, parse_double<true>(payload[row][col].c_str(), &success));
else if (scheme[col] == type_Float)
table.set_float(col, imported_rows, parse_float<true>(payload[row][col].c_str(), &success));
else if (scheme[col] == type_Bool)
table.set_bool(col, imported_rows, parse_bool<true>(payload[row][col].c_str(), &success));
else
REALM_ASSERT(false);
switch (scheme[col]) {
case type_String:
values.insert(*key, StringData(payload[row][col]));
break;
case type_Int:
values.insert(*key, parse_integer<true>(payload[row][col].c_str(), &success));
break;
case type_Double:
values.insert(*key, parse_double<true>(payload[row][col].c_str(), &success));
break;
case type_Float:
values.insert(*key, parse_float<true>(payload[row][col].c_str(), &success));
break;
case type_Bool:
values.insert(*key, parse_bool<true>(payload[row][col].c_str(), &success));
break;
default:
REALM_ASSERT(false);
break;
}

if (!success) {
// Remove all columns so that user can call csv_import() on it again
table.clear();

for (size_t t = 0; t < table.get_column_count(); t++)
table.remove_column(0);
auto keys = table.get_column_keys();
for (size_t i = keys.size(); i != 0;)
table.remove_column(keys[--i]);

std::stringstream sstm;

Expand Down Expand Up @@ -718,6 +735,7 @@ size_t Importer::import_csv(FILE* file, Table& table, std::vector<DataType>* imp
}
}

(void)table.create_object(ObjKey(import_rows), values);

if (!Quiet) {
if (imported_rows < 10)
Expand Down
13 changes: 10 additions & 3 deletions src/realm/exec/importer_tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,14 @@ const char* legend =
" -q: Quiet, only print upon errors\n"
" -f: Overwrite destination file if existing (default is to abort)\n"
" -l: Name of the resulting table (default is 'table')\n"
" -p: Separator to use (default: ',')"
"\n"
"Examples:\n"
" csv file.csv file.realm\n"
" csv -a=200000 -e file.csv file.realm\n"
" csv -t=ssdbi Name Email Height Gender Age file.csv -s=1 file.realm\n"
" csv -stdin file.realm < cat file.csv";
" csv -stdin file.realm < cat file.csv\n"
" csv -p=$'\\t' file.tsv file.realm";

namespace {

Expand Down Expand Up @@ -158,6 +160,11 @@ int main(int argc, char* argv[])
abort2(a >= argc - 4, "Too few arguments");
tablename = argv[++a];
}
else if (strncmp(argv[a], "-p", 2) == 0) {
std::cout << "separator: [" << argv[a][3] << "]" << std::endl;
abort2(strlen(argv[a]) != 4, "Set exactly one character for delimeter!");
separator_flag = argv[a][3];
}
else {
abort2(true, legend);
}
Expand Down Expand Up @@ -186,7 +193,7 @@ int main(int argc, char* argv[])

Importer importer;
importer.Quiet = quiet_flag;
importer.Separator = ',';
importer.Separator = separator_flag;
importer.Empty_as_string = empty_as_string_flag;

try {
Expand All @@ -206,7 +213,7 @@ int main(int argc, char* argv[])
}
}
catch (const std::runtime_error& error) {
std::cerr << error.what();
std::cerr << error.what() << std::endl;
exit(-1);
}

Expand Down
15 changes: 9 additions & 6 deletions src/realm/exec/realm_browser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@

using namespace realm;

bool get_table_ndx(size_t& ndx)
#define LL long long
#define ULL unsigned long long

static bool get_table_ndx(size_t& ndx)
{
std::cout << "Table ndx? ";
std::string inp;
Expand All @@ -16,7 +19,7 @@ bool get_table_ndx(size_t& ndx)
return *endp == '\0';
}

bool get_range(size_t size, size_t& begin, size_t& end)
static bool get_range(size_t size, size_t& begin, size_t& end)
{
std::cout << "Size " << size << ". Range? ";
std::string inp;
Expand Down Expand Up @@ -46,7 +49,7 @@ bool get_range(size_t size, size_t& begin, size_t& end)
return false;
}

void print_objects(ConstTableRef table, size_t begin, size_t end)
static void print_objects(ConstTableRef table, size_t begin, size_t end)
{
printf(" Object key");
auto col_keys = table->get_column_keys();
Expand All @@ -57,7 +60,7 @@ void print_objects(ConstTableRef table, size_t begin, size_t end)
for (size_t row = begin; row < end; row++) {
printf("%5zu ", row);
Obj obj = table->get_object(row);
printf(" %20zx", obj.get_key().value);
printf(" %20llx", (ULL)obj.get_key().value);
for (auto col : col_keys) {
auto col_type = table->get_column_type(col);
if (table->get_column_attr(col).test(col_attr_Nullable) && obj.is_null(col)) {
Expand All @@ -70,7 +73,7 @@ void print_objects(ConstTableRef table, size_t begin, size_t end)
}
switch (col_type) {
case type_Int:
printf(" %20ld", obj.get<Int>(col));
printf(" %20lld", (LL)obj.get<Int>(col));
break;
case type_Bool:
printf(" %20s", obj.get<Bool>(col) ? "true" : "false");
Expand Down Expand Up @@ -106,7 +109,7 @@ void print_objects(ConstTableRef table, size_t begin, size_t end)
break;
}
case type_Link: {
printf(" -> %12zx", obj.get<ObjKey>(col).value);
printf(" -> %12llx", (ULL)obj.get<ObjKey>(col).value);
break;
}
case type_LinkList: {
Expand Down
Loading