mirror of
https://github.com/xoseperez/espurna.git
synced 2026-03-03 23:14:15 +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.
90 lines
2.2 KiB
Python
90 lines
2.2 KiB
Python
import os
|
|
import functools
|
|
import subprocess
|
|
|
|
from .display import print_warning
|
|
|
|
|
|
try:
|
|
cached = functools.cache
|
|
except AttributeError:
|
|
cached = functools.lru_cache(None)
|
|
|
|
|
|
@cached
|
|
def app_revision():
|
|
def git(*args):
|
|
cmd = ["git"]
|
|
cmd.extend(args)
|
|
proc = subprocess.Popen(
|
|
cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE, universal_newlines=True
|
|
)
|
|
return proc.stdout.readlines()[0].strip()
|
|
|
|
revision = None
|
|
try:
|
|
revision = git("rev-parse", "--short=8", "HEAD")
|
|
except subprocess.CalledProcessError:
|
|
pass
|
|
except FileNotFoundError:
|
|
pass
|
|
|
|
return revision
|
|
|
|
|
|
@cached
|
|
def app_version(version_h):
|
|
version = None
|
|
with open(version_h, "r") as f:
|
|
for line in f:
|
|
if "define" in line and "APP_VERSION" in line:
|
|
version = line.split(" ")[-1]
|
|
version = version.strip().replace('"', "")
|
|
break
|
|
|
|
return version
|
|
|
|
|
|
def app_version_for_env(env):
|
|
return env.get("ESPURNA_BUILD_VERSION") or app_version(
|
|
os.path.join(env.get("PROJECT_DIR"), "espurna/config/version.h")
|
|
)
|
|
|
|
|
|
def app_revision_for_env(env):
|
|
return env.get("ESPURNA_BUILD_REVISION") or app_revision()
|
|
|
|
|
|
def app_suffix_for_env(env):
|
|
return env.get("ESPURNA_BUILD_VERSION_SUFFIX", "")
|
|
|
|
|
|
def app_combined_version(env):
|
|
version = app_version_for_env(env)
|
|
if not version:
|
|
raise ValueError("Version string cannot be empty")
|
|
|
|
revision = app_revision_for_env(env)
|
|
if revision:
|
|
# handle both 1.2.3-dev.git... and 1.2.3-git...
|
|
# and avoid 1.2.3.git... that cannot be parsed by the semantic_version module
|
|
middle = ".git" if "-" in version else "-git"
|
|
version = middle.join([version, revision])
|
|
|
|
suffix = app_suffix_for_env(env)
|
|
if suffix:
|
|
version = "+".join([version, suffix])
|
|
|
|
return version
|
|
|
|
|
|
def app_full_version_for_env(env):
|
|
return env.get("ESPURNA_BUILD_FULL_VERSION") or app_combined_version(env)
|
|
|
|
|
|
def app_inject_version(env):
|
|
def inject_string(env, flag, value):
|
|
env.Append(CPPDEFINES=[(flag, '\\"{}\\"'.format(value))])
|
|
|
|
inject_string(env, "APP_VERSION", app_full_version_for_env(env))
|