Dear PIO Team,I wanted to trigger some pre action for an ESP32 build to prepare some Web files.I did the following:
1.) create a pre_build.py file like:
# Custom actions when building program/firmware
def before_build(source, target, env):
print("Prepare headers before build")
# do stuff before build
env.AddPreAction("build", before_build)
2.) add pre:prebuild_sript.py to my env
[env]
platform = https://github.com/pioarduino/platform-espressif32/releases/download/stable/platform-espressif32.zip
framework = arduino
extra_scripts = pre:pre_build.py
But “print Prepare headers before build does not apear when I build.
What doe I make wrong?
The complete File looks like:
Same with buildprog instead of build?
Might also be related to
Is it still true that it’s not possible to define a pre action to the buildprog target?
If so, why does the documentation Pre & Post Actions — PlatformIO latest documentation specifically use this as an example:
# Custom actions when building program/firmware
#
env.AddPreAction("buildprog", callback...)
Of course, I write here because I also fail to do this. Running the code directly in the extra script would mean I won’t get any advantages of SCons, such as only rebuilding when it’s necessa…
Hi MaxGerhardt,
yes same with “buildprog” or “build”.
The strange thing is the post programm action works but the pre actions does not occur.
I think it would be vaoid to immediately execute the “pre build” function directly in the script, without it being attached to a pre action. Like, a direct function call to whetever you want to do.
You mean directly after line 3 ?
The print of the
“Current CLI…” and “Current Build targets” occur as empty array.
Can i call a bash script here in this file?
Do i need some subprocess stuff then?
No, instead of
do
before_build(None, None, env)
Wait a minute….
I saw actually the first time the output of the preaction but it is not repoducable
Here see my image it appears at last after build…
see last line in pic.
Any Idea to run a shell script in the pre_build.py script?
import subprocess
import shlex
subprocess.call(shlex.split('./test.sh param1 param2'))
Tried already but get permission denied.
Great Stuff!
can now build webpack header files before build.
If it’s just about GZipping, you may find it better to use the filesystem approach for the ESP32: You can just place the files verbatim in data/, build a filesystem and upload that. Then the [Question] ESP32: Compress files in Data to GZip before upload possible to SPIFFS? - #15 by szerintedmi can auto GZIP compress the files before upload, so the ESP32’s webserver serves compressed files.
Hi, no its not about gzip only.
1.) compile the Webfiles as minified files
2.) copy to data folder
3.) gzip files
4.) use xxd to create hexdump c-strings
5.) Add PROGMEM to it
6.) create include header files
=> to send from flash not from filesystem, it is said its faster than filesystem.