summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bin/render.cpp4
-rw-r--r--gyp/platform-android.gypi1
-rw-r--r--gyp/platform-ios.gypi1
-rw-r--r--gyp/platform-linux.gypi1
-rw-r--r--gyp/platform-osx.gypi1
-rw-r--r--include/mbgl/platform/platform.hpp3
-rw-r--r--include/mbgl/storage/default_file_source.hpp2
-rw-r--r--platform/android/src/asset_file_source.cpp2
-rw-r--r--platform/android/src/asset_root.cpp15
-rw-r--r--platform/android/src/native_map_view.cpp5
-rw-r--r--platform/darwin/asset_root.mm16
-rw-r--r--platform/default/asset_file_source.cpp2
-rw-r--r--platform/default/asset_root.cpp28
-rw-r--r--platform/default/default_file_source.cpp4
-rw-r--r--platform/ios/src/MGLMapView.mm2
-rw-r--r--platform/linux/main.cpp2
-rw-r--r--platform/osx/src/MGLMapView.mm5
-rw-r--r--test/api/repeated_render.cpp7
-rw-r--r--test/fixtures/api/assets.zipbin328264 -> 167696 bytes
-rw-r--r--test/fixtures/api/assets/streets.json (renamed from test/fixtures/tiles/streets.json)2
-rw-r--r--test/fixtures/api/assets/streets/0-0-0.vector.pbf (renamed from test/fixtures/tiles/streets/0-0-0.vector.pbf)bin482553 -> 482553 bytes
-rw-r--r--test/fixtures/api/water.json2
-rw-r--r--test/fixtures/storage/assets.zipbin1136 -> 1243 bytes
-rw-r--r--test/fixtures/storage/assets/directory/file (renamed from test/fixtures/storage/empty)0
-rw-r--r--test/fixtures/storage/assets/empty0
-rw-r--r--test/fixtures/storage/assets/nonempty (renamed from test/fixtures/storage/nonempty)0
-rw-r--r--test/fixtures/tiles/streets/15-17605-10749.vector.pbfbin143637 -> 0 bytes
-rw-r--r--test/fixtures/tiles/streets/15-17605-10750.vector.pbfbin123586 -> 0 bytes
-rw-r--r--test/storage/asset_file_source.cpp13
29 files changed, 29 insertions, 89 deletions
diff --git a/bin/render.cpp b/bin/render.cpp
index 26fd06d507..0bcb5dff73 100644
--- a/bin/render.cpp
+++ b/bin/render.cpp
@@ -30,6 +30,7 @@ int main(int argc, char *argv[]) {
double pixelRatio = 1.0;
static std::string output = "out.png";
std::string cache_file = "cache.sqlite";
+ std::string asset_root = ".";
std::vector<std::string> classes;
std::string token;
bool debug = false;
@@ -48,6 +49,7 @@ int main(int argc, char *argv[]) {
("debug", po::bool_switch(&debug)->default_value(debug), "Debug mode")
("output,o", po::value(&output)->value_name("file")->default_value(output), "Output file name")
("cache,d", po::value(&cache_file)->value_name("file")->default_value(cache_file), "Cache database file name")
+ ("assets,d", po::value(&asset_root)->value_name("file")->default_value(asset_root), "Directory to which asset:// URLs will resolve")
;
try {
@@ -64,7 +66,7 @@ int main(int argc, char *argv[]) {
using namespace mbgl;
util::RunLoop loop;
- DefaultFileSource fileSource(cache_file);
+ DefaultFileSource fileSource(cache_file, asset_root);
// Try to load the token from the environment.
if (!token.size()) {
diff --git a/gyp/platform-android.gypi b/gyp/platform-android.gypi
index 22558a237a..189fe933ee 100644
--- a/gyp/platform-android.gypi
+++ b/gyp/platform-android.gypi
@@ -11,7 +11,6 @@
'sources': [
'../platform/android/src/log_android.cpp',
- '../platform/android/src/asset_root.cpp',
'../platform/default/async_task.cpp',
'../platform/default/run_loop.cpp',
'../platform/default/thread.cpp',
diff --git a/gyp/platform-ios.gypi b/gyp/platform-ios.gypi
index 1a36cf046d..0c24663749 100644
--- a/gyp/platform-ios.gypi
+++ b/gyp/platform-ios.gypi
@@ -21,7 +21,6 @@
'../platform/darwin/log_nslog.mm',
'../platform/darwin/string_nsstring.mm',
'../platform/darwin/application_root.mm',
- '../platform/darwin/asset_root.mm',
'../platform/darwin/image.mm',
'../platform/darwin/nsthread.mm',
'../platform/darwin/reachability.m',
diff --git a/gyp/platform-linux.gypi b/gyp/platform-linux.gypi
index 00595aa720..22dc452f33 100644
--- a/gyp/platform-linux.gypi
+++ b/gyp/platform-linux.gypi
@@ -15,7 +15,6 @@
'../platform/default/string_stdlib.cpp',
'../platform/default/run_loop.cpp',
'../platform/default/application_root.cpp',
- '../platform/default/asset_root.cpp',
'../platform/default/thread.cpp',
'../platform/default/image.cpp',
'../platform/default/png_reader.cpp',
diff --git a/gyp/platform-osx.gypi b/gyp/platform-osx.gypi
index ed4abea68f..0c2d824ad6 100644
--- a/gyp/platform-osx.gypi
+++ b/gyp/platform-osx.gypi
@@ -21,7 +21,6 @@
'../platform/darwin/log_nslog.mm',
'../platform/darwin/string_nsstring.mm',
'../platform/darwin/application_root.mm',
- '../platform/darwin/asset_root.mm',
'../platform/darwin/image.mm',
'../platform/darwin/nsthread.mm',
'../platform/darwin/reachability.m',
diff --git a/include/mbgl/platform/platform.hpp b/include/mbgl/platform/platform.hpp
index f2550a3e13..087ce56f95 100644
--- a/include/mbgl/platform/platform.hpp
+++ b/include/mbgl/platform/platform.hpp
@@ -18,9 +18,6 @@ std::string lowercase(const std::string &string);
// Returns the path to the root folder of the application.
const std::string &applicationRoot();
-// Returns the path to the asset location.
-const std::string &assetRoot();
-
// Makes the current thread low priority.
void makeThreadLowPriority();
diff --git a/include/mbgl/storage/default_file_source.hpp b/include/mbgl/storage/default_file_source.hpp
index 83ea4adf5d..bedea25bef 100644
--- a/include/mbgl/storage/default_file_source.hpp
+++ b/include/mbgl/storage/default_file_source.hpp
@@ -7,7 +7,7 @@ namespace mbgl {
class DefaultFileSource : public FileSource {
public:
- DefaultFileSource(const std::string& cachePath = ":memory:", const std::string& root = "");
+ DefaultFileSource(const std::string& cachePath, const std::string& assetRoot);
~DefaultFileSource() override;
void setAccessToken(const std::string&);
diff --git a/platform/android/src/asset_file_source.cpp b/platform/android/src/asset_file_source.cpp
index 1f02f9cf4a..7eb2007778 100644
--- a/platform/android/src/asset_file_source.cpp
+++ b/platform/android/src/asset_file_source.cpp
@@ -99,7 +99,7 @@ private:
AssetFileSource::AssetFileSource(const std::string& root)
: thread(std::make_unique<util::Thread<Impl>>(
util::ThreadContext{"AssetFileSource", util::ThreadType::Worker, util::ThreadPriority::Regular},
- root.empty() ? platform::assetRoot() : root)) {
+ root)) {
}
AssetFileSource::~AssetFileSource() = default;
diff --git a/platform/android/src/asset_root.cpp b/platform/android/src/asset_root.cpp
deleted file mode 100644
index 5720f5731c..0000000000
--- a/platform/android/src/asset_root.cpp
+++ /dev/null
@@ -1,15 +0,0 @@
-#include <mbgl/platform/platform.hpp>
-#include "jni.hpp"
-
-#include <libgen.h>
-
-namespace mbgl {
-namespace platform {
-
-// Returns the path to the root folder of the application.
-const std::string &assetRoot() {
- return mbgl::android::apkPath;
-}
-
-}
-}
diff --git a/platform/android/src/native_map_view.cpp b/platform/android/src/native_map_view.cpp
index 96b48e12c6..5d6e240797 100644
--- a/platform/android/src/native_map_view.cpp
+++ b/platform/android/src/native_map_view.cpp
@@ -75,7 +75,10 @@ NativeMapView::NativeMapView(JNIEnv *env, jobject obj_, float pixelRatio_, int a
return;
}
- fileSource = std::make_unique<mbgl::DefaultFileSource>(mbgl::android::cachePath + "/mbgl-cache.db");
+ fileSource = std::make_unique<mbgl::DefaultFileSource>(
+ mbgl::android::cachePath + "/mbgl-cache.db",
+ mbgl::android::apkPath);
+
map = std::make_unique<mbgl::Map>(*this, *fileSource, MapMode::Continuous);
float zoomFactor = map->getMaxZoom() - map->getMinZoom() + 1;
diff --git a/platform/darwin/asset_root.mm b/platform/darwin/asset_root.mm
deleted file mode 100644
index a4a3d13c88..0000000000
--- a/platform/darwin/asset_root.mm
+++ /dev/null
@@ -1,16 +0,0 @@
-#import <Foundation/Foundation.h>
-
-#include <mbgl/platform/platform.hpp>
-
-namespace mbgl {
-namespace platform {
-
-// Returns the path to the root folder of the application.
-const std::string &assetRoot() {
- static const std::string root = []() -> std::string {
- return [[[[NSBundle mainBundle] resourceURL] path] UTF8String];
- }();
- return root;
-}
-}
-}
diff --git a/platform/default/asset_file_source.cpp b/platform/default/asset_file_source.cpp
index 5aa5730c94..2573966c72 100644
--- a/platform/default/asset_file_source.cpp
+++ b/platform/default/asset_file_source.cpp
@@ -67,7 +67,7 @@ private:
AssetFileSource::AssetFileSource(const std::string& root)
: thread(std::make_unique<util::Thread<Impl>>(
util::ThreadContext{"AssetFileSource", util::ThreadType::Worker, util::ThreadPriority::Regular},
- root.empty() ? platform::assetRoot() : root)) {
+ root)) {
}
AssetFileSource::~AssetFileSource() = default;
diff --git a/platform/default/asset_root.cpp b/platform/default/asset_root.cpp
deleted file mode 100644
index 2b20018c40..0000000000
--- a/platform/default/asset_root.cpp
+++ /dev/null
@@ -1,28 +0,0 @@
-#include <mbgl/platform/platform.hpp>
-
-#include <uv.h>
-#include <libgen.h>
-
-namespace mbgl {
-namespace platform {
-
-// Returns the path to the root folder of the application.
-const std::string &assetRoot() {
- 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<char *>(dir.data()), &max);
- } while (max == dir.size());
- dir.resize(max - 1);
- dir = dirname(const_cast<char *>(dir.c_str()));
- return dir;
- }();
- return root;
-}
-
-}
-}
diff --git a/platform/default/default_file_source.cpp b/platform/default/default_file_source.cpp
index 8f2f024a11..fcb45ee29a 100644
--- a/platform/default/default_file_source.cpp
+++ b/platform/default/default_file_source.cpp
@@ -31,8 +31,8 @@ public:
OnlineFileSource onlineFileSource;
};
-DefaultFileSource::DefaultFileSource(const std::string& cachePath, const std::string& root)
- : impl(std::make_unique<DefaultFileSource::Impl>(cachePath, root)) {
+DefaultFileSource::DefaultFileSource(const std::string& cachePath, const std::string& assetRoot)
+ : impl(std::make_unique<DefaultFileSource::Impl>(cachePath, assetRoot)) {
}
DefaultFileSource::~DefaultFileSource() = default;
diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm
index 0fdf2ea66a..25474997e0 100644
--- a/platform/ios/src/MGLMapView.mm
+++ b/platform/ios/src/MGLMapView.mm
@@ -280,7 +280,7 @@ std::chrono::steady_clock::duration MGLDurationInSeconds(float duration)
NSString *libraryDirectory = [paths objectAtIndex:0];
fileCachePath = [libraryDirectory stringByAppendingPathComponent:@"cache.db"];
}
- _mbglFileSource = new mbgl::DefaultFileSource([fileCachePath UTF8String]);
+ _mbglFileSource = new mbgl::DefaultFileSource([fileCachePath UTF8String], [[[[NSBundle mainBundle] resourceURL] path] UTF8String]);
// setup mbgl map
_mbglMap = new mbgl::Map(*_mbglView, *_mbglFileSource, mbgl::MapMode::Continuous);
diff --git a/platform/linux/main.cpp b/platform/linux/main.cpp
index d6cf10fe70..f90b5de849 100644
--- a/platform/linux/main.cpp
+++ b/platform/linux/main.cpp
@@ -105,7 +105,7 @@ int main(int argc, char *argv[]) {
view = std::make_unique<GLFWView>(fullscreen, benchmark);
- mbgl::DefaultFileSource fileSource("/tmp/mbgl-cache.db");
+ mbgl::DefaultFileSource fileSource("/tmp/mbgl-cache.db", ".");
fileSource.setMaximumCacheEntrySize(1 * 1024 * 1024); // 1 MB
fileSource.setMaximumCacheSize(50 * 1024 * 1024); // 50 MB
diff --git a/platform/osx/src/MGLMapView.mm b/platform/osx/src/MGLMapView.mm
index 64aa592f7c..947dd41b17 100644
--- a/platform/osx/src/MGLMapView.mm
+++ b/platform/osx/src/MGLMapView.mm
@@ -246,7 +246,7 @@ public:
error:nil];
NSURL *cacheURL = [cacheDirectoryURL URLByAppendingPathComponent:@"cache.db"];
NSString *cachePath = cacheURL ? cacheURL.path : @"";
- _mbglFileSource = new mbgl::DefaultFileSource(cachePath.UTF8String);
+ _mbglFileSource = new mbgl::DefaultFileSource(cachePath.UTF8String, [[[[NSBundle mainBundle] resourceURL] path] UTF8String]);
_mbglMap = new mbgl::Map(*_mbglView, *_mbglFileSource, mbgl::MapMode::Continuous);
@@ -524,8 +524,7 @@ public:
}
if (![styleURL scheme]) {
- // Assume a relative path into the application’s resource folder,
- // defined in mbgl::platform::assetRoot().
+ // Assume a relative path into the application’s resource folder.
styleURL = [NSURL URLWithString:[@"asset://" stringByAppendingString:styleURL.absoluteString]];
}
diff --git a/test/api/repeated_render.cpp b/test/api/repeated_render.cpp
index 3eab03de5b..788363f0d1 100644
--- a/test/api/repeated_render.cpp
+++ b/test/api/repeated_render.cpp
@@ -18,9 +18,10 @@ TEST(API, RepeatedRender) {
auto display = std::make_shared<mbgl::HeadlessDisplay>();
HeadlessView view(display, 1, 256, 512);
#ifdef MBGL_ASSET_ZIP
- DefaultFileSource fileSource(":memory", "test/fixtures/api/assets.zip");
+ // Regenerate with `cd test/fixtures/api/ && zip -r assets.zip assets/`
+ DefaultFileSource fileSource(":memory:", "test/fixtures/api/assets.zip");
#else
- DefaultFileSource fileSource;
+ DefaultFileSource fileSource(":memory:", "test/fixtures/api/assets");
#endif
Log::setObserver(std::make_unique<FixtureLogObserver>());
@@ -40,7 +41,7 @@ TEST(API, RepeatedRender) {
}
{
- map.setStyleJSON(style, "TEST_DATA/suite");
+ map.setStyleJSON(style, "");
std::promise<PremultipliedImage> promise;
map.renderStill([&promise](std::exception_ptr, PremultipliedImage&& image) {
promise.set_value(std::move(image));
diff --git a/test/fixtures/api/assets.zip b/test/fixtures/api/assets.zip
index 42a30f1c2a..fe00443f61 100644
--- a/test/fixtures/api/assets.zip
+++ b/test/fixtures/api/assets.zip
Binary files differ
diff --git a/test/fixtures/tiles/streets.json b/test/fixtures/api/assets/streets.json
index a848a1bf72..f7b259f0a6 100644
--- a/test/fixtures/tiles/streets.json
+++ b/test/fixtures/api/assets/streets.json
@@ -10,5 +10,5 @@
"name": "Streets",
"scheme": "xyz",
"tilejson": "2.0.0",
- "tiles": [ "asset://TEST_DATA/fixtures/tiles/streets/{z}-{x}-{y}.vector.pbf" ]
+ "tiles": [ "asset://streets/{z}-{x}-{y}.vector.pbf" ]
}
diff --git a/test/fixtures/tiles/streets/0-0-0.vector.pbf b/test/fixtures/api/assets/streets/0-0-0.vector.pbf
index a0f049ad43..a0f049ad43 100644
--- a/test/fixtures/tiles/streets/0-0-0.vector.pbf
+++ b/test/fixtures/api/assets/streets/0-0-0.vector.pbf
Binary files differ
diff --git a/test/fixtures/api/water.json b/test/fixtures/api/water.json
index c969b345ae..387471b842 100644
--- a/test/fixtures/api/water.json
+++ b/test/fixtures/api/water.json
@@ -4,7 +4,7 @@
"sources": {
"mapbox": {
"type": "vector",
- "url": "asset://TEST_DATA/fixtures/tiles/streets.json"
+ "url": "asset://streets.json"
}
},
"layers": [{
diff --git a/test/fixtures/storage/assets.zip b/test/fixtures/storage/assets.zip
index 3127798145..4006ee10f2 100644
--- a/test/fixtures/storage/assets.zip
+++ b/test/fixtures/storage/assets.zip
Binary files differ
diff --git a/test/fixtures/storage/empty b/test/fixtures/storage/assets/directory/file
index e69de29bb2..e69de29bb2 100644
--- a/test/fixtures/storage/empty
+++ b/test/fixtures/storage/assets/directory/file
diff --git a/test/fixtures/storage/assets/empty b/test/fixtures/storage/assets/empty
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/test/fixtures/storage/assets/empty
diff --git a/test/fixtures/storage/nonempty b/test/fixtures/storage/assets/nonempty
index 929bb23131..929bb23131 100644
--- a/test/fixtures/storage/nonempty
+++ b/test/fixtures/storage/assets/nonempty
diff --git a/test/fixtures/tiles/streets/15-17605-10749.vector.pbf b/test/fixtures/tiles/streets/15-17605-10749.vector.pbf
deleted file mode 100644
index 1f43a6c487..0000000000
--- a/test/fixtures/tiles/streets/15-17605-10749.vector.pbf
+++ /dev/null
Binary files differ
diff --git a/test/fixtures/tiles/streets/15-17605-10750.vector.pbf b/test/fixtures/tiles/streets/15-17605-10750.vector.pbf
deleted file mode 100644
index 1ad616a56c..0000000000
--- a/test/fixtures/tiles/streets/15-17605-10750.vector.pbf
+++ /dev/null
Binary files differ
diff --git a/test/storage/asset_file_source.cpp b/test/storage/asset_file_source.cpp
index 8c597027dc..d7910373f6 100644
--- a/test/storage/asset_file_source.cpp
+++ b/test/storage/asset_file_source.cpp
@@ -11,9 +11,10 @@ namespace {
std::string getFileSourceRoot() {
#ifdef MBGL_ASSET_ZIP
+ // Regenerate with `cd test/fixtures/storage/ && zip -r assets.zip assets/`
return "test/fixtures/storage/assets.zip";
#else
- return "";
+ return "test/fixtures/storage/assets";
#endif
}
@@ -22,7 +23,7 @@ public:
TestWorker(mbgl::AssetFileSource* fs_) : fs(fs_) {}
void run(std::function<void()> endCallback) {
- const std::string asset("asset://TEST_DATA/fixtures/storage/nonempty");
+ const std::string asset("asset://nonempty");
requestCallback = [this, asset, endCallback](mbgl::Response res) {
EXPECT_EQ(nullptr, res.error);
@@ -100,7 +101,7 @@ TEST_F(Storage, AssetEmptyFile) {
AssetFileSource fs(getFileSourceRoot());
- std::unique_ptr<FileRequest> req = fs.request({ Resource::Unknown, "asset://TEST_DATA/fixtures/storage/empty" }, [&](Response res) {
+ std::unique_ptr<FileRequest> req = fs.request({ Resource::Unknown, "asset://empty" }, [&](Response res) {
req.reset();
EXPECT_EQ(nullptr, res.error);
EXPECT_EQ(false, res.stale);
@@ -122,7 +123,7 @@ TEST_F(Storage, AssetNonEmptyFile) {
AssetFileSource fs(getFileSourceRoot());
- std::unique_ptr<FileRequest> req = fs.request({ Resource::Unknown, "asset://TEST_DATA/fixtures/storage/nonempty" }, [&](Response res) {
+ std::unique_ptr<FileRequest> req = fs.request({ Resource::Unknown, "asset://nonempty" }, [&](Response res) {
req.reset();
EXPECT_EQ(nullptr, res.error);
EXPECT_EQ(false, res.stale);
@@ -144,7 +145,7 @@ TEST_F(Storage, AssetNonExistentFile) {
AssetFileSource fs(getFileSourceRoot());
- std::unique_ptr<FileRequest> req = fs.request({ Resource::Unknown, "asset://TEST_DATA/fixtures/storage/does_not_exist" }, [&](Response res) {
+ std::unique_ptr<FileRequest> req = fs.request({ Resource::Unknown, "asset://does_not_exist" }, [&](Response res) {
req.reset();
ASSERT_NE(nullptr, res.error);
EXPECT_EQ(Response::Error::Reason::NotFound, res.error->reason);
@@ -167,7 +168,7 @@ TEST_F(Storage, AssetReadDirectory) {
AssetFileSource fs(getFileSourceRoot());
- std::unique_ptr<FileRequest> req = fs.request({ Resource::Unknown, "asset://TEST_DATA/fixtures/storage" }, [&](Response res) {
+ std::unique_ptr<FileRequest> req = fs.request({ Resource::Unknown, "asset://directory" }, [&](Response res) {
req.reset();
ASSERT_NE(nullptr, res.error);
EXPECT_EQ(Response::Error::Reason::NotFound, res.error->reason);