refactor mbgl travis scripts

source travis_helper.sh, run setup.sh

pushd/popd

sudo false

travis matrix with c++14 support?

drop setup_mesa.sh

update binding.gyp

language: c

drop thread_object, add async_queue

fix async_queue.hpp includes

std::make_unique

pip install awscli
This commit is contained in:
Mike Morris
2015-05-05 15:06:15 -04:00
parent 62816a9476
commit 1eeb7b65e9
13 changed files with 169 additions and 162 deletions

View File

@@ -1,29 +1,42 @@
language: cpp
# to prevent Travis from exporting CXX after matrix env
language: c
sudo: false
matrix:
include:
- os: linux
compiler: clang
env: FLAVOR=linux CXX=clang++-3.5 BUILDTYPE=Release
addons:
apt:
sources: [ 'ubuntu-toolchain-r-test', 'llvm-toolchain-precise-3.5' ]
packages: [ 'gdb', 'clang-3.5', 'libstdc++-4.9-dev', 'libstdc++6', 'libllvm3.4', 'xutils-dev', 'libxxf86vm-dev', 'x11proto-xf86vidmode-dev', 'mesa-utils' ]
- os: linux
compiler: gcc
env: JOBS=8
env: FLAVOR=linux CXX=g++-4.9 BUILDTYPE=Release
addons:
apt:
sources: [ 'ubuntu-toolchain-r-test' ]
packages: [ 'gdb', 'g++-4.9', 'gcc-4.9', 'libllvm3.4', 'xutils-dev', 'libxxf86vm-dev', 'x11proto-xf86vidmode-dev', 'mesa-utils' ]
- os: osx
compiler: clang
env: FLAVOR=osx BUILDTYPE=Release
env:
global:
- NODE_VERSION: 0.10.35
- NODE_VERSION: 0.10.36
- LD_LIBRARY_PATH: "/usr/local/lib"
- secure: pz/HAMQpnde//JJi3f+RcW32APN6g3QyFAH41JlZwgsM5Daj9RRoXqUcNg4hEyTvlThtc5t+wQQ2ejYAjMwDu00GAzRFJ03Sm45w2fPvith9fu4crXsyPUvWUfWPC0ajTXzorN4cwFwOoMoeo9DihLwb0EC0n4T6jWdBCae3k+s=
- secure: jYFAOQoMZkZVyc5AFPBKhR9oDqp5CciwCxFhVEHVjdImM+8V60loKazyw+bVLIjzKLnQbKKdiDudWL9TE1ylK/XSlF3K7o4gU2vIh5WzosKnU70Sanxd6tHt/Ui5eK+bAymKHbLdGiXIZtBZE0tML6+wgJ9vhV4ZKna5dM9tps4=
before_install:
- cd ./vendor/mbgl && source ./scripts/local_mason.sh && cd ../../
- source ./scripts/install_node.sh
- source ./vendor/mbgl/scripts/travis_helper.sh
- source ./vendor/mbgl/scripts/flags.sh
- source ./vendor/mbgl/scripts/travis_before_install.sh
- source ./scripts/setup_mesa.sh
- pushd ./vendor/mbgl
- source ./scripts/${TRAVIS_OS_NAME}/install.sh
- source ./scripts/${TRAVIS_OS_NAME}/setup.sh
- popd
- source ./scripts/install_node.sh
install:
- npm install --build-from-source
@@ -39,5 +52,3 @@ after_success:
git:
submodules: true
sudo: required

View File

@@ -21,32 +21,49 @@
'src/node_map.cpp',
'src/node_request.hpp',
'src/node_request.cpp',
'src/util/async_queue.hpp',
],
'variables': {
'cflags_cc': [
'-Wno-unused-parameter',
],
},
'conditions': [
['OS == "mac"', {
['OS=="mac"', {
'xcode_settings': {
"CLANG_CXX_LIBRARY": "libc++",
"CLANG_CXX_LANGUAGE_STANDARD":"c++11",
"GCC_VERSION": "com.apple.compilers.llvm.clang.1_0",
'MACOSX_DEPLOYMENT_TARGET': '10.9',
'OTHER_CPLUSPLUSFLAGS': [ '<@(cflags_cc)' ],
'CLANG_CXX_LIBRARY': 'libc++',
'CLANG_CXX_LANGUAGE_STANDARD': 'c++14',
'GCC_VERSION': 'com.apple.compilers.llvm.clang.1_0',
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
}
'GCC_ENABLE_CPP_RTTI': 'YES',
'OTHER_CPLUSPLUSFLAGS': [
'-Werror',
'-Wall',
'-Wextra',
'-Wshadow',
'-Wno-variadic-macros',
'-Wno-error=unused-parameter',
'-frtti',
'-fexceptions',
],
'GCC_WARN_PEDANTIC': 'YES',
'GCC_WARN_UNINITIALIZED_AUTOS': 'YES_AGGRESSIVE',
'MACOSX_DEPLOYMENT_TARGET': '10.9',
},
}, {
'cflags_cc': [
'-std=c++11',
'-std=c++14',
'-Werror',
'-Wall',
'-Wextra',
'-Wno-variadic-macros',
'-Wno-error=unused-parameter',
'-frtti',
'-fexceptions',
'<@(cflags_cc)',
],
'libraries': [ '<@(glfw3_ldflags)' ],
}]
}],
['OS=="linux"', {
'cflags_cc': [
'-Wno-unknown-pragmas', # We are using '#pragma mark', but it is only available on Darwin.
],
}],
],
},

View File

@@ -4,5 +4,12 @@ set -e
set -o pipefail
if [ ! -z "${AWS_ACCESS_KEY_ID}" ] && [ ! -z "${AWS_SECRET_ACCESS_KEY}" ] ; then
# Install and add awscli to PATH for uploading the results
mapbox_time "install_awscli" \
pip install --user awscli
export PATH="`python -m site --user-base`/bin:${PATH}"
mapbox_time_start "deploy_results"
(cd ./node_modules/mapbox-gl-test-suite/ && ./bin/deploy_results.sh)
mapbox_time_finish
fi

View File

@@ -3,7 +3,11 @@
set -e
set -o pipefail
# Mason exists on PATH from sourcing mbgl install script
mapbox_time "node" \
mason install node $NODE_VERSION
export PATH="`mason prefix node $NODE_VERSION`/bin":"$PATH"
node --version
npm --version

View File

@@ -1,9 +0,0 @@
#!/usr/bin/env bash
set -e
set -o pipefail
if [[ ${TRAVIS_OS_NAME} == "linux" ]]; then
export LD_LIBRARY_PATH=`mason prefix mesa 10.4.3`/lib:$LD_LIBRARY_PATH;
glxinfo;
fi

View File

@@ -1,8 +1,8 @@
#include "node_file_source.hpp"
#include "node_request.hpp"
#include "util/async_queue.hpp"
#include <mbgl/storage/request.hpp>
#include <mbgl/util/async_queue.hpp>
namespace node_mbgl {

View File

@@ -7,10 +7,10 @@
#include <map>
namespace mbgl { namespace util { template <typename T> class AsyncQueue; } }
namespace node_mbgl {
namespace util { template <typename T> class AsyncQueue; }
class NodeFileSource : public node::ObjectWrap, public mbgl::FileSource {
////////////////////////////////////////////////////////////////////////////////////////////////
// Static Node Methods
@@ -27,22 +27,22 @@ public:
~NodeFileSource();
mbgl::Request* request(const mbgl::Resource&, uv_loop_t*, Callback);
void cancel(mbgl::Request *request);
void cancel(mbgl::Request*);
void request(const mbgl::Resource&, Callback);
// visiblity?
void notify(mbgl::Request *request, const std::shared_ptr<const mbgl::Response> &response);
void notify(mbgl::Request*, const std::shared_ptr<const mbgl::Response>&);
private:
struct Action;
using Queue = mbgl::util::AsyncQueue<Action>;
using Queue = util::AsyncQueue<Action>;
void processAdd(mbgl::Request *request);
void processCancel(mbgl::Request *request);
void processAdd(mbgl::Request*);
void processCancel(mbgl::Request*);
private:
std::map<mbgl::Request *, v8::Persistent<v8::Object>> pending;
std::map<mbgl::Request*, v8::Persistent<v8::Object>> pending;
Queue *queue = nullptr;
};

View File

@@ -1,4 +1,5 @@
#include "node_log.hpp"
#include "util/async_queue.hpp"
#include <mbgl/map/environment.hpp>

View File

@@ -1,15 +1,14 @@
#pragma once
#include <mbgl/platform/log.hpp>
#include <mbgl/util/async_queue.hpp>
#include <node.h>
#include <nan.h>
namespace mbgl { namespace util { template <typename T> class AsyncQueue; } }
namespace node_mbgl {
namespace util { template <typename T> class AsyncQueue; }
class NodeLogObserver : public mbgl::Log::Observer {
public:
NodeLogObserver(v8::Handle<v8::Object> target);
@@ -22,7 +21,7 @@ private:
v8::Persistent<v8::Object> module;
struct LogMessage;
using Queue = mbgl::util::AsyncQueue<LogMessage>;
using Queue = util::AsyncQueue<LogMessage>;
Queue *queue = nullptr;
};

View File

@@ -1,85 +0,0 @@
#include "thread_object.hpp"
#include "node_file_source.hpp"
#include <unistd.h>
////////////////////////////////////////////////////////////////////////////////////////////////
// Static Node Methods
v8::Persistent<v8::FunctionTemplate> ThreadObject::constructorTemplate;
void ThreadObject::Init(v8::Handle<v8::Object> target) {
NanScope();
v8::Local<v8::FunctionTemplate> t = NanNew<v8::FunctionTemplate>(New);
t->InstanceTemplate()->SetInternalFieldCount(1);
t->SetClassName(NanNew("ThreadObject"));
NanAssignPersistent(constructorTemplate, t);
target->Set(NanNew("ThreadObject"), t->GetFunction());
}
NAN_METHOD(ThreadObject::New) {
NanScope();
if (!args.IsConstructCall()) {
return NanThrowTypeError("Use the new operator to create new ThreadObject objects");
}
if (args.Length() < 1 || !NanHasInstance(NodeFileSource::constructorTemplate, args[0])) {
return NanThrowTypeError("Requires a FileSource as first argument");
}
auto fs = ObjectWrap::Unwrap<NodeFileSource>(args[0]->ToObject());
auto to = new ThreadObject(fs);
to->Wrap(args.This());
NanReturnValue(args.This());
}
////////////////////////////////////////////////////////////////////////////////////////////////
// Instance
ThreadObject::ThreadObject(NodeFileSource *fs) {
self = v8::Persistent<v8::Object>::New(handle_);
auto async = new uv_async_t;
async->data = this;
uv_async_init(uv_default_loop(), async, [](uv_async_t *as, int) {
NanScope();
auto to = reinterpret_cast<ThreadObject *>(as->data);
to->self.Dispose();
uv_close((uv_handle_t *)as, [](uv_handle_t *handle) {
delete reinterpret_cast<uv_async_t *>(handle);
});
});
thread = std::thread([this, fs, async]() {
auto loop = uv_loop_new();
fs->request({ mbgl::Resource::Image, "http://example.com" }, loop, [&](const mbgl::Response &res) {
fprintf(stderr, "response.status: %d\n", res.status);
fprintf(stderr, "response.etag: %s\n", res.etag.c_str());
fprintf(stderr, "response.modified: %lld\n", res.modified);
fprintf(stderr, "response.expires: %lld\n", res.expires);
fprintf(stderr, "response.data.size: %ld\n", res.data.size());
fprintf(stderr, "response.message: %s\n", res.message.c_str());
});
uv_run(loop, UV_RUN_DEFAULT);
uv_loop_delete(loop);
// Notify that the loop has finished executing.
uv_async_send(async);
});
}
ThreadObject::~ThreadObject() {
thread.join();
}

View File

@@ -1,28 +0,0 @@
#pragma once
#include <node.h>
#include <nan.h>
#include <thread>
class NodeFileSource;
class ThreadObject : public node::ObjectWrap {
////////////////////////////////////////////////////////////////////////////////////////////////
// Static Node Methods
public:
static void Init(v8::Handle<v8::Object> target);
static NAN_METHOD(New);
static v8::Persistent<v8::FunctionTemplate> constructorTemplate;
////////////////////////////////////////////////////////////////////////////////////////////////
// Instance
private:
ThreadObject(NodeFileSource *fs);
~ThreadObject();
private:
std::thread thread;
v8::Persistent<v8::Object> self;
};

90
src/util/async_queue.hpp Normal file
View File

@@ -0,0 +1,90 @@
#pragma once
#include <uv.h>
#include <thread>
#include <mutex>
#include <functional>
#include <queue>
#include <string>
#if UV_VERSION_MAJOR == 0 && UV_VERSION_MINOR <= 10
#define UV_ASYNC_PARAMS(handle) uv_async_t *handle, int
#else
#define UV_ASYNC_PARAMS(handle) uv_async_t *handle
#endif
namespace node_mbgl {
namespace util {
template <typename T>
class AsyncQueue {
public:
AsyncQueue(uv_loop_t *loop, std::function<void(T &)> fn) :
callback(fn) {
async.data = this;
uv_async_init(loop, &async, [](UV_ASYNC_PARAMS(handle)) {
auto q = reinterpret_cast<AsyncQueue *>(handle->data);
q->process();
});
}
void send(T &&data) {
{
std::lock_guard<std::mutex> lock(mutex);
queue.push(std::make_unique<T>(std::move(data)));
}
uv_async_send(&async);
}
void send(std::unique_ptr<T> data) {
{
std::lock_guard<std::mutex> lock(mutex);
queue.push(std::move(data));
}
uv_async_send(&async);
}
void stop() {
uv_close((uv_handle_t *)&async, [](uv_handle_t *handle) {
delete reinterpret_cast<AsyncQueue *>(handle->data);
});
}
void ref() {
uv_ref((uv_handle_t *)&async);
}
void unref() {
uv_unref((uv_handle_t *)&async);
}
private:
~AsyncQueue() {
}
void process() {
std::unique_ptr<T> item;
while (true) {
mutex.lock();
if (queue.empty()) {
mutex.unlock();
break;
}
item = std::move(queue.front());
queue.pop();
mutex.unlock();
callback(*item);
}
}
private:
std::mutex mutex;
uv_async_t async;
std::queue<std::unique_ptr<T>> queue;
std::function<void(T &)> callback;
};
}
}

2
vendor/mbgl vendored