From 003ec6ff1ab9f9be6151783b3fc67a9f5c22f3ea Mon Sep 17 00:00:00 2001 From: david gauchard Date: Mon, 22 Oct 2018 23:02:02 +0200 Subject: [PATCH 1/5] Allowing API changes: add helper defines to identify versions --- cores/esp8266/Arduino.h | 1 + cores/esp8266/Esp-version.cpp | 13 ++++-------- cores/esp8266/core_esp8266_version.h | 30 ++++++++++++++++++++++++++++ package/README.md | 4 ++++ 4 files changed, 39 insertions(+), 9 deletions(-) create mode 100644 cores/esp8266/core_esp8266_version.h diff --git a/cores/esp8266/Arduino.h b/cores/esp8266/Arduino.h index b13817ae8f..19d4b20853 100644 --- a/cores/esp8266/Arduino.h +++ b/cores/esp8266/Arduino.h @@ -38,6 +38,7 @@ extern "C" { #include "esp8266_peri.h" #include "twi.h" #include "core_esp8266_features.h" +#include "core_esp8266_version.h" #define HIGH 0x1 #define LOW 0x0 diff --git a/cores/esp8266/Esp-version.cpp b/cores/esp8266/Esp-version.cpp index 866d5d2974..584b7ac89b 100644 --- a/cores/esp8266/Esp-version.cpp +++ b/cores/esp8266/Esp-version.cpp @@ -29,28 +29,23 @@ #define STR(x) STRHELPER(x) // stringifier static const char arduino_esp8266_git_ver [] PROGMEM = STR(ARDUINO_ESP8266_GIT_DESC); -#if LWIP_VERSION_MAJOR != 1 -static const char lwip2_version [] PROGMEM = "/lwIP:" STR(LWIP_VERSION_MAJOR) "." STR(LWIP_VERSION_MINOR) "." STR(LWIP_VERSION_REVISION); -#endif static const char bearssl_version [] PROGMEM = "/BearSSL:" STR(BEARSSL_GIT); String EspClass::getFullVersion() { return String(F("SDK:")) + system_get_sdk_version() - + F("/Core:") + FPSTR(arduino_esp8266_git_ver) + + F("/Core:v") + String(CORE_ESP8266_VERSION) + F("-git:") + FPSTR(arduino_esp8266_git_ver) #if LWIP_VERSION_MAJOR == 1 + F("/lwIP:") + String(LWIP_VERSION_MAJOR) + "." + String(LWIP_VERSION_MINOR) + "." + String(LWIP_VERSION_REVISION) -#else - + FPSTR(lwip2_version) -#endif #if LWIP_VERSION_IS_DEVELOPMENT + F("-dev") #endif #if LWIP_VERSION_IS_RC + F("rc") + String(LWIP_VERSION_RC) #endif -#ifdef LWIP_HASH_STR - + "(" + F(LWIP_HASH_STR) + ")" +#else // LWIP_VERSION_MAJOR != 1 + + F("/lwIP:") + + F(LWIP_HASH_STR) #endif + FPSTR(bearssl_version) ; diff --git a/cores/esp8266/core_esp8266_version.h b/cores/esp8266/core_esp8266_version.h new file mode 100644 index 0000000000..02889dec87 --- /dev/null +++ b/cores/esp8266/core_esp8266_version.h @@ -0,0 +1,30 @@ + +#ifndef __CORE_ESP8266_VERSION_H +#define __CORE_ESP8266_VERSION_H + +#define CORE_ESP8266_MAJOR (2) +#define CORE_ESP8266_MINOR (4) +#define CORE_ESP8266_REVISION (2) +#define CORE_ESP8266_RC (0) +#define CORE_ESP8266_DEVEL (1) + +#define CORE_ESP8266_VERSION ((CORE_ESP8266_MAJOR*10000) + (CORE_ESP8266_MINOR*1000) + (CORE_ESP8266_REVISION*100) + (CORE_ESP8266_RC*10) + (CORE_ESP8266_DEVEL)) + +// CORE_ESP8266_VERSION: +// 2.4.3-dev (after 2.4.2 release), or 24201 +// 2.5.0-dev (after 2.4.2 release) 24201 +// 2.5.0-rc1 first release candidate 24210 +// 2.5.0-rc1+ dev after first release candidate 24211 +// 2.5.0-rc2 second release candidate 24220 +// 2.5.0 release 25000 +// 2.5.1-dev 25001 +// 2.5.1-rc1 25010 +// 2.5.1 release 25100 + +// for example: +// 24211 should read as: +// "dev after first RC after 2.4.2" (for 2.4.3 or 2.5.0) +// CORE_ESP8266_DEVEL must be increased whenever API changes 24201 -> 24202 -> 24203 +// so one can always compare (#if CORE_ESP8266_VERSION < 24201 // previous api...) + +#endif // __CORE_ESP8266_ESP8266_VERSION_H diff --git a/package/README.md b/package/README.md index 93b7694880..bfb0680321 100644 --- a/package/README.md +++ b/package/README.md @@ -57,6 +57,8 @@ Here is an overview of the release process. See the section below for detailed i * When done, put release notes into a private Gist and send the link to other maintainers for review. + * Update versions in cores/esp8266/core_esp8266_version.h -and- platform.txt, and commit + 2. Tag the latest commit on the master branch. In this project, tags have form `X.Y.Z`, e.g. `2.4.0`, or `X.Y.Z-rcN` for release versions. Notice that there's no `v`at the beginning of the tag. Tags must be annotated, not lightweight tags. To create a tag, use git command (assuming that the master branch is checked out): ``` @@ -81,6 +83,8 @@ Here is an overview of the release process. See the section below for detailed i * The version in platform.txt file. This should correspond to the version of the *next* milestone, plus `-dev` suffix. E.g. `2.5.0-dev`. + * The version in cores/esp8266/core_esp8266_version.h. This should correspond to the current version + 1 (e.g. 24200 -> 24201) + * In main README.md: - in "Contributing" section, update the "easy issues" link to point to the next milestone. From a6129461d7a2b7dcd6fcdc9d22680922882d3a46 Mon Sep 17 00:00:00 2001 From: david gauchard Date: Fri, 26 Oct 2018 00:34:11 +0200 Subject: [PATCH 2/5] comments --- cores/esp8266/core_esp8266_version.h | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/cores/esp8266/core_esp8266_version.h b/cores/esp8266/core_esp8266_version.h index 02889dec87..2193c8df8e 100644 --- a/cores/esp8266/core_esp8266_version.h +++ b/cores/esp8266/core_esp8266_version.h @@ -2,20 +2,23 @@ #ifndef __CORE_ESP8266_VERSION_H #define __CORE_ESP8266_VERSION_H -#define CORE_ESP8266_MAJOR (2) -#define CORE_ESP8266_MINOR (4) -#define CORE_ESP8266_REVISION (2) -#define CORE_ESP8266_RC (0) -#define CORE_ESP8266_DEVEL (1) +#define CORE_ESP8266_MAJOR 2 +#define CORE_ESP8266_MINOR 4 +#define CORE_ESP8266_REVISION 2 +#define CORE_ESP8266_CBNR 0 +#define CORE_ESP8266_DEVEL 1 -#define CORE_ESP8266_VERSION ((CORE_ESP8266_MAJOR*10000) + (CORE_ESP8266_MINOR*1000) + (CORE_ESP8266_REVISION*100) + (CORE_ESP8266_RC*10) + (CORE_ESP8266_DEVEL)) +// CBNR = candidate before next release +// CORE_ESP8266_DEVEL must be increased whenever API changes (api signature update, or api addition, or api removal) + +#define CORE_ESP8266_VERSION ((CORE_ESP8266_MAJOR*10000) + (CORE_ESP8266_MINOR*1000) + (CORE_ESP8266_REVISION*100) + (CORE_ESP8266_CBNR*10) + (CORE_ESP8266_DEVEL)) // CORE_ESP8266_VERSION: // 2.4.3-dev (after 2.4.2 release), or 24201 // 2.5.0-dev (after 2.4.2 release) 24201 -// 2.5.0-rc1 first release candidate 24210 -// 2.5.0-rc1+ dev after first release candidate 24211 -// 2.5.0-rc2 second release candidate 24220 +// 2.5.0-rc1 first candidate before next release 24210 +// 2.5.0-rc1+ dev after first candidate 24211 +// 2.5.0-rc2 second candidate 24220 // 2.5.0 release 25000 // 2.5.1-dev 25001 // 2.5.1-rc1 25010 @@ -23,8 +26,6 @@ // for example: // 24211 should read as: -// "dev after first RC after 2.4.2" (for 2.4.3 or 2.5.0) -// CORE_ESP8266_DEVEL must be increased whenever API changes 24201 -> 24202 -> 24203 -// so one can always compare (#if CORE_ESP8266_VERSION < 24201 // previous api...) +// "dev after first candidate before next release after 2.4.2" (for either pre-2.4.3 or pre-2.5.0) #endif // __CORE_ESP8266_ESP8266_VERSION_H From 949d1656f9a281fc5a9d1452408adfc4b6ca86ef Mon Sep 17 00:00:00 2001 From: david gauchard Date: Sat, 27 Oct 2018 16:31:57 +0200 Subject: [PATCH 3/5] parse version from git-tag at compile time using constexpr --- cores/esp8266/Esp-version.cpp | 2 +- cores/esp8266/core_esp8266_version.h | 145 ++++++++++++++++++++++----- 2 files changed, 121 insertions(+), 26 deletions(-) diff --git a/cores/esp8266/Esp-version.cpp b/cores/esp8266/Esp-version.cpp index 584b7ac89b..a87ba32e71 100644 --- a/cores/esp8266/Esp-version.cpp +++ b/cores/esp8266/Esp-version.cpp @@ -34,7 +34,7 @@ static const char bearssl_version [] PROGMEM = "/BearSSL:" STR(BEARSSL_GIT); String EspClass::getFullVersion() { return String(F("SDK:")) + system_get_sdk_version() - + F("/Core:v") + String(CORE_ESP8266_VERSION) + F("-git:") + FPSTR(arduino_esp8266_git_ver) + + F("/Core:v") + String(uNIQ()) + F("-git:") + FPSTR(arduino_esp8266_git_ver) #if LWIP_VERSION_MAJOR == 1 + F("/lwIP:") + String(LWIP_VERSION_MAJOR) + "." + String(LWIP_VERSION_MINOR) + "." + String(LWIP_VERSION_REVISION) #if LWIP_VERSION_IS_DEVELOPMENT diff --git a/cores/esp8266/core_esp8266_version.h b/cores/esp8266/core_esp8266_version.h index 2193c8df8e..740b194d37 100644 --- a/cores/esp8266/core_esp8266_version.h +++ b/cores/esp8266/core_esp8266_version.h @@ -1,31 +1,126 @@ +/* + core_esp8266_version.h - parse "git describe" at compile time + Copyright (c) 2018 david gauchard. All rights reserved. + This file is part of the esp8266 core for Arduino environment. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + #ifndef __CORE_ESP8266_VERSION_H #define __CORE_ESP8266_VERSION_H -#define CORE_ESP8266_MAJOR 2 -#define CORE_ESP8266_MINOR 4 -#define CORE_ESP8266_REVISION 2 -#define CORE_ESP8266_CBNR 0 -#define CORE_ESP8266_DEVEL 1 - -// CBNR = candidate before next release -// CORE_ESP8266_DEVEL must be increased whenever API changes (api signature update, or api addition, or api removal) - -#define CORE_ESP8266_VERSION ((CORE_ESP8266_MAJOR*10000) + (CORE_ESP8266_MINOR*1000) + (CORE_ESP8266_REVISION*100) + (CORE_ESP8266_CBNR*10) + (CORE_ESP8266_DEVEL)) - -// CORE_ESP8266_VERSION: -// 2.4.3-dev (after 2.4.2 release), or 24201 -// 2.5.0-dev (after 2.4.2 release) 24201 -// 2.5.0-rc1 first candidate before next release 24210 -// 2.5.0-rc1+ dev after first candidate 24211 -// 2.5.0-rc2 second candidate 24220 -// 2.5.0 release 25000 -// 2.5.1-dev 25001 -// 2.5.1-rc1 25010 -// 2.5.1 release 25100 - -// for example: -// 24211 should read as: -// "dev after first candidate before next release after 2.4.2" (for either pre-2.4.3 or pre-2.5.0) +#include +// examples: +//#define ARDUINO_ESP8266_GIT_DESC 2.4.2-91-gcb05b86d +//#define ARDUINO_ESP8266_GIT_DESC 2.5.0rc3-1-gcb05b86d +//#define ARDUINO_ESP8266_GIT_DESC 2.5.0 + +#define STRHELPER(x) #x +#define STR(x) STRHELPER(x) + +#ifdef __cplusplus +extern "C++" +{ + +template constexpr +int eVAL (const char (&arr) [N], unsigned i) +{ + return ({ // <= c++11 requires a "return statement" + int ret = 0; + int sign = 1; + if (arr[i] == '-') + { + sign = -1; + i++; + } + while (arr[i] >= '0' && arr[i] <= '9') + ret = 10*ret + arr[i++] - '0'; + ret * sign; + }); +} + +template constexpr +int fIELDEVAL (const char (&arr) [N], unsigned f) +{ + return ({ // <= c++11 requires a "return statement" + unsigned i = 0; + while (f && arr[i]) + { + if (arr[i] == '-') + i++; + for (; arr[i] >= '0' && arr[i] <= '9'; i++); + f--; + for (; arr[i] && arr[i] != '-' && (arr[i] < '0' || arr[i] > '9'); i++); + } + eVAL(arr, i); + }); +} + +/* + * version major + */ +constexpr int mAJOR () { return fIELDEVAL(STR(ARDUINO_ESP8266_GIT_DESC), 0); } + +/* + * version minor + */ +constexpr int mINOR () { return fIELDEVAL(STR(ARDUINO_ESP8266_GIT_DESC), 1); } + +/* + * version revision + */ +constexpr int rEV () { return fIELDEVAL(STR(ARDUINO_ESP8266_GIT_DESC), 2); } + +/* + * git commit number since last tag (negative) or RC-number (positive) + */ +constexpr int gIT () { return fIELDEVAL(STR(ARDUINO_ESP8266_GIT_DESC), 3); } + +/* + * unique revision indentifier (never decreases) + */ +constexpr int uNIQ () +{ + return mAJOR() * 100000 + + mINOR() * 10000 + + rEV() * 1000 + + (gIT() < 0? -gIT(): gIT()? gIT() - 1000: 0); +} + +} // extern "C++" +#endif // __cplusplus + +#if TESTMEWITHGCC + +/* +"2.4.2-91-gcb05b86d" => 2 . 4 . 2 - -91 = 242091 +"2.5.0rc3-1-gcb05b86d" => 2 . 5 . 0 - 3 = 249003 +"2.5.0" => 2 . 5 . 0 - 0 = 250000 +*/ + +int main (void) +{ + printf("%d . %d . %d - %d = %d\n", + mAJOR(), + mINOR(), + rEV(), + gIT(), + uNIQ()); + return 0; +} +#endif // testme #endif // __CORE_ESP8266_ESP8266_VERSION_H From 2f8ca2156fa25ddb31d1161c29c3ad8a91a2a1c7 Mon Sep 17 00:00:00 2001 From: david gauchard Date: Sun, 28 Oct 2018 00:24:46 +0200 Subject: [PATCH 4/5] fix naming, update doc --- cores/esp8266/Esp-version.cpp | 2 +- cores/esp8266/core_esp8266_version.h | 117 +++++++++++++++++---------- libraries/esp8266/keywords.txt | 9 ++- package/README.md | 4 +- 4 files changed, 84 insertions(+), 48 deletions(-) diff --git a/cores/esp8266/Esp-version.cpp b/cores/esp8266/Esp-version.cpp index a87ba32e71..437204705c 100644 --- a/cores/esp8266/Esp-version.cpp +++ b/cores/esp8266/Esp-version.cpp @@ -34,7 +34,7 @@ static const char bearssl_version [] PROGMEM = "/BearSSL:" STR(BEARSSL_GIT); String EspClass::getFullVersion() { return String(F("SDK:")) + system_get_sdk_version() - + F("/Core:v") + String(uNIQ()) + F("-git:") + FPSTR(arduino_esp8266_git_ver) + + F("/Core:") + FPSTR(arduino_esp8266_git_ver) #if LWIP_VERSION_MAJOR == 1 + F("/lwIP:") + String(LWIP_VERSION_MAJOR) + "." + String(LWIP_VERSION_MINOR) + "." + String(LWIP_VERSION_REVISION) #if LWIP_VERSION_IS_DEVELOPMENT diff --git a/cores/esp8266/core_esp8266_version.h b/cores/esp8266/core_esp8266_version.h index 740b194d37..dc705e2ac9 100644 --- a/cores/esp8266/core_esp8266_version.h +++ b/cores/esp8266/core_esp8266_version.h @@ -23,10 +23,6 @@ #define __CORE_ESP8266_VERSION_H #include -// examples: -//#define ARDUINO_ESP8266_GIT_DESC 2.4.2-91-gcb05b86d -//#define ARDUINO_ESP8266_GIT_DESC 2.5.0rc3-1-gcb05b86d -//#define ARDUINO_ESP8266_GIT_DESC 2.5.0 #define STRHELPER(x) #x #define STR(x) STRHELPER(x) @@ -35,92 +31,127 @@ extern "C++" { +// Following constexpr functions are compiled and executed +// *after* pre-processing and *during* compilation +// +// Their result is treated like a numeric constant in final binary code. +// git tags must be in the form: +// - .. (2.4.2) (2.5.0) +// - ..-rc (2.5.0-rc1) (2.5.0-rc2) +// +// "git describe" = ARDUINO_ESP8266_GIT_DESC will thus be in the form: +// - (2.4.2) (2.5.0) +// - --g (2.4.2-91-gcb05b86d) (2.5.0-rc3-1-gcb05b86d) +// +// Examples: +// case 2.4.2 (fresh version/tag) +// esp8266CoreVersionSubRevision() is 0 Numeric is: 20402000 +// case 2.4.2-91-gcb05b86d: +// esp8266CoreVersionSubRevision() is -91 Numeric is: 20402091 +// case 2.5.0-rc3-1-gcb05b86d: +// esp8266CoreVersionSubRevision() is 3 Numeric is: 20499903 +// case 2.5.0: +// esp8266CoreVersionSubRevision() is 0 Numeric is: 20500000 + +constexpr +bool constexpr_isDecimal (const char c) +{ + return c >= '0' && c <= '9'; +} + +template constexpr +bool constexpr_isMinus (const char (&arr) [N], unsigned i) +{ + return arr[i] == '-' && constexpr_isDecimal(arr[i+1]); +} + template constexpr -int eVAL (const char (&arr) [N], unsigned i) +int constexpr_atoi (const char (&arr) [N], unsigned i) { return ({ // <= c++11 requires a "return statement" int ret = 0; int sign = 1; - if (arr[i] == '-') + if (arr[i] == '-') { sign = -1; i++; } - while (arr[i] >= '0' && arr[i] <= '9') + while (constexpr_isDecimal(arr[i])) ret = 10*ret + arr[i++] - '0'; ret * sign; }); } template constexpr -int fIELDEVAL (const char (&arr) [N], unsigned f) +int constexpr_extract_int (const char (&arr) [N], unsigned f) { return ({ // <= c++11 requires a "return statement" unsigned i = 0; while (f && arr[i]) { - if (arr[i] == '-') + if (constexpr_isMinus(arr, i)) i++; - for (; arr[i] >= '0' && arr[i] <= '9'; i++); + for (; constexpr_isDecimal(arr[i]); i++); f--; - for (; arr[i] && arr[i] != '-' && (arr[i] < '0' || arr[i] > '9'); i++); + for (; arr[i] && !constexpr_isMinus(arr, i) && !constexpr_isDecimal(arr[i]); i++); } - eVAL(arr, i); + constexpr_atoi(arr, i); }); } /* * version major */ -constexpr int mAJOR () { return fIELDEVAL(STR(ARDUINO_ESP8266_GIT_DESC), 0); } +constexpr +int esp8266CoreVersionMajor () +{ + return constexpr_extract_int(STR(ARDUINO_ESP8266_GIT_DESC), 0); +} /* * version minor */ -constexpr int mINOR () { return fIELDEVAL(STR(ARDUINO_ESP8266_GIT_DESC), 1); } +constexpr +int esp8266CoreVersionMinor () +{ + return constexpr_extract_int(STR(ARDUINO_ESP8266_GIT_DESC), 1); +} /* * version revision */ -constexpr int rEV () { return fIELDEVAL(STR(ARDUINO_ESP8266_GIT_DESC), 2); } +constexpr +int esp8266CoreVersionRevision () +{ + return constexpr_extract_int(STR(ARDUINO_ESP8266_GIT_DESC), 2); +} /* - * git commit number since last tag (negative) or RC-number (positive) + * git commit number since last tag (negative) + * or RC-number (positive) */ -constexpr int gIT () { return fIELDEVAL(STR(ARDUINO_ESP8266_GIT_DESC), 3); } +constexpr +int esp8266CoreVersionSubRevision () +{ + return constexpr_extract_int(STR(ARDUINO_ESP8266_GIT_DESC), 3); +} /* * unique revision indentifier (never decreases) */ -constexpr int uNIQ () +constexpr +int esp8266CoreVersionNumeric () { - return mAJOR() * 100000 - + mINOR() * 10000 - + rEV() * 1000 - + (gIT() < 0? -gIT(): gIT()? gIT() - 1000: 0); + return esp8266CoreVersionMajor() * 10000000 + + esp8266CoreVersionMinor() * 100000 + + esp8266CoreVersionRevision() * 1000 + + (esp8266CoreVersionSubRevision() < 0 ? + -esp8266CoreVersionSubRevision() : + esp8266CoreVersionSubRevision() ? + esp8266CoreVersionSubRevision() - 100 : + 0); } } // extern "C++" #endif // __cplusplus - -#if TESTMEWITHGCC - -/* -"2.4.2-91-gcb05b86d" => 2 . 4 . 2 - -91 = 242091 -"2.5.0rc3-1-gcb05b86d" => 2 . 5 . 0 - 3 = 249003 -"2.5.0" => 2 . 5 . 0 - 0 = 250000 -*/ - -int main (void) -{ - printf("%d . %d . %d - %d = %d\n", - mAJOR(), - mINOR(), - rEV(), - gIT(), - uNIQ()); - return 0; -} -#endif // testme - #endif // __CORE_ESP8266_ESP8266_VERSION_H diff --git a/libraries/esp8266/keywords.txt b/libraries/esp8266/keywords.txt index f6bb96b5d7..b0492666a5 100644 --- a/libraries/esp8266/keywords.txt +++ b/libraries/esp8266/keywords.txt @@ -77,4 +77,11 @@ WAKE_RFCAL LITERAL1 WAKE_NO_RFCAL LITERAL1 WAKE_RF_DISABLED LITERAL1 ADC_VCC LITERAL1 -ADC_TOUT LITERAL1 \ No newline at end of file +ADC_TOUT LITERAL1 + +# constexpr +esp8266CoreVersionMajor LITERAL1 +esp8266CoreVersionMinor LITERAL1 +esp8266CoreVersionRevision LITERAL1 +esp8266CoreVersionSubRevision LITERAL1 +esp8266CoreVersionNumeric LITERAL1 diff --git a/package/README.md b/package/README.md index bfb0680321..917a3ed34f 100644 --- a/package/README.md +++ b/package/README.md @@ -57,7 +57,7 @@ Here is an overview of the release process. See the section below for detailed i * When done, put release notes into a private Gist and send the link to other maintainers for review. - * Update versions in cores/esp8266/core_esp8266_version.h -and- platform.txt, and commit + * Update `version` to the release in platform.txt and commit. E.g. `2.5.0`. 2. Tag the latest commit on the master branch. In this project, tags have form `X.Y.Z`, e.g. `2.4.0`, or `X.Y.Z-rcN` for release versions. Notice that there's no `v`at the beginning of the tag. Tags must be annotated, not lightweight tags. To create a tag, use git command (assuming that the master branch is checked out): @@ -83,8 +83,6 @@ Here is an overview of the release process. See the section below for detailed i * The version in platform.txt file. This should correspond to the version of the *next* milestone, plus `-dev` suffix. E.g. `2.5.0-dev`. - * The version in cores/esp8266/core_esp8266_version.h. This should correspond to the current version + 1 (e.g. 24200 -> 24201) - * In main README.md: - in "Contributing" section, update the "easy issues" link to point to the next milestone. From 9f3cca994e63815d91e5935c978574f703485922 Mon Sep 17 00:00:00 2001 From: David Gauchard Date: Mon, 26 Nov 2018 14:16:52 +0100 Subject: [PATCH 5/5] introduce namespaces --- cores/esp8266/Esp-version.cpp | 1 + cores/esp8266/core_esp8266_version.h | 62 ++++++++++++++++------------ libraries/esp8266/keywords.txt | 14 ++++--- 3 files changed, 44 insertions(+), 33 deletions(-) diff --git a/cores/esp8266/Esp-version.cpp b/cores/esp8266/Esp-version.cpp index 437204705c..9939acfb89 100644 --- a/cores/esp8266/Esp-version.cpp +++ b/cores/esp8266/Esp-version.cpp @@ -35,6 +35,7 @@ String EspClass::getFullVersion() { return String(F("SDK:")) + system_get_sdk_version() + F("/Core:") + FPSTR(arduino_esp8266_git_ver) + + F("=") + String(esp8266::coreVersionNumeric()) #if LWIP_VERSION_MAJOR == 1 + F("/lwIP:") + String(LWIP_VERSION_MAJOR) + "." + String(LWIP_VERSION_MINOR) + "." + String(LWIP_VERSION_REVISION) #if LWIP_VERSION_IS_DEVELOPMENT diff --git a/cores/esp8266/core_esp8266_version.h b/cores/esp8266/core_esp8266_version.h index dc705e2ac9..5018744df7 100644 --- a/cores/esp8266/core_esp8266_version.h +++ b/cores/esp8266/core_esp8266_version.h @@ -53,20 +53,22 @@ extern "C++" // case 2.5.0: // esp8266CoreVersionSubRevision() is 0 Numeric is: 20500000 +namespace conststr { + constexpr -bool constexpr_isDecimal (const char c) +bool isDecimal (const char c) { return c >= '0' && c <= '9'; } template constexpr -bool constexpr_isMinus (const char (&arr) [N], unsigned i) +bool isMinus (const char (&arr) [N], unsigned i) { - return arr[i] == '-' && constexpr_isDecimal(arr[i+1]); + return arr[i] == '-' && isDecimal(arr[i+1]); } template constexpr -int constexpr_atoi (const char (&arr) [N], unsigned i) +int atoi (const char (&arr) [N], unsigned i) { return ({ // <= c++11 requires a "return statement" int ret = 0; @@ -76,54 +78,58 @@ int constexpr_atoi (const char (&arr) [N], unsigned i) sign = -1; i++; } - while (constexpr_isDecimal(arr[i])) + while (isDecimal(arr[i])) ret = 10*ret + arr[i++] - '0'; ret * sign; }); } template constexpr -int constexpr_extract_int (const char (&arr) [N], unsigned f) +int parseNthInteger (const char (&arr) [N], unsigned f) { return ({ // <= c++11 requires a "return statement" unsigned i = 0; while (f && arr[i]) { - if (constexpr_isMinus(arr, i)) + if (isMinus(arr, i)) i++; - for (; constexpr_isDecimal(arr[i]); i++); + for (; isDecimal(arr[i]); i++); f--; - for (; arr[i] && !constexpr_isMinus(arr, i) && !constexpr_isDecimal(arr[i]); i++); + for (; arr[i] && !isMinus(arr, i) && !isDecimal(arr[i]); i++); } - constexpr_atoi(arr, i); + atoi(arr, i); }); } +}; // namespace conststr + +namespace esp8266 { + /* * version major */ constexpr -int esp8266CoreVersionMajor () +int coreVersionMajor () { - return constexpr_extract_int(STR(ARDUINO_ESP8266_GIT_DESC), 0); + return conststr::parseNthInteger(STR(ARDUINO_ESP8266_GIT_DESC), 0); } /* * version minor */ constexpr -int esp8266CoreVersionMinor () +int coreVersionMinor () { - return constexpr_extract_int(STR(ARDUINO_ESP8266_GIT_DESC), 1); + return conststr::parseNthInteger(STR(ARDUINO_ESP8266_GIT_DESC), 1); } /* * version revision */ constexpr -int esp8266CoreVersionRevision () +int coreVersionRevision () { - return constexpr_extract_int(STR(ARDUINO_ESP8266_GIT_DESC), 2); + return conststr::parseNthInteger(STR(ARDUINO_ESP8266_GIT_DESC), 2); } /* @@ -131,27 +137,29 @@ int esp8266CoreVersionRevision () * or RC-number (positive) */ constexpr -int esp8266CoreVersionSubRevision () +int coreVersionSubRevision () { - return constexpr_extract_int(STR(ARDUINO_ESP8266_GIT_DESC), 3); + return conststr::parseNthInteger(STR(ARDUINO_ESP8266_GIT_DESC), 3); } /* * unique revision indentifier (never decreases) */ constexpr -int esp8266CoreVersionNumeric () +int coreVersionNumeric () { - return esp8266CoreVersionMajor() * 10000000 - + esp8266CoreVersionMinor() * 100000 - + esp8266CoreVersionRevision() * 1000 - + (esp8266CoreVersionSubRevision() < 0 ? - -esp8266CoreVersionSubRevision() : - esp8266CoreVersionSubRevision() ? - esp8266CoreVersionSubRevision() - 100 : - 0); + return coreVersionMajor() * 10000000 + + coreVersionMinor() * 100000 + + coreVersionRevision() * 1000 + + (coreVersionSubRevision() < 0 ? + -coreVersionSubRevision() : + coreVersionSubRevision() ? + coreVersionSubRevision() - 100 : + 0); } +}; // namespace esp8266 + } // extern "C++" #endif // __cplusplus #endif // __CORE_ESP8266_ESP8266_VERSION_H diff --git a/libraries/esp8266/keywords.txt b/libraries/esp8266/keywords.txt index b0492666a5..3936385554 100644 --- a/libraries/esp8266/keywords.txt +++ b/libraries/esp8266/keywords.txt @@ -79,9 +79,11 @@ WAKE_RF_DISABLED LITERAL1 ADC_VCC LITERAL1 ADC_TOUT LITERAL1 -# constexpr -esp8266CoreVersionMajor LITERAL1 -esp8266CoreVersionMinor LITERAL1 -esp8266CoreVersionRevision LITERAL1 -esp8266CoreVersionSubRevision LITERAL1 -esp8266CoreVersionNumeric LITERAL1 +####################################### +# namespace esp8266 +####################################### +coreVersionMajor LITERAL1 +coreVersionMinor LITERAL1 +coreVersionRevision LITERAL1 +coreVersionSubRevision LITERAL1 +coreVersionNumeric LITERAL1