Skip to content

Commit

Permalink
[PIO] Generate filename at build, not in post processing
Browse files Browse the repository at this point in the history
Generate filename, included in the build
Use post Python scripts to move files to the right directory
Use post Python scripts to generate .bin.gz files.
  • Loading branch information
TD-er committed May 2, 2020
1 parent 9538a71 commit 7844047
Show file tree
Hide file tree
Showing 20 changed files with 190 additions and 60 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,5 @@ tools/vagrant/Custom.h
.buildcache/
tools/vagrant/pio_envlist.txt

build_output/
Expand Down
8 changes: 6 additions & 2 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,16 @@ build_flags = -DFEATURE_ARDUINO_OTA
upload_port = 192.168.1.152



[debug_flags]
build_flags =

[mqtt_flags]
build_flags = -DMQTT_MAX_PACKET_SIZE=1024

[extra_scripts_default]
extra_scripts = pre:tools/pio/generate-compiletime-defines.py
tools/pio/name-firmware.py
tools/pio/gzip-firmware.py

[common]
lib_ldf_mode = chain
Expand All @@ -73,7 +76,8 @@ upload_speed = 115200
monitor_speed = 115200
;targets = size, checkprogsize
targets =
extra_scripts = pre:pre_default_check.py
extra_scripts = pre:tools/pio/pre_default_check.py
${extra_scripts_default.extra_scripts}


[env]
Expand Down
2 changes: 1 addition & 1 deletion platformio_core_defs.ini
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ build_flags = ${esp82xx_2_6_x.build_flags}
extends = esp82xx_2_6_x
platform = https://github.com/platformio/platform-espressif8266.git
build_flags = ${esp82xx_2_6_x.build_flags}
-DPIO_FRAMEWORK_ARDUINO_ESPRESSIF_SDK22x_191105
-DPIO_FRAMEWORK_ARDUINO_ESPRESSIF_SDK22x_191122
platform_packages =
framework-arduinoespressif8266 @ https://github.com/esp8266/Arduino.git

Expand Down
5 changes: 3 additions & 2 deletions platformio_esp32_envs.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ board_build.f_flash = 80000000L
board_build.flash_mode = dout
board_upload.maximum_size = 1900544
board_build.partitions = esp32_partition_app1810k_spiffs316k.csv
extra_scripts = post:post_esp32.py
extra_scripts = post:tools/pio/post_esp32.py
${extra_scripts_default.extra_scripts}
build_unflags = -Wall
build_flags = ${mqtt_flags.build_flags}
-D BUILD_GIT='"${sysenv.TRAVIS_TAG}"'
Expand All @@ -32,7 +33,7 @@ platform = ${esp32_common.platform}
build_flags = ${esp32_common.build_flags} -DPLUGIN_BUILD_CUSTOM
board = esp32dev
extra_scripts = ${esp32_common.extra_scripts}
pre:pre_custom_esp32.py
pre:tools/pio/pre_custom_esp32.py

[env:test_ESP32_4M316k]
extends = esp32_common
Expand Down
15 changes: 9 additions & 6 deletions platformio_esp82xx_envs.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ build_flags = ${regular_platform.build_flags}
-DBUILD_NO_DEBUG
-DPLUGIN_BUILD_CUSTOM

[esp8266_scripts_custom]
extra_scripts = pre:tools/pio/pre_custom_esp82xx.py
${extra_scripts_default.extra_scripts}

; Custom: 4M1M version --------------------------
[env:custom_ESP8266_4M1M]
Expand All @@ -21,7 +24,7 @@ build_flags = ${regular_platform.build_flags}
${esp8266_4M1M.build_flags}
-DPLUGIN_BUILD_CUSTOM
lib_ignore = ${regular_platform.lib_ignore}
extra_scripts = pre:pre_custom_esp82xx.py
extra_scripts = ${esp8266_scripts_custom.extra_scripts}


[env:custom_sdk3_ESP8266_4M1M]
Expand All @@ -32,7 +35,7 @@ build_flags = ${core_2_7_0_sdk3.build_flags}
${esp8266_4M1M.build_flags}
-DPLUGIN_BUILD_CUSTOM
lib_ignore = ${core_2_7_0_sdk3.lib_ignore}
extra_scripts = pre:pre_custom_esp82xx.py
extra_scripts = ${esp8266_scripts_custom.extra_scripts}


[env:custom_beta_ESP8266_4M1M]
Expand All @@ -43,7 +46,7 @@ build_flags = ${beta_platform.build_flags}
${esp8266_4M1M.build_flags}
-DPLUGIN_BUILD_CUSTOM
lib_ignore = ${beta_platform.lib_ignore}
extra_scripts = pre:pre_custom_esp82xx.py
extra_scripts = ${esp8266_scripts_custom.extra_scripts}


; Custom: 4M2M version --------------------------
Expand All @@ -55,7 +58,7 @@ build_flags = ${regular_platform.build_flags}
${esp8266_4M1M.build_flags}
-DPLUGIN_BUILD_CUSTOM
lib_ignore = ${regular_platform.lib_ignore}
extra_scripts = pre:pre_custom_esp82xx.py
extra_scripts = ${esp8266_scripts_custom.extra_scripts}

; Custom: 1M version --------------------------
[env:custom_ESP8266_1M]
Expand All @@ -66,7 +69,7 @@ build_flags = ${regular_platform.build_flags}
${esp8266_1M.build_flags}
-DPLUGIN_BUILD_CUSTOM
lib_ignore = ${regular_platform.lib_ignore}
extra_scripts = pre:pre_custom_esp82xx.py
extra_scripts = ${esp8266_scripts_custom.extra_scripts}

[env:custom_beta_ESP8266_1M]
extends = esp8266_1M
Expand All @@ -76,7 +79,7 @@ build_flags = ${beta_platform.build_flags}
${esp8266_1M.build_flags}
-DPLUGIN_BUILD_CUSTOM
lib_ignore = ${beta_platform.lib_ignore}
extra_scripts = pre:pre_custom_esp82xx.py
extra_scripts = ${esp8266_scripts_custom.extra_scripts}



Expand Down
17 changes: 10 additions & 7 deletions platformio_special_envs.ini
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ build_flags = ${regular_platform.build_flags}
${debug_pio.build_flags}
${esp8266_4M1M.build_flags}
-DPLUGIN_BUILD_CUSTOM
lib_ignore = ESP32_ping, ESP32WebServer
extra_scripts = pre:pre_custom_esp82xx.py
lib_ignore = ${regular_platform.lib_ignore}
extra_scripts = ${esp8266_scripts_custom.extra_scripts}


[env:spec_debug_beta_custom_ESP8266_4M1M]
Expand All @@ -32,16 +32,18 @@ build_flags = ${beta_platform.build_flags}
${debug_pio.build_flags}
${esp8266_4M1M.build_flags}
-DPLUGIN_BUILD_CUSTOM
lib_ignore = ESP32_ping, ESP32WebServer
extra_scripts = pre:pre_custom_esp82xx.py
lib_ignore = ${beta_platform.lib_ignore}
extra_scripts = ${esp8266_scripts_custom.extra_scripts}


[env:spec_debug_custom_ESP32_4M316k]
extends = esp32_common, debug_pio
platform = ${esp32_common.platform}
build_flags = ${esp32_common.build_flags} ${debug_pio.build_flags} -DPLUGIN_BUILD_CUSTOM
board = esp32dev
extra_scripts = pre:pre_custom_esp32.py
extra_scripts = ${esp32_common.extra_scripts}
pre:tools/pio/pre_custom_esp32.py




Expand All @@ -52,6 +54,7 @@ extra_scripts = pre:pre_custom_esp32.py
extends = esp8266_4M1M
platform = ${regular_platform.platform}
platform_packages = ${regular_platform.platform_packages}
lib_ignore = ESP32_ping, ESP32WebServer
lib_ignore = ${regular_platform.lib_ignore}
build_flags = ${esp8266_4M1M.build_flags} -DMEMORY_ANALYSIS -DPLUGIN_BUILD_CUSTOM -w -DUSE_NON_STANDARD_24_TASKS -DTASKS_MAX=24
extra_scripts = pre:pre_memanalyze.py
extra_scripts = pre:tools/pio/pre_memanalyze.py
pre:tools/pio/generate-compiletime-defines.py
7 changes: 4 additions & 3 deletions src/StringProvider.ino
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "StringProviderTypes.h"

#include "src/Helpers/CompiletimeDefines.h"

String getInternalLabel(LabelType::Enum label, char replaceSpace) {
return to_internal_string(getLabel(label), replaceSpace);
}
Expand Down Expand Up @@ -174,9 +176,8 @@ String getValue(LabelType::Enum label) {
case LabelType::SYSTEM_LIBRARIES: return getSystemLibraryString();
case LabelType::PLUGIN_COUNT: return String(deviceCount + 1);
case LabelType::PLUGIN_DESCRIPTION: return getPluginDescriptionString();
case LabelType::BUILD_TIME: return String(CRCValues.compileDate) + " " + String(CRCValues.compileTime);
case LabelType::BINARY_FILENAME: return String(CRCValues.binaryFilename);

case LabelType::BUILD_TIME: return get_build_date() + " " + get_build_time();
case LabelType::BINARY_FILENAME: return get_build_filename();
case LabelType::SYSLOG_LOG_LEVEL: return getLogLevelDisplayString(Settings.SyslogLevel);
case LabelType::SERIAL_LOG_LEVEL: return getLogLevelDisplayString(getSerialLogLevel());
case LabelType::WEB_LOG_LEVEL: return getLogLevelDisplayString(getWebLogLevel());
Expand Down
37 changes: 7 additions & 30 deletions src/WebServer_SysInfoPage.ino
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ void handle_sysinfo_json() {
json_prop(F("plugins"), getPluginDescriptionString());
json_prop(F("md5"), String(CRCValues.compileTimeMD5[0], HEX));
json_number(F("md5_check"), String(CRCValues.checkPassed()));
json_prop(F("build_time"), String(CRCValues.compileTime));
json_prop(F("filename"), String(CRCValues.binaryFilename));
json_prop(F("build_time"), get_build_time());
json_prop(F("filename"), getValue(LabelType::BINARY_FILENAME));
json_close();

json_open(false, F("esp"));
Expand Down Expand Up @@ -412,37 +412,14 @@ void handle_sysinfo_Firmware() {
addHtml(" ");
addHtml(getPluginDescriptionString());

bool filenameDummy = String(CRCValues.binaryFilename).startsWith(F("ThisIsTheDummy"));

if (!filenameDummy) {
addRowLabel(F("Build Md5"));

String html;
html.reserve(64);

for (byte i = 0; i < 16; i++) {
html += String(CRCValues.compileTimeMD5[i], HEX);
}
addHtml(html);

addRowLabel(F("Md5 check"));

if (!CRCValues.checkPassed()) {
addHtml(F("<font color = 'red'>fail !</font>"));
}
else {
addHtml(F("passed."));
}
addRowLabel(F("Build Origin"));
if (official_build()) {
addHtml(F("Travis Build"));
} else {
addHtml(F("<b>Self built!</b>"));
}
addRowLabelValue_copy(LabelType::BUILD_TIME);

addRowLabel_copy(getLabel(LabelType::BINARY_FILENAME));

if (filenameDummy) {
addHtml(F("<b>Self built!</b>"));
} else {
addHtml(String(CRCValues.binaryFilename));
}
}

void handle_sysinfo_SystemStatus() {
Expand Down
7 changes: 3 additions & 4 deletions src/_CPlugin_Helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@
#include "ESPEasy_common.h"

#include "src/DataStructs/SecurityStruct.h"
#include "src/DataStructs/CRCStruct.h"
#include "src/DataStructs/SettingsStruct.h"

#include "src/DataStructs/ControllerSettingsStruct.h"
#include "src/DataStructs/ESPEasyLimits.h"
#include "src/DataStructs/TimingStats.h"

#include "src/Globals/CRCValues.h"
#include "src/Globals/Settings.h"
#include "src/Globals/SecuritySettings.h"
#include "src/Globals/ESPEasyWiFiEvent.h"

#include "src/Helpers/CompiletimeDefines.h"
#include "src/Helpers/ESPEasy_time_calc.h"

#include <WiFiClient.h>
Expand Down Expand Up @@ -125,9 +124,9 @@ String get_user_agent_request_header_field() {
request += F("ESP Easy/");
request += BUILD;
request += '/';
request += String(CRCValues.compileDate);
request += get_build_date();
request += ' ';
request += String(CRCValues.compileTime);
request += get_build_time();
request += "\r\n";
agent_size = request.length();
return request;
Expand Down
26 changes: 26 additions & 0 deletions src/src/Helpers/CompiletimeDefines.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include "CompiletimeDefines.h"

#ifndef BUILD_BINARY_FILENAME
// FIXME TD-er: Commented out to check if all PIO environments include the pre:tools/pio/generate-compiletime-defines.py
//#define BUILD_BINARY_FILENAME "ThisIsTheDummyPlaceHolderForTheBinaryFilename64ByteLongFilenames"
#endif

String get_build_filename() {
return F(BUILD_BINARY_FILENAME);
}

String get_build_time() {
return __TIME__;
}

String get_build_date() {
return __DATE__;
}

bool official_build() {
#ifdef CONTINUOUS_INTEGRATION
return true;
#else
return false;
#endif
}
12 changes: 12 additions & 0 deletions src/src/Helpers/CompiletimeDefines.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef HELPERS_COMPILETIMEDEFINES_H
#define HELPERS_COMPILETIMEDEFINES_H

#include <Arduino.h>

String get_build_filename();
String get_build_time();
String get_build_date();
bool official_build();


#endif // HELPERS_COMPILETIMEDEFINES_H
6 changes: 3 additions & 3 deletions src/src/Helpers/SystemVariables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "../Globals/CRCValues.h"
#include "StringConverter.h"
#include "../../ESPEasy-Globals.h"

#include "CompiletimeDefines.h"

#ifdef USES_MQTT
# include "../Globals/MQTT.h"
Expand Down Expand Up @@ -103,11 +103,11 @@ void SystemVariables::parseSystemVariables(String& s, boolean useURLencode)
case SSID: value = (wifiStatus == ESPEASY_WIFI_DISCONNECTED) ? F("--") : WiFi.SSID(); break;
case SUNRISE: SMART_REPL_T(SystemVariables::toString(enumval), replSunRiseTimeString); break;
case SUNSET: SMART_REPL_T(SystemVariables::toString(enumval), replSunSetTimeString); break;
case SYSBUILD_DATE: value = String(CRCValues.compileDate); break;
case SYSBUILD_DATE: value = get_build_date(); break;
case SYSBUILD_DESCR: value = getValue(LabelType::BUILD_DESC); break;
case SYSBUILD_FILENAME: value = getValue(LabelType::BINARY_FILENAME); break;
case SYSBUILD_GIT: value = getValue(LabelType::GIT_BUILD); break;
case SYSBUILD_TIME: value = String(CRCValues.compileTime); break;
case SYSBUILD_TIME: value = get_build_time(); break;
case SYSDAY: value = String(node_time.day()); break;
case SYSDAY_0: value = timeReplacement_leadZero(node_time.day()); break;
case SYSHEAP: value = String(ESP.getFreeHeap()); break;
Expand Down
39 changes: 39 additions & 0 deletions tools/pio/generate-compiletime-defines.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

Import('env')
import os
import shutil
from datetime import date


def get_build_filename():
today = date.today()
d1 = today.strftime("%Y%m%d")
return 'ESP_Easy_mega_{}_{}'.format(d1, env["PIOENV"])


def gen_compiletime_defines(node):
"""
`node.name` - a name of File System Node
`node.get_path()` - a relative path
`node.get_abspath()` - an absolute path
"""

# do not modify node if file name does not contain "CRCStruct"
if "CompiletimeDefines.cpp" not in node.name:
return node

# now, we can override ANY SCons variables (CPPDEFINES, CCFLAGS, etc.,) for the specific file
# pass SCons variables as extra keyword arguments to `env.Object()` function
# p.s: run `pio run -t envdump` to see a list with SCons variables

return env.Object(
node,
CPPDEFINES=env["CPPDEFINES"]
+ [("BUILD_BINARY_FILENAME", '\"\"\"{}\"\"\"'.format(get_build_filename()))],
CCFLAGS=env["CCFLAGS"]
)

#return node


env.AddBuildMiddleware(gen_compiletime_defines)
Loading

0 comments on commit 7844047

Please sign in to comment.