mirror of
https://github.com/xoseperez/espurna.git
synced 2026-03-03 06:54:16 +01:00
Multiple ways to specify version string through environment variables:
- `ESPURNA_BUILD_FULL_VERSION` to set full version string
By default it is empty, and the version is combined using the values specified below
- `ESPURNA_BUILD_VERSION` to modify the first part of the version string (1.15.0-dev)
By default, uses espurna/config/version.h APP_VERSION value
- `ESPURNA_BUILD_REVISION` to specify revision part of the version string
For example 12345678, which is expanded as either .git12345678 or -git12345678
(depending on whether the version string contains hyphen)
By default, use git to retrieve the first 8 characters of the current HEAD SHA value
- `ESPURNA_BUILD_VERSION_SUFFIX` to specify build metadata part of the string
For example nightly20210607, which is added to the full version as 1.15.0-dev+nightly20210607
Empty by defauld
Adds -t build-and-copy which uses the values above to copy firmware.bin, configurable with:
- `ESPURNA_BUILD_NAME` to set the suffix of the filename.
By default, uses the $PIOENV (aka the string after the env: in the .ini file)
- `ESPURNA_BUILD_DESTINATION` to specify where to copy the .bin files
By default, uses $PROJECT_DIR
Resulting file is stored at:
${ESPURNA_BUILD_DESTINATION}/${ESPURNA_BUILD_FULL_VERSION}/espurna-${ESPURNA_BUILD_FULL_VERSION}-${ESPURNA_BUILD_NAME}.bin
In addition, modify generate_release_sh.py to use the new environment variables.
65 lines
1.9 KiB
Python
65 lines
1.9 KiB
Python
import atexit
|
|
import os
|
|
import shutil
|
|
import tempfile
|
|
import functools
|
|
|
|
from .display import print_warning
|
|
from .version import app_full_version_for_env
|
|
|
|
|
|
def try_remove(path):
|
|
try:
|
|
os.remove(path)
|
|
except: # pylint: disable=bare-except
|
|
print_warning("Please manually remove the file `{}`".format(path))
|
|
|
|
|
|
# emulate .ino concatenation to speed up compilation times
|
|
def merge_cpp(sources, output):
|
|
with tempfile.TemporaryFile() as tmp:
|
|
tmp.write(b"// !!! Automatically generated file; DO NOT EDIT !!! \n")
|
|
tmp.write(b'#include "espurna.h"\n')
|
|
for source in sources:
|
|
src_include = '#include "{}"\n'.format(source)
|
|
tmp.write(src_include.encode("utf-8"))
|
|
|
|
tmp.seek(0)
|
|
|
|
with open(output, "wb") as fobj:
|
|
shutil.copyfileobj(tmp, fobj)
|
|
atexit.register(try_remove, output)
|
|
|
|
|
|
def firmware_prefix(env):
|
|
return "espurna-{}".format(app_full_version_for_env(env))
|
|
|
|
|
|
# generate an common name for the current build
|
|
def firmware_filename(env):
|
|
suffix = "{}.bin".format(env["ESPURNA_BUILD_NAME"] or env["PIOENV"])
|
|
return "-".join([firmware_prefix(env), suffix])
|
|
|
|
|
|
def firmware_destination(env):
|
|
destdir = env["ESPURNA_BUILD_DESTINATION"] or env["PROJECT_DIR"]
|
|
subdir = os.path.join(destdir, firmware_prefix(env))
|
|
|
|
return os.path.join(subdir, firmware_filename(env))
|
|
|
|
|
|
def app_add_target_build_and_copy(env):
|
|
from SCons.Script import Copy
|
|
|
|
copy_dest = firmware_destination(env)
|
|
copy = env.Command(
|
|
copy_dest, "${BUILD_DIR}/${PROGNAME}.bin", Copy("$TARGET", "$SOURCE")
|
|
)
|
|
env.AddTarget(
|
|
"build-and-copy",
|
|
copy_dest,
|
|
actions=None, # command invocation already handles this
|
|
title="Build firmware.bin and store a copy",
|
|
description="Build and store firmware.bin as $ESPURNA_BUILD_DESTINATION/espurna-<version>-$ESPURNA_BUILD_NAME.bin (default destination is $PROJECT_DIR)",
|
|
)
|