From 6bb4ddcdd85e06101ef22acc5e927919fa99d4af Mon Sep 17 00:00:00 2001 From: Jerry Jacobs Date: Fri, 22 Apr 2016 22:25:34 +0200 Subject: [PATCH 01/20] Initial integration of download from cmake, add cpack config file --- CMakeLists.txt | 30 ++++++++++++++++++++++++++---- cmake/CPackConfig.txt | 27 +++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 4 deletions(-) create mode 100644 cmake/CPackConfig.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index f85859c..213519e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,6 +54,11 @@ endif() set(MPACK_FILE "mpack-amalgamation-${MPACK_VERSION}.tar.gz") set(MPACK_DIR "${CONTRIB_DIR}/mpack-amalgamation-${MPACK_VERSION}") +file(DOWNLOAD + "https://github.com/ludocode/mpack/releases/download/v${MPACK_VERSION}/${MPACK_FILE}" + "${CMAKE_SOURCE_DIR}/contrib/${MPACK_FILE}" +) + if(NOT EXISTS "${CMAKE_SOURCE_DIR}/contrib/${MPACK_FILE}") message(FATAL_ERROR "\nMPack source is missing: contrib/${MPACK_FILE}\nTo build from the repository, you need to fetch dependencies with tools/fetch.sh") endif() @@ -72,6 +77,11 @@ include_directories(SYSTEM ${CMAKE_BINARY_DIR} ${MPACK_DIR}/src) set(RAPIDJSON_FILE "rapidjson-${RAPIDJSON_COMMIT}.tar.gz") set(RAPIDJSON_DIR "${CONTRIB_DIR}/rapidjson-${RAPIDJSON_COMMIT}") +file(DOWNLOAD + "https://github.com/miloyip/rapidjson/archive/${RAPIDJSON_COMMIT}.tar.gz" + "${CMAKE_SOURCE_DIR}/contrib/${RAPIDJSON_FILE}" +) + if(NOT EXISTS "${CMAKE_SOURCE_DIR}/contrib/${RAPIDJSON_FILE}") message(FATAL_ERROR "\nRapidJSON source is missing: contrib/${RAPIDJSON_FILE}\nTo build from the repository, you need to fetch dependencies with tools/fetch.sh") endif() @@ -86,6 +96,11 @@ include_directories(SYSTEM ${RAPIDJSON_DIR}/include) set(LIBB64_FILE "libb64-${LIBB64_VERSION}.zip") set(LIBB64_DIR "${CONTRIB_DIR}/libb64-${LIBB64_VERSION}") +file(DOWNLOAD + "http://downloads.sourceforge.net/project/libb64/libb64/libb64/${LIBB64_FILE}?use_mirror=autoselect" + "${CMAKE_SOURCE_DIR}/contrib/${LIBB64_FILE}" +) + if(NOT EXISTS "${CMAKE_SOURCE_DIR}/contrib/${LIBB64_FILE}") message(FATAL_ERROR "\nlibb64 source is missing: contrib/${LIBB64_FILE}\nTo build from the repository, you need to fetch dependencies with tools/fetch.sh") endif() @@ -109,14 +124,18 @@ add_executable(json2msgpack src/json2msgpack.cpp ${MPACK_SRCS} ${LIBB64_SRCS}) install(TARGETS msgpack2json json2msgpack DESTINATION bin) -install(FILES ${CMAKE_SOURCE_DIR}/docs/msgpack2json.1 DESTINATION ${CMAKE_INSTALL_PREFIX}/man/man1) -install(FILES ${CMAKE_SOURCE_DIR}/docs/json2msgpack.1 DESTINATION ${CMAKE_INSTALL_PREFIX}/man/man1) +# Man pages if(NOT EXISTS "${CMAKE_SOURCE_DIR}/docs/msgpack2json.1") - message(FATAL_ERROR "\nmsgpack2json man page is missing: docs/msgpack2json.1\nTo build from the repository, you need to generate manpages with tools/man.sh") + message(WARNING "\nmsgpack2json man page is missing: docs/msgpack2json.1\nTo build from the repository, you need to generate manpages with tools/man.sh") +else() + install(FILES ${CMAKE_SOURCE_DIR}/docs/msgpack2json.1 DESTINATION ${CMAKE_INSTALL_PREFIX}/man/man1) endif() + if(NOT EXISTS "${CMAKE_SOURCE_DIR}/docs/json2msgpack.1") - message(FATAL_ERROR "\njson2msgpack man page is missing: docs/json2msgpack.1\nTo build from the repository, you need to generate manpages with tools/man.sh") + message(WARNING "\njson2msgpack man page is missing: docs/json2msgpack.1\nTo build from the repository, you need to generate manpages with tools/man.sh") +else() + install(FILES ${CMAKE_SOURCE_DIR}/docs/json2msgpack.1 DESTINATION ${CMAKE_INSTALL_PREFIX}/man/man1) endif() @@ -153,3 +172,6 @@ add_test("json2msgpack-base64-mixed-bin" ${COMPARE} ${TESTS_DIR}/base64-bin #add_test("json2msgpack-base64-bin" ${COMPARE_SCRIPT} ${TESTS_DIR}/base64-bin.mp valgrind ./json2msgpack -bi ${TESTS_DIR}/base64-prefix.json) #add_test("json2msgpack-base64-bin-lax" ${COMPARE_SCRIPT} ${TESTS_DIR}/base64-bin.mp valgrind ./json2msgpack -lbi ${TESTS_DIR}/base64-prefix-lax.json) + +include(cmake/CPackConfig.txt) +include(CPack) diff --git a/cmake/CPackConfig.txt b/cmake/CPackConfig.txt new file mode 100644 index 0000000..6ab8555 --- /dev/null +++ b/cmake/CPackConfig.txt @@ -0,0 +1,27 @@ +SET(CPACK_CMAKE_GENERATOR "Unix Makefiles") +#SET(CPACK_GENERATOR "STGZ;TGZ;TZ") +#SET(CPACK_INSTALL_CMAKE_PROJECTS "/home/andy/vtk/CMake-bin;CMake;ALL;/") +#SET(CPACK_NSIS_DISPLAY_NAME "CMake 2.5") +#SET(CPACK_OUTPUT_CONFIG_FILE "/home/andy/vtk/CMake-bin/CPackConfig.cmake") +#SET(CPACK_PACKAGE_DESCRIPTION_FILE "/home/andy/vtk/CMake/Copyright.txt") +#SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "CMake is a build tool") +#SET(CPACK_PACKAGE_EXECUTABLES "ccmake;CMake") +#SET(CPACK_PACKAGE_FILE_NAME "cmake-2.5.0-Linux-i686") +#SET(CPACK_PACKAGE_INSTALL_DIRECTORY "CMake 2.5") +#SET(CPACK_PACKAGE_INSTALL_REGISTRY_KEY "CMake 2.5.0") +#SET(CPACK_PACKAGE_NAME "CMake") +#SET(CPACK_PACKAGE_VENDOR "Kitware") +#SET(CPACK_PACKAGE_VERSION "2.5.0") +#SET(CPACK_PACKAGE_VERSION_MAJOR "2") +#SET(CPACK_PACKAGE_VERSION_MINOR "5") +#SET(CPACK_PACKAGE_VERSION_PATCH "0") +#SET(CPACK_RESOURCE_FILE_LICENSE "/home/andy/vtk/CMake/Copyright.txt") +#SET(CPACK_RESOURCE_FILE_README "/home/andy/vtk/CMake/Templates/CPack.GenericDescription.txt") +#SET(CPACK_RESOURCE_FILE_WELCOME "/home/andy/vtk/CMake/Templates/CPack.GenericWelcome.txt") +#SET(CPACK_SOURCE_GENERATOR "TGZ;TZ") +#SET(CPACK_SOURCE_OUTPUT_CONFIG_FILE "/home/andy/vtk/CMake-bin/CPackSourceConfig.cmake") +#SET(CPACK_SOURCE_PACKAGE_FILE_NAME "cmake-2.5.0") +#SET(CPACK_SOURCE_STRIP_FILES "") +#SET(CPACK_STRIP_FILES "bin/ccmake;bin/cmake;bin/cpack;bin/ctest") +#SET(CPACK_SYSTEM_NAME "Linux-i686") +#SET(CPACK_TOPLEVEL_TAG "Linux-i686") From 2d4e4fcce5b07599fe75b2013c7560668c95c5e4 Mon Sep 17 00:00:00 2001 From: Jerry Jacobs Date: Fri, 22 Apr 2016 22:42:46 +0200 Subject: [PATCH 02/20] Initial work on debian package generation when /etc/debian_version is detected --- CMakeLists.txt | 3 +++ cmake/CPackConfig.txt | 7 ++++++- cmake/OSDetection.txt | 6 ++++++ 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 cmake/OSDetection.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 213519e..5c61a05 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,8 @@ project(msgpack2json) set(CONTRIB_DIR ${CMAKE_BINARY_DIR}/contrib) file(MAKE_DIRECTORY ${CONTRIB_DIR}) + + if(NOT CMAKE_BUILD_TYPE) message(STATUS "No build type selected, default to Release") set(CMAKE_BUILD_TYPE "Release") @@ -173,5 +175,6 @@ add_test("json2msgpack-base64-mixed-bin" ${COMPARE} ${TESTS_DIR}/base64-bin #add_test("json2msgpack-base64-bin" ${COMPARE_SCRIPT} ${TESTS_DIR}/base64-bin.mp valgrind ./json2msgpack -bi ${TESTS_DIR}/base64-prefix.json) #add_test("json2msgpack-base64-bin-lax" ${COMPARE_SCRIPT} ${TESTS_DIR}/base64-bin.mp valgrind ./json2msgpack -lbi ${TESTS_DIR}/base64-prefix-lax.json) +include(cmake/OSDetection.txt) include(cmake/CPackConfig.txt) include(CPack) diff --git a/cmake/CPackConfig.txt b/cmake/CPackConfig.txt index 6ab8555..ae7f3c5 100644 --- a/cmake/CPackConfig.txt +++ b/cmake/CPackConfig.txt @@ -1,4 +1,9 @@ -SET(CPACK_CMAKE_GENERATOR "Unix Makefiles") +set(CPACK_CMAKE_GENERATOR "Unix Makefiles") +if(${CMAKE_SYSTEM_VARIANT} STREQUAL "Debian") + set(CPACK_GENERATOR "DEB") + set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Jerry Jacobs") + set(CPACK_PACKAGE_CONTACT "jerry.jacobs@xor-gate.org") +endif() #SET(CPACK_GENERATOR "STGZ;TGZ;TZ") #SET(CPACK_INSTALL_CMAKE_PROJECTS "/home/andy/vtk/CMake-bin;CMake;ALL;/") #SET(CPACK_NSIS_DISPLAY_NAME "CMake 2.5") diff --git a/cmake/OSDetection.txt b/cmake/OSDetection.txt new file mode 100644 index 0000000..58a152e --- /dev/null +++ b/cmake/OSDetection.txt @@ -0,0 +1,6 @@ +if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") + if(EXISTS "/etc/debian_version") + message(STATUS "Debian-based Linux OS detected") + set(CMAKE_SYSTEM_VARIANT "Debian") + endif() +endif() From 29139ab9a9e823fd3a7067a281f27f7ebffddeaa Mon Sep 17 00:00:00 2001 From: Jerry Jacobs Date: Fri, 22 Apr 2016 22:56:53 +0200 Subject: [PATCH 03/20] Fixup correct package name, version and arch generation --- CMakeLists.txt | 8 ++++++-- cmake/CPackConfig.txt | 5 +++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5c61a05..5c5bf3e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,11 +6,15 @@ include(CheckCXXCompilerFlag) project(msgpack2json) +# compat with cmake > 3.0, this should be autodetected with the git command (tag) or a released file +set(PROJECT_VERSION_MAJOR 0) +set(PROJECT_VERSION_MINOR 3) +set(PROJECT_VERSION_PATCH 1) +set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}") + set(CONTRIB_DIR ${CMAKE_BINARY_DIR}/contrib) file(MAKE_DIRECTORY ${CONTRIB_DIR}) - - if(NOT CMAKE_BUILD_TYPE) message(STATUS "No build type selected, default to Release") set(CMAKE_BUILD_TYPE "Release") diff --git a/cmake/CPackConfig.txt b/cmake/CPackConfig.txt index ae7f3c5..329ee7c 100644 --- a/cmake/CPackConfig.txt +++ b/cmake/CPackConfig.txt @@ -1,8 +1,13 @@ set(CPACK_CMAKE_GENERATOR "Unix Makefiles") if(${CMAKE_SYSTEM_VARIANT} STREQUAL "Debian") set(CPACK_GENERATOR "DEB") + set(CPACK_PACKAGE_NAME "msgpack-tools") + string(TOLOWER "${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}" CPACK_SYSTEM_NAME) + set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${PROJECT_VERSION}-${CPACK_SYSTEM_NAME}" ) + set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "https://github.com/ludocode/msgpack-tools") set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Jerry Jacobs") set(CPACK_PACKAGE_CONTACT "jerry.jacobs@xor-gate.org") + set(CPACK_DEBIAN_PACKAGE_DESCRIPTION "Command-line tools for converting between MessagePack and JSON") endif() #SET(CPACK_GENERATOR "STGZ;TGZ;TZ") #SET(CPACK_INSTALL_CMAKE_PROJECTS "/home/andy/vtk/CMake-bin;CMake;ALL;/") From e6bd37ad14635e087eab4ec05dc57b8194cf1f60 Mon Sep 17 00:00:00 2001 From: Jerry Jacobs Date: Fri, 22 Apr 2016 23:02:53 +0200 Subject: [PATCH 04/20] CPackDeb: Fix package version meta, strip binaries when emitting into cpack --- cmake/CPackConfig.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cmake/CPackConfig.txt b/cmake/CPackConfig.txt index 329ee7c..ae4823f 100644 --- a/cmake/CPackConfig.txt +++ b/cmake/CPackConfig.txt @@ -1,7 +1,9 @@ +set(CPACK_STRIP_FILES True) set(CPACK_CMAKE_GENERATOR "Unix Makefiles") if(${CMAKE_SYSTEM_VARIANT} STREQUAL "Debian") set(CPACK_GENERATOR "DEB") set(CPACK_PACKAGE_NAME "msgpack-tools") + set(CPACK_PACKAGE_VERSION "${PROJECT_VERSION}") string(TOLOWER "${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}" CPACK_SYSTEM_NAME) set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${PROJECT_VERSION}-${CPACK_SYSTEM_NAME}" ) set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "https://github.com/ludocode/msgpack-tools") From 3c3dec9bd6953fa4d6211afbc14f1267c8a93ab8 Mon Sep 17 00:00:00 2001 From: Nicholas Fraser Date: Sat, 16 Jul 2016 10:58:34 -0400 Subject: [PATCH 05/20] Added CHANGELOG.md --- CHANGELOG.md | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..4639b84 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,36 @@ +msgpack-tools v0.4 +------------------ + +Changes: + +- Fixed issues with stream parsing (e.g. piping to/from netcat) +- Fixed man page installation directory (`prefix/share/man`) + +msgpack-tools v0.3.1 +-------------------- + +Changes: + +- Fixed build errors on old compilers that default to C89 + +msgpack-tools v0.3 +------------------ + +Changes: + +- Switched JSON parsing library to RapidJSON +- Updated [`configure`](https://github.com/nemequ/configure-cmake) script to support `LDFLAGS` and non-bash shells + +msgpack-tools v0.2 +------------------ + +Changes: + +- Renamed project to **msgpack-tools** +- Added `./configure` CMake wrapper from [nemequ/configure-cmake](https://github.com/nemequ/configure-cmake) +- Updated MPack and YAJL versions + +msgpack2json v0.1 +----------------- + +Initial release From 396b832a822591e87c1a01bfeaaf7ae1d77b1adc Mon Sep 17 00:00:00 2001 From: Nicholas Fraser Date: Sat, 16 Jul 2016 12:19:39 -0400 Subject: [PATCH 06/20] Fixed incorrect buffer size in msgpack2json This also changes json2msgpack to use the same size buffer instead of a stack allocation. --- src/common.h | 2 ++ src/json2msgpack.cpp | 4 +++- src/msgpack2json.cpp | 4 ++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/common.h b/src/common.h index e2c43bd..8d0536e 100644 --- a/src/common.h +++ b/src/common.h @@ -41,4 +41,6 @@ extern "C" { #define VERSION "0.4" +#define BUFFER_SIZE 65536 + #endif diff --git a/src/json2msgpack.cpp b/src/json2msgpack.cpp index 7dbecfe..3c81ed6 100644 --- a/src/json2msgpack.cpp +++ b/src/json2msgpack.cpp @@ -223,8 +223,9 @@ static bool output(options_t* options, Document& document) { out_file = stdout; } + char* buffer = (char*)malloc(BUFFER_SIZE); mpack_writer_t writer; - mpack_writer_init_stack(&writer); + mpack_writer_init(&writer, buffer, BUFFER_SIZE); mpack_writer_set_context(&writer, out_file); mpack_writer_set_flush(&writer, flush); @@ -233,6 +234,7 @@ static bool output(options_t* options, Document& document) { mpack_error_t error = mpack_writer_destroy(&writer); if (out_file != stdout) fclose(out_file); + free(buffer); return error == mpack_ok; } diff --git a/src/msgpack2json.cpp b/src/msgpack2json.cpp index 31eaa54..b696687 100644 --- a/src/msgpack2json.cpp +++ b/src/msgpack2json.cpp @@ -261,8 +261,8 @@ static bool convert(options_t* options) { mpack_reader_set_fill(&reader, fill); mpack_reader_set_context(&reader, in_file); - char* buffer = (char*)malloc(65536); - FileWriteStream stream(out_file, buffer, sizeof(buffer)); + char* buffer = (char*)malloc(BUFFER_SIZE); + FileWriteStream stream(out_file, buffer, BUFFER_SIZE); bool ret; if (options->pretty) { From f8237f19ee9ecad9284d93348bda006e22ec035e Mon Sep 17 00:00:00 2001 From: Nicholas Fraser Date: Sat, 16 Jul 2016 11:16:58 -0400 Subject: [PATCH 07/20] Removed top-level array/map requirement Fixes #3 --- CHANGELOG.md | 8 ++++++++ CMakeLists.txt | 5 +++++ src/msgpack2json.cpp | 44 +++++++++++++++++++++-------------------- tests/value-int.json | 1 + tests/value-int.mp | 1 + tests/value-string.json | 1 + tests/value-string.mp | 1 + tools/test-compare.sh | 2 +- 8 files changed, 41 insertions(+), 22 deletions(-) create mode 100644 tests/value-int.json create mode 100644 tests/value-int.mp create mode 100644 tests/value-string.json create mode 100644 tests/value-string.mp diff --git a/CHANGELOG.md b/CHANGELOG.md index 4639b84..4480590 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +Unreleased +---------- + +Changes: + +- Removed top-level array/map requirement +- Fixed incorrect buffer sizes + msgpack-tools v0.4 ------------------ diff --git a/CMakeLists.txt b/CMakeLists.txt index ad98f7b..7cc8f4e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -148,5 +148,10 @@ add_test("json2msgpack-base64-detect-bin-one" ${COMPARE} ${TESTS_DIR}/base64-bin add_test("json2msgpack-base64-mixed-partial" ${COMPARE} ${TESTS_DIR}/base64-partial-ext.mp ${VALGRIND} ./json2msgpack -bB 50 -i ${TESTS_DIR}/base64-mixed.json) add_test("json2msgpack-base64-mixed-bin" ${COMPARE} ${TESTS_DIR}/base64-bin-ext.mp ${VALGRIND} ./json2msgpack -bB 22 -i ${TESTS_DIR}/base64-mixed.json) +add_test("json2msgpack-value-string" ${COMPARE} ${TESTS_DIR}/value-string.mp ${VALGRIND} ./json2msgpack -i ${TESTS_DIR}/value-string.json) +add_test("json2msgpack-value-int" ${COMPARE} ${TESTS_DIR}/value-int.mp ${VALGRIND} ./json2msgpack -i ${TESTS_DIR}/value-int.json) +add_test("msgpack2json-value-string" ${COMPARE} ${TESTS_DIR}/value-string.json ${VALGRIND} ./msgpack2json -i ${TESTS_DIR}/value-string.mp) +add_test("msgpack2json-value-int" ${COMPARE} ${TESTS_DIR}/value-int.json ${VALGRIND} ./msgpack2json -i ${TESTS_DIR}/value-int.mp) + #add_test("json2msgpack-base64-bin" ${COMPARE_SCRIPT} ${TESTS_DIR}/base64-bin.mp valgrind ./json2msgpack -bi ${TESTS_DIR}/base64-prefix.json) #add_test("json2msgpack-base64-bin-lax" ${COMPARE_SCRIPT} ${TESTS_DIR}/base64-bin.mp valgrind ./json2msgpack -lbi ${TESTS_DIR}/base64-prefix-lax.json) diff --git a/src/msgpack2json.cpp b/src/msgpack2json.cpp index b696687..831dd58 100644 --- a/src/msgpack2json.cpp +++ b/src/msgpack2json.cpp @@ -145,17 +145,11 @@ static bool base64_ext(mpack_reader_t* reader, WriterType& writer, options_t* op } template -static bool element(mpack_reader_t* reader, WriterType& writer, options_t* options, int depth) { +static bool element(mpack_reader_t* reader, WriterType& writer, options_t* options) { const mpack_tag_t tag = mpack_read_tag(reader); if (mpack_reader_error(reader) != mpack_ok) return false; - if (!options->debug && depth == 0 && (tag.type != mpack_type_map && tag.type != mpack_type_array)) { - fprintf(stderr, "%s: Top-level object must be a map or array. Try debug viewing mode (-d)\n", options->command); - return false; - } - - // TODO check not depth zero switch (tag.type) { case mpack_type_bool: return writer.Bool(tag.v.b); case mpack_type_nil: return writer.Null(); @@ -199,7 +193,7 @@ static bool element(mpack_reader_t* reader, WriterType& writer, options_t* optio if (!writer.StartArray()) return false; for (size_t i = 0; i < tag.v.l; ++i) - if (!element(reader, writer, options, depth + 1)) + if (!element(reader, writer, options)) return false; mpack_done_array(reader); return writer.EndArray(); @@ -210,7 +204,7 @@ static bool element(mpack_reader_t* reader, WriterType& writer, options_t* optio for (size_t i = 0; i < tag.v.l; ++i) { if (options->debug) { - element(reader, writer, options, depth + 1); + element(reader, writer, options); } else { uint32_t len = mpack_expect_str(reader); if (mpack_reader_error(reader) != mpack_ok) { @@ -221,7 +215,7 @@ static bool element(mpack_reader_t* reader, WriterType& writer, options_t* optio return false; } - if (!element(reader, writer, options, depth + 1)) + if (!element(reader, writer, options)) return false; } mpack_done_map(reader); @@ -261,19 +255,27 @@ static bool convert(options_t* options) { mpack_reader_set_fill(&reader, fill); mpack_reader_set_context(&reader, in_file); + bool ret; char* buffer = (char*)malloc(BUFFER_SIZE); - FileWriteStream stream(out_file, buffer, BUFFER_SIZE); + { + FileWriteStream stream(out_file, buffer, BUFFER_SIZE); - bool ret; - if (options->pretty) { - PrettyWriter writer(stream); - ret = element(&reader, writer, options, 0); - // RapidJSON's PrettyWriter does not add a final - // newline at the end of the JSON - putc('\n', out_file); - } else { - Writer writer(stream); - ret = element(&reader, writer, options, 0); + if (options->pretty) { + PrettyWriter writer(stream); + ret = element(&reader, writer, options); + + // RapidJSON's PrettyWriter does not add a final + // newline at the end of the JSON + putc('\n', out_file); + + } else { + Writer writer(stream); + ret = element(&reader, writer, options); + } + + // Writer/FileWriteStream do not flush when writing standalone values: + // https://github.com/miloyip/rapidjson/issues/684 + stream.Flush(); } free(buffer); diff --git a/tests/value-int.json b/tests/value-int.json new file mode 100644 index 0000000..7813681 --- /dev/null +++ b/tests/value-int.json @@ -0,0 +1 @@ +5 \ No newline at end of file diff --git a/tests/value-int.mp b/tests/value-int.mp new file mode 100644 index 0000000..b0b2b1c --- /dev/null +++ b/tests/value-int.mp @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/tests/value-string.json b/tests/value-string.json new file mode 100644 index 0000000..45021e7 --- /dev/null +++ b/tests/value-string.json @@ -0,0 +1 @@ +"OK" \ No newline at end of file diff --git a/tests/value-string.mp b/tests/value-string.mp new file mode 100644 index 0000000..e9a89b7 --- /dev/null +++ b/tests/value-string.mp @@ -0,0 +1 @@ +˘OK \ No newline at end of file diff --git a/tools/test-compare.sh b/tools/test-compare.sh index e857063..97e0f89 100755 --- a/tools/test-compare.sh +++ b/tools/test-compare.sh @@ -12,4 +12,4 @@ if [ $RESULT -ne 0 ]; then exit 1 fi -diff "$EXPECTED" "test-out.tmp" +diff -u "$EXPECTED" "test-out.tmp" From 9a232b898374caa2e17b6d2b89220f39ae37a2dc Mon Sep 17 00:00:00 2001 From: Nicholas Fraser Date: Sat, 16 Jul 2016 14:53:25 -0400 Subject: [PATCH 08/20] Bumped RapidJSON version to latest master, 369de87 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7cc8f4e..a57ef5b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,7 +33,7 @@ else() endif() set(MPACK_COMMIT "8c13a0d7f8a1232a189634768b94740861cbaf3e") -set(RAPIDJSON_COMMIT "75d0e4ff652769309052bbbb3745da12a572af9a") +set(RAPIDJSON_COMMIT "369de87e5d7da05786731a712f25ab9b46c4b0ce") set(LIBB64_VERSION "1.2.1") if(CMAKE_BUILD_TOOL MATCHES "(msdev|devenv|nmake)") From 70c760f16f18b0dc17e585cfa95dc5f894fc1868 Mon Sep 17 00:00:00 2001 From: Nicholas Fraser Date: Sat, 16 Jul 2016 17:45:51 -0400 Subject: [PATCH 09/20] Added build badges for each branch --- README.md | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 59441e2..d93cb0f 100644 --- a/README.md +++ b/README.md @@ -10,9 +10,14 @@ They can be used for dumping MessagePack from a file or web API to a human-reada ## Build Status -| [Travis-CI](https://travis-ci.org/) | -| :-------: | -| [![Build Status](https://travis-ci.org/ludocode/msgpack-tools.svg?branch=master)](https://travis-ci.org/ludocode/msgpack-tools/branches) | +[travis-home]: https://travis-ci.org/ +[travis-msgpack-tools]: https://travis-ci.org/ludocode/msgpack-tools/branches + + +| Branch | [Travis-CI][travis-home] | +| :-------: | :-------: | +| _master_ | [Build Status][travis-msgpack-tools] | +| _develop_ | [Build Status][travis-msgpack-tools] | ## Examples From bd0305d351e8978c00f7d0237781a9093fdb1524 Mon Sep 17 00:00:00 2001 From: Nicholas Fraser Date: Sat, 16 Jul 2016 18:25:22 -0400 Subject: [PATCH 10/20] Fixed build issues with CMake downloading dependencies --- CMakeLists.txt | 2 +- cmake/CPackConfig.txt | 2 +- tools/ci.sh | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9051fc9..a46ff26 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -61,7 +61,7 @@ set(MPACK_FILE "mpack-${MPACK_COMMIT}.tar.gz") set(MPACK_DIR "${CONTRIB_DIR}/mpack-${MPACK_COMMIT}") file(DOWNLOAD - "https://github.com/ludocode/mpack/releases/download/v${MPACK_VERSION}/${MPACK_FILE}" + "https://github.com/ludocode/mpack/archive/${MPACK_COMMIT}.tar.gz" "${CMAKE_SOURCE_DIR}/contrib/${MPACK_FILE}" ) diff --git a/cmake/CPackConfig.txt b/cmake/CPackConfig.txt index ae4823f..2cd393c 100644 --- a/cmake/CPackConfig.txt +++ b/cmake/CPackConfig.txt @@ -1,6 +1,6 @@ set(CPACK_STRIP_FILES True) set(CPACK_CMAKE_GENERATOR "Unix Makefiles") -if(${CMAKE_SYSTEM_VARIANT} STREQUAL "Debian") +if("${CMAKE_SYSTEM_VARIANT}" STREQUAL "Debian") set(CPACK_GENERATOR "DEB") set(CPACK_PACKAGE_NAME "msgpack-tools") set(CPACK_PACKAGE_VERSION "${PROJECT_VERSION}") diff --git a/tools/ci.sh b/tools/ci.sh index 5e615e5..f6f3e65 100755 --- a/tools/ci.sh +++ b/tools/ci.sh @@ -8,7 +8,6 @@ else CMAKE_BUILD_TYPE=Release fi -tools/fetch.sh || exit $? tools/man.sh || exit $? mkdir -p build From d535aaa8c7f0d4fb9678d262977d2d64e86c4153 Mon Sep 17 00:00:00 2001 From: Nicholas Fraser Date: Sat, 16 Jul 2016 18:30:34 -0400 Subject: [PATCH 11/20] Made CMake not re-download dependencies --- CMakeLists.txt | 48 +++++++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a46ff26..9f6388c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -59,14 +59,16 @@ endif() set(MPACK_FILE "mpack-${MPACK_COMMIT}.tar.gz") set(MPACK_DIR "${CONTRIB_DIR}/mpack-${MPACK_COMMIT}") +set(MPACK_URL "https://github.com/ludocode/mpack/archive/${MPACK_COMMIT}.tar.gz") -file(DOWNLOAD - "https://github.com/ludocode/mpack/archive/${MPACK_COMMIT}.tar.gz" - "${CMAKE_SOURCE_DIR}/contrib/${MPACK_FILE}" -) - -if(NOT EXISTS "${CMAKE_SOURCE_DIR}/contrib/${MPACK_FILE}") - message(FATAL_ERROR "\nMPack source is missing: contrib/${MPACK_FILE}\nTo build from the repository, you need to fetch dependencies with tools/fetch.sh") +if(EXISTS "${CMAKE_SOURCE_DIR}/contrib/${MPACK_FILE}") + message(STATUS "Found package: ${MPACK_FILE}") +else() + message(STATUS "Downloading: ${MPACK_FILE}") + file(DOWNLOAD ${MPACK_URL} "${CMAKE_SOURCE_DIR}/contrib/${MPACK_FILE}") + if(NOT EXISTS "${CMAKE_SOURCE_DIR}/contrib/${MPACK_FILE}") + message(FATAL_ERROR "\nFailed to download source file: ${MPACK_FILE}\nFrom: ${MPACK_URL}") + endif() endif() execute_process(COMMAND ${CMAKE_COMMAND} -E tar xzf ${CMAKE_SOURCE_DIR}/contrib/${MPACK_FILE} WORKING_DIRECTORY ${CONTRIB_DIR}) @@ -79,14 +81,16 @@ include_directories(SYSTEM ${CMAKE_BINARY_DIR} ${MPACK_DIR}/src) set(RAPIDJSON_FILE "rapidjson-${RAPIDJSON_COMMIT}.tar.gz") set(RAPIDJSON_DIR "${CONTRIB_DIR}/rapidjson-${RAPIDJSON_COMMIT}") +set(RAPIDJSON_URL "https://github.com/miloyip/rapidjson/archive/${RAPIDJSON_COMMIT}.tar.gz") -file(DOWNLOAD - "https://github.com/miloyip/rapidjson/archive/${RAPIDJSON_COMMIT}.tar.gz" - "${CMAKE_SOURCE_DIR}/contrib/${RAPIDJSON_FILE}" -) - -if(NOT EXISTS "${CMAKE_SOURCE_DIR}/contrib/${RAPIDJSON_FILE}") - message(FATAL_ERROR "\nRapidJSON source is missing: contrib/${RAPIDJSON_FILE}\nTo build from the repository, you need to fetch dependencies with tools/fetch.sh") +if(EXISTS "${CMAKE_SOURCE_DIR}/contrib/${RAPIDJSON_FILE}") + message(STATUS "Found package: ${RAPIDJSON_FILE}") +else() + message(STATUS "Downloading: ${RAPIDJSON_FILE}") + file(DOWNLOAD ${RAPIDJSON_URL} "${CMAKE_SOURCE_DIR}/contrib/${RAPIDJSON_FILE}") + if(NOT EXISTS "${CMAKE_SOURCE_DIR}/contrib/${RAPIDJSON_FILE}") + message(FATAL_ERROR "\nFailed to download source file: ${RAPIDJSON_FILE}\nFrom: ${RAPIDJSON_URL}") + endif() endif() execute_process(COMMAND ${CMAKE_COMMAND} -E tar xzf ${CMAKE_SOURCE_DIR}/contrib/${RAPIDJSON_FILE} WORKING_DIRECTORY ${CONTRIB_DIR}) @@ -98,14 +102,16 @@ include_directories(SYSTEM ${RAPIDJSON_DIR}/include) set(LIBB64_FILE "libb64-${LIBB64_VERSION}.zip") set(LIBB64_DIR "${CONTRIB_DIR}/libb64-${LIBB64_VERSION}") +set(LIBB64_URL "http://downloads.sourceforge.net/project/libb64/libb64/libb64/${LIBB64_FILE}?use_mirror=autoselect") -file(DOWNLOAD - "http://downloads.sourceforge.net/project/libb64/libb64/libb64/${LIBB64_FILE}?use_mirror=autoselect" - "${CMAKE_SOURCE_DIR}/contrib/${LIBB64_FILE}" -) - -if(NOT EXISTS "${CMAKE_SOURCE_DIR}/contrib/${LIBB64_FILE}") - message(FATAL_ERROR "\nlibb64 source is missing: contrib/${LIBB64_FILE}\nTo build from the repository, you need to fetch dependencies with tools/fetch.sh") +if(EXISTS "${CMAKE_SOURCE_DIR}/contrib/${LIBB64_FILE}") + message(STATUS "Found package: ${LIBB64_FILE}") +else() + message(STATUS "Downloading: ${LIBB64_FILE}") + file(DOWNLOAD ${LIBB64_URL} "${CMAKE_SOURCE_DIR}/contrib/${LIBB64_FILE}") + if(NOT EXISTS "${CMAKE_SOURCE_DIR}/contrib/${LIBB64_FILE}") + message(FATAL_ERROR "\nFailed to download source file: ${LIBB64_FILE}\nFrom: ${LIBB64_URL}") + endif() endif() execute_process(COMMAND ${CMAKE_COMMAND} -E tar xf "${CMAKE_SOURCE_DIR}/contrib/${LIBB64_FILE}" WORKING_DIRECTORY "${CONTRIB_DIR}") From 9b1d425247d53f265099c8c1ff0a092cb2f97668 Mon Sep 17 00:00:00 2001 From: Nicholas Fraser Date: Sat, 16 Jul 2016 18:33:37 -0400 Subject: [PATCH 12/20] Bumped version to 0.5 --- CMakeLists.txt | 13 +++++++++---- src/common.h | 2 -- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9f6388c..a590fbd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,9 +8,14 @@ project(msgpack2json) # compat with cmake > 3.0, this should be autodetected with the git command (tag) or a released file set(PROJECT_VERSION_MAJOR 0) -set(PROJECT_VERSION_MINOR 3) -set(PROJECT_VERSION_PATCH 1) -set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}") +set(PROJECT_VERSION_MINOR 5) +set(PROJECT_VERSION_PATCH 0) + +if(PROJECT_VERSION_PATCH STREQUAL "0") + set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}") +else() + set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}") +endif() set(CONTRIB_DIR ${CMAKE_BINARY_DIR}/contrib) file(MAKE_DIRECTORY ${CONTRIB_DIR}) @@ -46,7 +51,7 @@ if(CMAKE_BUILD_TOOL MATCHES "(msdev|devenv|nmake)") # Windows support is not implemented yet add_definitions(/W2) else() - set(FLAGS "-Wall -Wextra -DLIBB64_VERSION=\\\"${LIBB64_VERSION}\\\"") + set(FLAGS "-Wall -Wextra -DVERSION=\\\"${PROJECT_VERSION}\\\" -DLIBB64_VERSION=\\\"${LIBB64_VERSION}\\\"") set(CMAKE_C_FLAGS_DEBUG "${C_FLAGS} ${FLAGS} -g -O0 -DDEBUG") set(CMAKE_C_FLAGS_RELEASE "${C_FLAGS} ${FLAGS} -O3 -DNDEBUG -fPIC -DPIC") set(CMAKE_CXX_FLAGS_DEBUG "${CXX_FLAGS} ${FLAGS} -g -O0 -DDEBUG") diff --git a/src/common.h b/src/common.h index 8d0536e..2105878 100644 --- a/src/common.h +++ b/src/common.h @@ -39,8 +39,6 @@ extern "C" { #include "b64/cencode.h" } -#define VERSION "0.4" - #define BUFFER_SIZE 65536 #endif From 0e278649b21886e0dffd00bb3d4bc40009320abb Mon Sep 17 00:00:00 2001 From: Nicholas Fraser Date: Sat, 16 Jul 2016 19:20:32 -0400 Subject: [PATCH 13/20] Added manpage generation to CMake --- CMakeLists.txt | 47 ++++++++++++++++++++++++++++++++++++++--------- tools/ci.sh | 12 ++++++------ tools/debug.sh | 2 +- 3 files changed, 45 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a590fbd..bb4dd32 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -131,23 +131,52 @@ file(GLOB_RECURSE LIBB64_SRCS ${LIBB64_DIR}/src/*.c) include_directories(SYSTEM ${LIBB64_DIR}/include) -# targets +# executable targets add_executable(msgpack2json src/msgpack2json.cpp ${MPACK_SRCS} ${LIBB64_SRCS}) add_executable(json2msgpack src/json2msgpack.cpp ${MPACK_SRCS} ${LIBB64_SRCS}) install(TARGETS msgpack2json json2msgpack DESTINATION bin) -if(NOT EXISTS "${CMAKE_SOURCE_DIR}/docs/msgpack2json.1") - message(WARNING "\nmsgpack2json man page is missing: docs/msgpack2json.1\nTo build from the repository, you need to generate manpages with tools/man.sh") -else() - install(FILES ${CMAKE_SOURCE_DIR}/docs/msgpack2json.1 DESTINATION ${CMAKE_INSTALL_PREFIX}/share/man/man1) -endif() -if(NOT EXISTS "${CMAKE_SOURCE_DIR}/docs/json2msgpack.1") - message(WARNING "\njson2msgpack man page is missing: docs/json2msgpack.1\nTo build from the repository, you need to generate manpages with tools/man.sh") -else() +# manpages + +if(EXISTS "${CMAKE_SOURCE_DIR}/docs/msgpack2json.1" AND EXISTS "${CMAKE_SOURCE_DIR}/docs/json2msgpack.1") + # install pre-generated pages + message(STATUS "Found pre-generated man pages: docs/msgpack2json.1 docs/json2msgpack.1") + install(FILES ${CMAKE_SOURCE_DIR}/docs/msgpack2json.1 DESTINATION ${CMAKE_INSTALL_PREFIX}/share/man/man1) install(FILES ${CMAKE_SOURCE_DIR}/docs/json2msgpack.1 DESTINATION ${CMAKE_INSTALL_PREFIX}/share/man/man1) +else() + + # try to find md2man-roff + find_program(MD2MAN-ROFF md2man-roff) + if(MD2MAN-ROFF STREQUAL "MD2MAN-ROFF-NOTFOUND") + message(WARNING "\nmd2man-roff is not installed. Man pages will not be created!\nSee: https://github.com/sunaku/md2man") + else() + + # add custom commands to build man pages + # cmake is insanely verbose for creating custom builders + + message(STATUS "Found md2man-roff: ${MD2MAN-ROFF}") + add_custom_command( + OUTPUT ${CMAKE_BINARY_DIR}/msgpack2json.1 + MAIN_DEPENDENCY ${CMAKE_SOURCE_DIR}/docs/msgpack2json.md + COMMAND ${MD2MAN-ROFF} ${CMAKE_SOURCE_DIR}/docs/msgpack2json.md > ${CMAKE_BINARY_DIR}/msgpack2json.1 + VERBATIM) + add_custom_target(msgpack2json-man DEPENDS ${CMAKE_BINARY_DIR}/msgpack2json.1) + add_dependencies(msgpack2json msgpack2json-man) + install(FILES ${CMAKE_BINARY_DIR}/msgpack2json.1 DESTINATION ${CMAKE_INSTALL_PREFIX}/share/man/man1) + + add_custom_command( + OUTPUT ${CMAKE_BINARY_DIR}/json2msgpack.1 + MAIN_DEPENDENCY ${CMAKE_SOURCE_DIR}/docs/json2msgpack.md + COMMAND ${MD2MAN-ROFF} ${CMAKE_SOURCE_DIR}/docs/json2msgpack.md > ${CMAKE_BINARY_DIR}/json2msgpack.1 + VERBATIM) + add_custom_target(json2msgpack-man DEPENDS ${CMAKE_BINARY_DIR}/json2msgpack.1) + add_dependencies(json2msgpack json2msgpack-man) + install(FILES ${CMAKE_BINARY_DIR}/json2msgpack.1 DESTINATION ${CMAKE_INSTALL_PREFIX}/share/man/man1) + + endif() endif() diff --git a/tools/ci.sh b/tools/ci.sh index f6f3e65..72ad70f 100755 --- a/tools/ci.sh +++ b/tools/ci.sh @@ -8,18 +8,18 @@ else CMAKE_BUILD_TYPE=Release fi -tools/man.sh || exit $? - mkdir -p build cd build if [[ "$CC" == "scan-build" ]]; then unset CXX CC=`which clang` - cmake -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} .. || exit $? + cmake -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_INSTALL_PREFIX="./install" .. || exit $? unset CC - scan-build -o analysis --use-cc=`which clang` --status-bugs make all test || exit $? + scan-build -o analysis --use-cc=`which clang` --status-bugs make all test install || exit $? else - cmake -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} .. || exit $? - make all test || exit $? + cmake -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_INSTALL_PREFIX="./install" .. || exit $? + make all test install || exit $? fi + +find install diff --git a/tools/debug.sh b/tools/debug.sh index eb1f7a8..ac15e0a 100755 --- a/tools/debug.sh +++ b/tools/debug.sh @@ -2,6 +2,6 @@ BUILD="`dirname $0`/../build" mkdir -p "$BUILD" cd "$BUILD" -cmake -DCMAKE_BUILD_TYPE=Debug .. || exit $? +cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX="./install" .. || exit $? make || exit $? CTEST_OUTPUT_ON_FAILURE=1 make test || exit $? From 08aa86adb83952914211d702fad46377f02b8587 Mon Sep 17 00:00:00 2001 From: Nicholas Fraser Date: Sat, 16 Jul 2016 19:26:34 -0400 Subject: [PATCH 14/20] Added AUTHORS file --- AUTHORS | 2 ++ tools/package.sh | 1 + 2 files changed, 3 insertions(+) create mode 100644 AUTHORS diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..f122d71 --- /dev/null +++ b/AUTHORS @@ -0,0 +1,2 @@ +Nicholas Fraser +Jerry Jacobs diff --git a/tools/package.sh b/tools/package.sh index 8a7a7f9..4adb336 100755 --- a/tools/package.sh +++ b/tools/package.sh @@ -4,6 +4,7 @@ NAME=msgpack-tools-${VERSION} FILES="\ README.md \ LICENSE \ + AUTHORS \ CMakeLists.txt \ configure \ contrib \ From c13de92f6e2da0e08fb53c7fe3feea1b2c9f3812 Mon Sep 17 00:00:00 2001 From: Nicholas Fraser Date: Sat, 16 Jul 2016 19:34:44 -0400 Subject: [PATCH 15/20] Moved CPack configuration into CMakeLists.txt --- CMakeLists.txt | 24 +++++++++++++++++------- cmake/CPackConfig.txt | 39 --------------------------------------- cmake/OSDetection.txt | 6 ------ 3 files changed, 17 insertions(+), 52 deletions(-) delete mode 100644 cmake/CPackConfig.txt delete mode 100644 cmake/OSDetection.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index bb4dd32..8f7a488 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -165,7 +165,7 @@ else() VERBATIM) add_custom_target(msgpack2json-man DEPENDS ${CMAKE_BINARY_DIR}/msgpack2json.1) add_dependencies(msgpack2json msgpack2json-man) - install(FILES ${CMAKE_BINARY_DIR}/msgpack2json.1 DESTINATION ${CMAKE_INSTALL_PREFIX}/share/man/man1) + install(FILES ${CMAKE_BINARY_DIR}/msgpack2json.1 DESTINATION share/man/man1) add_custom_command( OUTPUT ${CMAKE_BINARY_DIR}/json2msgpack.1 @@ -174,7 +174,7 @@ else() VERBATIM) add_custom_target(json2msgpack-man DEPENDS ${CMAKE_BINARY_DIR}/json2msgpack.1) add_dependencies(json2msgpack json2msgpack-man) - install(FILES ${CMAKE_BINARY_DIR}/json2msgpack.1 DESTINATION ${CMAKE_INSTALL_PREFIX}/share/man/man1) + install(FILES ${CMAKE_BINARY_DIR}/json2msgpack.1 DESTINATION share/man/man1) endif() endif() @@ -216,9 +216,19 @@ add_test("json2msgpack-value-int" ${COMPARE} ${TESTS_DIR}/value-int. add_test("msgpack2json-value-string" ${COMPARE} ${TESTS_DIR}/value-string.json ${VALGRIND} ./msgpack2json -i ${TESTS_DIR}/value-string.mp) add_test("msgpack2json-value-int" ${COMPARE} ${TESTS_DIR}/value-int.json ${VALGRIND} ./msgpack2json -i ${TESTS_DIR}/value-int.mp) -#add_test("json2msgpack-base64-bin" ${COMPARE_SCRIPT} ${TESTS_DIR}/base64-bin.mp valgrind ./json2msgpack -bi ${TESTS_DIR}/base64-prefix.json) -#add_test("json2msgpack-base64-bin-lax" ${COMPARE_SCRIPT} ${TESTS_DIR}/base64-bin.mp valgrind ./json2msgpack -lbi ${TESTS_DIR}/base64-prefix-lax.json) -include(cmake/OSDetection.txt) -include(cmake/CPackConfig.txt) -include(CPack) +# packaging + +if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux" AND EXISTS "/etc/debian_version") + message(STATUS "Debian-based Linux OS detected") + set(CPACK_GENERATOR "DEB") + set(CPACK_PACKAGE_NAME "msgpack-tools") + set(CPACK_PACKAGE_VERSION "${PROJECT_VERSION}") + string(TOLOWER "${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}" CPACK_SYSTEM_NAME) + set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${PROJECT_VERSION}-${CPACK_SYSTEM_NAME}" ) + set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "https://github.com/ludocode/msgpack-tools") + set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Jerry Jacobs") + set(CPACK_PACKAGE_CONTACT "jerry.jacobs@xor-gate.org") + set(CPACK_DEBIAN_PACKAGE_DESCRIPTION "Command-line tools for converting between MessagePack and JSON") + include(CPack) +endif() diff --git a/cmake/CPackConfig.txt b/cmake/CPackConfig.txt deleted file mode 100644 index 2cd393c..0000000 --- a/cmake/CPackConfig.txt +++ /dev/null @@ -1,39 +0,0 @@ -set(CPACK_STRIP_FILES True) -set(CPACK_CMAKE_GENERATOR "Unix Makefiles") -if("${CMAKE_SYSTEM_VARIANT}" STREQUAL "Debian") - set(CPACK_GENERATOR "DEB") - set(CPACK_PACKAGE_NAME "msgpack-tools") - set(CPACK_PACKAGE_VERSION "${PROJECT_VERSION}") - string(TOLOWER "${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}" CPACK_SYSTEM_NAME) - set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${PROJECT_VERSION}-${CPACK_SYSTEM_NAME}" ) - set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "https://github.com/ludocode/msgpack-tools") - set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Jerry Jacobs") - set(CPACK_PACKAGE_CONTACT "jerry.jacobs@xor-gate.org") - set(CPACK_DEBIAN_PACKAGE_DESCRIPTION "Command-line tools for converting between MessagePack and JSON") -endif() -#SET(CPACK_GENERATOR "STGZ;TGZ;TZ") -#SET(CPACK_INSTALL_CMAKE_PROJECTS "/home/andy/vtk/CMake-bin;CMake;ALL;/") -#SET(CPACK_NSIS_DISPLAY_NAME "CMake 2.5") -#SET(CPACK_OUTPUT_CONFIG_FILE "/home/andy/vtk/CMake-bin/CPackConfig.cmake") -#SET(CPACK_PACKAGE_DESCRIPTION_FILE "/home/andy/vtk/CMake/Copyright.txt") -#SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "CMake is a build tool") -#SET(CPACK_PACKAGE_EXECUTABLES "ccmake;CMake") -#SET(CPACK_PACKAGE_FILE_NAME "cmake-2.5.0-Linux-i686") -#SET(CPACK_PACKAGE_INSTALL_DIRECTORY "CMake 2.5") -#SET(CPACK_PACKAGE_INSTALL_REGISTRY_KEY "CMake 2.5.0") -#SET(CPACK_PACKAGE_NAME "CMake") -#SET(CPACK_PACKAGE_VENDOR "Kitware") -#SET(CPACK_PACKAGE_VERSION "2.5.0") -#SET(CPACK_PACKAGE_VERSION_MAJOR "2") -#SET(CPACK_PACKAGE_VERSION_MINOR "5") -#SET(CPACK_PACKAGE_VERSION_PATCH "0") -#SET(CPACK_RESOURCE_FILE_LICENSE "/home/andy/vtk/CMake/Copyright.txt") -#SET(CPACK_RESOURCE_FILE_README "/home/andy/vtk/CMake/Templates/CPack.GenericDescription.txt") -#SET(CPACK_RESOURCE_FILE_WELCOME "/home/andy/vtk/CMake/Templates/CPack.GenericWelcome.txt") -#SET(CPACK_SOURCE_GENERATOR "TGZ;TZ") -#SET(CPACK_SOURCE_OUTPUT_CONFIG_FILE "/home/andy/vtk/CMake-bin/CPackSourceConfig.cmake") -#SET(CPACK_SOURCE_PACKAGE_FILE_NAME "cmake-2.5.0") -#SET(CPACK_SOURCE_STRIP_FILES "") -#SET(CPACK_STRIP_FILES "bin/ccmake;bin/cmake;bin/cpack;bin/ctest") -#SET(CPACK_SYSTEM_NAME "Linux-i686") -#SET(CPACK_TOPLEVEL_TAG "Linux-i686") diff --git a/cmake/OSDetection.txt b/cmake/OSDetection.txt deleted file mode 100644 index 58a152e..0000000 --- a/cmake/OSDetection.txt +++ /dev/null @@ -1,6 +0,0 @@ -if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") - if(EXISTS "/etc/debian_version") - message(STATUS "Debian-based Linux OS detected") - set(CMAKE_SYSTEM_VARIANT "Debian") - endif() -endif() From 47df8c8bc3fd45e5a6e41463bb3565f207946865 Mon Sep 17 00:00:00 2001 From: Nicholas Fraser Date: Sat, 16 Jul 2016 19:50:09 -0400 Subject: [PATCH 16/20] Updated CI to make Debian package --- CMakeLists.txt | 3 +-- tools/ci.sh | 18 +++++++++++++----- tools/debug.sh | 2 +- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8f7a488..044bb1f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -224,8 +224,7 @@ if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux" AND EXISTS "/etc/debian_version") set(CPACK_GENERATOR "DEB") set(CPACK_PACKAGE_NAME "msgpack-tools") set(CPACK_PACKAGE_VERSION "${PROJECT_VERSION}") - string(TOLOWER "${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}" CPACK_SYSTEM_NAME) - set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${PROJECT_VERSION}-${CPACK_SYSTEM_NAME}" ) + set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${PROJECT_VERSION}-${CMAKE_SYSTEM_PROCESSOR}" ) set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "https://github.com/ludocode/msgpack-tools") set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Jerry Jacobs") set(CPACK_PACKAGE_CONTACT "jerry.jacobs@xor-gate.org") diff --git a/tools/ci.sh b/tools/ci.sh index 72ad70f..c511012 100755 --- a/tools/ci.sh +++ b/tools/ci.sh @@ -8,18 +8,26 @@ else CMAKE_BUILD_TYPE=Release fi +export CTEST_OUTPUT_ON_FAILURE=1 + mkdir -p build cd build if [[ "$CC" == "scan-build" ]]; then unset CXX CC=`which clang` - cmake -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_INSTALL_PREFIX="./install" .. || exit $? + cmake -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_INSTALL_PREFIX="./prefix" .. || exit $? unset CC - scan-build -o analysis --use-cc=`which clang` --status-bugs make all test install || exit $? + scan-build -o analysis --use-cc=`which clang` --status-bugs make all test || exit $? else - cmake -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_INSTALL_PREFIX="./install" .. || exit $? - make all test install || exit $? + cmake -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_INSTALL_PREFIX="./prefix" .. || exit $? + make all test || exit $? +fi + +if [ -e /etc/debian_version ]; then + make package fi -find install +make install +echo " Installed files:" +find prefix diff --git a/tools/debug.sh b/tools/debug.sh index ac15e0a..6ec7794 100755 --- a/tools/debug.sh +++ b/tools/debug.sh @@ -2,6 +2,6 @@ BUILD="`dirname $0`/../build" mkdir -p "$BUILD" cd "$BUILD" -cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX="./install" .. || exit $? +cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX="./prefix" .. || exit $? make || exit $? CTEST_OUTPUT_ON_FAILURE=1 make test || exit $? From 8f5d93860e2aa3dd7c7120f847631f751743fe0a Mon Sep 17 00:00:00 2001 From: Nicholas Fraser Date: Sat, 16 Jul 2016 20:06:57 -0400 Subject: [PATCH 17/20] Updated packaging script --- tools/package.sh | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/tools/package.sh b/tools/package.sh index 4adb336..79059af 100755 --- a/tools/package.sh +++ b/tools/package.sh @@ -1,10 +1,21 @@ #!/bin/bash -VERSION=`cat src/common.h | grep "#define VERSION" | grep -o '".*"' | sed 's/"//g'` +MAJOR=`cat CMakeLists.txt | grep "set(PROJECT_VERSION_MAJOR" | grep -o '[0-9][0-9]*'` +MINOR=`cat CMakeLists.txt | grep "set(PROJECT_VERSION_MINOR" | grep -o '[0-9][0-9]*'` +PATCH=`cat CMakeLists.txt | grep "set(PROJECT_VERSION_PATCH" | grep -o '[0-9][0-9]*'` +if [ "$PATCH" == "0" ]; then + VERSION="$MAJOR.$MINOR" +else + VERSION="$MAJOR.$MINOR.$PATCH" +fi + +echo "Packaging version ${VERSION}" + NAME=msgpack-tools-${VERSION} FILES="\ README.md \ LICENSE \ AUTHORS \ + CHANGELOG.md \ CMakeLists.txt \ configure \ contrib \ @@ -33,6 +44,10 @@ FILES="\ tests/basic-min.json \ tests/basic.json \ tests/basic.mp \ + tests/value-int.json \ + tests/value-int.mp \ + tests/value-string.json \ + tests/value-string.mp \ tools \ tools/debug.sh \ tools/valgrind.sh \ @@ -41,6 +56,7 @@ FILES="\ tools/test-fail.sh \ " -tools/fetch.sh || exit $? -tools/man.sh || exit $? +md2man-roff docs/json2msgpack.md > docs/json2msgpack.1 || exit $? +md2man-roff docs/msgpack2json.md > docs/msgpack2json.1 || exit $? + tar -czf ${NAME}.tar.gz --transform "s@^@$NAME/@" --no-recursion ${FILES} From 31562548ed6b4b6fd80b24163c769be79d099d57 Mon Sep 17 00:00:00 2001 From: Nicholas Fraser Date: Sat, 16 Jul 2016 20:08:08 -0400 Subject: [PATCH 18/20] Updated changelog --- CHANGELOG.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4480590..3b4e489 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,11 @@ -Unreleased ----------- +msgpack-tools v0.5 +------------------ Changes: -- Removed top-level array/map requirement +- Removed top-level array/map requirement (#3) +- Moved dependency downloading and man page generation into CMake build process (#2) +- Added support for build .deb package (#1) - Fixed incorrect buffer sizes msgpack-tools v0.4 From 9a374300ec05928ed74de2627f07edc207f64234 Mon Sep 17 00:00:00 2001 From: Nicholas Fraser Date: Sat, 16 Jul 2016 20:13:54 -0400 Subject: [PATCH 19/20] Deleted obsolete fetch.sh and man.sh --- tools/fetch.sh | 38 -------------------------------------- tools/man.sh | 7 ------- 2 files changed, 45 deletions(-) delete mode 100755 tools/fetch.sh delete mode 100755 tools/man.sh diff --git a/tools/fetch.sh b/tools/fetch.sh deleted file mode 100755 index 3da9062..0000000 --- a/tools/fetch.sh +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/bash - -# This script fetches the dependencies. It pulls the versions -# and commits from CMakeLists.txt. - -mkdir -p contrib -pushd contrib - -getstring() { - cat ../CMakeLists.txt | grep "set($1" | grep -o '".*"' | sed 's/"//g' -} - -# fetch mpack -MPACK_COMMIT=`getstring MPACK_COMMIT` -MPACK_FILE="mpack-${MPACK_COMMIT}.tar.gz" -if ! [ -e "$MPACK_FILE" ]; then - MPACK_URL="https://github.com/ludocode/mpack/archive/${MPACK_COMMIT}.tar.gz" - curl -L -o "${MPACK_FILE}.tmp" "${MPACK_URL}" || exit $? - mv "${MPACK_FILE}.tmp" "${MPACK_FILE}" -fi - -# fetch rapidjson -RAPIDJSON_COMMIT=`getstring RAPIDJSON_COMMIT` -RAPIDJSON_FILE="rapidjson-${RAPIDJSON_COMMIT}.tar.gz" -if ! [ -e "$RAPIDJSON_FILE" ]; then - RAPIDJSON_URL="https://github.com/miloyip/rapidjson/archive/${RAPIDJSON_COMMIT}.tar.gz" - curl -L -o "${RAPIDJSON_FILE}.tmp" "${RAPIDJSON_URL}" || exit $? - mv "${RAPIDJSON_FILE}.tmp" "${RAPIDJSON_FILE}" -fi - -# fetch libb64 -LIBB64_VERSION=`getstring LIBB64_VERSION` -LIBB64_FILE="libb64-${LIBB64_VERSION}.zip" -if ! [ -e "$LIBB64_FILE" ]; then - LIBB64_URL="http://downloads.sourceforge.net/project/libb64/libb64/libb64/${LIBB64_FILE}?use_mirror=autoselect" - curl -L -o "${LIBB64_FILE}.tmp" "${LIBB64_URL}" || exit $? - mv "${LIBB64_FILE}.tmp" "${LIBB64_FILE}" -fi diff --git a/tools/man.sh b/tools/man.sh deleted file mode 100755 index 2f694a8..0000000 --- a/tools/man.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash -# Requires md2man-roff: https://github.com/sunaku/md2man -cd "`dirname $0`/.." -VERSION=`cat src/common.h | grep "#define VERSION" | grep -o '".*"' | sed 's/"//g'` -cd docs -cat json2msgpack.md | sed "s/\$version/$VERSION/" | md2man-roff > json2msgpack.1 || exit $? -cat msgpack2json.md | sed "s/\$version/$VERSION/" | md2man-roff > msgpack2json.1 || exit $? From 6a7bfaffd2a520018f610e05d002947106b4cb28 Mon Sep 17 00:00:00 2001 From: Nicholas Fraser Date: Sat, 16 Jul 2016 20:19:09 -0400 Subject: [PATCH 20/20] Fixed version numbers in man pages --- CMakeLists.txt | 4 ++-- tools/clean.sh | 1 + tools/package.sh | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 044bb1f..3184bd6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -161,7 +161,7 @@ else() add_custom_command( OUTPUT ${CMAKE_BINARY_DIR}/msgpack2json.1 MAIN_DEPENDENCY ${CMAKE_SOURCE_DIR}/docs/msgpack2json.md - COMMAND ${MD2MAN-ROFF} ${CMAKE_SOURCE_DIR}/docs/msgpack2json.md > ${CMAKE_BINARY_DIR}/msgpack2json.1 + COMMAND cat ${CMAKE_SOURCE_DIR}/docs/msgpack2json.md | sed "s/\$version/${PROJECT_VERSION}/" | ${MD2MAN-ROFF} > ${CMAKE_BINARY_DIR}/msgpack2json.1 VERBATIM) add_custom_target(msgpack2json-man DEPENDS ${CMAKE_BINARY_DIR}/msgpack2json.1) add_dependencies(msgpack2json msgpack2json-man) @@ -170,7 +170,7 @@ else() add_custom_command( OUTPUT ${CMAKE_BINARY_DIR}/json2msgpack.1 MAIN_DEPENDENCY ${CMAKE_SOURCE_DIR}/docs/json2msgpack.md - COMMAND ${MD2MAN-ROFF} ${CMAKE_SOURCE_DIR}/docs/json2msgpack.md > ${CMAKE_BINARY_DIR}/json2msgpack.1 + COMMAND cat ${CMAKE_SOURCE_DIR}/docs/json2msgpack.md | sed "s/\$version/${PROJECT_VERSION}/" | ${MD2MAN-ROFF} > ${CMAKE_BINARY_DIR}/json2msgpack.1 VERBATIM) add_custom_target(json2msgpack-man DEPENDS ${CMAKE_BINARY_DIR}/json2msgpack.1) add_dependencies(json2msgpack json2msgpack-man) diff --git a/tools/clean.sh b/tools/clean.sh index 052062f..5f2cf35 100755 --- a/tools/clean.sh +++ b/tools/clean.sh @@ -1,3 +1,4 @@ #!/bin/bash -x rm -rf build +rm -f docs/*.1 rm -rf CMakeCache.txt CMakeFiles CTestTestfile.cmake Makefile cmake_install.cmake mpack-config.h diff --git a/tools/package.sh b/tools/package.sh index 79059af..320481a 100755 --- a/tools/package.sh +++ b/tools/package.sh @@ -56,7 +56,7 @@ FILES="\ tools/test-fail.sh \ " -md2man-roff docs/json2msgpack.md > docs/json2msgpack.1 || exit $? -md2man-roff docs/msgpack2json.md > docs/msgpack2json.1 || exit $? +cat docs/json2msgpack.md | sed "s/\$version/$VERSION/" | md2man-roff > docs/json2msgpack.1 || exit $? +cat docs/msgpack2json.md | sed "s/\$version/$VERSION/" | md2man-roff > docs/msgpack2json.1 || exit $? tar -czf ${NAME}.tar.gz --transform "s@^@$NAME/@" --no-recursion ${FILES}