Skip to content

Commit

Permalink
fbt: source collection improvements (#3181)
Browse files Browse the repository at this point in the history
* fbt: reduced amount of redundant compilation units
* fbt: added GatherSources() method which can reject source paths starting with "!" in sources list; optimized apps' source lists
* docs: updated on path exclusion for `sources`
* apps: examples: fixed example_advanced_plugins source list
* docs: more details on `sources`; apps: narrower sources lists
  • Loading branch information
hedger authored Nov 1, 2023
1 parent bf8984a commit 7bd3bd7
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 12 deletions.
3 changes: 3 additions & 0 deletions applications/examples/example_plugins/application.fam
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ App(
entry_point="example_plugins_app",
stack_size=2 * 1024,
fap_category="Examples",
sources=["*.c", "!plugin*.c"],
)

App(
Expand All @@ -21,11 +22,13 @@ App(
apptype=FlipperAppType.PLUGIN,
entry_point="example_plugin1_ep",
requires=["example_plugins", "example_plugins_multi"],
sources=["plugin1.c"],
)

App(
appid="example_plugin2",
apptype=FlipperAppType.PLUGIN,
entry_point="example_plugin2_ep",
requires=["example_plugins_multi"],
sources=["plugin2.c"],
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ App(
entry_point="example_advanced_plugins_app",
stack_size=2 * 1024,
fap_category="Examples",
sources=["*.c*", "!plugin*.c"],
)

App(
Expand Down
1 change: 1 addition & 0 deletions applications/main/ibutton/application.fam
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ App(
apptype=FlipperAppType.STARTUP,
targets=["f7"],
entry_point="ibutton_on_system_start",
sources=["ibutton_cli.c"],
order=60,
)
6 changes: 6 additions & 0 deletions applications/main/infrared/application.fam
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ App(
icon="A_Infrared_14",
stack_size=3 * 1024,
order=40,
sources=["*.c", "!infrared_cli.c"],
resources="resources",
fap_libs=["assets"],
fap_icon="icon.png",
Expand All @@ -18,5 +19,10 @@ App(
apptype=FlipperAppType.STARTUP,
targets=["f7"],
entry_point="infrared_on_system_start",
sources=[
"infrared_cli.c",
"infrared_brute_force.c",
"infrared_signal.c",
],
order=20,
)
1 change: 1 addition & 0 deletions applications/main/lfrfid/application.fam
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ App(
targets=["f7"],
apptype=FlipperAppType.STARTUP,
entry_point="lfrfid_on_system_start",
sources=["lfrfid_cli.c"],
order=50,
)
12 changes: 12 additions & 0 deletions applications/main/nfc/application.fam
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ App(
stack_size=5 * 1024,
order=30,
resources="resources",
sources=[
"*.c",
"!plugins",
"!nfc_cli.c",
],
fap_libs=["assets"],
fap_icon="icon.png",
fap_category="NFC",
Expand All @@ -21,6 +26,7 @@ App(
entry_point="all_in_one_plugin_ep",
targets=["f7"],
requires=["nfc"],
sources=["plugins/supported_cards/all_in_one.c"],
)

App(
Expand All @@ -29,6 +35,7 @@ App(
entry_point="opal_plugin_ep",
targets=["f7"],
requires=["nfc"],
sources=["plugins/supported_cards/opal.c"],
)

App(
Expand All @@ -37,6 +44,7 @@ App(
entry_point="myki_plugin_ep",
targets=["f7"],
requires=["nfc"],
sources=["plugins/supported_cards/myki.c"],
)

App(
Expand All @@ -45,6 +53,7 @@ App(
entry_point="troika_plugin_ep",
targets=["f7"],
requires=["nfc"],
sources=["plugins/supported_cards/troika.c"],
)

App(
Expand All @@ -53,6 +62,7 @@ App(
entry_point="plantain_plugin_ep",
targets=["f7"],
requires=["nfc"],
sources=["plugins/supported_cards/plantain.c"],
)

App(
Expand All @@ -61,12 +71,14 @@ App(
entry_point="two_cities_plugin_ep",
targets=["f7"],
requires=["nfc"],
sources=["plugins/supported_cards/two_cities.c"],
)

App(
appid="nfc_start",
targets=["f7"],
apptype=FlipperAppType.STARTUP,
entry_point="nfc_on_system_start",
sources=["nfc_cli.c"],
order=30,
)
6 changes: 6 additions & 0 deletions applications/main/subghz/application.fam
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ App(
icon="A_Sub1ghz_14",
stack_size=3 * 1024,
order=10,
sources=[
"*.c",
"!subghz_cli.c",
"!helpers/subghz_chat.c",
],
resources="resources",
fap_libs=["assets", "hwdrivers"],
fap_icon="icon.png",
Expand All @@ -18,5 +23,6 @@ App(
targets=["f7"],
apptype=FlipperAppType.STARTUP,
entry_point="subghz_on_system_start",
sources=["subghz_cli.c", "helpers/subghz_chat.c"],
order=40,
)
2 changes: 1 addition & 1 deletion documentation/AppManifests.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Only two parameters are mandatory: **_appid_** and **_apptype_**. Others are opt

The following parameters are used only for [FAPs](./AppsOnSDCard.md):

- **sources**: list of strings, file name masks used for gathering sources within the app folder. The default value of `["*.c*"]` includes C and C++ source files. Applications cannot use the `"lib"` folder for their own source code, as it is reserved for **fap_private_libs**.
- **sources**: list of strings, file name masks used for gathering sources within the app folder. The default value of `["*.c*"]` includes C and C++ source files. Applications cannot use the `"lib"` folder for their own source code, as it is reserved for **fap_private_libs**. Paths starting with `"!"` are excluded from the list of sources. They can also include wildcard characters and directory names. For example, a value of `["*.c*", "!plugins"]` will include all C and C++ source files in the app folder except those in the `plugins` (and `lib`) folders. Paths with no wildcards (`*, ?`) are treated as full literal paths for both inclusion and exclusion.
- **fap_version**: string, application version. The default value is "0.1". You can also use a tuple of 2 numbers in the form of (x,y) to specify the version. It is also possible to add more dot-separated parts to the version, like patch number, but only major and minor version numbers are stored in the built .fap.
- **fap_icon**: name of a `.png` file, 1-bit color depth, 10x10px, to be embedded within `.fap` file.
- **fap_libs**: list of extra libraries to link the application against. Provides access to extra functions that are not exported as a part of main firmware at the expense of increased `.fap` file size and RAM consumption.
Expand Down
2 changes: 1 addition & 1 deletion firmware.scons
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ sources = [apps_c]
# Gather sources only from app folders in current configuration
sources.extend(
itertools.chain.from_iterable(
fwenv.GlobRecursive(source_type, appdir.relpath, exclude=["lib"])
fwenv.GatherSources([source_type, "!lib"], appdir.relpath)
for appdir, source_type in fwenv["APPBUILD"].get_builtin_app_folders()
)
)
Expand Down
12 changes: 3 additions & 9 deletions scripts/fbt_tools/fbt_extapps.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,10 @@ def _build_app(self):
CPPPATH=[self.app_work_dir, self.app._appdir],
)

app_sources = list(
itertools.chain.from_iterable(
self.app_env.GlobRecursive(
source_type,
self.app_work_dir,
exclude="lib",
)
for source_type in self.app.sources
)
app_sources = self.app_env.GatherSources(
[self.app.sources, "!lib"], self.app_work_dir
)

if not app_sources:
raise UserError(f"No source files found for {self.app.appid}")

Expand Down
27 changes: 26 additions & 1 deletion scripts/fbt_tools/sconsrecursiveglob.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import itertools

import SCons
from fbt.util import GLOB_FILE_EXCLUSION
from SCons.Script import Flatten
from SCons.Node.FS import has_glob_magic
from SCons.Script import Flatten


def GlobRecursive(env, pattern, node=".", exclude=[]):
Expand All @@ -23,12 +25,35 @@ def GlobRecursive(env, pattern, node=".", exclude=[]):
# Otherwise, just assume that file at path exists
else:
results.append(node.File(pattern))
## Debug
# print(f"Glob result for {pattern} from {node}: {results}")
return results


def GatherSources(env, sources_list, node="."):
sources_list = list(set(Flatten(sources_list)))
include_sources = list(filter(lambda x: not x.startswith("!"), sources_list))
exclude_sources = list(x[1:] for x in sources_list if x.startswith("!"))
gathered_sources = list(
itertools.chain.from_iterable(
env.GlobRecursive(
source_type,
node,
exclude=exclude_sources,
)
for source_type in include_sources
)
)
## Debug
# print(
# f"Gathered sources for {sources_list} from {node}: {list(f.path for f in gathered_sources)}"
# )
return gathered_sources


def generate(env):
env.AddMethod(GlobRecursive)
env.AddMethod(GatherSources)


def exists(env):
Expand Down

0 comments on commit 7bd3bd7

Please sign in to comment.