8000 Make core infer platform and cpu_arch, while bundle_id must be provided by SDK's by danieltabacaru · Pull Request #6612 · realm/realm-core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Make core infer platform and cpu_arch, while bundle_id must be provided by SDK's #6612

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

Merged
merged 9 commits into from
May 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
10000
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
* None.

### Breaking changes
* None.
* `platform` and `cpu_arch` fields in the `device_info` structure in App::Config can no longer be provided by the SDK's, they are inferred by the library ([PR #6612](https://github.com/realm/realm-core/pull/6612))
* `bundle_id` is now a required field in the `device_info` structure in App::Config ([PR #6612](https://github.com/realm/realm-core/pull/6612))

### Compatibility
* Fileformat: Generates files with format v23. Reads and automatically upgrade from fileformat v5.
Expand Down
3 changes: 1 addition & 2 deletions src/realm.h
Original file line number Diff line number Diff line change
Expand Up @@ -2855,18 +2855,17 @@ RLM_API void realm_app_config_set_base_url(realm_app_config_t*, const char*) RLM
RLM_API void realm_app_config_set_local_app_name(realm_app_config_t*, const char*) RLM_API_NOEXCEPT;
RLM_API void realm_app_config_set_local_app_version(realm_app_config_t*, const char*) RLM_API_NOEXCEPT;
RLM_API void realm_app_config_set_default_request_timeout(realm_app_config_t*, uint64_t ms) RLM_API_NOEXCEPT;
RLM_API void realm_app_config_set_platform(realm_app_config_t*, const char*) RLM_API_NOEXCEPT;
RLM_API void realm_app_config_set_platform_version(realm_app_config_t*, const char*) RLM_API_NOEXCEPT;
RLM_API void realm_app_config_set_sdk_version(realm_app_config_t*, const char*) RLM_API_NOEXCEPT;
RLM_API void realm_app_config_set_sdk(realm_app_config_t* config, const char* sdk) RLM_API_NOEXCEPT;
RLM_API void realm_app_config_set_cpu_arch(realm_app_config_t* config, const char* cpu_arch) RLM_API_NOEXCEPT;
RLM_API void realm_app_config_set_device_name(realm_app_config_t* config, const char* device_name) RLM_API_NOEXCEPT;
RLM_API void realm_app_config_set_device_version(realm_app_config_t* config,
const char* device_version) RLM_API_NOEXCEPT;
RLM_API void realm_app_config_set_framework_name(realm_app_config_t* config,
const char* framework_name) RLM_API_NOEXCEPT;
RLM_API void realm_app_config_set_framework_version(realm_app_config_t* config,
const char* framework_version) RLM_API_NOEXCEPT;
RLM_API void realm_app_config_set_bundle_id(realm_app_config_t* config, const char* bundle_id) RLM_API_NOEXCEPT;

/**
* Get an existing @a realm_app_credentials_t and return it's json representation
Expand Down
15 changes: 5 additions & 10 deletions src/realm/object-store/c_api/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,6 @@ RLM_API void realm_app_config_set_default_request_timeout(realm_app_config_t* co
config->default_request_timeout_ms = ms;
}

RLM_API void realm_app_config_set_platform(realm_app_config_t* config, const char* platform) noexcept
{
config->device_info.platform = std::string(platform);
}

RLM_API void realm_app_config_set_platform_version(realm_app_config_t* config, const char* platform_version) noexcept
{
config->device_info.platform_version = std::string(platform_version);
Expand All @@ -234,11 +229,6 @@ RLM_API void realm_app_config_set_sdk(realm_app_config_t* config, const char* sd
config->device_info.sdk = std::string(sdk);
}

RLM_API void realm_app_config_set_cpu_arch(realm_app_config_t* config, const char* cpu_arch) noexcept
{
config->device_info.cpu_arch = std::string(cpu_arch);
}

RLM_API void realm_app_config_set_device_name(realm_app_config_t* config, const char* device_name) noexcept
{
config->device_info.device_name = std::string(device_name);
Expand All @@ -260,6 +250,11 @@ RLM_API void realm_app_config_set_framework_version(realm_app_config_t* config,
config->device_info.framework_version = std::string(framework_version);
}

RLM_API void realm_app_config_set_bundle_id(realm_app_config_t* config, const char* bundle_id) noexcept
{
config->device_info.bundle_id = std::string(bundle_id);
}

RLM_API const char* realm_app_credentials_serialize_as_json(realm_app_credentials_t* app_credentials) noexcept
{
return wrap_err([&] {
Expand Down
40 changes: 31 additions & 9 deletions src/realm/object-store/sync/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <realm/sync/network/http.hpp>
#include <realm/util/base64.hpp>
#include <realm/util/flat_map.hpp>
#include <realm/util/platform_info.hpp>
#include <realm/util/uri.hpp>
#include <realm/object-store/sync/app_utils.hpp>
#include <realm/object-store/sync/impl/sync_metadata.hpp>
Expand Down Expand Up @@ -187,6 +188,29 @@ std::mutex s_apps_mutex;
namespace realm {
namespace app {

App::Config::DeviceInfo::DeviceInfo()
: platform(util::get_library_platform())
, cpu_arch(util::get_library_cpu_arch())
, core_version(REALM_VERSION_STRING)
{
}

App::Config::DeviceInfo::DeviceInfo(std::string a_platform_version, std::string an_sdk_version, std::string an_sdk,
std::string a_device_name, std::string a_device_version,
std::string a_framework_name, std::string a_framework_version,
std::string a_bundle_id)
: DeviceInfo()
{
platform_version = a_platform_version;
sdk_version = an_sdk_version;
sdk = an_sdk;
device_name = a_device_name;
device_version = a_device_version;
framework_name = a_framework_name;
framework_version = a_framework_version;
bundle_id = a_bundle_id;
}

SharedApp App::get_shared_app(const Config& config, const SyncClientConfig& sync_client_config)
{
std::lock_guard<std::mutex> lock(s_apps_mutex);
Expand Down Expand Up @@ -250,21 +274,18 @@ App::App(const Config& config)
}
#endif
REALM_ASSERT(m_config.transport);

if (m_config.device_info.platform.empty()) {
throw InvalidArgument("You must specify the Platform in App::Config::device");
}
REALM_ASSERT(!m_config.device_info.platform.empty());

if (m_config.device_info.platform_version.empty()) {
throw InvalidArgument("You must specify the Platform Version in App::Config::device");
throw InvalidArgument("You must specify the Platform Version in App::Config::device_info");
}

if (m_config.device_info.sdk.empty()) {
throw InvalidArgument("You must specify the SDK Name in App::Config::device");
throw InvalidArgument("You must specify the SDK Name in App::Config::device_info");
}

if (m_config.device_info.sdk_version.empty()) {
throw InvalidArgument("You must specify the SDK Version in App::Config::device");
throw InvalidArgument("You must specify the SDK Version in App::Config::device_info");
}

// change the scheme in the base url to ws from http to satisfy the sync client
Expand Down Expand Up @@ -592,7 +613,7 @@ void App::attach_auth_options(BsonDocument& body)

log_debug("App: version info: platform: %1 version: %2 - sdk: %3 - sdk version: %4 - core version: %5",
m_config.device_info.platform, m_config.device_info.platform_version, m_config.device_info.sdk,
m_config.device_info.sdk_version, REALM_VERSION_STRING);
m_config.device_info.sdk_version, m_config.device_info.core_version);
options["appId"] = m_config.app_id;
options["platform"] = m_config.device_info.platform;
options["platformVersion"] = m_config.device_info.platform_version;
Expand All @@ -603,7 +624,8 @@ void App::attach_auth_options(BsonDocument& body)
options["deviceVersion"] = m_config.device_info.device_version;
options["frameworkName"] = m_config.device_info.framework_name;
options["frameworkVersion"] = m_config.device_info.framework_version;
options["coreVersion"] = REALM_VERSION_STRING;
options["coreVersion"] = m_config.device_info.core_version;
options["bundleId"] = m_config.device_info.bundle_id;

body["options"] = BsonDocument({{"device", options}});
}
Expand Down
16 changes: 12 additions & 4 deletions src/realm/object-store/sync/app.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,25 @@ class App : public std::enable_shared_from_this<App>,
struct Config {
// Information about the device where the app is running
struct DeviceInfo {
std::string platform; // json: platform
std::string platform_version; // json: platformVersion
std::string sdk_version; // json: sdkVersion
std::string sdk; // json: sdk
std::string cpu_arch; // json: cpuArch
std::string device_name; // json: deviceName
std::string device_version; // json: deviceVersion
std::string framework_name; // json: frameworkName
std::string framework_version; // json: frameworkVersion
// Other parameters provided to server no included here:
// * CoreVersion - populated by Sync when the device info is sent
std::string bundle_id; // json: bundleId

DeviceInfo();
DeviceInfo(std::string, std::string, std::string, std::string, std::string, std::string, std::string,
std::string);

private:
friend App;

std::string platform; // json: platform
std::string cpu_arch; // json: cpuArch
std::string core_version; // json: coreVersion
};

std::string app_id;
Expand Down
5 changes: 5 additions & 0 deletions src/realm/util/features.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,13 @@

#if defined ANDROID || defined __ANDROID_API__
#define REALM_ANDROID 1
#define REALM_LINUX 0
#elif defined(__linux__)
#define REALM_ANDROID 0
#define REALM_LINUX 1
#else
#define REALM_ANDROID 0
#define REALM_LINUX 0
#endif

#if defined _WIN32
Expand Down
39 changes: 39 additions & 0 deletions src/realm/util/platform_info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,45 @@ inline std::string get_platform_info()
info.machine); // Throws
}

inline std::string get_library_platform()
{
#if REALM_ANDROID
return "Android";
#elif REALM_WINDOWS
return "Windows";
#elif REALM_UWP
return "UWP";
#elif REALM_MACCATALYST // test Catalyst first because it's a subset of iOS
return "Mac Catalyst";
#elif REALM_IOS
return "iOS";
#elif REALM_TVOS
return "tvOS";
#elif REALM_WATCHOS
return "watchOS";
#elif REALM_PLATFORM_APPLE
return "macOS";
#elif REALM_LINUX
return "Linux";
#endif

return "unknown";
}

inline std::string get_library_cpu_arch()
{
#if REALM_ARCHITECTURE_ARM32
return "arm";
#elif REALM_ARCHITECTURE_ARM64
return "arm64";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it would be more consistent to call this "arm64-v8a"

Checking https://docs.google.com/document/d/1jUeN71gzQoLoYxHUawzIQaDVD2xDLbtbWkmxjIMcN-U I see you followed the spec to the letter, but I guess we can still change it, if others agree.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both are used, depending on what platform you ask, we see both values on Kotlin Multiplatform. I don't have strong preferences either way so 🤷. I would slightly prefer arm64 just because it is easier on the eyes and easier to write, but if anyone feels strongly about either one, I would just go with that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're kind of nitpicking here, but I also don't see much value in overly verbose names. So I'd vote for x86, x64, arm, and arm64.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with Nikola about not using overly verbose names, but if I understand correctly the device architecture can be seen by users looking at logs on the backend, so maybe it should make sense in the context of the platform. x64 is specifically a Microsoft thing, but x86_64, x86, arm64, and arm are certainly generic enough.

Copy link
Contributor
@nielsenko nielsenko May 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with that 👍 I just felt the current discrepancy in verbosity was odd, ie. armeabi-v7a vs arm64. Your suggestion @nirinchev jives well with me, and now that we only have to change it here in realm-core it shouldn't take long.

#elif REALM_ARCHITECTURE_X86_32
return "x86";
#elif REALM_ARCHITECTURE_X86_64
return "x86_64";
#endif

return "unknown";
}

} // namespace util
} // namespace realm
Expand Down
16 changes: 7 additions & 9 deletions test/object-store/c_api/c_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,16 +343,17 @@ class CApiUnitTestTransport : public app::GenericNetworkTransport {
nlohmann::json({{"device",
{{"appId", "app_id_123"},
{"appVersion", "some_app_version"},
{"platform", "some_platform_name"},
{"platform", util::get_library_platform()},
{"platformVersion", "some_platform_version"},
{"sdk", "some_sdk_name"},
{"sdkVersion", "some_sdk_version"},
{"cpuArch", "some_cpu_arch"},
{"cpuArch", util::get_library_cpu_arch()},
{"deviceName", "some_device_name"},
{"deviceVersion", "some_device_version"},
{"frameworkName", "some_framework_name"},
{"frameworkVersion", "some_framework_version"},
{"coreVersion", REALM_VERSION_STRING}}}}));
{"coreVersion", REALM_VERSION_STRING},
{"bundleId", "some_bundle_id"}}}}));

CHECK(request.timeout_ms == 60000);

Expand Down Expand Up @@ -632,9 +633,6 @@ TEST_CASE("C API (non-database)", "[c_api]") {
realm_app_config_set_default_request_timeout(app_config.get(), 2500);
CHECK(app_config->default_request_timeout_ms == 2500);

realm_app_config_set_platform(app_config.get(), "some_platform_name");
CHECK(app_config->device_info.platform == "some_platform_name");

realm_app_config_set_platform_version(app_config.get(), "some_platform_version");
CHECK(app_config->device_info.platform_version == "some_platform_version");

Expand All @@ -644,9 +642,6 @@ TEST_CASE("C API (non-database)", "[c_api]") {
realm_app_config_set_sdk(app_config.get(), "some_sdk_name");
CHECK(app_config->device_info.sdk == "some_sdk_name");

realm_app_config_set_cpu_arch(app_config.get(), "some_cpu_arch");
CHECK(app_config->device_info.cpu_arch == "some_cpu_arch");

realm_app_config_set_device_name(app_config.get(), "some_device_name");
CHECK(app_config->device_info.device_name == "some_device_name");

Expand All @@ -659,6 +654,9 @@ TEST_CASE("C API (non-database)", "[c_api]") {
realm_app_config_set_framework_version(app_config.get(), "some_framework_version");
CHECK(app_config->device_info.framework_version == "some_framework_version");

realm_app_config_set_bundle_id(app_config.get(), "some_bundle_id");
CHECK(app_config->device_info.bundle_id == "some_bundle_id");

auto test_app = std::make_shared<app::App>(*app_config);
auto credentials = app::AppCredentials::anonymous();
// Verify the values above are included in the login request
Expand Down
8 changes: 5 additions & 3 deletions test/object-store/sync/app.cpp
2851
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include <realm/util/base64.hpp>
#include <realm/util/logger.hpp>
#include <realm/util/overload.hpp>
#include <realm/util/platform_info.hpp>
#include <realm/util/uri.hpp>
#include <realm/sync/network/websocket.hpp>

Expand Down Expand Up @@ -3598,16 +3599,17 @@ class UnitTestTransport : public GenericNetworkTransport {
nlohmann::json({{"device",
{{"appId", "app_id"},
{&quo F438 t;appVersion", "A Local App Version"},
{"platform", "Object Store Test Platform"},
{"platform", util::get_library_platform()},
{"platformVersion", "Object Store Test Platform Version"},
{"sdk", "SDK Name"},
{"sdkVersion", "SDK Version"},
{"cpuArch", "CPU Arch"},
{"cpuArch", util::get_library_cpu_arch()},
{"deviceName", "Device Name"},
{"deviceVersion", "Device Version"},
{"frameworkName", "Framework Name"},
{"frameworkVersion", "Framework Version"},
{"coreVersion", REALM_VERSION_STRING}}}}));
{"coreVersion", REALM_VERSION_STRING},
{"bundleId", "Bundle Id"}}}}));

CHECK(request.timeout_ms == 60000);

Expand Down
4 changes: 2 additions & 2 deletions test/object-store/util/baas_admin_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,8 @@ inline app::App::Config get_config(Factory factory, const AppSession& app_sessio
util::none,
util::Optional<std::string>("A Local App Version"),
util::none,
{"Object Store Platform Tests", "Object Store Platform Version Blah", "An sdk version", "An sdk name",
"A cpu arch", "A device name", "A device version", "A framework name", "A framework version"}};
{"Object Store Platform Version Blah", "An sdk version", "An sdk name", "A device name",
"A device version", "A framework name", "A framework version", "A bundle id"}};
}

} // namespace realm
Expand Down
6 changes: 2 additions & 4 deletions test/object-store/util/test_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,16 +287,12 @@ void set_app_config_defaults(app::App::Config& app_config,
{
if (!app_config.transport)
app_config.transport = transport;
if (app_config.device_info.platform.empty())
app_config.device_info.platform = "Object Store Test Platform";
if (app_config.device_info.platform_version.empty())
app_config.device_info.platform_version = "Object Store Test Platform Version";
if (app_config.device_info.sdk_version.empty())
app_config.device_info.sdk_version = "SDK Version";
if (app_config.device_info.sdk.empty())
app_config.device_info.sdk = "SDK Name";
if (app_config.device_info.cpu_arch.empty())
app_config.device_info.cpu_arch = "CPU Arch";
if (app_config.device_info.device_name.empty())
app_config.device_info.device_name = "Device Name";
if (app_config.device_info.device_version.empty())
Expand All @@ -305,6 +301,8 @@ void set_app_config_defaults(app::App::Config& app_config,
app_config.device_info.framework_name = "Framework Name";
if (app_config.device_info.framework_version.empty())
app_config.device_info.framework_version = "Framework Version";
if (app_config.device_info.bundle_id.empty())
app_config.device_info.bundle_id = "Bundle Id";
if (app_config.app_id.empty())
app_config.app_id = "app_id";
if (!app_config.local_app_version)
Expand Down
0