Before compiling the project, I need to run the generate.sh or generate.bat script each time, which first compresses the file data and then forms a C array from it and saves it as a header file.
The problem is that depending on the situation (release / debug), the script performs different actions.
How can I implement the correct execution of my script just before compiling the project via extra_skript.py?
The current implementation of the script does not work.
My script takes too long to execute, resulting in errors.
Building in release mode
Compiling .pio/build/release/esp-idf/main/ClickEncoder.c.o
Compiling .pio/build/release/esp-idf/main/addon.c.o
Compiling .pio/build/release/esp-idf/main/addonucg.c.o
Compiling .pio/build/release/esp-idf/main/bt_x01.c.o
Compiling .pio/build/release/esp-idf/main/cencode.c.o
Compiling .pio/build/release/esp-idf/main/custom.c.o
Compiling .pio/build/release/esp-idf/main/eeprom.c.o
Compiling .pio/build/release/esp-idf/main/gpios.c.o
Compiling .pio/build/release/esp-idf/main/interface.c.o
Compiling .pio/build/release/esp-idf/main/irnec.c.o
before_build([".pio/build/release/esp-idf/main/main.c.o"], ["main/main.c"])
before_build WORK
Requesting mini-me of webpage/script.js. . .
Compiling .pio/build/release/esp-idf/main/ota.c.o
Compiling .pio/build/release/esp-idf/main/servers.c.o
Compiling .pio/build/release/esp-idf/main/telnet.c.o
Compiling .pio/build/release/esp-idf/main/vs1053.c.o
Compiling .pio/build/release/esp-idf/main/vs1053b-patches.c.o
Compiling .pio/build/release/esp-idf/main/webclient.c.o
Compiling .pio/build/release/esp-idf/main/webserver.c.o
Compiling .pio/build/release/esp-idf/main/websocket.c.o
In file included from main/webserver.c:10:
include/serv-fs.h:23:10: fatal error: release_page.h: No such file or directory
My platfomio.ini:
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[platformio]
src_dir = main
lib_dir = components
description = ESP32-Radiola
default_envs = release
[env]
platform = https://github.com/platformio/platform-espressif32.git
framework = espidf
board = esp-wrover-kit
monitor_speed = 115200
board_build.partitions = partitions.csv
monitor_flags =
--echo
--raw
extra_scripts = extra_script.py
[common]
build_flags =
-DCONFIG_SPIRAM_CACHE_WORKAROUND
-Iinclude
-Icomponents/audio_player/src
-Icomponents/tda7313
-Icomponents/fifo/src
-Icomponents/ucglib/src
-Icomponents/xpt2046
-DCONFIG_RELEASE
[env:release]
build_type = release
build_flags =
-D FILENAME=ESP32Radiola-release
${common.build_flags}
[env:debug]
build_type = debug
monitor_filters = esp32_exception_decoder
build_flags =
-D FILENAME=ESP32Radiola-debug
${common.build_flags}
-UCONFIG_RELEASE
My extra_script.py:
# -*- coding: utf-8 -*-
import sys
from importlib import reload
# from os.path import isfile, join
from sys import platform
import requests
import subprocess
Import("env")
filename = ""
my_flags = env.ParseFlags(env['BUILD_FLAGS'])
#
for x in my_flags.get("CPPDEFINES"):
# print(x)
if isinstance(x, list):
# grab as key, value
k, v = x
if k == "FILENAME":
filename = v
# no need to iterate further
break
env.Replace(PROGNAME="%s" % str(filename))
# print(env.Dump())
# print(env.subst("$PIOENV"))
# print(env.subst("$TARGET"))
# exit(0)
BUILD_DIR = env.subst("$BUILD_DIR")
def before_build(source, target, env):
print("before_build WORK")
#exit(0)
PROJECT_INCLUDE_DIR = env.subst("$PROJECT_INCLUDE_DIR")
mode = env.subst("$PIOENV")
if mode == 'release':
try:
js_file = 'webpage/script.js'
except:
print("Missing input file")
sys.exit()
# Grab the file contents
with open(js_file, 'r') as c:
js = c.read()
# Pack it, ship it
payload = {'input': js}
url = 'https://javascript-minifier.com/raw'
print("Requesting mini-me of {}. . .".format(c.name))
r = requests.post(url, payload)
# Write out minified version
minified = js_file.rstrip('.js')+'.min.js'
with open(minified, 'w') as m:
m.write(r.text)
print("Minification complete. See {}".format(m.name))
if platform == "linux":
# linux
subprocess.call("./generate.sh " +
PROJECT_INCLUDE_DIR + ' ' + mode, shell=True)
elif platform == "darwin":
# OS X
pass
elif platform == "win32":
# Windows...
subprocess.call('./generate.bat' +
PROJECT_INCLUDE_DIR + ' ' + mode, shell=True)
env.AddPreAction("${BUILD_DIR}/esp-idf/main/main.c.o", before_build)
I execute the command pio run --list-targets
Environment Group Name Title Description
------------- -------- ----------- --------------------------- -----------------------------------------------------
release Advanced compiledb Compilation Database Generate compilation database `compile_commands.json`
release Generic clean Clean
release Platform buildfs Build Filesystem Image
release Platform erase Erase Flash
release Platform menuconfig Run Menuconfig
release Platform size Program Size Calculate program size
release Platform upload Upload
release Platform uploadfs Upload Filesystem Image
release Platform uploadfsota Upload Filesystem Image OTA
debug Advanced compiledb Compilation Database Generate compilation database `compile_commands.json`
debug Generic clean Clean
debug Platform buildfs Build Filesystem Image
debug Platform erase Erase Flash
debug Platform menuconfig Run Menuconfig
debug Platform size Program Size Calculate program size
debug Platform upload Upload
debug Platform uploadfs Upload Filesystem Image
debug Platform uploadfsota Upload Filesystem Image OTA
Why isn’t buildprog
listed?
Although there is a buildprog
on the documentation page.
If in extra_script.py
line env.AddPreAction("${BUILD_DIR}/esp-idf/main/main.c.o", before_build)
is replaced by env.AddPreAction("buildprog", before_build)
, then my script is still launched AFTER the project is built.
Archiving .pio/build/release/lib718/libaudio_player.a
Indexing .pio/build/release/lib718/libaudio_player.a
Archiving .pio/build/release/lib47d/libtda7313.a
Indexing .pio/build/release/lib47d/libtda7313.a
Archiving .pio/build/release/lib350/libucglib.a
Indexing .pio/build/release/lib350/libucglib.a
Linking .pio/build/release/firmware.elf
Building .pio/build/release/firmware.bin
esptool.py v2.6
before_build(["buildprog"], [".pio/build/release/firmware.bin"])
before_build WORK
*** [buildprog] Explicit exit, status 0
Where is the logic?