Merge pull request #12896 from sillyfrog/python-pio-updates

Python PIO tool controls using environment variables
This commit is contained in:
Theo Arends 2021-08-16 15:08:47 +02:00 committed by GitHub
commit 370bf89915
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 4 deletions

View File

@ -28,6 +28,7 @@ def map_gzip(source, target, env):
map_file.unlink() map_file.unlink()
if not tasmotapiolib.is_env_set(tasmotapiolib.DISABLE_MAP_GZ):
env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", [map_gzip]) env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", [map_gzip])
# gzip only for ESP8266 # gzip only for ESP8266
@ -65,4 +66,5 @@ if env["PIOPLATFORM"] != "espressif32":
) )
) )
if not tasmotapiolib.is_env_set(tasmotapiolib.DISABLE_BIN_GZ):
env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", [bin_gzip]) env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", [bin_gzip])

View File

@ -1,5 +1,18 @@
"""Supporting library for pio-tools scripts""" """Supporting library for pio-tools scripts"""
import pathlib import pathlib
import os
# Constants for environment variables that can be set to control build output file
# locations and formats
# if set to 1, will not gzip esp8266 bin files
DISABLE_BIN_GZ = "TASMOTA_DISABLE_BIN_GZ"
# if set, an alternative ptah to put generated .bin files
BIN_DIR = "TASMOTA_BIN_DIR"
# if set to 1, will not gzip generated .map files
DISABLE_MAP_GZ = "TASMOTA_DISABLE_MAP_GZ"
# if set, an alternative path to put generated .map files
MAP_DIR = "TASMOTA_MAP_DIR"
OUTPUT_DIR = pathlib.Path("build_output") OUTPUT_DIR = pathlib.Path("build_output")
@ -13,7 +26,7 @@ def get_final_bin_path(env) -> pathlib.Path:
"""Path to the final destination for the .bin """Path to the final destination for the .bin
If the parent directory does not exist, it will be created""" If the parent directory does not exist, it will be created"""
firmware_dir = OUTPUT_DIR / "firmware" firmware_dir = get_override_path(BIN_DIR)
firmware_dir.mkdir(parents=True, exist_ok=True) firmware_dir.mkdir(parents=True, exist_ok=True)
return firmware_dir / "{}.bin".format(get_variant(env)) return firmware_dir / "{}.bin".format(get_variant(env))
@ -22,7 +35,7 @@ def get_final_map_path(env) -> pathlib.Path:
"""Path to the final destination for the .map file """Path to the final destination for the .map file
If the parent directory does not exist, it will be created""" If the parent directory does not exist, it will be created"""
map_dir = OUTPUT_DIR / "map" map_dir = get_override_path(MAP_DIR)
map_dir.mkdir(parents=True, exist_ok=True) map_dir.mkdir(parents=True, exist_ok=True)
return map_dir / "{}.map".format(get_variant(env)) return map_dir / "{}.map".format(get_variant(env))
@ -47,3 +60,28 @@ def get_source_map_path(env) -> pathlib.Path:
return fwmap_path return fwmap_path
raise FileNotFoundError raise FileNotFoundError
def get_override_path(pathtype) -> pathlib.Path:
"""
Returns a path to a givens override path if set, otherwise OUTPUT_DIR is used
pathtype must be either MAP_DIR or BIN_DIR.
"""
override = os.environ.get(pathtype)
if override:
return pathlib.Path(override)
if pathtype == BIN_DIR:
return OUTPUT_DIR / "firmware"
elif pathtype == MAP_DIR:
return OUTPUT_DIR / "map"
raise ValueError
def is_env_set(name: str):
"""True if the enviornment variable <name> is set to `1`"""
val = os.environ.get(name.upper())
if val:
val = val.strip()
return val == "1"
return False