2022-06-26 12:00:03 +00:00
|
|
|
import os
|
|
|
|
import subprocess
|
2023-05-03 05:48:49 +00:00
|
|
|
|
2022-11-02 15:15:40 +00:00
|
|
|
from ansi.color import fg
|
2023-05-03 05:48:49 +00:00
|
|
|
from SCons.Action import Action
|
|
|
|
from SCons.Builder import Builder
|
|
|
|
from SCons.Errors import StopError
|
2023-10-30 15:17:30 +00:00
|
|
|
from SCons.Node.FS import File
|
2022-06-26 12:00:03 +00:00
|
|
|
|
|
|
|
|
2023-10-30 15:17:30 +00:00
|
|
|
def _icons_emitter(target, source, env):
|
2023-08-10 16:21:56 +00:00
|
|
|
icons_src = env.GlobRecursive("*.png", env["ICON_SRC_DIR"])
|
2023-10-06 07:11:02 +00:00
|
|
|
icons_src += env.GlobRecursive("**/frame_rate", env["ICON_SRC_DIR"])
|
2023-08-10 16:21:56 +00:00
|
|
|
|
2022-06-26 12:00:03 +00:00
|
|
|
target = [
|
2022-10-06 13:55:57 +00:00
|
|
|
target[0].File(env.subst("${ICON_FILE_NAME}.c")),
|
|
|
|
target[0].File(env.subst("${ICON_FILE_NAME}.h")),
|
2022-06-26 12:00:03 +00:00
|
|
|
]
|
2023-08-10 16:21:56 +00:00
|
|
|
return target, icons_src
|
2022-06-26 12:00:03 +00:00
|
|
|
|
|
|
|
|
2023-10-30 15:17:30 +00:00
|
|
|
def _proto_emitter(target, source, env):
|
2022-06-26 12:00:03 +00:00
|
|
|
target = []
|
|
|
|
for src in source:
|
|
|
|
basename = os.path.splitext(src.name)[0]
|
|
|
|
target.append(env.File(f"compiled/{basename}.pb.c"))
|
|
|
|
target.append(env.File(f"compiled/{basename}.pb.h"))
|
|
|
|
return target, source
|
|
|
|
|
|
|
|
|
2023-10-30 15:17:30 +00:00
|
|
|
def _dolphin_emitter(target, source, env):
|
2022-06-26 12:00:03 +00:00
|
|
|
res_root_dir = source[0].Dir(env["DOLPHIN_RES_TYPE"])
|
2023-10-31 11:27:58 +00:00
|
|
|
source = list()
|
2023-02-08 09:35:38 +00:00
|
|
|
source.extend(env.GlobRecursive("*.*", res_root_dir.srcnode()))
|
2022-06-26 12:00:03 +00:00
|
|
|
|
|
|
|
target_base_dir = target[0]
|
|
|
|
env.Replace(_DOLPHIN_OUT_DIR=target[0])
|
2023-10-31 11:27:58 +00:00
|
|
|
env.Replace(_DOLPHIN_SRC_DIR=res_root_dir)
|
2022-06-26 12:00:03 +00:00
|
|
|
|
|
|
|
if env["DOLPHIN_RES_TYPE"] == "external":
|
2022-10-25 22:15:02 +00:00
|
|
|
target = [target_base_dir.File("manifest.txt")]
|
|
|
|
## A detailed list of files to be generated
|
2023-10-31 11:27:58 +00:00
|
|
|
# Not used ATM, becasuse it inflates the internal dependency graph too much
|
2023-10-30 15:17:30 +00:00
|
|
|
# Preserve original paths, do .png -> .bm conversion
|
2023-10-31 11:27:58 +00:00
|
|
|
# target.extend(
|
|
|
|
# map(
|
|
|
|
# lambda node: target_base_dir.File(
|
|
|
|
# res_root_dir.rel_path(node).replace(".png", ".bm")
|
|
|
|
# ),
|
|
|
|
# filter(lambda node: isinstance(node, File), source),
|
|
|
|
# )
|
|
|
|
# )
|
2022-06-26 12:00:03 +00:00
|
|
|
else:
|
|
|
|
asset_basename = f"assets_dolphin_{env['DOLPHIN_RES_TYPE']}"
|
|
|
|
target = [
|
|
|
|
target_base_dir.File(asset_basename + ".c"),
|
|
|
|
target_base_dir.File(asset_basename + ".h"),
|
|
|
|
]
|
|
|
|
|
2023-10-31 11:27:58 +00:00
|
|
|
## Debug output
|
2022-10-25 22:15:02 +00:00
|
|
|
# print(
|
|
|
|
# f"Dolphin res type: {env['DOLPHIN_RES_TYPE']},\ntarget files:",
|
|
|
|
# list(f.path for f in target),
|
|
|
|
# f"\nsource files:",
|
|
|
|
# list(f.path for f in source),
|
|
|
|
# )
|
2022-06-26 12:00:03 +00:00
|
|
|
return target, source
|
|
|
|
|
|
|
|
|
2023-10-30 15:17:30 +00:00
|
|
|
def __invoke_git(args, source_dir):
|
2022-06-26 12:00:03 +00:00
|
|
|
cmd = ["git"]
|
|
|
|
cmd.extend(args)
|
|
|
|
return (
|
|
|
|
subprocess.check_output(cmd, cwd=source_dir, stderr=subprocess.STDOUT)
|
|
|
|
.strip()
|
|
|
|
.decode()
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-10-30 15:17:30 +00:00
|
|
|
def _proto_ver_generator(target, source, env):
|
2022-06-26 12:00:03 +00:00
|
|
|
target_file = target[0]
|
|
|
|
src_dir = source[0].dir.abspath
|
2023-11-10 07:22:34 +00:00
|
|
|
|
|
|
|
def fetch(unshallow=False):
|
|
|
|
git_args = ["fetch", "--tags"]
|
|
|
|
if unshallow:
|
|
|
|
git_args.append("--unshallow")
|
|
|
|
|
|
|
|
try:
|
|
|
|
__invoke_git(git_args, source_dir=src_dir)
|
|
|
|
except (subprocess.CalledProcessError, EnvironmentError):
|
|
|
|
# Not great, not terrible
|
|
|
|
print(fg.boldred("Git: fetch failed"))
|
|
|
|
|
|
|
|
def describe():
|
|
|
|
try:
|
|
|
|
return __invoke_git(
|
|
|
|
["describe", "--tags", "--abbrev=0"],
|
|
|
|
source_dir=src_dir,
|
|
|
|
)
|
|
|
|
except (subprocess.CalledProcessError, EnvironmentError):
|
|
|
|
return None
|
|
|
|
|
|
|
|
fetch()
|
|
|
|
git_describe = describe()
|
|
|
|
if not git_describe:
|
|
|
|
fetch(unshallow=True)
|
|
|
|
git_describe = describe()
|
|
|
|
|
|
|
|
if not git_describe:
|
|
|
|
raise StopError("Failed to process git tags for protobuf versioning")
|
2022-06-26 12:00:03 +00:00
|
|
|
|
|
|
|
git_major, git_minor = git_describe.split(".")
|
|
|
|
version_file_data = (
|
|
|
|
"#pragma once",
|
|
|
|
f"#define PROTOBUF_MAJOR_VERSION {git_major}",
|
|
|
|
f"#define PROTOBUF_MINOR_VERSION {git_minor}",
|
|
|
|
"",
|
|
|
|
)
|
|
|
|
with open(str(target_file), "wt") as file:
|
|
|
|
file.write("\n".join(version_file_data))
|
|
|
|
|
|
|
|
|
2022-10-06 13:55:57 +00:00
|
|
|
def CompileIcons(env, target_dir, source_dir, *, icon_bundle_name="assets_icons"):
|
2023-08-10 16:21:56 +00:00
|
|
|
return env.IconBuilder(
|
2022-10-06 13:55:57 +00:00
|
|
|
target_dir,
|
2023-08-10 16:21:56 +00:00
|
|
|
None,
|
|
|
|
ICON_SRC_DIR=source_dir,
|
2022-10-06 13:55:57 +00:00
|
|
|
ICON_FILE_NAME=icon_bundle_name,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-06-26 12:00:03 +00:00
|
|
|
def generate(env):
|
|
|
|
env.SetDefault(
|
2022-11-02 15:15:40 +00:00
|
|
|
ASSETS_COMPILER="${FBT_SCRIPT_DIR}/assets.py",
|
|
|
|
NANOPB_COMPILER="${ROOT_DIR}/lib/nanopb/generator/nanopb_generator.py",
|
2022-06-26 12:00:03 +00:00
|
|
|
)
|
2022-10-06 13:55:57 +00:00
|
|
|
env.AddMethod(CompileIcons)
|
|
|
|
|
|
|
|
if not env["VERBOSE"]:
|
|
|
|
env.SetDefault(
|
|
|
|
ICONSCOMSTR="\tICONS\t${TARGET}",
|
|
|
|
PROTOCOMSTR="\tPROTO\t${SOURCE}",
|
|
|
|
DOLPHINCOMSTR="\tDOLPHIN\t${DOLPHIN_RES_TYPE}",
|
|
|
|
PBVERCOMSTR="\tPBVER\t${TARGET}",
|
|
|
|
)
|
2022-06-26 12:00:03 +00:00
|
|
|
|
|
|
|
env.Append(
|
|
|
|
BUILDERS={
|
|
|
|
"IconBuilder": Builder(
|
|
|
|
action=Action(
|
2023-10-30 15:17:30 +00:00
|
|
|
[
|
|
|
|
[
|
|
|
|
"${PYTHON3}",
|
|
|
|
"${ASSETS_COMPILER}",
|
|
|
|
"icons",
|
|
|
|
"${ICON_SRC_DIR}",
|
|
|
|
"${TARGET.dir}",
|
|
|
|
"--filename",
|
|
|
|
"${ICON_FILE_NAME}",
|
|
|
|
],
|
|
|
|
],
|
2022-06-26 12:00:03 +00:00
|
|
|
"${ICONSCOMSTR}",
|
|
|
|
),
|
2023-10-30 15:17:30 +00:00
|
|
|
emitter=_icons_emitter,
|
2022-06-26 12:00:03 +00:00
|
|
|
),
|
|
|
|
"ProtoBuilder": Builder(
|
|
|
|
action=Action(
|
2023-10-30 15:17:30 +00:00
|
|
|
[
|
|
|
|
[
|
|
|
|
"${PYTHON3}",
|
|
|
|
"${NANOPB_COMPILER}",
|
|
|
|
"-q",
|
|
|
|
"-I${SOURCE.dir.posix}",
|
|
|
|
"-D${TARGET.dir.posix}",
|
|
|
|
"${SOURCES.posix}",
|
|
|
|
],
|
|
|
|
],
|
2022-06-26 12:00:03 +00:00
|
|
|
"${PROTOCOMSTR}",
|
|
|
|
),
|
2023-10-30 15:17:30 +00:00
|
|
|
emitter=_proto_emitter,
|
2022-06-26 12:00:03 +00:00
|
|
|
suffix=".pb.c",
|
|
|
|
src_suffix=".proto",
|
|
|
|
),
|
|
|
|
"DolphinSymBuilder": Builder(
|
|
|
|
action=Action(
|
2023-10-30 15:17:30 +00:00
|
|
|
[
|
|
|
|
[
|
|
|
|
"${PYTHON3}",
|
|
|
|
"${ASSETS_COMPILER}",
|
|
|
|
"dolphin",
|
|
|
|
"-s",
|
|
|
|
"dolphin_${DOLPHIN_RES_TYPE}",
|
2023-10-31 11:27:58 +00:00
|
|
|
"${_DOLPHIN_SRC_DIR}",
|
2023-10-30 15:17:30 +00:00
|
|
|
"${_DOLPHIN_OUT_DIR}",
|
|
|
|
],
|
|
|
|
],
|
2022-06-26 12:00:03 +00:00
|
|
|
"${DOLPHINCOMSTR}",
|
|
|
|
),
|
2023-10-30 15:17:30 +00:00
|
|
|
emitter=_dolphin_emitter,
|
2022-06-26 12:00:03 +00:00
|
|
|
),
|
|
|
|
"DolphinExtBuilder": Builder(
|
|
|
|
action=Action(
|
2023-10-30 15:17:30 +00:00
|
|
|
[
|
|
|
|
[
|
|
|
|
"${PYTHON3}",
|
|
|
|
"${ASSETS_COMPILER}",
|
|
|
|
"dolphin",
|
2023-10-31 11:27:58 +00:00
|
|
|
"${_DOLPHIN_SRC_DIR}",
|
2023-10-30 15:17:30 +00:00
|
|
|
"${_DOLPHIN_OUT_DIR}",
|
|
|
|
],
|
|
|
|
],
|
2022-06-26 12:00:03 +00:00
|
|
|
"${DOLPHINCOMSTR}",
|
|
|
|
),
|
2023-10-30 15:17:30 +00:00
|
|
|
emitter=_dolphin_emitter,
|
2022-06-26 12:00:03 +00:00
|
|
|
),
|
|
|
|
"ProtoVerBuilder": Builder(
|
|
|
|
action=Action(
|
2023-10-30 15:17:30 +00:00
|
|
|
_proto_ver_generator,
|
2022-06-26 12:00:03 +00:00
|
|
|
"${PBVERCOMSTR}",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def exists(env):
|
|
|
|
return True
|