Bläddra i källkod

Added a script to build a single file distribution

Benoit Blanchon 8 år sedan
förälder
incheckning
ad972725de

+ 1 - 1
README.md

@@ -82,7 +82,7 @@ root.printTo(Serial);
 Documentation
 -------------
 
-The documentation is available online in the [ArduinoJson wiki](https://github.com/bblanchon/ArduinoJson/wiki).
+The documentation is available online in the [ArduinoJson Website](https://github.com/bblanchon/ArduinoJson/).
 
 The [ArduinoJson Assistant](https://bblanchon.github.io/ArduinoJson/assistant/) helps you get started with the library.
 

+ 3 - 0
include/ArduinoJson.h

@@ -5,5 +5,8 @@
 // https://github.com/bblanchon/ArduinoJson
 // If you like this project, please add a star!
 
+#pragma once
+
 #include "ArduinoJson.hpp"
+
 using namespace ArduinoJson;

+ 0 - 2
include/ArduinoJson.hpp

@@ -19,5 +19,3 @@
 #include "ArduinoJson/JsonObjectImpl.hpp"
 #include "ArduinoJson/JsonVariantImpl.hpp"
 #include "ArduinoJson/Serialization/JsonSerializerImpl.hpp"
-
-using namespace ArduinoJson;

+ 4 - 0
include/ArduinoJson/StringTraits/ArduinoStream.hpp

@@ -7,6 +7,8 @@
 
 #pragma once
 
+#if ARDUINOJSON_ENABLE_ARDUINO_STREAM
+
 #include <Stream.h>
 
 #include "../TypeTraits/EnableIf.hpp"
@@ -59,3 +61,5 @@ struct StringTraits<TStream,
     : ArduinoStreamTraits {};
 }
 }
+
+#endif

+ 4 - 0
include/ArduinoJson/StringTraits/FlashString.hpp

@@ -7,6 +7,8 @@
 
 #pragma once
 
+#if ARDUINOJSON_ENABLE_PROGMEM
+
 namespace ArduinoJson {
 namespace Internals {
 template <>
@@ -50,3 +52,5 @@ struct StringTraits<const __FlashStringHelper*, void> {
 };
 }
 }
+
+#endif

+ 4 - 0
include/ArduinoJson/StringTraits/StdStream.hpp

@@ -7,6 +7,8 @@
 
 #pragma once
 
+#if ARDUINOJSON_ENABLE_STD_STREAM
+
 #include <istream>
 #include "../TypeTraits/EnableIf.hpp"
 #include "../TypeTraits/IsBaseOf.hpp"
@@ -57,3 +59,5 @@ struct StringTraits<TStream,
     : StdStreamTraits {};
 }
 }
+
+#endif

+ 4 - 0
include/ArduinoJson/StringTraits/StdString.hpp

@@ -7,6 +7,8 @@
 
 #pragma once
 
+#if ARDUINOJSON_ENABLE_STD_STRING || ARDUINOJSON_ENABLE_ARDUINO_STRING
+
 #if ARDUINOJSON_ENABLE_ARDUINO_STRING
 #include <WString.h>
 #endif
@@ -60,3 +62,5 @@ struct StringTraits<std::string, void> : StdStringTraits<std::string> {};
 #endif
 }
 }
+
+#endif

+ 3 - 15
include/ArduinoJson/StringTraits/StringTraits.hpp

@@ -23,23 +23,11 @@ struct StringTraits<TString&, void> : StringTraits<TString> {};
 }
 }
 
-#include "CharPointer.hpp"
-
-#if ARDUINOJSON_ENABLE_STD_STRING || ARDUINOJSON_ENABLE_ARDUINO_STRING
-#include "StdString.hpp"
-#endif
-
-#if ARDUINOJSON_ENABLE_STD_STREAM
-#include "StdStream.hpp"
-#endif
-
-#if ARDUINOJSON_ENABLE_ARDUINO_STREAM
 #include "ArduinoStream.hpp"
-#endif
-
-#if ARDUINOJSON_ENABLE_PROGMEM
+#include "CharPointer.hpp"
 #include "FlashString.hpp"
-#endif
+#include "StdStream.hpp"
+#include "StdString.hpp"
 
 namespace ArduinoJson {
 namespace TypeTraits {

+ 44 - 0
scripts/build-single-header.sh

@@ -0,0 +1,44 @@
+#!/bin/bash
+
+TAG=$(git describe)
+RE_INCLUDE='^#include[[:space:]]*["<](.*)[">]'
+RE_EMPTY='^(#pragma[[:space:]]+once)?[[:space:]]*(//.*)?$'
+
+declare -A INCLUDED
+
+process()
+{
+	local PARENT=$1
+	local FOLDER=$(dirname $1)
+	local SHOW_COMMENT=$2
+	while IFS= read -r LINE; do
+		if [[ $LINE =~ $RE_INCLUDE ]]; then
+			local CHILD=${BASH_REMATCH[1]}
+			pushd "$FOLDER" > /dev/null
+			if [[ -e $CHILD ]]; then
+				local CHILD_PATH=$(realpath $CHILD)
+				if [[ ! ${INCLUDED[$CHILD_PATH]} ]]; then
+					#echo "// $PARENT -> $CHILD"
+					INCLUDED[$CHILD_PATH]=true
+					process "$CHILD" false
+				fi
+			else
+				if [[ ! ${INCLUDED[$CHILD]} ]]; then
+					echo "$LINE"
+					INCLUDED[$CHILD]=true
+				fi
+			fi
+			popd > /dev/null
+		elif [[ "${SHOW_COMMENT}" = "true" ]] ; then
+			echo "$LINE"
+		elif [[ ! $LINE =~ $RE_EMPTY ]]; then
+			echo "$LINE"
+		fi
+	done < $PARENT
+}
+
+cd $(dirname $0)/../
+INCLUDED=()
+process include/ArduinoJson.h true > ../ArduinoJson-$TAG.h
+INCLUDED=()
+process include/ArduinoJson.hpp true > ../ArduinoJson-$TAG.hpp