diff --git a/Makefile b/Makefile index 584fe2a2e..a29e30cab 100644 --- a/Makefile +++ b/Makefile @@ -109,3 +109,4 @@ distclean: clean -find ./mapnik-packaging/osx/out/packages -type d ! -name 'packages' -maxdepth 1 -exec rm -rf {} \; .PHONY: mbgl test linux build/test/Makefile +# DO NOT DELETE diff --git a/configure b/configure index b92f97758..d8a5e08ed 100755 --- a/configure +++ b/configure @@ -1,144 +1,55 @@ -#!/usr/bin/env python -import optparse -import os -import pprint -import re -import shlex -import subprocess -import sys +#!/usr/bin/env bash -root_dir = os.path.dirname(__file__) +set -e +set -o pipefail -# parse our options -parser = optparse.OptionParser() +. ~/.nvm/nvm.sh +nvm use 0.10 -parser.add_option("--debug", - action="store_true", - dest="debug", - help="Also build debug build") +LIBCURL_VERSION=system +GLFW_VERSION=a21f2377 +LIBPNG_VERSION=1.6.13 +SQLITE_VERSION=system +LIBUV_VERSION=0.10.28 -parser.add_option("--node", - action="store", - dest="node", - help="Name of the node executable (defaults to node)") +mason install libcurl ${LIBCURL_VERSION} +mason install glfw ${GLFW_VERSION} +mason install libpng ${LIBPNG_VERSION} +mason install sqlite ${SQLITE_VERSION} +mason install libuv ${LIBUV_VERSION} -parser.add_option("--npm", - action="store", - dest="npm", - help="Name of the npm executable (defaults to npm)") +BOOST_ROOT=/usr +if [ -d '/usr/local/boost' ]; then BOOST_ROOT='/usr/local' ; fi -parser.add_option("--pkg-config-root", - action="store", - dest="pkgconfig_root", - help="Path to pkg-config directory") - -parser.add_option("--boost", - action="store", - dest="boost_root", - help="Path to boost (defaults to /usr/local)") - -(options, args) = parser.parse_args() - -def pkg_config(pkg, pkgconfig_root): - env = os.environ.copy() - if pkgconfig_root: - env["PKG_CONFIG_PATH"] = pkgconfig_root - env["PKG_CONFIG_ALLOW_SYSTEM_CFLAGS"] = "1" - env["PKG_CONFIG_ALLOW_SYSTEM_LIBS"] = "1" - cmd = subprocess.Popen(['pkg-config', '--static', '--libs', pkg], stdout=subprocess.PIPE, env=env) - libs, ret = cmd.communicate() - if (ret): return None - - cmd = subprocess.Popen(['pkg-config', '--static', '--cflags', pkg], stdout=subprocess.PIPE, env=env) - cflags, ret = cmd.communicate() - if (ret): return None - - return (libs, cflags) - -def configure_mbgl(o): - if options.boost_root: - o['variables']['boost_root'] = options.boost_root - else: - o['variables']['boost_root'] = '/usr/local' - if options.node: - o['variables']['node'] = options.node - else: - o['variables']['node'] = 'node' - if options.npm: - o['variables']['npm'] = options.npm - else: - o['variables']['npm'] = 'npm' - o['target_defaults']['default_configuration'] = 'Debug' if options.debug else 'Release' - - -def fix_frameworks(libs): - # don't split "-framework Foo" - return re.split('(? config.gypi - write('config.gypi', "# Do not edit. Generated by the configure script.\n" + - pprint.pformat(output, indent=2) + "\n") +cat config.gypi diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp index a69943aa7..bea82e6b4 100644 --- a/include/mbgl/map/map.hpp +++ b/include/mbgl/map/map.hpp @@ -143,10 +143,15 @@ public: private: // uv async callbacks +#if UV_VERSION_MAJOR == 0 && UV_VERSION_MINOR <= 10 + static void render(uv_async_t *async, int status); + static void terminate(uv_async_t *async, int status); + static void cleanup(uv_async_t *async, int status); +#else static void render(uv_async_t *async); static void terminate(uv_async_t *async); static void cleanup(uv_async_t *async); - static void delete_async(uv_handle_t *handle); +#endif // Setup void setup(); diff --git a/include/mbgl/util/uv_detail.hpp b/include/mbgl/util/uv_detail.hpp index e0a57ce65..f80ca1bff 100644 --- a/include/mbgl/util/uv_detail.hpp +++ b/include/mbgl/util/uv_detail.hpp @@ -24,17 +24,31 @@ private: class loop { public: inline loop() { +#if UV_VERSION_MAJOR == 0 && UV_VERSION_MINOR <= 10 + l = uv_loop_new(); + if (l == nullptr) { +#else + l = new uv_loop_t; if (uv_loop_init(&l) != 0) { +#endif throw std::runtime_error("failed to initialize loop"); } } - inline ~loop() { uv_loop_close(&l); } + inline ~loop() { +#if UV_VERSION_MAJOR == 0 && UV_VERSION_MINOR <= 10 + uv_loop_delete(l); +#else + uv_loop_close(l); + delete l; +#endif - inline uv_loop_t *operator*() { return &l; } + } + + inline uv_loop_t *operator*() { return l; } private: - uv_loop_t l; + uv_loop_t *l = nullptr; }; class mutex { diff --git a/src/map/map.cpp b/src/map/map.cpp index a1543dbda..f255c3ff6 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -145,10 +145,6 @@ void Map::stop(stop_callback cb, void *data) { async = false; } -void Map::delete_async(uv_handle_t *handle) { - delete (uv_async_t *)handle; -} - void Map::run() { #ifndef NDEBUG if (!async) { @@ -203,7 +199,11 @@ void Map::cleanup() { } } +#if UV_VERSION_MAJOR == 0 && UV_VERSION_MINOR <= 10 +void Map::cleanup(uv_async_t *async, int) { +#else void Map::cleanup(uv_async_t *async) { +#endif Map *map = static_cast(async->data); map->view.make_active(); @@ -221,7 +221,11 @@ void Map::setReachability(bool reachable) { } } +#if UV_VERSION_MAJOR == 0 && UV_VERSION_MINOR <= 10 +void Map::render(uv_async_t *async, int) { +#else void Map::render(uv_async_t *async) { +#endif Map *map = static_cast(async->data); assert(uv_thread_self() == map->map_thread); @@ -241,7 +245,11 @@ void Map::render(uv_async_t *async) { } } +#if UV_VERSION_MAJOR == 0 && UV_VERSION_MINOR <= 10 +void Map::terminate(uv_async_t *async, int) { +#else void Map::terminate(uv_async_t *async) { +#endif // Closes all open handles on the loop. This means that the loop will automatically terminate. Map *map = static_cast(async->data); assert(uv_thread_self() == map->map_thread); diff --git a/src/storage/file_request_baton.cpp b/src/storage/file_request_baton.cpp index 127c78f3e..d4c135fd7 100644 --- a/src/storage/file_request_baton.cpp +++ b/src/storage/file_request_baton.cpp @@ -29,7 +29,11 @@ void FileRequestBaton::notify_error(uv_fs_t *req) { if (ptr->request && req->result < 0 && !ptr->canceled && req->result != UV_ECANCELED) { ptr->request->response = std::unique_ptr(new Response); ptr->request->response->code = req->result == UV_ENOENT ? 404 : 500; +#if UV_VERSION_MAJOR == 0 && UV_VERSION_MINOR <= 10 + ptr->request->response->message = uv_strerror(uv_last_error(req->loop)); +#else ptr->request->response->message = uv_strerror(int(req->result)); +#endif ptr->request->notify(); } } @@ -54,7 +58,8 @@ void FileRequestBaton::file_opened(uv_fs_t *req) { uv_fs_close(req->loop, req, fd, file_closed); } else { ptr->fd = fd; - uv_fs_fstat(req->loop, req, fd, file_stated); + const int r = uv_fs_fstat(req->loop, req, fd, file_stated); + assert(r == 0); } } } @@ -63,7 +68,7 @@ void FileRequestBaton::file_stated(uv_fs_t *req) { FileRequestBaton *ptr = (FileRequestBaton *)req->data; assert(ptr->thread_id == uv_thread_self()); - if (req->result < 0 || ptr->canceled || !ptr->request) { + if (req->result != 0 || ptr->canceled || !ptr->request) { // Stating failed or was canceled. We already have an open file handle // though, which we'll have to close. notify_error(req); @@ -71,13 +76,22 @@ void FileRequestBaton::file_stated(uv_fs_t *req) { uv_fs_req_cleanup(req); uv_fs_close(req->loop, req, ptr->fd, file_closed); } else { - if (static_cast(req->ptr)->st_size > std::numeric_limits::max()) { +#if UV_VERSION_MAJOR == 0 && UV_VERSION_MINOR <= 10 + const uv_statbuf_t *stat = static_cast(req->ptr); +#else + const uv_stat_t *stat = static_cast(req->ptr); +#endif + if (stat->st_size > std::numeric_limits::max()) { // File is too large for us to open this way because uv_buf's only support unsigned // ints as maximum size. if (ptr->request) { ptr->request->response = std::unique_ptr(new Response); ptr->request->response->code = UV_EFBIG; +#if UV_VERSION_MAJOR == 0 && UV_VERSION_MINOR <= 10 + ptr->request->response->message = uv_strerror(uv_err_t {UV_EFBIG, 0}); +#else ptr->request->response->message = uv_strerror(UV_EFBIG); +#endif ptr->request->notify(); } @@ -85,11 +99,15 @@ void FileRequestBaton::file_stated(uv_fs_t *req) { uv_fs_close(req->loop, req, ptr->fd, file_closed); } else { const unsigned int size = - (unsigned int)(static_cast(req->ptr)->st_size); + (unsigned int)(stat->st_size); ptr->body.resize(size); ptr->buffer = uv_buf_init(const_cast(ptr->body.data()), size); uv_fs_req_cleanup(req); +#if UV_VERSION_MAJOR == 0 && UV_VERSION_MINOR <= 10 + uv_fs_read(req->loop, req, ptr->fd, ptr->buffer.base, ptr->buffer.len, -1, file_read); +#else uv_fs_read(req->loop, req, ptr->fd, &ptr->buffer, 1, 0, file_read); +#endif } } } diff --git a/src/storage/http_request.cpp b/src/storage/http_request.cpp index 1b799d489..ca1412fd9 100644 --- a/src/storage/http_request.cpp +++ b/src/storage/http_request.cpp @@ -77,7 +77,11 @@ void HTTPRequest::startHTTPRequest(std::unique_ptr &&res) { http_baton->response = std::move(res); http_baton->async->data = new util::ptr(http_baton); +#if UV_VERSION_MAJOR == 0 && UV_VERSION_MINOR <= 10 + uv_async_init(loop, http_baton->async, [](uv_async_t *async, int) { +#else uv_async_init(loop, http_baton->async, [](uv_async_t *async) { +#endif util::ptr &http_baton = *(util::ptr *)async->data; if (http_baton->request) { @@ -193,7 +197,12 @@ void HTTPRequest::retryHTTPRequest(std::unique_ptr &&res, uint64_t tim backoff_timer = new uv_timer_t(); uv_timer_init(loop, backoff_timer); backoff_timer->data = new RetryBaton(this, std::move(res)); + +#if UV_VERSION_MAJOR == 0 && UV_VERSION_MINOR <= 10 + uv_timer_start(backoff_timer, [](uv_timer_t *timer, int) { +#else uv_timer_start(backoff_timer, [](uv_timer_t *timer) { +#endif std::unique_ptr pair { static_cast(timer->data) }; pair->first->startHTTPRequest(std::move(pair->second)); pair->first->backoff_timer = nullptr; diff --git a/src/util/uv.cpp b/src/util/uv.cpp index b97074f05..03a885d30 100644 --- a/src/util/uv.cpp +++ b/src/util/uv.cpp @@ -5,6 +5,11 @@ namespace uv { std::string cwd() { +#if UV_VERSION_MAJOR == 0 && UV_VERSION_MINOR <= 10 + char dir[512]; + uv_cwd(dir, 512); + return dir; +#else size_t max = 0; std::string dir; do { @@ -14,6 +19,7 @@ std::string cwd() { } while (max == dir.size()); dir.resize(max - 1); return dir; +#endif } void deleter::operator()(uv_async_t *async) {