I’d like to perform different actions depending on whether the “build” or “clean” targets are running. I couldn’t figure out a way to determine this from within my “pre:” extra_scripts
script. Is there a way to do this?
I should add: I’m using a shell script, called from this python (named build-prep.sh):
import os
os.system('. build-prep.sh')
I get this:
NameError: name 'SCons' is not defined:
Here’s the full “extra_scripts” script:
from SCons.Script import (COMMAND_LINE_TARGETS, AlwaysBuild,
Builder, Default, DefaultEnvironment)
print(COMMAND_LINE_TARGETS)
Is there a simple “extra_scripts” script that tells me true or false to this question:
“Is the current target ‘clean’?”
None of my experiments have worked, and I’m not following the example. Also, I’m brand new at Python and at SCons, so I’m having much difficulty figuring this out.
extra_scripts are not invoked when the target is only clean in the first place, so this case can’t be catched.
When I run “clean”, this prints for “pre:my_script.py”:
Current CLI targets []
Current Build targets []
Here’s the “extra_script” script (“pre”):
Import("env")
print("Current CLI targets", COMMAND_LINE_TARGETS)
print("Current Build targets", BUILD_TARGETS)
I’m entirely unclear when “pre” scripts run and when “post” scripts run.
Here’s what I’m trying to do: I have a shell script that runs as part of a “post” python script (it’s one line: os.system('. build-prep.sh')
) that processes some data and creates some source files just before compilation. I want to delete those files when I call “clean”.
Ah–
Yeah extra_scripts = pre:test.py
with
Import("env")
if env.IsCleanTarget():
print("==== WE WANT TO DO A CLEAN ====")
works fine.
> pio run -t clean -v -e gd32350g_start
Processing gd32350g_start (board: gd32350g_start; framework: arduino; platform: https://github.com/CommunityGD32Cores/platform-gd32.git; platform_packages: framework-arduinogd32@https://github.com/CommunityGD32Cores/ArduinoCore-GD32.git; monitor_speed: 115200; extra_scripts: pre:experiment.py)
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------[]
==== WE WANT TO DO A CLEAN ====
Removing .pio\build\gd32350g_start
Done cleaning