Skip to content

Commit

Permalink
Improve build speed
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieucarbou committed May 3, 2024
1 parent 1548d8e commit 86be1c7
Show file tree
Hide file tree
Showing 13 changed files with 76 additions and 76 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build-oss.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ jobs:
if: ${{ startsWith(matrix.environment, 'oss-') }}
uses: actions/cache@v4
with:
key: ${{ runner.os }}-libdeps-oss
path: .pio/libdeps
key: ${{ runner.os }}-pio-oss-${{ matrix.environment }}
path: .pio

- name: Python
uses: actions/setup-python@v5
Expand Down
6 changes: 3 additions & 3 deletions include/YaSolR.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@
#include <ESPAsyncWebServer.h>
#include <WebSerialLite.h>

#ifdef APP_VERSION_TRIAL
#ifdef APP_MODEL_TRIAL
#include <MycilaTrial.h>
#endif

#ifdef APP_VERSION_PRO
#ifdef APP_MODEL_PRO
#include <ESPDashPro.h>
#else
#include <ESPDash.h>
Expand Down Expand Up @@ -133,6 +133,6 @@ extern Mycila::Task configureSystemTemperatureSensorTask;
extern Mycila::Task configureTaskMonitorTask;
extern Mycila::Task configureZCDTask;

#ifdef APP_VERSION_TRIAL
#ifdef APP_MODEL_TRIAL
extern Mycila::Task trialTask;
#endif
7 changes: 4 additions & 3 deletions include/YaSolRWebsite.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@

#include <map>

#ifdef APP_VERSION_PRO
#ifdef APP_MODEL_PRO
#define PUSH_BUTTON_CARD_CB ()
#else
#define ENERGY_CARD GENERIC_CARD
#define PUSH_BUTTON_CARD BUTTON_CARD
#define PUSH_BUTTON_CARD_CB (int32_t value)
#endif

// TODO: simplify
namespace YaSolR {
class WebsiteClass {
public:
Expand Down Expand Up @@ -64,7 +65,7 @@ namespace YaSolR {

Statistic _timeStat = Statistic(&dashboard, "Time");
Statistic _uptimeStat = Statistic(&dashboard, "Uptime");
#ifdef APP_VERSION_TRIAL
#ifdef APP_MODEL_TRIAL
Statistic _trialRemainingStat = Statistic(&dashboard, "Remaining Trial Time");
#endif

Expand Down Expand Up @@ -110,7 +111,7 @@ namespace YaSolR {
Card _output2Current = Card(&dashboard, ENERGY_CARD, "Output 2 Current", "A");
Card _output2Resistance = Card(&dashboard, ENERGY_CARD, "Output 2 Resistance", "Ω");

#ifdef APP_VERSION_PRO
#ifdef APP_MODEL_PRO
// health
Card _stateBuzzer = Card(&dashboard, STATUS_CARD, "Buzzer", DASH_STATUS_IDLE);
Card _stateDisplay = Card(&dashboard, STATUS_CARD, "Display", DASH_STATUS_IDLE);
Expand Down
42 changes: 14 additions & 28 deletions lib/MycilaAppInfo/MycilaAppInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,54 +7,40 @@
#include <Esp.h>

#ifndef APP_NAME
#define APP_NAME "YaSolR"
#define APP_NAME "Beelance"
#endif

#ifndef APP_MANUFACTURER
#define APP_MANUFACTURER "Mathieu Carbou"
#endif

#ifdef APP_VERSION_PRO
#ifdef APP_VERSION_TRIAL
#ifdef APP_MODEL_PRO
#ifdef APP_MODEL_TRIAL
#define APP_MODEL "Trial"
#else
#define APP_MODEL "Pro"
#endif
#endif

#ifdef APP_VERSION_OSS
#ifdef APP_MODEL_OSS
#define APP_MODEL "OSS"
#endif

#ifndef APP_VERSION
#define APP_VERSION ""
#endif

#ifndef BUILD_HASH
#define BUILD_HASH ""
#endif

#ifndef BUILD_BRANCH
#define BUILD_BRANCH ""
#endif

#ifndef BUILD_TIMESAMP
#define BUILD_TIMESAMP ""
#endif

#ifndef BUILD_NAME
#define BUILD_NAME ""
#endif
extern const char* __COMPILED_APP_VERSION__;
extern const char* __COMPILED_BUILD_BRANCH__;
extern const char* __COMPILED_BUILD_HASH__;
extern const char* __COMPILED_BUILD_NAME__;
extern const char* __COMPILED_BUILD_TIMESTAMP__;

Mycila::AppInfoClass::AppInfoClass() : id(_getEspId()),
name(APP_NAME),
version(APP_VERSION),
version(__COMPILED_APP_VERSION__),
model(APP_MODEL),
manufacturer(APP_MANUFACTURER),
firmware(String(APP_NAME) + "-" + (version.indexOf("_") >= 0 ? version.substring(0, version.indexOf("_")) : version) + "-" + BUILD_NAME + ".bin"),
buildBranch(BUILD_BRANCH),
buildHash(BUILD_HASH),
buildDate(strlen(BUILD_TIMESAMP) == 0 ? __DATE__ " " __TIME__ : BUILD_TIMESAMP),
firmware(String(APP_NAME) + "-" + (version.indexOf("_") >= 0 ? version.substring(0, version.indexOf("_")) : version) + "-" + __COMPILED_BUILD_NAME__ + ".bin"),
buildBranch(__COMPILED_BUILD_BRANCH__),
buildHash(__COMPILED_BUILD_HASH__),
buildDate(strlen(__COMPILED_BUILD_TIMESTAMP__) == 0 ? __DATE__ " " __TIME__ : __COMPILED_BUILD_TIMESTAMP__),
debug(firmware.indexOf("debug") >= 0),
trial(firmware.indexOf("trial") >= 0) {}

Expand Down
1 change: 1 addition & 0 deletions lib/MycilaTemperatureSensor/MycilaTemperatureSensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ float Mycila::TemperatureSensor::read() {
return _temperature;
}

// TODO: remove
String Mycila::TemperatureSensor::getTemperatureAsString() const {
if (!_enabled || !isValid())
return "??.??";
Expand Down
54 changes: 32 additions & 22 deletions pio/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
import os
from datetime import datetime, timezone

Import("env")

def get_build_flag():

def do_main():
# hash
ret = subprocess.run(
["git", "rev-parse", "HEAD"], stdout=subprocess.PIPE, text=True, check=False
Expand Down Expand Up @@ -48,27 +50,35 @@ def get_build_flag():
if has_local_modifications:
version += "_modified"

return (
'-D APP_VERSION=\\"'
+ version
+ '\\" '
+ '-D BUILD_BRANCH=\\"'
+ branch
+ '\\" '
+ '-D BUILD_HASH=\\"'
+ short_hash
+ '\\" '
+ '-D BUILD_TIMESAMP=\\"'
+ datetime.now(timezone.utc).isoformat()
+ '\\"'
)
constantFile = os.path.join(env.subst("$BUILD_DIR"), "__compiled_constants.c")
with open(constantFile, "w") as f:
f.write(
f'const char* __COMPILED_APP_VERSION__ = "{version}";\n'
f'const char* __COMPILED_BUILD_BRANCH__ = "{branch}";\n'
f'const char* __COMPILED_BUILD_HASH__ = "{short_hash}";\n'
f'const char* __COMPILED_BUILD_NAME__ = "{env["PIOENV"]}";\n'
f'const char* __COMPILED_BUILD_TIMESTAMP__ = "{datetime.now(timezone.utc).isoformat()}";\n'
)

env.AppendUnique(PIOBUILDFILES=[constantFile])

# buildFlags = (
# '-D APP_VERSION=\\"'
# + version
# + '\\" '
# + '-D BUILD_BRANCH=\\"'
# + branch
# + '\\" '
# + '-D BUILD_HASH=\\"'
# + short_hash
# + '\\" '
# + '-D BUILD_TIMESTAMP=\\"'
# + datetime.now(timezone.utc).isoformat()
# + '\\"'
# )

# print("Build flags: " + buildFlags)
# env.Append(BUILD_FLAGS=[buildFlags])

build_flags = get_build_flag()

if "SCons.Script" == __name__:
print("Firmware Revision: " + build_flags)
Import("env")
env.Append(BUILD_FLAGS=[get_build_flag()])
elif "__main__" == __name__:
print(build_flags)
do_main()
6 changes: 3 additions & 3 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -133,23 +133,23 @@ build_flags =
; --------------------------------------------------------------------

[oss]
build_flags = -D APP_VERSION_OSS
build_flags = -D APP_MODEL_OSS
lib_deps =
ayushsharma82/ElegantOTA @ 3.1.1
lib_ignore =
ElegantOTAPro
ESPDASHPro

[pro]
build_flags = -D APP_VERSION_PRO
build_flags = -D APP_MODEL_PRO
lib_deps =
lib_ignore =
ESPDASH

[trial]
build_flags =
${pro.build_flags}
-D APP_VERSION_TRIAL
-D APP_MODEL_TRIAL
; 4 days trial (345600 seconds)
-D MYCILA_TRIAL_DURATION=345600
lib_deps =
Expand Down
1 change: 1 addition & 0 deletions src/YaSolR_HADiscovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#define TAG "HA-DISCO"

// TODO: simplify
void YaSolR::YaSolRClass::publishHADiscovery() {
if (!Mycila::Config.getBool(KEY_HA_DISCOVERY_ENABLE))
return;
Expand Down
1 change: 1 addition & 0 deletions src/YaSolR_MQTT_Publish.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#define TAG "MQTT"

// TODO: simplify
void YaSolR::YaSolRClass::publishMQTT() {
if (Mycila::MQTT.isConnected()) {
const String baseTopic = Mycila::Config.get(KEY_MQTT_TOPIC);
Expand Down
8 changes: 4 additions & 4 deletions src/YaSolR_Tasks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Mycila::Task systemTemperatureTask("systemTemperatureSensor.read()", [](void* pa
});
Mycila::Task websiteTask("YaSolR.updateWebsite()", [](void* params) { YaSolR::YaSolR.updateWebsite(); });

#ifdef APP_VERSION_TRIAL
#ifdef APP_MODEL_TRIAL
Mycila::Task trialTask("Trial.validate()", [](void* params) { Mycila::Trial.validate(); });
#endif

Expand Down Expand Up @@ -131,7 +131,7 @@ Mycila::Task otaPrepareTask("otaPrepareTask", [](void* params) {
jsy.end();
Mycila::ZCD.end();
Mycila::MQTT.end();
#ifdef APP_VERSION_TRIAL
#ifdef APP_MODEL_TRIAL
trialTask.pause();
Mycila::Trial.end();
#endif
Expand Down Expand Up @@ -492,7 +492,7 @@ void YaSolR::YaSolRClass::_initTasks() {
lightsTask.setManager(&loopTaskManager);
lightsTask.setInterval(500 * Mycila::TaskDuration::MILLISECONDS);

#ifdef APP_VERSION_TRIAL
#ifdef APP_MODEL_TRIAL
trialTask.setType(Mycila::TaskType::FOREVER);
trialTask.setManager(&loopTaskManager);
trialTask.setInterval(20 * Mycila::TaskDuration::SECONDS);
Expand Down Expand Up @@ -690,7 +690,7 @@ void YaSolR::YaSolRClass::_initTasks() {
startNetworkServicesTask.setDebugWhen(DEBUG_ENABLED);
stopNetworkServicesTask.setDebugWhen(DEBUG_ENABLED);
systemTemperatureTask.setDebugWhen(DEBUG_ENABLED);
#ifdef APP_VERSION_TRIAL
#ifdef APP_MODEL_TRIAL
trialTask.setDebugWhen(DEBUG_ENABLED);
#endif
#endif
Expand Down
16 changes: 8 additions & 8 deletions src/YaSolR_Website_Init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/
#include <YaSolRWebsite.h>

#ifdef APP_VERSION_PRO
#ifdef APP_MODEL_PRO
#include <ElegantOTAPro.h>
#else
#include <ElegantOTA.h>
Expand All @@ -21,7 +21,7 @@ extern const uint8_t config_html_gz_end[] asm("_binary__pio_data_config_html_gz_

void YaSolR::WebsiteClass::init() {
// pro mode
#ifdef APP_VERSION_PRO
#ifdef APP_MODEL_PRO
dashboard.setTitle((Mycila::AppInfo.name + " " + Mycila::AppInfo.model).c_str());

// dropdowns
Expand Down Expand Up @@ -278,7 +278,7 @@ void YaSolR::WebsiteClass::init() {

// ota

#ifdef APP_VERSION_PRO
#ifdef APP_MODEL_PRO
ElegantOTA.setID(Mycila::AppInfo.firmware.c_str());
ElegantOTA.setTitle((Mycila::AppInfo.name + " Web Updater").c_str());
ElegantOTA.setFWVersion(Mycila::AppInfo.version.c_str());
Expand Down Expand Up @@ -321,7 +321,7 @@ void YaSolR::WebsiteClass::init() {
_relaySwitch(&_relay1Switch, NAME_RELAY1);
_relaySwitch(&_relay2Switch, NAME_RELAY2);

#ifdef APP_VERSION_PRO
#ifdef APP_MODEL_PRO
// management

_boolConfig(&_debugMode, KEY_DEBUG_ENABLE);
Expand Down Expand Up @@ -488,7 +488,7 @@ void YaSolR::WebsiteClass::_sliderConfig(Card* card, const char* key) {
}

void YaSolR::WebsiteClass::_numConfig(Card* card, const char* key) {
#ifdef APP_VERSION_PRO
#ifdef APP_MODEL_PRO
card->attachCallback([key](const char* value) {
if (strlen(value) == 0) {
Mycila::Config.unset(key);
Expand All @@ -508,13 +508,13 @@ void YaSolR::WebsiteClass::_boolConfig(Card* card, const char* key) {
}

void YaSolR::WebsiteClass::_textConfig(Card* card, const char* key) {
#ifdef APP_VERSION_PRO
#ifdef APP_MODEL_PRO
card->attachCallback([key](const char* value) { Mycila::Config.set(key, value); });
#endif
}

void YaSolR::WebsiteClass::_daysConfig(Card* card, const char* key) {
#ifdef APP_VERSION_PRO
#ifdef APP_MODEL_PRO
card->attachCallback([key, card, this](const char* value) {
card->update(value);
dashboard.refreshCard(card);
Expand All @@ -524,7 +524,7 @@ void YaSolR::WebsiteClass::_daysConfig(Card* card, const char* key) {
}

void YaSolR::WebsiteClass::_passwordConfig(Card* card, const char* key) {
#ifdef APP_VERSION_PRO
#ifdef APP_MODEL_PRO
card->attachCallback([key, card, this](const char* value) {
if (strlen(value) == 0) {
Mycila::Config.unset(key);
Expand Down
4 changes: 2 additions & 2 deletions src/YaSolR_Website_Update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void YaSolR::WebsiteClass::_update(bool skipWebSocketPush) {
_wifiRSSIStat.set((String(ESPConnect.getWiFiRSSI()) + " dBm").c_str());
_wifiSignalStat.set((String(ESPConnect.getWiFiSignalQuality()) + " %").c_str());
_wifiSSIDStat.set(ESPConnect.getWiFiSSID().c_str());
#ifdef APP_VERSION_TRIAL
#ifdef APP_MODEL_TRIAL
_trialRemainingStat.set((String(Mycila::Trial.getRemaining()) + " s").c_str());
#endif

Expand Down Expand Up @@ -114,7 +114,7 @@ void YaSolR::WebsiteClass::_update(bool skipWebSocketPush) {
_output2THDi.update(output2.getTHDi() * 100);
_output2Energy.update(output2.getEnergy());

#ifdef APP_VERSION_PRO
#ifdef APP_MODEL_PRO
// management tab

_debugMode.update(Mycila::Config.getBool(KEY_DEBUG_ENABLE));
Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void setup() {
Mycila::System.begin();

// trial
#ifdef APP_VERSION_TRIAL
#ifdef APP_MODEL_TRIAL
Mycila::Trial.begin();
#endif

Expand Down

0 comments on commit 86be1c7

Please sign in to comment.