From 008cae118b5f94f6351e65d5c68d4adb7ea9b712 Mon Sep 17 00:00:00 2001 From: hedger Date: Sun, 18 Sep 2022 21:25:57 +0400 Subject: [PATCH 1/3] fbt: removed assets rebuild on git commit id change; added explicit dependency for SDK source on compiled assets parts; removed unneeded sdk regeneration runs --- assets/SConscript | 13 +---------- firmware.scons | 2 +- site_scons/fbt/sdk.py | 39 +++++++++++++++++--------------- site_scons/site_tools/fbt_sdk.py | 1 + 4 files changed, 24 insertions(+), 31 deletions(-) diff --git a/assets/SConscript b/assets/SConscript index 9776b3fdb..47713d1a6 100644 --- a/assets/SConscript +++ b/assets/SConscript @@ -1,16 +1,5 @@ Import("env") -from fbt.version import get_fast_git_version_id - -# HACHHACK -# Currently injected to CPPPATH by libs - since they are built earlier and depend on assets -# env.Append( -# CPPPATH=[ -# Dir("./compiled"), -# ] -# ) -version_value = Value(get_fast_git_version_id()) - assetsenv = env.Clone( tools=["fbt_assets"], FW_LIB_NAME="assets", @@ -77,7 +66,6 @@ assetsenv.Alias("proto_ver", proto_ver) # Gather everything into a static lib assets_parts = (icons, proto, dolphin_blocking, dolphin_internal, proto_ver) -assetsenv.Depends(assets_parts, version_value) assetslib = assetsenv.Library("${FW_LIB_NAME}", assets_parts) assetsenv.Install("${LIB_DIST_DIR}", assetslib) @@ -113,6 +101,7 @@ if assetsenv["IS_BASE_FIRMWARE"]: ) # Exporting resources node to external environment + env["FW_ASSETS_HEADERS"] = assets_parts env["FW_RESOURCES"] = resources assetsenv.Alias("resources", resources) diff --git a/firmware.scons b/firmware.scons index 962c70725..530634ef2 100644 --- a/firmware.scons +++ b/firmware.scons @@ -302,7 +302,7 @@ if fwenv["IS_BASE_FIRMWARE"]: "-D__inline__=inline", ], ) - Depends(sdk_source, fwenv["SDK_HEADERS"]) + Depends(sdk_source, (fwenv["SDK_HEADERS"], fwenv["FW_ASSETS_HEADERS"])) sdk_tree = fwenv.SDKTree("sdk/sdk.opts", "sdk_origin") AlwaysBuild(sdk_tree) diff --git a/site_scons/fbt/sdk.py b/site_scons/fbt/sdk.py index b8ae7fb76..3d4a17b2f 100644 --- a/site_scons/fbt/sdk.py +++ b/site_scons/fbt/sdk.py @@ -329,7 +329,6 @@ class SdkCache: self.sdk = ApiEntries() self.disabled_entries = set() self.new_entries = set() - self.loaded_dirty = False self.loaded_dirty_version = False self.version_action = VersionBump.NONE @@ -340,8 +339,7 @@ class SdkCache: return ( self.version != SdkVersion(0, 0) and self.version_action == VersionBump.NONE - and not self.loaded_dirty - and not self.new_entries + and not self._have_pending_entries() ) def _filter_enabled(self, sdk_entries): @@ -388,21 +386,12 @@ class SdkCache: if self._load_version_only: raise Exception("Only SDK version was loaded, cannot save") - version_is_clean = True - if self.loaded_dirty: - # There are still new entries and version was already updated - version_is_clean = False - if self.version_action == VersionBump.MINOR: self.version = SdkVersion(self.version.major, self.version.minor + 1) - version_is_clean = False elif self.version_action == VersionBump.MAJOR: self.version = SdkVersion(self.version.major + 1, 0) - version_is_clean = False - if version_is_clean: - print(f"API version {self.version} is up to date") - else: + if self._have_pending_entries(): self.new_entries.add(self.version) print( f"API version is still WIP: {self.version}. Review the changes and re-run command." @@ -418,16 +407,23 @@ class SdkCache: ) ) ) + else: + print(f"API version {self.version} is up to date") - if not version_is_clean or self.loaded_dirty_version: - # Regenerate cache file + regenerate_csv = ( + self.loaded_dirty_version + or self._have_pending_entries() + or self.version_action != VersionBump.NONE + ) + + if regenerate_csv: str_cache_entries = [self.version] name_getter = operator.attrgetter("name") str_cache_entries.extend(sorted(self.sdk.headers, key=name_getter)) str_cache_entries.extend(sorted(self.sdk.functions, key=name_getter)) str_cache_entries.extend(sorted(self.sdk.variables, key=name_getter)) - with open(self.cache_file_name, "w", newline="") as f: + with open(self.cache_file_name, "wt", newline="") as f: writer = csv.DictWriter(f, fieldnames=SdkCache.CSV_FIELD_NAMES) writer.writeheader() @@ -476,13 +472,20 @@ class SdkCache: f"Cannot load symbol cache '{self.cache_file_name}'! File does not exist" ) - with open(self.cache_file_name, "r") as f: + with open(self.cache_file_name, "rt") as f: reader = csv.DictReader(f) for row in reader: self._process_entry(row) if self._load_version_only and row.get("entry") == SdkVersion.csv_type: break - self.loaded_dirty = bool(self.new_entries) + + def _have_pending_entries(self) -> bool: + return any( + filter( + lambda e: not isinstance(e, SdkVersion), + self.new_entries, + ) + ) def sync_sets( self, known_set: Set[Any], new_set: Set[Any], update_version: bool = True diff --git a/site_scons/site_tools/fbt_sdk.py b/site_scons/site_tools/fbt_sdk.py index 26d663650..f6c2d452e 100644 --- a/site_scons/site_tools/fbt_sdk.py +++ b/site_scons/site_tools/fbt_sdk.py @@ -15,6 +15,7 @@ from fbt.sdk import SdkCollector, SdkCache def prebuild_sdk_emitter(target, source, env): target.append(env.ChangeFileExtension(target[0], ".d")) + target.append(env.ChangeFileExtension(target[0], ".i.c")) return target, source From d9d5cc6373fb9bbc4cd36c1f3b02565a429cb14a Mon Sep 17 00:00:00 2001 From: hedger Date: Sun, 18 Sep 2022 22:16:15 +0400 Subject: [PATCH 2/3] fbt: changed stock plugins to EXTERNAL apps; restored building app as a PLUGIN as a part of main fw as well as a .fap; readme fixes --- applications/plugins/bt_hid_app/application.fam | 2 +- applications/plugins/music_player/application.fam | 2 +- applications/plugins/picopass/application.fam | 2 +- applications/plugins/snake_game/application.fam | 2 +- documentation/AppManifests.md | 8 ++++---- fbt_options.py | 2 +- site_scons/extapps.scons | 5 ++++- 7 files changed, 13 insertions(+), 10 deletions(-) diff --git a/applications/plugins/bt_hid_app/application.fam b/applications/plugins/bt_hid_app/application.fam index e6a3b1752..8751e38e1 100644 --- a/applications/plugins/bt_hid_app/application.fam +++ b/applications/plugins/bt_hid_app/application.fam @@ -1,7 +1,7 @@ App( appid="bt_hid", name="Bluetooth Remote", - apptype=FlipperAppType.PLUGIN, + apptype=FlipperAppType.EXTERNAL, entry_point="bt_hid_app", stack_size=1 * 1024, cdefines=["APP_BLE_HID"], diff --git a/applications/plugins/music_player/application.fam b/applications/plugins/music_player/application.fam index 76787e097..c2df4e51a 100644 --- a/applications/plugins/music_player/application.fam +++ b/applications/plugins/music_player/application.fam @@ -1,7 +1,7 @@ App( appid="music_player", name="Music Player", - apptype=FlipperAppType.PLUGIN, + apptype=FlipperAppType.EXTERNAL, entry_point="music_player_app", cdefines=["APP_MUSIC_PLAYER"], requires=[ diff --git a/applications/plugins/picopass/application.fam b/applications/plugins/picopass/application.fam index 887d0324c..7a81e0804 100644 --- a/applications/plugins/picopass/application.fam +++ b/applications/plugins/picopass/application.fam @@ -1,7 +1,7 @@ App( appid="picopass", name="PicoPass Reader", - apptype=FlipperAppType.PLUGIN, + apptype=FlipperAppType.EXTERNAL, entry_point="picopass_app", requires=[ "storage", diff --git a/applications/plugins/snake_game/application.fam b/applications/plugins/snake_game/application.fam index d55f53bb1..b299619a5 100644 --- a/applications/plugins/snake_game/application.fam +++ b/applications/plugins/snake_game/application.fam @@ -1,7 +1,7 @@ App( appid="snake_game", name="Snake Game", - apptype=FlipperAppType.PLUGIN, + apptype=FlipperAppType.EXTERNAL, entry_point="snake_game_app", cdefines=["APP_SNAKE_GAME"], requires=["gui"], diff --git a/documentation/AppManifests.md b/documentation/AppManifests.md index 5e7ceb939..58ac292d7 100644 --- a/documentation/AppManifests.md +++ b/documentation/AppManifests.md @@ -1,6 +1,6 @@ # Flipper Application Manifests (.fam) -All components of Flipper Zero firmware — services, user applications, system settings — are developed independently. Each component has a build system manifest file, named `application.fam`, defining basic properties of a components and its relations to other parts of the system. +All components of Flipper Zero firmware — services, user applications, system settings — are developed independently. Each component has a build system manifest file, named `application.fam`, defining basic properties of a component and its relations to other parts of the system. When building firmware, **`fbt`** collects all application manifests, processes their dependencies and builds only those components that are utilized in current build configuration. See [fbt docs](./fbt.md#firmware-application-set) for details on build configurations. @@ -21,12 +21,12 @@ Only 2 parameters are mandatoty: ***appid*** and ***apptype***, others are optio | SERVICE | System service, created at early startup | | SYSTEM | Application not being shown in any menus. Can be started by other apps or from CLI | | APP | Regular application for main menu | -| PLUGIN | Application to be built as .fap plugin | +| PLUGIN | Application to be built as a part of firmware an to be placed in Plugins menu | | DEBUG | Application only visible in Debug menu with debug mode enabled | | ARCHIVE | One and only Archive app | | SETTINGS | Application to be placed in System settings menu | -| STARTUP | Callback function to run at system startup. Does not define a separate app | -| EXTERNAL | Application to be built as .fap plugin | +| STARTUP | Callback function to run at system startup. Does not define a standalone app | +| EXTERNAL | Application to be built as a .fap executable file | | METAPACKAGE | Does not define any code to be run, used for declaring dependencies and application bundles | * **name**: Name to show in menus. diff --git a/fbt_options.py b/fbt_options.py index bdf8fc03b..820fca871 100644 --- a/fbt_options.py +++ b/fbt_options.py @@ -74,7 +74,7 @@ FIRMWARE_APPS = { # Settings "settings_apps", # Plugins - # "basic_plugins", + "basic_plugins", # Debug # "debug_apps", ], diff --git a/site_scons/extapps.scons b/site_scons/extapps.scons index cfffda04f..c4df2ceed 100644 --- a/site_scons/extapps.scons +++ b/site_scons/extapps.scons @@ -63,7 +63,10 @@ def build_app_as_external(env, appdef): extapps["dist"][appdef.appid] = (appdef.fap_category, compact_elf) -apps_to_build_as_faps = [FlipperAppType.PLUGIN, FlipperAppType.EXTERNAL] +apps_to_build_as_faps = [ + # FlipperAppType.PLUGIN, + FlipperAppType.EXTERNAL, +] if appenv["DEBUG_TOOLS"]: apps_to_build_as_faps.append(FlipperAppType.DEBUG) From 7235f8104500995ec6c7316cc408e291696812c8 Mon Sep 17 00:00:00 2001 From: hedger Date: Sun, 18 Sep 2022 22:19:21 +0400 Subject: [PATCH 3/3] fbt: restored certain apps to PLUGIN type --- applications/plugins/bt_hid_app/application.fam | 2 +- applications/plugins/music_player/application.fam | 2 +- applications/plugins/snake_game/application.fam | 2 +- fbt_options.py | 5 +++-- site_scons/extapps.scons | 2 +- 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/applications/plugins/bt_hid_app/application.fam b/applications/plugins/bt_hid_app/application.fam index 8751e38e1..e6a3b1752 100644 --- a/applications/plugins/bt_hid_app/application.fam +++ b/applications/plugins/bt_hid_app/application.fam @@ -1,7 +1,7 @@ App( appid="bt_hid", name="Bluetooth Remote", - apptype=FlipperAppType.EXTERNAL, + apptype=FlipperAppType.PLUGIN, entry_point="bt_hid_app", stack_size=1 * 1024, cdefines=["APP_BLE_HID"], diff --git a/applications/plugins/music_player/application.fam b/applications/plugins/music_player/application.fam index c2df4e51a..76787e097 100644 --- a/applications/plugins/music_player/application.fam +++ b/applications/plugins/music_player/application.fam @@ -1,7 +1,7 @@ App( appid="music_player", name="Music Player", - apptype=FlipperAppType.EXTERNAL, + apptype=FlipperAppType.PLUGIN, entry_point="music_player_app", cdefines=["APP_MUSIC_PLAYER"], requires=[ diff --git a/applications/plugins/snake_game/application.fam b/applications/plugins/snake_game/application.fam index b299619a5..d55f53bb1 100644 --- a/applications/plugins/snake_game/application.fam +++ b/applications/plugins/snake_game/application.fam @@ -1,7 +1,7 @@ App( appid="snake_game", name="Snake Game", - apptype=FlipperAppType.EXTERNAL, + apptype=FlipperAppType.PLUGIN, entry_point="snake_game_app", cdefines=["APP_SNAKE_GAME"], requires=["gui"], diff --git a/fbt_options.py b/fbt_options.py index 820fca871..716f99fdf 100644 --- a/fbt_options.py +++ b/fbt_options.py @@ -73,8 +73,9 @@ FIRMWARE_APPS = { "system_apps", # Settings "settings_apps", - # Plugins - "basic_plugins", + # Stock plugins - no longer built into fw, now they're .faps + # Yet you can still build them as a part of fw + # "basic_plugins", # Debug # "debug_apps", ], diff --git a/site_scons/extapps.scons b/site_scons/extapps.scons index c4df2ceed..4cb5e35cf 100644 --- a/site_scons/extapps.scons +++ b/site_scons/extapps.scons @@ -64,7 +64,7 @@ def build_app_as_external(env, appdef): apps_to_build_as_faps = [ - # FlipperAppType.PLUGIN, + FlipperAppType.PLUGIN, FlipperAppType.EXTERNAL, ] if appenv["DEBUG_TOOLS"]: