diff options
author | ArthurSonzogni <sonzogniarthur@gmail.com> | 2020-04-29 16:45:05 +0300 |
---|---|---|
committer | ArthurSonzogni <sonzogniarthur@gmail.com> | 2020-06-28 14:34:26 +0300 |
commit | 29433267e8e2dab0a63fe2098f34c31ef6140a5a (patch) | |
tree | 570a7b67f6825f02e66187e26063adee3e375e76 |
Initial commit without calling 'update.py'
-rw-r--r-- | CMakeLists.txt | 14 | ||||
-rw-r--r-- | LICENSE.MIT | 21 | ||||
-rw-r--r-- | README.md | 41 | ||||
-rw-r--r-- | meson.build | 7 | ||||
-rwxr-xr-x | update.py | 64 |
5 files changed, 147 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..d0f6b6d --- /dev/null +++ b/README.md @@ -0,0 +1,41 @@ +# Release-tracking repository for nlohmann/json + +This repository is based on: [astoeckel/json](https://github.com/astoeckel/json) +The goal is to provide a lightweight repository tracking every releases of +[nlohmann/json](https://github.com/nlohmann/json). +This repository is compatible with cmake [FetchContent](https://cmake.org/cmake/help/v3.11/module/FetchContent.html). + +You can depends on nlohmann/json using: + +**Example**: +~~~cmake +include(FetchContent) + +FetchContent_Declare(json + GIT_REPOSITORY https://github.com/ArthurSonzogni/nlohman_json + GIT_TAG no-tag-yet) + +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) +~~~ + +You can replace always replace the URL by the official repository: +https://github.com/nlohmann/json +The only difference is the download size. It will several orders of magnitude +larger. + +This repository is fully autonomous. It updates itself every week using github +actions. + +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..443d900 --- /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']) |