fbt: fixes for ufbt compat (#1940)
* fbt: split sdk management code * scripts: fixed import handling * fbt: sdk: reformatted paths * scrips: dist: bundling libs as a build artifact * fbt: sdk: better path management * typo fix * fbt: sdk: minor path handling fixes * toolchain: fixed windows toolchain download Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
@@ -8,7 +8,7 @@ import os
|
||||
import pathlib
|
||||
from fbt.elfmanifest import assemble_manifest_data
|
||||
from fbt.appmanifest import FlipperApplication, FlipperManifestException
|
||||
from fbt.sdk import SdkCache
|
||||
from fbt.sdk.cache import SdkCache
|
||||
import itertools
|
||||
from ansi.color import fg
|
||||
|
||||
|
@@ -4,7 +4,7 @@ from SCons.Action import Action
|
||||
from SCons.Errors import UserError
|
||||
|
||||
# from SCons.Scanner import C
|
||||
from SCons.Script import Mkdir, Copy, Delete, Entry
|
||||
from SCons.Script import Entry
|
||||
from SCons.Util import LogicalLines
|
||||
|
||||
import os.path
|
||||
@@ -12,7 +12,8 @@ import posixpath
|
||||
import pathlib
|
||||
import json
|
||||
|
||||
from fbt.sdk import SdkCollector, SdkCache
|
||||
from fbt.sdk.collector import SdkCollector
|
||||
from fbt.sdk.cache import SdkCache
|
||||
|
||||
|
||||
def ProcessSdkDepends(env, filename):
|
||||
@@ -49,15 +50,19 @@ def prebuild_sdk_create_origin_file(target, source, env):
|
||||
|
||||
|
||||
class SdkMeta:
|
||||
def __init__(self, env):
|
||||
def __init__(self, env, tree_builder: "SdkTreeBuilder"):
|
||||
self.env = env
|
||||
self.treebuilder = tree_builder
|
||||
|
||||
def save_to(self, json_manifest_path: str):
|
||||
meta_contents = {
|
||||
"sdk_symbols": self.env["SDK_DEFINITION"].name,
|
||||
"sdk_symbols": self.treebuilder.build_sdk_file_path(
|
||||
self.env["SDK_DEFINITION"].path
|
||||
),
|
||||
"cc_args": self._wrap_scons_vars("$CCFLAGS $_CCCOMCOM"),
|
||||
"cpp_args": self._wrap_scons_vars("$CXXFLAGS $CCFLAGS $_CCCOMCOM"),
|
||||
"linker_args": self._wrap_scons_vars("$LINKFLAGS"),
|
||||
"linker_script": self.env.subst("${LINKER_SCRIPT_PATH}"),
|
||||
}
|
||||
with open(json_manifest_path, "wt") as f:
|
||||
json.dump(meta_contents, f, indent=4)
|
||||
@@ -68,6 +73,8 @@ class SdkMeta:
|
||||
|
||||
|
||||
class SdkTreeBuilder:
|
||||
SDK_DIR_SUBST = "SDK_ROOT_DIR"
|
||||
|
||||
def __init__(self, env, target, source) -> None:
|
||||
self.env = env
|
||||
self.target = target
|
||||
@@ -88,6 +95,8 @@ class SdkTreeBuilder:
|
||||
self.header_depends = list(
|
||||
filter(lambda fname: fname.endswith(".h"), depends.split()),
|
||||
)
|
||||
self.header_depends.append(self.env.subst("${LINKER_SCRIPT_PATH}"))
|
||||
self.header_depends.append(self.env.subst("${SDK_DEFINITION}"))
|
||||
self.header_dirs = sorted(
|
||||
set(map(os.path.normpath, map(os.path.dirname, self.header_depends)))
|
||||
)
|
||||
@@ -102,17 +111,33 @@ class SdkTreeBuilder:
|
||||
)
|
||||
|
||||
sdk_dirs = ", ".join(f"'{dir}'" for dir in self.header_dirs)
|
||||
for dir in full_fw_paths:
|
||||
if dir in sdk_dirs:
|
||||
filtered_paths.append(
|
||||
posixpath.normpath(posixpath.join(self.target_sdk_dir_name, dir))
|
||||
)
|
||||
filtered_paths.extend(
|
||||
map(
|
||||
self.build_sdk_file_path,
|
||||
filter(lambda path: path in sdk_dirs, full_fw_paths),
|
||||
)
|
||||
)
|
||||
|
||||
sdk_env = self.env.Clone()
|
||||
sdk_env.Replace(CPPPATH=filtered_paths)
|
||||
meta = SdkMeta(sdk_env)
|
||||
sdk_env.Replace(
|
||||
CPPPATH=filtered_paths,
|
||||
LINKER_SCRIPT=self.env.subst("${APP_LINKER_SCRIPT}"),
|
||||
ORIG_LINKER_SCRIPT_PATH=self.env["LINKER_SCRIPT_PATH"],
|
||||
LINKER_SCRIPT_PATH=self.build_sdk_file_path("${ORIG_LINKER_SCRIPT_PATH}"),
|
||||
)
|
||||
|
||||
meta = SdkMeta(sdk_env, self)
|
||||
meta.save_to(self.target[0].path)
|
||||
|
||||
def build_sdk_file_path(self, orig_path: str) -> str:
|
||||
return posixpath.normpath(
|
||||
posixpath.join(
|
||||
self.SDK_DIR_SUBST,
|
||||
self.target_sdk_dir_name,
|
||||
orig_path,
|
||||
)
|
||||
).replace("\\", "/")
|
||||
|
||||
def emitter(self, target, source, env):
|
||||
target_folder = target[0]
|
||||
target = [target_folder.File("sdk.opts")]
|
||||
@@ -128,8 +153,6 @@ class SdkTreeBuilder:
|
||||
for sdkdir in dirs_to_create:
|
||||
os.makedirs(sdkdir, exist_ok=True)
|
||||
|
||||
shutil.copy2(self.env["SDK_DEFINITION"].path, self.sdk_root_dir.path)
|
||||
|
||||
for header in self.header_depends:
|
||||
shutil.copy2(header, self.sdk_deploy_dir.File(header).path)
|
||||
|
||||
|
Reference in New Issue
Block a user