From 6f349a796c718b598acd72d541eea7bcc4649325 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Fri, 23 Jan 2015 02:54:20 -0800 Subject: [PATCH] execute the correct server path and use the exepath for application root rather than the cwd --- platform/default/application_root.cpp | 18 ++++++++++++++++-- test/headless/headless.cpp | 3 +-- test/storage/storage.cpp | 3 +-- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/platform/default/application_root.cpp b/platform/default/application_root.cpp index 654d105c7..6669a049a 100644 --- a/platform/default/application_root.cpp +++ b/platform/default/application_root.cpp @@ -1,14 +1,28 @@ #include -#include +#include +#include namespace mbgl { namespace platform { // Returns the path to the root folder of the application. const std::string &applicationRoot() { - static const std::string root = uv::cwd(); + static const std::string root = []() -> std::string { + size_t max = 0; + std::string dir; + do { + // Gradually increase the length of the string in case the path was truncated. + max += 256; + dir.resize(max); + uv_exepath(const_cast(dir.data()), &max); + } while (max == dir.size()); + dir.resize(max - 1); + dir = dirname(const_cast(dir.c_str())); + return dir; + }(); return root; } + } } diff --git a/test/headless/headless.cpp b/test/headless/headless.cpp index 9f19c2c56..cd976be27 100644 --- a/test/headless/headless.cpp +++ b/test/headless/headless.cpp @@ -4,7 +4,6 @@ #include #include #include -#include #include #include @@ -30,7 +29,7 @@ void rewriteLocalScheme(rapidjson::Value &value, rapidjson::Document::AllocatorT class HeadlessTest : public ::testing::TestWithParam { public: static void SetUpTestCase() { - const auto server = mbgl::platform::applicationRoot() + "/TEST_DATA/headless/server.js"; + const auto server = mbgl::test::getBaseDirectory() + "/headless/server.js"; pid = mbgl::test::startServer(server.c_str()); display = std::make_shared(); } diff --git a/test/storage/storage.cpp b/test/storage/storage.cpp index 5dbd13dcd..99386a02c 100644 --- a/test/storage/storage.cpp +++ b/test/storage/storage.cpp @@ -1,10 +1,9 @@ #include "storage.hpp" -#include pid_t Storage::pid = 0; void Storage::SetUpTestCase() { - const auto server = mbgl::platform::applicationRoot() + "/TEST_DATA/storage/server.js"; + const auto server = mbgl::test::getBaseDirectory() + "/storage/server.js"; pid = mbgl::test::startServer(server.c_str()); }