Skip to content

Commit

Permalink
fbt: reworking targets & assets handling WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
hedger committed Oct 19, 2023
1 parent e664159 commit 8fc60a7
Show file tree
Hide file tree
Showing 172 changed files with 162 additions and 185 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
/applications/examples/example_thermo/ @skotopes @DrZlo13 @hedger @gsurkov

# Firmware targets
/firmware/ @skotopes @DrZlo13 @hedger @nminaylov
/targets/ @skotopes @DrZlo13 @hedger @nminaylov

# Assets
/assets/resources/infrared/ @skotopes @DrZlo13 @hedger @gsurkov
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ jobs:
- name: 'Check API versions for consistency between targets'
run: |
set -e
N_API_HEADER_SIGNATURES=`ls -1 firmware/targets/f*/api_symbols.csv | xargs -I {} sh -c "head -n2 {} | md5sum" | sort -u | wc -l`
N_API_HEADER_SIGNATURES=`ls -1 targets/f*/api_symbols.csv | xargs -I {} sh -c "head -n2 {} | md5sum" | sort -u | wc -l`
if [ $N_API_HEADER_SIGNATURES != 1 ] ; then
echo API versions aren\'t matching for available targets. Please update!
echo API versions are:
head -n2 firmware/targets/f*/api_symbols.csv
head -n2 targets/f*/api_symbols.csv
exit 1
fi
Expand Down
2 changes: 1 addition & 1 deletion SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ if GetOption("fullenv") or any(
]
dist_resource_arguments = [
"-r",
'"${ROOT_DIR.abspath}/assets/resources"',
'${RESOURCES_ROOT}"',
]
dist_splash_arguments = (
[
Expand Down
2 changes: 1 addition & 1 deletion applications/services/loader/loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ static FlipperInternalApplication const* loader_find_application_by_name_in_list
const FlipperInternalApplication* list,
const uint32_t n_apps) {
for(size_t i = 0; i < n_apps; i++) {
if(strcmp(name, list[i].name) == 0) {
if((strcmp(name, list[i].name) == 0) || (strcmp(name, list[i].appid) == 0)) {
return &list[i];
}
}
Expand Down
1 change: 0 additions & 1 deletion applications/system/snake_game/application.fam
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ App(
entry_point="snake_game_app",
requires=["gui"],
stack_size=1 * 1024,
targets=["f7"],
fap_version="1.0",
fap_description="Classic Snake Game",
fap_icon="snake_10px.png",
Expand Down
43 changes: 33 additions & 10 deletions assets/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ assetsenv = env.Clone(
tools=["fbt_assets"],
FW_LIB_NAME="assets",
GIT_UNIX_TIMESTAMP=get_git_commit_unix_timestamp(),
RESOURCES_STATIC_ROOT=env.Dir("#/assets/resources"),
)
assetsenv.ApplyLibFlags()

Expand Down Expand Up @@ -65,34 +66,56 @@ env.SetDefault(FW_RESOURCES=None)
if assetsenv["IS_BASE_FIRMWARE"]:
# External dolphin animations
dolphin_external = assetsenv.DolphinExtBuilder(
assetsenv.Dir("#/assets/resources/dolphin"),
assetsenv.Dir("${RESOURCES_ROOT}/dolphin"),
assetsenv.Dir("#/assets/dolphin"),
DOLPHIN_RES_TYPE="external",
)
if assetsenv["FORCE"]:
assetsenv.AlwaysBuild(dolphin_external)
assetsenv.Alias("dolphin_ext", dolphin_external)
assetsenv.Clean(dolphin_external, assetsenv.Dir("#/assets/resources/dolphin"))
assetsenv.Clean(dolphin_external, assetsenv.Dir("${RESOURCES_ROOT}/dolphin"))

# Copy src files to resources
# base_resources = assetsenv.Install(
# "${RESOURCES_ROOT}", assetsenv.Dir("#/assets/resources")
# )
# base_resources = Command(
# "${RESOURCES_ROOT}",
# assetsenv.Dir("#/assets/resources"),
# Copy("$TARGET", "$SOURCE"),
# )
# assetsenv.AlwaysBuild(base_resources)

# Resources manifest
resources = assetsenv.Command(
"#/assets/resources/Manifest",
"${RESOURCES_ROOT}/Manifest",
assetsenv.GlobRecursive(
"*",
assetsenv.Dir("resources").srcnode(),
"${RESOURCES_ROOT}",
exclude=["Manifest"],
),
action=Action(
'${PYTHON3} "${ASSETS_COMPILER}" manifest "${TARGET.dir.posix}" --timestamp=${GIT_UNIX_TIMESTAMP}',
[
[
"${PYTHON3}",
"${ASSETS_COMPILER}",
"manifest",
"${TARGET.dir.posix}",
"--timestamp=${GIT_UNIX_TIMESTAMP}",
"--static-dir=${RESOURCES_STATIC_ROOT}",
]
],
"${RESMANIFESTCOMSTR}",
),
)
assetsenv.Precious(resources)

# assetsenv.Depends(resources, base_resources)
# assetsenv.Precious(resources)
assetsenv.AlwaysBuild(resources)
assetsenv.Clean(
resources,
assetsenv.Dir("#/assets/resources/apps"),
)
# assetsenv.Clean(
# resources,
# assetsenv.Dir("{$/apps"),
# )

# Exporting resources node to external environment
env.Replace(FW_RESOURCES=resources)
Expand Down
6 changes: 4 additions & 2 deletions firmware.scons
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ env = ENV.Clone(
IS_BASE_FIRMWARE=fw_build_meta["type"] == "firmware",
FW_FLAVOR=fw_build_meta["flavor"],
LIB_DIST_DIR=fw_build_meta["build_dir"].Dir("lib"),
RESOURCES_ROOT=fw_build_meta["build_dir"].Dir("resources"),
TARGETS_ROOT=Dir("#/targets"),
LINT_SOURCES=[
Dir("applications"),
],
Expand All @@ -37,7 +39,7 @@ env = ENV.Clone(
CPPPATH=[
"#/furi",
*(f"#/{app_dir[0]}" for app_dir in ENV["APPDIRS"] if app_dir[1]),
"#/firmware/targets/furi_hal_include",
"#/targets/furi_hal_include",
],
# Specific flags for building libraries - always do optimized builds
FW_LIB_OPTS={
Expand Down Expand Up @@ -104,7 +106,7 @@ lib_targets = env.BuildModules(
[
"lib",
"assets",
"firmware",
"targets",
"furi",
],
)
Expand Down
12 changes: 12 additions & 0 deletions scripts/assets.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python3

import os
import shutil

from flipper.app import App
from flipper.assets.icon import file2image
Expand Down Expand Up @@ -53,6 +54,11 @@ def init(self):
type=int,
required=False,
)
self.parser_manifest.add_argument(
"--static-dir",
help="Static files to add to resources",
required=True,
)
self.parser_manifest.set_defaults(func=self.manifest)

self.parser_copro = self.subparsers.add_parser(
Expand Down Expand Up @@ -220,6 +226,12 @@ def manifest(self):
if not os.path.isdir(directory_path):
self.logger.error(f'"{directory_path}" is not a directory')
exit(255)

shutil.copytree(
self.args.static_dir,
directory_path,
dirs_exist_ok=True,
)
manifest_file = os.path.join(directory_path, "Manifest")
old_manifest = Manifest()
if os.path.exists(manifest_file):
Expand Down
23 changes: 12 additions & 11 deletions scripts/fbt_tools/fbt_hwtarget.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@


class HardwareTargetLoader:
def __init__(self, env, target_scons_dir, target_id):
def __init__(self, env, root_target_scons_dir, target_id):
self.env = env
self.target_scons_dir = target_scons_dir
self.all_targets_root_dir = root_target_scons_dir
self.target_dir = self._getTargetDir(target_id)
# self.target_id = target_id
self.layered_target_dirs = []
Expand All @@ -23,7 +23,7 @@ def __init__(self, env, target_scons_dir, target_id):
self._processTargetDefinitions(target_id)

def _getTargetDir(self, target_id):
return self.target_scons_dir.Dir(f"f{target_id}")
return self.all_targets_root_dir.Dir(f"f{target_id}")

def _loadDescription(self, target_id):
target_json_file = self._getTargetDir(target_id).File("target.json")
Expand All @@ -34,14 +34,14 @@ def _loadDescription(self, target_id):
return vals

def _processTargetDefinitions(self, target_id):
self.layered_target_dirs.append(f"targets/f{target_id}")
target_dir = self._getTargetDir(target_id)
self.layered_target_dirs.append(target_dir)

config = self._loadDescription(target_id)

for path_list in ("include_paths", "sdk_header_paths"):
getattr(self, path_list).extend(
f"#/firmware/targets/f{target_id}/{p}"
for p in config.get(path_list, [])
target_dir.Dir(p) for p in config.get(path_list, [])
)

self.excluded_sources.extend(config.get("excluded_sources", []))
Expand All @@ -50,7 +50,7 @@ def _processTargetDefinitions(self, target_id):

file_attrs = (
# (name, use_src_node)
("startup_script", False),
("startup_script", True),
("linker_script_flash", True),
("linker_script_ram", True),
("linker_script_app", True),
Expand All @@ -59,9 +59,10 @@ def _processTargetDefinitions(self, target_id):

for attr_name, use_src_node in file_attrs:
if (val := config.get(attr_name)) and not getattr(self, attr_name):
node = self.env.File(f"firmware/targets/f{target_id}/{val}")
node = target_dir.File(val)
if use_src_node:
node = node.srcnode()
# print(f"Got node {node}, {node.path} for {attr_name}")
setattr(self, attr_name, node)

for attr_name in ("linker_dependencies",):
Expand All @@ -84,8 +85,8 @@ def gatherSources(self):
)
seen_filenames.update(f.name for f in accepted_sources)
sources.extend(accepted_sources)
# print(f"Found {len(sources)} sources: {list(f.name for f in sources)}")
return sources
# print(f"Found {len(sources)} sources: {list(f.path for f in sources)}")
return list(f.get_path(self.all_targets_root_dir) for f in sources)

def gatherSdkHeaders(self):
sdk_headers = []
Expand All @@ -101,7 +102,7 @@ def gatherSdkHeaders(self):


def ConfigureForTarget(env, target_id):
target_loader = HardwareTargetLoader(env, env.Dir("#/firmware/targets"), target_id)
target_loader = HardwareTargetLoader(env, env["TARGETS_ROOT"], target_id)
env.Replace(
TARGET_CFG=target_loader,
SDK_DEFINITION=target_loader.sdk_symbols,
Expand Down
60 changes: 0 additions & 60 deletions scripts/meta.py

This file was deleted.

2 changes: 1 addition & 1 deletion site_scons/extapps.scons
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ appenv = ENV["APPENV"] = ENV.Clone(
"fbt_assets",
"fbt_sdk",
],
RESOURCES_ROOT=ENV.Dir("#/assets/resources"),
# RESOURCES_ROOT=ENV["BUILD_DIR"].Dir("resources"),
)

appenv.Replace(
Expand Down
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 8fc60a7

Please sign in to comment.