mirror of
https://github.com/DarkFlippers/unleashed-firmware.git
synced 2025-12-12 04:34:43 +04:00
Merge branch 'ofw-dev' into dev
This commit is contained in:
@@ -23,6 +23,10 @@ class VersionData:
|
||||
version: str
|
||||
target: int
|
||||
build_is_dirty: bool
|
||||
# Since version 1.1
|
||||
firmware_origin: str = ""
|
||||
git_origin: str = ""
|
||||
# More fields may be added in the future
|
||||
extra: Optional[Dict[str, str]] = field(default_factory=dict)
|
||||
|
||||
|
||||
@@ -52,7 +56,7 @@ class VersionLoader:
|
||||
|
||||
# Struct version 1.0
|
||||
extra_data = int(self.version_ptr[5].cast(self._uint_type))
|
||||
return VersionData(
|
||||
version_data = VersionData(
|
||||
git_hash=self.version_ptr[1].cast(self._cstr_type).string(),
|
||||
git_branch=self.version_ptr[2].cast(self._cstr_type).string(),
|
||||
build_date=self.version_ptr[3].cast(self._cstr_type).string(),
|
||||
@@ -60,6 +64,12 @@ class VersionLoader:
|
||||
target=extra_data & 0xF,
|
||||
build_is_dirty=bool((extra_data >> 8) & 0xF),
|
||||
)
|
||||
if minor >= 1:
|
||||
version_data.firmware_origin = (
|
||||
self.version_ptr[6].cast(self._cstr_type).string()
|
||||
)
|
||||
version_data.git_origin = self.version_ptr[7].cast(self._cstr_type).string()
|
||||
return version_data
|
||||
|
||||
def load_unversioned(self):
|
||||
"""Parse an early version of the version struct."""
|
||||
@@ -104,6 +114,10 @@ class FlipperFwVersion(gdb.Command):
|
||||
print(f"\tGit commit: {v.version.git_hash}")
|
||||
print(f"\tDirty: {v.version.build_is_dirty}")
|
||||
print(f"\tHW Target: {v.version.target}")
|
||||
if v.version.firmware_origin:
|
||||
print(f"\tOrigin: {v.version.firmware_origin}")
|
||||
if v.version.git_origin:
|
||||
print(f"\tGit origin: {v.version.git_origin}")
|
||||
|
||||
|
||||
FlipperFwVersion()
|
||||
|
||||
67
scripts/fbt_tools/fbt_envhooks.py
Normal file
67
scripts/fbt_tools/fbt_envhooks.py
Normal file
@@ -0,0 +1,67 @@
|
||||
"""
|
||||
|
||||
To introduce changes to firmware build environment that are specific to your fork:
|
||||
|
||||
create a file "scripts/fbt/fbt_hooks.py"
|
||||
|
||||
With it, you can define functions that will be called at specific points of
|
||||
firmware build configuration, with environment as an argument.
|
||||
|
||||
For example, you can define a function `PreConfigureFwEnvionment(env)` that
|
||||
defines that will be a part of SDK build, so applications can
|
||||
use them for conditional compilation.
|
||||
|
||||
Here is a list of all available hooks:
|
||||
|
||||
PreConfigureFwEnvionment(env):
|
||||
This function is called on firmware environment (incl. updater)
|
||||
before any major configuration is done.
|
||||
|
||||
PostConfigureFwEnvionment(env):
|
||||
This function is called on firmware environment (incl. updater)
|
||||
after all configuration is done.
|
||||
|
||||
PreConfigureUfbtEnvionment(env):
|
||||
This function is called on ufbt environment at the beginning of
|
||||
its configuration, before dist environment is created.
|
||||
|
||||
PostConfigureUfbtEnvionment(env):
|
||||
This function is called on ufbt dist_env environment after all
|
||||
configuration and target creation is done.
|
||||
"""
|
||||
|
||||
|
||||
class DefaultFbtHooks:
|
||||
pass
|
||||
|
||||
|
||||
try:
|
||||
from fbt import fbt_hooks
|
||||
except ImportError:
|
||||
fbt_hooks = DefaultFbtHooks()
|
||||
|
||||
|
||||
def generate(env):
|
||||
stub_hook = lambda env: None
|
||||
control_hooks = [
|
||||
"PreConfigureFwEnvionment",
|
||||
"PostConfigureFwEnvionment",
|
||||
"PreConfigureUfbtEnvionment",
|
||||
"PostConfigureUfbtEnvionment",
|
||||
]
|
||||
|
||||
if (
|
||||
isinstance(fbt_hooks, DefaultFbtHooks)
|
||||
and env.subst("${FIRMWARE_ORIGIN}") != "Official"
|
||||
):
|
||||
# If fbt_hooks.py is not present, but we are not building official firmware,
|
||||
# create "scripts/fbt/fbt_hooks.py" to implement changes to firmware build environment.
|
||||
pass
|
||||
|
||||
for hook_name in control_hooks:
|
||||
hook_fn = getattr(fbt_hooks, hook_name, stub_hook)
|
||||
env.AddMethod(hook_fn, hook_name)
|
||||
|
||||
|
||||
def exists():
|
||||
return True
|
||||
@@ -19,7 +19,9 @@ def generate(env):
|
||||
BUILDERS={
|
||||
"VersionBuilder": Builder(
|
||||
action=Action(
|
||||
'${PYTHON3} "${VERSION_SCRIPT}" generate -t ${TARGET_HW} -o ${TARGET.dir.posix} --dir "${ROOT_DIR}"',
|
||||
'${PYTHON3} "${VERSION_SCRIPT}" generate '
|
||||
"-t ${TARGET_HW} -fw-origin ${FIRMWARE_ORIGIN} "
|
||||
'-o ${TARGET.dir.posix} --dir "${ROOT_DIR}"',
|
||||
"${VERSIONCOMSTR}",
|
||||
),
|
||||
emitter=version_emitter,
|
||||
|
||||
@@ -98,6 +98,7 @@ env = core_env.Clone(
|
||||
"fbt_apps",
|
||||
"fbt_extapps",
|
||||
"fbt_assets",
|
||||
"fbt_envhooks",
|
||||
("compilation_db", {"COMPILATIONDB_COMSTR": "\tCDB\t${TARGET}"}),
|
||||
],
|
||||
FBT_FAP_DEBUG_ELF_ROOT=ufbt_build_dir,
|
||||
@@ -117,6 +118,8 @@ env = core_env.Clone(
|
||||
wrap_tempfile(env, "LINKCOM")
|
||||
wrap_tempfile(env, "ARCOM")
|
||||
|
||||
env.PreConfigureUfbtEnvionment()
|
||||
|
||||
# print(env.Dump())
|
||||
|
||||
# Dist env
|
||||
@@ -474,3 +477,5 @@ dist_env.PhonyTarget(
|
||||
"env",
|
||||
"@echo $( ${FBT_SCRIPT_DIR}/toolchain/fbtenv.sh $)",
|
||||
)
|
||||
|
||||
dist_env.PostConfigureUfbtEnvionment()
|
||||
|
||||
@@ -52,8 +52,23 @@ class GitVersion:
|
||||
"GIT_BRANCH": branch,
|
||||
"VERSION": version,
|
||||
"BUILD_DIRTY": dirty and 1 or 0,
|
||||
"GIT_ORIGIN": ",".join(self._get_git_origins()),
|
||||
}
|
||||
|
||||
def _get_git_origins(self):
|
||||
try:
|
||||
remotes = self._exec_git("remote -v")
|
||||
except subprocess.CalledProcessError:
|
||||
return set()
|
||||
origins = set()
|
||||
for line in remotes.split("\n"):
|
||||
if not line:
|
||||
continue
|
||||
_, destination = line.split("\t")
|
||||
url, _ = destination.split(" ")
|
||||
origins.add(url)
|
||||
return origins
|
||||
|
||||
def _exec_git(self, args):
|
||||
cmd = ["git"]
|
||||
cmd.extend(args.split(" "))
|
||||
@@ -81,6 +96,13 @@ class Main(App):
|
||||
help="hardware target",
|
||||
required=True,
|
||||
)
|
||||
self.parser_generate.add_argument(
|
||||
"-fw-origin",
|
||||
dest="firmware_origin",
|
||||
type=str,
|
||||
help="firmware origin",
|
||||
required=True,
|
||||
)
|
||||
self.parser_generate.add_argument("--dir", dest="sourcedir", required=True)
|
||||
self.parser_generate.set_defaults(func=self.generate)
|
||||
|
||||
@@ -96,6 +118,7 @@ class Main(App):
|
||||
{
|
||||
"BUILD_DATE": build_date.strftime("%d-%m-%Y"),
|
||||
"TARGET": self.args.target,
|
||||
"FIRMWARE_ORIGIN": self.args.firmware_origin,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user