mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-06 05:21:22 +03:00
constexpr helpers to identify core version (#5269)
This commit is contained in:
parent
fcdffc5dfd
commit
c6777149a8
@ -38,6 +38,7 @@ extern "C" {
|
|||||||
#include "esp8266_peri.h"
|
#include "esp8266_peri.h"
|
||||||
#include "twi.h"
|
#include "twi.h"
|
||||||
#include "core_esp8266_features.h"
|
#include "core_esp8266_features.h"
|
||||||
|
#include "core_esp8266_version.h"
|
||||||
|
|
||||||
#define HIGH 0x1
|
#define HIGH 0x1
|
||||||
#define LOW 0x0
|
#define LOW 0x0
|
||||||
|
@ -35,6 +35,7 @@ String EspClass::getFullVersion()
|
|||||||
{
|
{
|
||||||
return String(F("SDK:")) + system_get_sdk_version()
|
return String(F("SDK:")) + system_get_sdk_version()
|
||||||
+ F("/Core:") + FPSTR(arduino_esp8266_git_ver)
|
+ F("/Core:") + FPSTR(arduino_esp8266_git_ver)
|
||||||
|
+ F("=") + String(esp8266::coreVersionNumeric())
|
||||||
#if LWIP_VERSION_MAJOR == 1
|
#if LWIP_VERSION_MAJOR == 1
|
||||||
+ F("/lwIP:") + String(LWIP_VERSION_MAJOR) + "." + String(LWIP_VERSION_MINOR) + "." + String(LWIP_VERSION_REVISION)
|
+ F("/lwIP:") + String(LWIP_VERSION_MAJOR) + "." + String(LWIP_VERSION_MINOR) + "." + String(LWIP_VERSION_REVISION)
|
||||||
#if LWIP_VERSION_IS_DEVELOPMENT
|
#if LWIP_VERSION_IS_DEVELOPMENT
|
||||||
@ -47,9 +48,9 @@ String EspClass::getFullVersion()
|
|||||||
+ F("/lwIP:")
|
+ F("/lwIP:")
|
||||||
#if LWIP_IPV6
|
#if LWIP_IPV6
|
||||||
+ F("IPv6+")
|
+ F("IPv6+")
|
||||||
#endif
|
#endif // LWIP_IPV6
|
||||||
+ F(LWIP_HASH_STR)
|
+ F(LWIP_HASH_STR)
|
||||||
#endif
|
#endif // LWIP_VERSION_MAJOR != 1
|
||||||
+ FPSTR(bearssl_version)
|
+ FPSTR(bearssl_version)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
165
cores/esp8266/core_esp8266_version.h
Normal file
165
cores/esp8266/core_esp8266_version.h
Normal file
@ -0,0 +1,165 @@
|
|||||||
|
|
||||||
|
/*
|
||||||
|
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
|
||||||
|
|
||||||
|
#include <core_version.h>
|
||||||
|
|
||||||
|
#define STRHELPER(x) #x
|
||||||
|
#define STR(x) STRHELPER(x)
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
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:
|
||||||
|
// - <major>.<minor>.<revision> (2.4.2) (2.5.0)
|
||||||
|
// - <major>.<minor>.<revision>-rc<rc> (2.5.0-rc1) (2.5.0-rc2)
|
||||||
|
//
|
||||||
|
// "git describe" = ARDUINO_ESP8266_GIT_DESC will thus be in the form:
|
||||||
|
// - <tag> (2.4.2) (2.5.0)
|
||||||
|
// - <tag>-<numberOfCommits>-g<git-hash> (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
|
||||||
|
|
||||||
|
namespace conststr {
|
||||||
|
|
||||||
|
constexpr
|
||||||
|
bool isDecimal (const char c)
|
||||||
|
{
|
||||||
|
return c >= '0' && c <= '9';
|
||||||
|
}
|
||||||
|
|
||||||
|
template<unsigned N> constexpr
|
||||||
|
bool isMinus (const char (&arr) [N], unsigned i)
|
||||||
|
{
|
||||||
|
return arr[i] == '-' && isDecimal(arr[i+1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<unsigned N> constexpr
|
||||||
|
int atoi (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 (isDecimal(arr[i]))
|
||||||
|
ret = 10*ret + arr[i++] - '0';
|
||||||
|
ret * sign;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
template<unsigned N> constexpr
|
||||||
|
int parseNthInteger (const char (&arr) [N], unsigned f)
|
||||||
|
{
|
||||||
|
return ({ // <= c++11 requires a "return statement"
|
||||||
|
unsigned i = 0;
|
||||||
|
while (f && arr[i])
|
||||||
|
{
|
||||||
|
if (isMinus(arr, i))
|
||||||
|
i++;
|
||||||
|
for (; isDecimal(arr[i]); i++);
|
||||||
|
f--;
|
||||||
|
for (; arr[i] && !isMinus(arr, i) && !isDecimal(arr[i]); i++);
|
||||||
|
}
|
||||||
|
atoi(arr, i);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}; // namespace conststr
|
||||||
|
|
||||||
|
namespace esp8266 {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* version major
|
||||||
|
*/
|
||||||
|
constexpr
|
||||||
|
int coreVersionMajor ()
|
||||||
|
{
|
||||||
|
return conststr::parseNthInteger(STR(ARDUINO_ESP8266_GIT_DESC), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* version minor
|
||||||
|
*/
|
||||||
|
constexpr
|
||||||
|
int coreVersionMinor ()
|
||||||
|
{
|
||||||
|
return conststr::parseNthInteger(STR(ARDUINO_ESP8266_GIT_DESC), 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* version revision
|
||||||
|
*/
|
||||||
|
constexpr
|
||||||
|
int coreVersionRevision ()
|
||||||
|
{
|
||||||
|
return conststr::parseNthInteger(STR(ARDUINO_ESP8266_GIT_DESC), 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* git commit number since last tag (negative)
|
||||||
|
* or RC-number (positive)
|
||||||
|
*/
|
||||||
|
constexpr
|
||||||
|
int coreVersionSubRevision ()
|
||||||
|
{
|
||||||
|
return conststr::parseNthInteger(STR(ARDUINO_ESP8266_GIT_DESC), 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* unique revision indentifier (never decreases)
|
||||||
|
*/
|
||||||
|
constexpr
|
||||||
|
int coreVersionNumeric ()
|
||||||
|
{
|
||||||
|
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
|
@ -77,4 +77,13 @@ WAKE_RFCAL LITERAL1
|
|||||||
WAKE_NO_RFCAL LITERAL1
|
WAKE_NO_RFCAL LITERAL1
|
||||||
WAKE_RF_DISABLED LITERAL1
|
WAKE_RF_DISABLED LITERAL1
|
||||||
ADC_VCC LITERAL1
|
ADC_VCC LITERAL1
|
||||||
ADC_TOUT LITERAL1
|
ADC_TOUT LITERAL1
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# namespace esp8266
|
||||||
|
#######################################
|
||||||
|
coreVersionMajor LITERAL1
|
||||||
|
coreVersionMinor LITERAL1
|
||||||
|
coreVersionRevision LITERAL1
|
||||||
|
coreVersionSubRevision LITERAL1
|
||||||
|
coreVersionNumeric LITERAL1
|
||||||
|
@ -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.
|
* When done, put release notes into a private Gist and send the link to other maintainers for review.
|
||||||
|
|
||||||
|
* 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):
|
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):
|
||||||
|
|
||||||
```
|
```
|
||||||
|
Loading…
x
Reference in New Issue
Block a user