diff options
author | Leith Bade <leith@mapbox.com> | 2014-12-10 19:13:21 +1100 |
---|---|---|
committer | Leith Bade <leith@mapbox.com> | 2014-12-10 19:13:21 +1100 |
commit | 69cd7268d783a5e449de38ab40dfe5a28fa76f64 (patch) | |
tree | a4951f03d039c2775317678d66afb0e61eb2f1ea | |
parent | c55cd7f473ca532193697882c48436d2f98885d2 (diff) | |
parent | 318ef5d44314814f4dd7da2ba8c532b0119bdb35 (diff) | |
download | qtlocation-mapboxgl-69cd7268d783a5e449de38ab40dfe5a28fa76f64.tar.gz |
Merge branch 'master' of github.com:mapbox/mapbox-gl-native into android-mason
Conflicts:
platform/default/http_request_baton_curl.cpp
-rw-r--r-- | gyp/install.gypi | 1 | ||||
-rw-r--r-- | gyp/mbgl-core.gypi | 1 | ||||
-rw-r--r-- | gyp/mbgl-ios.gypi | 3 | ||||
-rw-r--r-- | gyp/mbgl-linux.gypi | 3 | ||||
-rw-r--r-- | gyp/mbgl-osx.gypi | 3 | ||||
-rw-r--r-- | gyp/version.gypi | 31 | ||||
-rw-r--r-- | include/mbgl/util/constants.hpp (renamed from src/mbgl/util/constants.hpp) | 1 | ||||
-rw-r--r-- | mapboxgl.gyp | 1 | ||||
-rw-r--r-- | platform/darwin/http_request_baton_cocoa.mm | 13 | ||||
-rw-r--r-- | platform/default/http_request_baton_curl.cpp | 18 | ||||
-rw-r--r-- | scripts/build-version.py | 89 | ||||
-rw-r--r-- | test/test.gyp | 1 |
12 files changed, 164 insertions, 1 deletions
diff --git a/gyp/install.gypi b/gyp/install.gypi index d46900dfff..56591d27d4 100644 --- a/gyp/install.gypi +++ b/gyp/install.gypi @@ -22,6 +22,7 @@ 'conditions': [ ['OS == "linux"', { 'other_ldflags': [ + '<@(nu_static_libs)', '<@(png_static_libs)', '<@(jpeg_static_libs)', '<@(glfw3_static_libs)', diff --git a/gyp/mbgl-core.gypi b/gyp/mbgl-core.gypi index 279051968c..ea279f2dad 100644 --- a/gyp/mbgl-core.gypi +++ b/gyp/mbgl-core.gypi @@ -7,6 +7,7 @@ 'hard_dependency': 1, 'dependencies': [ 'shaders', + 'version', ], 'variables': { 'cflags_cc': [ diff --git a/gyp/mbgl-ios.gypi b/gyp/mbgl-ios.gypi index a79737b0cd..e3d7fbbc7a 100644 --- a/gyp/mbgl-ios.gypi +++ b/gyp/mbgl-ios.gypi @@ -30,6 +30,9 @@ 'type': 'static_library', 'standalone_static_library': 1, 'hard_dependency': 1, + 'dependencies': [ + 'version', + ], 'sources': [ '../platform/ios/cache_database_library.mm', '../platform/ios/shader_cache_library.mm', diff --git a/gyp/mbgl-linux.gypi b/gyp/mbgl-linux.gypi index c42a49d9d1..c39d165a30 100644 --- a/gyp/mbgl-linux.gypi +++ b/gyp/mbgl-linux.gypi @@ -5,6 +5,9 @@ 'type': 'static_library', 'standalone_static_library': 1, 'hard_dependency': 1, + 'dependencies': [ + 'version', + ], 'variables': { 'cflags_cc': [ '<@(png_cflags)', diff --git a/gyp/mbgl-osx.gypi b/gyp/mbgl-osx.gypi index 542f6cb9e3..193341abc5 100644 --- a/gyp/mbgl-osx.gypi +++ b/gyp/mbgl-osx.gypi @@ -5,6 +5,9 @@ 'type': 'static_library', 'standalone_static_library': 1, 'hard_dependency': 1, + 'dependencies': [ + 'version', + ], 'sources': [ '../platform/osx/cache_database_application_support.mm', '../platform/osx/shader_cache_application_support.mm', diff --git a/gyp/version.gypi b/gyp/version.gypi new file mode 100644 index 0000000000..ca68f0eb57 --- /dev/null +++ b/gyp/version.gypi @@ -0,0 +1,31 @@ +{ + 'targets': [ + { + 'target_name': 'version', + 'type': 'none', + 'hard_dependency': 1, + 'actions': [ + { + 'action_name': 'Build Version File', + 'inputs': [ + '../scripts/build-version.py', + ], + 'outputs': [ + '<(SHARED_INTERMEDIATE_DIR)/include/mbgl/util/version.hpp', + '<(SHARED_INTERMEDIATE_DIR)/src/mbgl/util/mbgl_version.cpp', + ], + 'action': ['<@(python)', 'scripts/build-version.py', '<(SHARED_INTERMEDIATE_DIR)', '<!@(git describe --tags --always --abbrev=0)', '<!@(git rev-parse HEAD)'], + } + ], + 'direct_dependent_settings': { + 'sources': [ + '<(SHARED_INTERMEDIATE_DIR)/include/mbgl/util/version.hpp', + '<(SHARED_INTERMEDIATE_DIR)/src/mbgl/util/mbgl_version.cpp', + ], + 'include_dirs': [ + '<(SHARED_INTERMEDIATE_DIR)/include', + ] + } + }, + ] +} diff --git a/src/mbgl/util/constants.hpp b/include/mbgl/util/constants.hpp index 98365e0f32..78c92643d2 100644 --- a/src/mbgl/util/constants.hpp +++ b/include/mbgl/util/constants.hpp @@ -8,7 +8,6 @@ namespace mbgl { namespace util { extern const float tileSize; - } namespace debug { diff --git a/mapboxgl.gyp b/mapboxgl.gyp index 3978ebf0ad..7ce215dc6a 100644 --- a/mapboxgl.gyp +++ b/mapboxgl.gyp @@ -2,6 +2,7 @@ 'includes': [ './gyp/common.gypi', './gyp/shaders.gypi', + './gyp/version.gypi', './gyp/styles.gypi', './gyp/certificates.gypi', './gyp/mbgl-core.gypi', diff --git a/platform/darwin/http_request_baton_cocoa.mm b/platform/darwin/http_request_baton_cocoa.mm index 472154dc2f..4a59837e32 100644 --- a/platform/darwin/http_request_baton_cocoa.mm +++ b/platform/darwin/http_request_baton_cocoa.mm @@ -2,6 +2,7 @@ #include <mbgl/util/std.hpp> #include <mbgl/util/parsedate.h> #include <mbgl/util/time.hpp> +#include <mbgl/util/version.hpp> #include <uv.h> @@ -14,6 +15,8 @@ namespace mbgl { dispatch_once_t request_initialize = 0; NSURLSession *session = nullptr; +NSString *userAgent = nil; + void HTTPRequestBaton::start(const util::ptr<HTTPRequestBaton> &ptr) { assert(std::this_thread::get_id() == ptr->threadId); @@ -28,6 +31,14 @@ void HTTPRequestBaton::start(const util::ptr<HTTPRequestBaton> &ptr) { sessionConfig.URLCache = nil; session = [NSURLSession sessionWithConfiguration:sessionConfig]; + + // Write user agent string + NSDictionary *systemVersion = [NSDictionary dictionaryWithContentsOfFile:@"/System/Library/CoreServices/SystemVersion.plist"]; + userAgent = [NSString stringWithFormat:@"MapboxGL/%d.%d.%d (+https://mapbox.com/mapbox-gl/; %s; %@ %@)", + version::major, version::minor, version::patch, version::revision, + [systemVersion objectForKey:@"ProductName"], + [systemVersion objectForKey:@"ProductVersion"] + ]; }); NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@(baton->path.c_str())]]; @@ -40,6 +51,8 @@ void HTTPRequestBaton::start(const util::ptr<HTTPRequestBaton> &ptr) { } } + [request addValue:userAgent forHTTPHeaderField:@"User-Agent"]; + NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *res, NSError *error) { if (error) { diff --git a/platform/default/http_request_baton_curl.cpp b/platform/default/http_request_baton_curl.cpp index 74c6187e76..9e8cf64716 100644 --- a/platform/default/http_request_baton_curl.cpp +++ b/platform/default/http_request_baton_curl.cpp @@ -4,6 +4,7 @@ #include <mbgl/util/time.hpp> #include <mbgl/util/string.hpp> #include <mbgl/util/std.hpp> +#include <mbgl/util/version.hpp> #ifdef __ANDROID__ #include <mbgl/android/jni.hpp> @@ -14,6 +15,8 @@ #include <uv.h> #include <curl/curl.h> +#include <sys/utsname.h> + #include <queue> #include <cassert> #include <cstring> @@ -509,9 +512,22 @@ static CURLcode sslctx_function(CURL */*curl*/, void *sslctx, void */*parm*/) { } #endif +std::string buildUserAgentString() { +#ifdef __ANDROID__ + return util::sprintf<128>("MapboxGL/%d.%d.%d (+https://mapbox.com/mapbox-gl/; %s; %s %s)", + version::major, version::minor, version::patch, version::revision, "Android", mbgl::android::androidRelease.c_str()); +#else + utsname name; + uname(&name); + return util::sprintf<128>("MapboxGL/%d.%d.%d (+https://mapbox.com/mapbox-gl/; %s; %s %s)", + version::major, version::minor, version::patch, version::revision, name.sysname, name.release); +#endif +} + // This function must run in the CURL thread. void start_request(void *const ptr) { assert(std::this_thread::get_id() == thread_id); + static const std::string userAgent = buildUserAgentString(); // The Context object stores information that we need to retain throughout the request, such // as the actual CURL easy handle, the baton, and the list of headers. The Context itself is @@ -553,6 +569,8 @@ void start_request(void *const ptr) { curl_easy_setopt(context->handle, CURLOPT_HEADERFUNCTION, curl_header_cb); curl_easy_setopt(context->handle, CURLOPT_HEADERDATA, &context->baton->response); curl_easy_setopt(context->handle, CURLOPT_ACCEPT_ENCODING, "gzip, deflate"); + curl_easy_setopt(context->handle, CURLOPT_USERAGENT, userAgent.c_str()); + curl_easy_setopt(context->handle, CURLOPT_SHARE, share); // Start requesting the information. curl_multi_add_handle(multi, context->handle); diff --git a/scripts/build-version.py b/scripts/build-version.py new file mode 100644 index 0000000000..8261aea536 --- /dev/null +++ b/scripts/build-version.py @@ -0,0 +1,89 @@ +#!/usr/bin/env python + +import sys, os, errno + + +output_dir = sys.argv[1] + +if len(sys.argv) <= 3: + tag = [0, 0, 0] + rev = sys.argv[2][0:8] +else: + # When they're identical, the git describe can't find a tag and reports the rev instead. + if sys.argv[2] == sys.argv[3]: + tag = [0, 0, 0] + else: + tag = map(int, sys.argv[2].split('.')) + rev = sys.argv[3][0:8] + + +def mkdir_p(path): + try: + os.makedirs(path) + except OSError as exc: # Python >2.5 + if exc.errno == errno.EEXIST and os.path.isdir(path): + pass + else: raise + + +header = """// NOTE: DO NOT CHANGE THIS FILE. IT IS AUTOMATICALLY GENERATED. +#ifndef MBGL_UTIL_VERSION +#define MBGL_UTIL_VERSION + +#define MBGL_VERSION 0x{major:02x}{minor:02x}{patch:02x} +#define MBGL_VERSION_STRING "{major}.{minor}.{patch}" +#define MBGL_VERSION_MAJOR {major} +#define MBGL_VERSION_MINOR {minor} +#define MBGL_VERSION_PATCH {patch} +#define MBGL_VERSION_REV "{rev}" + +namespace mbgl {{ +namespace version {{ + +extern const int major, minor, patch; +extern const char *revision; +extern const char *string; +extern const unsigned int number; + +}} +}} + +#endif +""".format( + major = tag[0], + minor = tag[1], + patch = tag[2], + rev = rev +) + +header_path = os.path.join(output_dir, 'include/mbgl/util/version.hpp') +mkdir_p(os.path.dirname(header_path)) +with open(header_path, 'w') as f: f.write(header) + +source = """// NOTE: DO NOT CHANGE THIS FILE. IT IS AUTOMATICALLY GENERATED. +#include <mbgl/util/version.hpp> + +namespace mbgl {{ +namespace version {{ + +const int major = {major}; +const int minor = {minor}; +const int patch = {patch}; +const char *revision = "{rev}"; +const char *string = "{major}.{minor}.{patch}"; +const unsigned int number = 0x{major:02x}{minor:02x}{patch:02x}; + +}} +}} +""".format( + major = tag[0], + minor = tag[1], + patch = tag[2], + rev = rev +) + +# Note: We can't use version.cpp since libuv already has a file named version.c. +# Having another one here would overwrite that file and cause missing symbols errors. +source_path = os.path.join(output_dir, 'src/mbgl/util/mbgl_version.cpp') +mkdir_p(os.path.dirname(source_path)) +with open(source_path, 'w') as f: f.write(source) diff --git a/test/test.gyp b/test/test.gyp index 5aec5ac3ac..e33cf36894 100644 --- a/test/test.gyp +++ b/test/test.gyp @@ -1,6 +1,7 @@ { 'includes': [ '../gyp/common.gypi', + '../gyp/version.gypi', '../gyp/mbgl-platform.gypi', ], 'variables' : { |