diff options
author | ArthurSonzogni <sonzogniarthur@gmail.com> | 2020-04-29 16:45:05 +0300 |
---|---|---|
committer | ArthurSonzogni <sonzogniarthur@gmail.com> | 2020-05-01 15:23:26 +0300 |
commit | 12c98e5c67385b62776af4e74f55b56360c55512 (patch) | |
tree | bc0757acabfa6eb73f2333b46838b19d925afad2 |
Initial commit without calling 'update.py'
-rw-r--r-- | CMakeLists.txt | 14 | ||||
-rw-r--r-- | LICENSE.MIT | 21 | ||||
-rw-r--r-- | README.md | 40 | ||||
-rw-r--r-- | meson.build | 7 | ||||
-rwxr-xr-x | update.py | 64 |
5 files changed, 146 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..5d6a605 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.1) +project(nlohmann_json LANGUAGES CXX) + +add_library(nlohmann_json INTERFACE) +add_library(nlohmann_json::nlohmann_json ALIAS nlohmann_json) +target_include_directories(nlohmann_json + INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/include +) + +if (${CMAKE_VERSION} VERSION_LESS "3.8.0") + target_compile_features(nlohmann_json INTERFACE cxx_range_for) +else() + target_compile_features(nlohmann_json INTERFACE cxx_std_11) +endif() diff --git a/LICENSE.MIT b/LICENSE.MIT new file mode 100644 index 0000000..00599af --- /dev/null +++ b/LICENSE.MIT @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2013-2017 Niels Lohmann + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..ea84f0d --- /dev/null +++ b/README.md @@ -0,0 +1,40 @@ +# Release-tracking repository for nlohmann/json + +This repository is based on: +https://github.com/astoeckel/json + +It provides a lightweight repository tracking every releases of +https://github.com/nlohmann/json. You can then depends on it using CMake +[FetchContent](https://cmake.org/cmake/help/v3.11/module/FetchContent.html). + +Example: +~~~cmake +include(FetchContent) + +FetchContent_Declare(json + GIT_REPOSITORY + https://github.com/ArthurSonzogni/nlohmann_json_cmake_fetchcontent + GIT_TAG v3.7.3) + +FetchContent_GetProperties(json) +if(NOT json_POPULATED) + FetchContent_Populate(json) + add_subdirectory(${json_SOURCE_DIR} ${json_BINARY_DIR} EXCLUDE_FROM_ALL) +endif() + +target_link_libraries(foo PRIVATE nlohmann_json::nlohmann_json) +~~~ + +Of course, you can use replace the lightweight repository with the official one: +https://github.com/nlohmann/json + +The script ./update.py made by @astoeckel automatically download every +nlohmann::json releases and put them into their corresponding git tag. + +See: +- [#2073](https://github.com/nlohmann/json/issues/2073), +- [#732](https://github.com/nlohmann/json/issues/732), +- [#620](https://github.com/nlohmann/json/issues/620), +- [#556](https://github.com/nlohmann/json/issues/556), +- [#482](https://github.com/nlohmann/json/issues/482), +- [#96](https://github.com/nlohmann/json/issues/96) diff --git a/meson.build b/meson.build new file mode 100644 index 0000000..3cc6c76 --- /dev/null +++ b/meson.build @@ -0,0 +1,7 @@ +project('nlohmann_json', 'cpp') + +nlohmann_json_inc = include_directories('include') + +nlohmann_json_dep = declare_dependency( + include_directories : nlohmann_json_inc +) diff --git a/update.py b/update.py new file mode 100755 index 0000000..23ee226 --- /dev/null +++ b/update.py @@ -0,0 +1,64 @@ +#!/usr/bin/env python3 + +import sys, os +import json +import subprocess +import urllib.request +import hashlib + +# Go to the directory this script is stored in +os.chdir(os.path.dirname(os.path.realpath(__file__))) + +# Download release data +releases = json.loads(str(urllib.request.urlopen('https://api.github.com/repos/nlohmann/json/releases').read(), 'utf-8')) + +# Fetch all releases and the corresponding URL +release_url_map = [] +for release in releases: + for asset in release['assets']: + if asset['name'] == 'json.hpp': + release_url_map.append((release['tag_name'], asset['browser_download_url'], release['body'])) + +# List all git tags +process = subprocess.Popen(['git', 'tag'], stdout=subprocess.PIPE) +tags, _ = process.communicate() +tags = set(filter(None, str(tags, 'utf-8').split("\n"))) +print("Releases already contained in this repository are " + str(tags)) + +# Go over the release_url_map in reverse order; if a release is not yet a Git +# tag, download the file, commit and add a tag +did_update = False +for tag, url, body in release_url_map[::-1]: + if not tag in tags: + print("Downloading release " + tag + " from " + url) + os.makedirs('./include', mode=0o777, exist_ok=True) + os.makedirs('./include/nlohmann', mode=0o777, exist_ok=True) + data = urllib.request.urlopen(url).read(); + with open('./include/nlohmann/json.hpp', 'wb') as f: + f.write(data) + + # Try to download the json_fwd.hpp header -- only exists since release + # v3.1.0 + has_json_fwd = False + try: + json_fwd_url = 'https://github.com/nlohmann/json/raw/{}/include/nlohmann/json_fwd.hpp'.format(tag); + print("Trying to download " + json_fwd_url) + data = urllib.request.urlopen(json_fwd_url).read(); + with open('./include/nlohmann/json_fwd.hpp', 'wb') as f: + f.write(data) + has_json_fwd = True + except: + pass + + subprocess.call(['git', 'add', './include/nlohmann/json.hpp']) + if has_json_fwd: + subprocess.call(['git', 'add', './include/nlohmann/json_fwd.hpp']) + subprocess.call(['git', 'commit', '-m', 'Upstream release ' + tag]) + subprocess.call(['git', 'tag', '-a', tag, '-m', body]) + + did_update = True + +# Push the updated Git repository +if did_update: + subprocess.call(['git', 'push', '--tags']) + subprocess.call(['git', 'push']) |