2023-10-30 18:17:30 +03:00
|
|
|
import os
|
|
|
|
import shutil
|
|
|
|
|
|
|
|
from SCons.Action import Action
|
|
|
|
from SCons.Builder import Builder
|
|
|
|
from SCons.Errors import StopError
|
|
|
|
from SCons.Node.FS import Dir, File
|
|
|
|
|
|
|
|
|
2023-10-31 14:27:58 +03:00
|
|
|
def __generate_resources_dist_entries(env):
|
|
|
|
src_target_entries = []
|
|
|
|
|
2023-10-30 18:17:30 +03:00
|
|
|
resources_root = env.Dir(env["RESOURCES_ROOT"])
|
|
|
|
|
|
|
|
for app_artifacts in env["FW_EXTAPPS"].application_map.values():
|
|
|
|
for _, dist_path in filter(
|
|
|
|
lambda dist_entry: dist_entry[0], app_artifacts.dist_entries
|
|
|
|
):
|
2023-10-31 14:27:58 +03:00
|
|
|
src_target_entries.append(
|
|
|
|
(
|
|
|
|
app_artifacts.compact,
|
|
|
|
resources_root.File(dist_path),
|
|
|
|
)
|
|
|
|
)
|
2023-10-30 18:17:30 +03:00
|
|
|
|
|
|
|
# Deploy apps' resources too
|
|
|
|
for app in env["APPBUILD"].apps:
|
|
|
|
if not app.resources:
|
|
|
|
continue
|
|
|
|
apps_resource_dir = app._appdir.Dir(app.resources)
|
|
|
|
for res_file in env.GlobRecursive("*", apps_resource_dir):
|
|
|
|
if not isinstance(res_file, File):
|
|
|
|
continue
|
2023-10-31 14:27:58 +03:00
|
|
|
src_target_entries.append(
|
|
|
|
(
|
|
|
|
res_file,
|
|
|
|
resources_root.File(
|
|
|
|
res_file.get_path(apps_resource_dir),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
)
|
2023-10-30 18:17:30 +03:00
|
|
|
|
|
|
|
# Deploy other stuff from _EXTRA_DIST
|
|
|
|
for extra_dist in env["_EXTRA_DIST"]:
|
|
|
|
if isinstance(extra_dist, Dir):
|
2023-10-31 14:27:58 +03:00
|
|
|
src_target_entries.append(
|
|
|
|
(
|
|
|
|
extra_dist,
|
|
|
|
resources_root.Dir(extra_dist.name),
|
2023-10-30 18:17:30 +03:00
|
|
|
)
|
2023-10-31 14:27:58 +03:00
|
|
|
)
|
2023-10-30 18:17:30 +03:00
|
|
|
else:
|
|
|
|
raise StopError(f"Unsupported extra dist type: {type(extra_dist)}")
|
|
|
|
|
2023-10-31 14:27:58 +03:00
|
|
|
return src_target_entries
|
|
|
|
|
|
|
|
|
|
|
|
def _resources_dist_emitter(target, source, env):
|
|
|
|
src_target_entries = __generate_resources_dist_entries(env)
|
|
|
|
source = list(map(lambda entry: entry[0], src_target_entries))
|
2023-10-30 18:17:30 +03:00
|
|
|
return (target, source)
|
|
|
|
|
|
|
|
|
|
|
|
def _resources_dist_action(target, source, env):
|
2023-10-31 14:27:58 +03:00
|
|
|
dist_entries = __generate_resources_dist_entries(env)
|
|
|
|
assert len(dist_entries) == len(source)
|
2023-10-30 18:17:30 +03:00
|
|
|
shutil.rmtree(env.Dir(env["RESOURCES_ROOT"]).abspath, ignore_errors=True)
|
2023-10-31 14:27:58 +03:00
|
|
|
for src, target in dist_entries:
|
|
|
|
if isinstance(src, File):
|
|
|
|
os.makedirs(os.path.dirname(target.path), exist_ok=True)
|
|
|
|
shutil.copy(src.path, target.path)
|
|
|
|
elif isinstance(src, Dir):
|
|
|
|
shutil.copytree(src.path, target.path)
|
|
|
|
else:
|
|
|
|
raise StopError(f"Unsupported dist entry type: {type(src)}")
|
2023-10-30 18:17:30 +03:00
|
|
|
|
|
|
|
|
|
|
|
def generate(env, **kw):
|
|
|
|
env.SetDefault(
|
|
|
|
ASSETS_COMPILER="${FBT_SCRIPT_DIR}/assets.py",
|
|
|
|
)
|
|
|
|
|
|
|
|
if not env["VERBOSE"]:
|
|
|
|
env.SetDefault(
|
|
|
|
RESOURCEDISTCOMSTR="\tRESDIST\t${RESOURCES_ROOT}",
|
|
|
|
RESMANIFESTCOMSTR="\tMANIFST\t${TARGET}",
|
|
|
|
)
|
|
|
|
|
|
|
|
env.Append(
|
|
|
|
BUILDERS={
|
|
|
|
"ManifestBuilder": Builder(
|
2023-10-31 14:27:58 +03:00
|
|
|
action=[
|
|
|
|
Action(
|
|
|
|
_resources_dist_action,
|
|
|
|
"${RESOURCEDISTCOMSTR}",
|
|
|
|
),
|
|
|
|
Action(
|
2023-10-30 18:17:30 +03:00
|
|
|
[
|
2023-10-31 14:27:58 +03:00
|
|
|
[
|
|
|
|
"${PYTHON3}",
|
|
|
|
"${ASSETS_COMPILER}",
|
|
|
|
"manifest",
|
|
|
|
"${TARGET.dir.posix}",
|
|
|
|
"--timestamp=${GIT_UNIX_TIMESTAMP}",
|
|
|
|
]
|
|
|
|
],
|
|
|
|
"${RESMANIFESTCOMSTR}",
|
|
|
|
),
|
|
|
|
],
|
|
|
|
emitter=_resources_dist_emitter,
|
2023-10-30 18:17:30 +03:00
|
|
|
),
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def exists(env):
|
|
|
|
return True
|