From d73ec27b3d4197a5360416eb5d999a26c4780ede Mon Sep 17 00:00:00 2001 From: Jordan Bayles Date: Wed, 17 Jul 2019 12:59:56 -0700 Subject: [PATCH 1/3] Cleanup versioning strategy Currently, versioning is a mess. CMake and Meson have seperate build version number storage locations, with no way of knowing you need to have both. Plus, due to recent revisions the amalgamate script is broken unless you build first, and may still be broken afterwards. This PR fixes some issues with versioning, and adds comments clarifying what has to be done when doing a release. --- CMakeLists.txt | 12 +++--- CONTRIBUTING.md | 1 - amalgamate.py | 38 ++++++++++--------- .../version.h.in => include/json/version.h | 19 ++++++---- meson.build | 35 ++++++----------- src/lib_json/CMakeLists.txt | 5 +-- version.txt | 1 - 7 files changed, 54 insertions(+), 57 deletions(-) mode change 100644 => 100755 amalgamate.py rename src/lib_json/version.h.in => include/json/version.h (53%) delete mode 100644 version.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 381d08b0a..cbac1b208 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -63,7 +63,13 @@ if(NOT DEFINED CMAKE_BUILD_TYPE) endif() project(JSONCPP - VERSION 1.9.0 # [.[.[.]]] + # Note: version must be updated in three places when doing a release. This + # annoying process ensures that amalgamate, CMake, and meson all report the + # correct version. + # 1. /meson.build + # 2. /include/json/version.h + # 3. /CMakeLists.txt + VERSION 1.9.2 # [.[.[.]]] LANGUAGES CXX) message(STATUS "JsonCpp Version: ${JSONCPP_VERSION_MAJOR}.${JSONCPP_VERSION_MINOR}.${JSONCPP_VERSION_PATCH}") @@ -89,10 +95,6 @@ set(DEBUG_LIBNAME_SUFFIX "" CACHE STRING "Optional suffix to append to the libra set(JSONCPP_USE_SECURE_MEMORY "0" CACHE STRING "-D...=1 to use memory-wiping allocator for STL" ) -# File version.h is only regenerated on CMake configure step -configure_file( "${PROJECT_SOURCE_DIR}/src/lib_json/version.h.in" - "${PROJECT_BINARY_DIR}/include/json/version.h" - NEWLINE_STYLE UNIX ) configure_file( "${PROJECT_SOURCE_DIR}/version.in" "${PROJECT_BINARY_DIR}/version" NEWLINE_STYLE UNIX ) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b7e4ab7af..3e14b2b31 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -26,7 +26,6 @@ Then, LIB_TYPE=shared #LIB_TYPE=static meson --buildtype ${BUILD_TYPE} --default-library ${LIB_TYPE} . build-${LIB_TYPE} - #ninja -v -C build-${LIB_TYPE} test # This stopped working on my Mac. ninja -v -C build-${LIB_TYPE} cd build-${LIB_TYPE} meson test --no-rebuild --print-errorlogs diff --git a/amalgamate.py b/amalgamate.py old mode 100644 new mode 100755 index c12215a8b..7b41e2e5b --- a/amalgamate.py +++ b/amalgamate.py @@ -1,3 +1,5 @@ +#!/usr/bin/env python + """Amalgamate json-cpp library sources into a single source and header file. Works with python2.6+ and python3.4+. @@ -9,6 +11,9 @@ import os.path import sys +INCLUDE_PATH = "include/json" +SRC_PATH = "src/lib_json" + class AmalgamationFile: def __init__(self, top_dir): self.top_dir = top_dir @@ -66,15 +71,15 @@ def amalgamate_source(source_top_dir=None, header.add_text("/// If defined, indicates that the source file is amalgamated") header.add_text("/// to prevent private header inclusion.") header.add_text("#define JSON_IS_AMALGAMATION") - header.add_file("include/json/version.h") - header.add_file("include/json/allocator.h") - header.add_file("include/json/config.h") - header.add_file("include/json/forwards.h") - header.add_file("include/json/features.h") - header.add_file("include/json/value.h") - header.add_file("include/json/reader.h") - header.add_file("include/json/writer.h") - header.add_file("include/json/assertions.h") + header.add_file(os.path.join(INCLUDE_PATH, "version.h")) + header.add_file(os.path.join(INCLUDE_PATH, "allocator.h")) + header.add_file(os.path.join(INCLUDE_PATH, "config.h")) + header.add_file(os.path.join(INCLUDE_PATH, "forwards.h")) + header.add_file(os.path.join(INCLUDE_PATH, "features.h")) + header.add_file(os.path.join(INCLUDE_PATH, "value.h")) + header.add_file(os.path.join(INCLUDE_PATH, "reader.h")) + header.add_file(os.path.join(INCLUDE_PATH, "writer.h")) + header.add_file(os.path.join(INCLUDE_PATH, "assertions.h")) header.add_text("#endif //ifndef JSON_AMALGAMATED_H_INCLUDED") target_header_path = os.path.join(os.path.dirname(target_source_path), header_include_path) @@ -94,8 +99,8 @@ def amalgamate_source(source_top_dir=None, header.add_text("/// If defined, indicates that the source file is amalgamated") header.add_text("/// to prevent private header inclusion.") header.add_text("#define JSON_IS_AMALGAMATION") - header.add_file("include/json/config.h") - header.add_file("include/json/forwards.h") + header.add_file(os.path.join(INCLUDE_PATH, "config.h")) + header.add_file(os.path.join(INCLUDE_PATH, "forwards.h")) header.add_text("#endif //ifndef JSON_FORWARD_AMALGAMATED_H_INCLUDED") target_forward_header_path = os.path.join(os.path.dirname(target_source_path), @@ -116,12 +121,11 @@ def amalgamate_source(source_top_dir=None, #endif """) source.add_text("") - lib_json = "src/lib_json" - source.add_file(os.path.join(lib_json, "json_tool.h")) - source.add_file(os.path.join(lib_json, "json_reader.cpp")) - source.add_file(os.path.join(lib_json, "json_valueiterator.inl")) - source.add_file(os.path.join(lib_json, "json_value.cpp")) - source.add_file(os.path.join(lib_json, "json_writer.cpp")) + source.add_file(os.path.join(SRC_PATH, "json_tool.h")) + source.add_file(os.path.join(SRC_PATH, "json_reader.cpp")) + source.add_file(os.path.join(SRC_PATH, "json_valueiterator.inl")) + source.add_file(os.path.join(SRC_PATH, "json_value.cpp")) + source.add_file(os.path.join(SRC_PATH, "json_writer.cpp")) print("Writing amalgamated source to %r" % target_source_path) source.write_to(target_source_path) diff --git a/src/lib_json/version.h.in b/include/json/version.h similarity index 53% rename from src/lib_json/version.h.in rename to include/json/version.h index 4cf439ccc..75f1e423c 100644 --- a/src/lib_json/version.h.in +++ b/include/json/version.h @@ -1,12 +1,17 @@ -// DO NOT EDIT. This file (and "version") is a template used by the build system -// (either CMake or Meson) to generate a "version.h" header file. #ifndef JSON_VERSION_H_INCLUDED #define JSON_VERSION_H_INCLUDED -#define JSONCPP_VERSION_STRING "@JSONCPP_VERSION@" -#define JSONCPP_VERSION_MAJOR @JSONCPP_VERSION_MAJOR@ -#define JSONCPP_VERSION_MINOR @JSONCPP_VERSION_MINOR@ -#define JSONCPP_VERSION_PATCH @JSONCPP_VERSION_PATCH@ +// Note: version must be updated in three places when doing a release. This +// annoying process ensures that amalgamate, CMake, and meson all report the +// correct version. +// 1. /meson.build +// 2. /include/json/version.h +// 3. /CMakeLists.txt + +#define JSONCPP_VERSION_STRING "1.9.2" +#define JSONCPP_VERSION_MAJOR 1 +#define JSONCPP_VERSION_MINOR 9 +#define JSONCPP_VERSION_PATCH 2 #define JSONCPP_VERSION_QUALIFIER #define JSONCPP_VERSION_HEXA ((JSONCPP_VERSION_MAJOR << 24) \ | (JSONCPP_VERSION_MINOR << 16) \ @@ -15,7 +20,7 @@ #ifdef JSONCPP_USING_SECURE_MEMORY #undef JSONCPP_USING_SECURE_MEMORY #endif -#define JSONCPP_USING_SECURE_MEMORY @JSONCPP_USE_SECURE_MEMORY@ +#define JSONCPP_USING_SECURE_MEMORY 0 // If non-zero, the library zeroes any memory that it has allocated before // it frees its memory. diff --git a/meson.build b/meson.build index 8de947c4c..b3230a3a7 100644 --- a/meson.build +++ b/meson.build @@ -1,7 +1,15 @@ project( 'jsoncpp', 'cpp', - version : '1.9.0', + + # Note: version must be updated in three places when doing a release. This + # annoying process ensures that amalgamate, CMake, and meson all report the + # correct version. + # 1. /meson.build + # 2. /include/json/version.h + # 3. /CMakeLists.txt + + version : '1.9.2', default_options : [ 'buildtype=release', 'cpp_std=c++11', @@ -9,25 +17,6 @@ project( license : 'Public Domain', meson_version : '>= 0.50.0') -jsoncpp_ver_arr = meson.project_version().split('.') -jsoncpp_major_version = jsoncpp_ver_arr[0] -jsoncpp_minor_version = jsoncpp_ver_arr[1] -jsoncpp_patch_version = jsoncpp_ver_arr[2] - -jsoncpp_cdata = configuration_data() -jsoncpp_cdata.set('JSONCPP_VERSION', meson.project_version()) -jsoncpp_cdata.set('JSONCPP_VERSION_MAJOR', jsoncpp_major_version) -jsoncpp_cdata.set('JSONCPP_VERSION_MINOR', jsoncpp_minor_version) -jsoncpp_cdata.set('JSONCPP_VERSION_PATCH', jsoncpp_patch_version) -jsoncpp_cdata.set('JSONCPP_USE_SECURE_MEMORY',0) - -jsoncpp_gen_sources = configure_file( - input : 'src/lib_json/version.h.in', - output : 'version.h', - configuration : jsoncpp_cdata, - install : true, - install_dir : join_paths(get_option('prefix'), get_option('includedir'), 'json') -) jsoncpp_headers = [ 'include/json/allocator.h', @@ -39,6 +28,7 @@ jsoncpp_headers = [ 'include/json/json.h', 'include/json/reader.h', 'include/json/value.h', + 'include/json/version.h', 'include/json/writer.h'] jsoncpp_include_directories = include_directories('include') @@ -56,8 +46,7 @@ endif jsoncpp_lib = library( 'jsoncpp', - [ jsoncpp_gen_sources, - jsoncpp_headers, + [ jsoncpp_headers, 'src/lib_json/json_tool.h', 'src/lib_json/json_reader.cpp', 'src/lib_json/json_value.cpp', @@ -79,7 +68,7 @@ jsoncpp_dep = declare_dependency( include_directories : jsoncpp_include_directories, link_with : jsoncpp_lib, version : meson.project_version(), - sources : jsoncpp_gen_sources) + ) # tests python = import('python3').find_python() diff --git a/src/lib_json/CMakeLists.txt b/src/lib_json/CMakeLists.txt index 2392092af..0fa2f5953 100644 --- a/src/lib_json/CMakeLists.txt +++ b/src/lib_json/CMakeLists.txt @@ -45,9 +45,9 @@ set( PUBLIC_HEADERS ${JSONCPP_INCLUDE_DIR}/json/features.h ${JSONCPP_INCLUDE_DIR}/json/value.h ${JSONCPP_INCLUDE_DIR}/json/reader.h + ${JSONCPP_INCLUDE_DIR}/json/version.h ${JSONCPP_INCLUDE_DIR}/json/writer.h ${JSONCPP_INCLUDE_DIR}/json/assertions.h - ${PROJECT_BINARY_DIR}/include/json/version.h ) source_group( "Public API" FILES ${PUBLIC_HEADERS} ) @@ -57,8 +57,7 @@ set(jsoncpp_sources json_reader.cpp json_valueiterator.inl json_value.cpp - json_writer.cpp - version.h.in) + json_writer.cpp) # Install instructions for this target if(JSONCPP_WITH_CMAKE_PACKAGE) diff --git a/version.txt b/version.txt deleted file mode 100644 index bfa363e76..000000000 --- a/version.txt +++ /dev/null @@ -1 +0,0 @@ -1.8.4 From f3004785681289926036eae98bcbfe8bf6d10784 Mon Sep 17 00:00:00 2001 From: Jordan Bayles Date: Wed, 17 Jul 2019 13:06:29 -0700 Subject: [PATCH 2/3] Run clang format --- include/json/reader.h | 2 +- include/json/version.h | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/json/reader.h b/include/json/reader.h index ce216a3dc..d737ecfa0 100644 --- a/include/json/reader.h +++ b/include/json/reader.h @@ -376,7 +376,7 @@ bool JSON_API parseFromStream(CharReader::Factory const&, /** \brief Read from 'sin' into 'root'. * * Always keep comments from the input JSON. - * + * * This can be used to read a file into a particular sub-object. * For example: * \code diff --git a/include/json/version.h b/include/json/version.h index 75f1e423c..56f6f5edc 100644 --- a/include/json/version.h +++ b/include/json/version.h @@ -13,9 +13,9 @@ #define JSONCPP_VERSION_MINOR 9 #define JSONCPP_VERSION_PATCH 2 #define JSONCPP_VERSION_QUALIFIER -#define JSONCPP_VERSION_HEXA ((JSONCPP_VERSION_MAJOR << 24) \ - | (JSONCPP_VERSION_MINOR << 16) \ - | (JSONCPP_VERSION_PATCH << 8)) +#define JSONCPP_VERSION_HEXA \ + ((JSONCPP_VERSION_MAJOR << 24) | (JSONCPP_VERSION_MINOR << 16) | \ + (JSONCPP_VERSION_PATCH << 8)) #ifdef JSONCPP_USING_SECURE_MEMORY #undef JSONCPP_USING_SECURE_MEMORY From 35cf0db1169f0c8f04113da767098773c9a47b66 Mon Sep 17 00:00:00 2001 From: Jordan Bayles Date: Wed, 17 Jul 2019 15:26:51 -0700 Subject: [PATCH 3/3] Update SOVERSION.... --- CMakeLists.txt | 3 ++- include/json/version.h | 1 + meson.build | 4 ++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cbac1b208..b4eb83039 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -69,11 +69,12 @@ project(JSONCPP # 1. /meson.build # 2. /include/json/version.h # 3. /CMakeLists.txt + # IMPORTANT: also update the SOVERSION!! VERSION 1.9.2 # [.[.[.]]] LANGUAGES CXX) message(STATUS "JsonCpp Version: ${JSONCPP_VERSION_MAJOR}.${JSONCPP_VERSION_MINOR}.${JSONCPP_VERSION_PATCH}") -set( JSONCPP_SOVERSION 21 ) +set( JSONCPP_SOVERSION 22 ) option(JSONCPP_WITH_TESTS "Compile and (for jsoncpp_check) run JsonCpp test executables" ON) option(JSONCPP_WITH_POST_BUILD_UNITTEST "Automatically run unit-tests as a post build step" ON) diff --git a/include/json/version.h b/include/json/version.h index 56f6f5edc..ff94372b0 100644 --- a/include/json/version.h +++ b/include/json/version.h @@ -7,6 +7,7 @@ // 1. /meson.build // 2. /include/json/version.h // 3. /CMakeLists.txt +// IMPORTANT: also update the SOVERSION!! #define JSONCPP_VERSION_STRING "1.9.2" #define JSONCPP_VERSION_MAJOR 1 diff --git a/meson.build b/meson.build index b3230a3a7..d1f49897a 100644 --- a/meson.build +++ b/meson.build @@ -8,7 +8,7 @@ project( # 1. /meson.build # 2. /include/json/version.h # 3. /CMakeLists.txt - + # IMPORTANT: also update the SOVERSION!! version : '1.9.2', default_options : [ 'buildtype=release', @@ -51,7 +51,7 @@ jsoncpp_lib = library( 'src/lib_json/json_reader.cpp', 'src/lib_json/json_value.cpp', 'src/lib_json/json_writer.cpp'], - soversion : 21, + soversion : 22, install : true, include_directories : jsoncpp_include_directories, cpp_args: dll_export_flag)