@@ -7,6 +7,7 @@
|
||||
'hard_dependency': 1,
|
||||
'dependencies': [
|
||||
'shaders',
|
||||
'version',
|
||||
],
|
||||
'variables': {
|
||||
'cflags_cc': [
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -5,6 +5,9 @@
|
||||
'type': 'static_library',
|
||||
'standalone_static_library': 1,
|
||||
'hard_dependency': 1,
|
||||
'dependencies': [
|
||||
'version',
|
||||
],
|
||||
'variables': {
|
||||
'cflags_cc': [
|
||||
'<@(png_cflags)',
|
||||
|
||||
@@ -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',
|
||||
|
||||
31
gyp/version.gypi
Normal file
31
gyp/version.gypi
Normal file
@@ -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 --abbrev=0)', '<!@(git rev-parse --short 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',
|
||||
]
|
||||
}
|
||||
},
|
||||
]
|
||||
}
|
||||
@@ -8,8 +8,6 @@ namespace mbgl {
|
||||
namespace util {
|
||||
|
||||
extern const float tileSize;
|
||||
extern const char *userAgent;
|
||||
|
||||
}
|
||||
|
||||
namespace debug {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
'includes': [
|
||||
'./gyp/common.gypi',
|
||||
'./gyp/shaders.gypi',
|
||||
'./gyp/version.gypi',
|
||||
'./gyp/styles.gypi',
|
||||
'./gyp/certificates.gypi',
|
||||
'./gyp/mbgl-core.gypi',
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include <mbgl/util/std.hpp>
|
||||
#include <mbgl/util/parsedate.h>
|
||||
#include <mbgl/util/time.hpp>
|
||||
#include <mbgl/util/constants.hpp>
|
||||
#include <mbgl/util/version.hpp>
|
||||
|
||||
#include <uv.h>
|
||||
|
||||
@@ -15,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->thread_id);
|
||||
|
||||
@@ -29,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())]];
|
||||
@@ -41,7 +51,7 @@ void HTTPRequestBaton::start(const util::ptr<HTTPRequestBaton> &ptr) {
|
||||
}
|
||||
}
|
||||
|
||||
[request addValue:@(util::userAgent) forHTTPHeaderField:@"User-Agent"];
|
||||
[request addValue:userAgent forHTTPHeaderField:@"User-Agent"];
|
||||
|
||||
NSURLSessionDataTask *task = [session dataTaskWithRequest:request
|
||||
completionHandler:^(NSData *data, NSURLResponse *res, NSError *error) {
|
||||
|
||||
@@ -3,11 +3,13 @@
|
||||
#include <mbgl/util/time.hpp>
|
||||
#include <mbgl/util/string.hpp>
|
||||
#include <mbgl/util/std.hpp>
|
||||
#include <mbgl/util/constants.hpp>
|
||||
#include <mbgl/util/version.hpp>
|
||||
|
||||
#include <uv.h>
|
||||
#include <curl/curl.h>
|
||||
|
||||
#include <sys/utsname.h>
|
||||
|
||||
#include <queue>
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
@@ -406,9 +408,17 @@ size_t curl_header_cb(char * const buffer, const size_t size, const size_t nmemb
|
||||
return length;
|
||||
}
|
||||
|
||||
std::string buildUserAgentString() {
|
||||
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);
|
||||
}
|
||||
|
||||
// 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
|
||||
@@ -445,7 +455,7 @@ 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, util::userAgent);
|
||||
curl_easy_setopt(context->handle, CURLOPT_USERAGENT, userAgent.c_str());
|
||||
curl_easy_setopt(context->handle, CURLOPT_SHARE, share);
|
||||
|
||||
// Start requesting the information.
|
||||
|
||||
80
scripts/build-version.py
Normal file
80
scripts/build-version.py
Normal file
@@ -0,0 +1,80 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import sys, os, errno
|
||||
|
||||
|
||||
output_dir = sys.argv[1]
|
||||
tag = map(int, sys.argv[2].split('.'))
|
||||
rev = sys.argv[3]
|
||||
|
||||
|
||||
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)
|
||||
@@ -1,7 +1,6 @@
|
||||
#include <mbgl/util/constants.hpp>
|
||||
|
||||
const float mbgl::util::tileSize = 512.0f;
|
||||
const char *mbgl::util::userAgent = "MapboxGL/1.0 (+https://mapbox.com/mapbox-gl/)";
|
||||
|
||||
#if defined(DEBUG)
|
||||
const bool mbgl::debug::tileParseWarnings = false;
|
||||
|
||||
Reference in New Issue
Block a user