Skip to content

Commit

Permalink
ICU Version for Ubuntu arm64.
Browse files Browse the repository at this point in the history
  • Loading branch information
rerdavies committed Nov 27, 2024
1 parent 80ce909 commit 20604ac
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 15 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ react/package-lock.json

src/dbus/bluez_adaptor.h
src/dbus/bluez_proxy.h

CMakeFiles
3 changes: 0 additions & 3 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -658,9 +658,6 @@ add_executable(pipedalconfig
)

target_link_libraries(pipedalconfig PRIVATE PiPedalCommon pthread atomic uuid stdc++fs asound
icui18n
icuuc
icudata

)

Expand Down
75 changes: 63 additions & 12 deletions src/Locale.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "ss.hpp"
#include <mutex>
#include "Utf8Utils.hpp"
#include <filesystem>

#define U_SHOW_CPLUSPLUS_API 0

Expand All @@ -50,9 +51,46 @@

using namespace pipedal;
using namespace std;
namespace fs = std::filesystem;

static inline bool isDigit(char c)
{
return c >= '0' && c <= '9';
}
static bool getSoVersionNumber(const std::string&fileName, int *version)
{
auto fnamePos = fileName.find_last_of('/');
if (fnamePos == std::string::npos)
{
fnamePos = 0;
}
auto extensionPos = fileName.find(".so.",fnamePos);
if (extensionPos == std::string::npos)
{
return false;
}


const char *p = fileName.c_str() + extensionPos + 4;

if (!isDigit(*p)) {
return false;
}
int n = 0;
while (isDigit(*p))
{
n = n*10 + *p-'0';
++p;
}
if (*p != '\0' && *p != '.')
{
return false;
}
*version = n;
return true;
}
// Function to get ICU version dynamically
int getICUVersion(void* libHandle) {
static int getICUVersion(void* libHandle) {

// pares the dlerror to get the version number. :-/
dlerror(); // clear the error.
Expand All @@ -61,22 +99,35 @@ int getICUVersion(void* libHandle) {
std::string error = dlerror();
// "/lib/aarch64-linux-gnu/libicui18n.so.74: undefined symbol: nonExistentFunction"

auto nPos = error.find(".so.");
auto nPos = error.find(":");
if (nPos == std::string::npos)
{
throw std::runtime_error("Unable to determine version of libicui18n.so");
return false;
}
const char *p = error.c_str() + nPos + 4;
std::string fileName = error.substr(nPos);

int version = 0;
while (*p >= '0' && *p <= '9')
{
version = version*10 + *p-'0';
++p;
}
if (*p != ':' && *p != '.')
int version = -1;

if (!getSoVersionNumber(fileName,&version))
{
throw std::runtime_error("Unable to determine version of libicui18n.so");
fs::path basePath = fileName;
fs::path parentDirectory = basePath.parent_path();
auto fileName = basePath.filename().string();
for (auto&entry: fs::directory_iterator(parentDirectory))
{
if (entry. path().filename().string().starts_with(fileName))
{
if (getSoVersionNumber(entry.path().string(),&version))
{
break;
}

}
}
if (version == -1)
{
throw std::runtime_error(SS("Unable to determine libicui18n.so version: " << error));
}
}
return version;
}
Expand Down
1 change: 1 addition & 0 deletions src/templates/pipedald.service.template
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Restart=on-failure
Type=notify
LimitMEMLOCK=infinity
LimitRTPRIO=95
Nice=-9
ExecStart=${COMMAND}
User=pipedal_d
Group=pipedal_d
Expand Down

0 comments on commit 20604ac

Please sign in to comment.