-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSConstruct
More file actions
79 lines (66 loc) · 2.59 KB
/
Copy pathSConstruct
File metadata and controls
79 lines (66 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
from pathlib import Path
import os, sys
import platform
import subprocess
"""
The default cross-compilation toolchain can be specified in a
custom `config_defaults.mk` file and passed via the `CONFIG_DEFAULT_FILE`
environment variable.
export CONFIG_DEFAULT_FILE=linux_x86_cross_cp0_config_defaults.mk
scons -j8
"""
cross_package_enabled = False
local_path = Path(os.getcwd())
sdk_path = local_path.parent.parent / "SDK"
version_file = local_path.parent.parent / "ext_components" / "cp0_lvgl" / "sdk_version.txt"
version = version_file.read_text(encoding="utf-8")
static_lib_path = sdk_path / "github_source" / f"static_lib_{version}"
if os.environ.get("CardputerZero", '') == 'y':
os.environ["CONFIG_DEFAULT_FILE"] = "linux_x86_cross_cp0_config_defaults.mk"
if os.environ.get("CONFIG_DEFAULT_FILE") == None:
if platform.machine() == 'x86_64':
os.environ["CONFIG_DEFAULT_FILE"] = "linux_x86_sdl2_config_defaults.mk"
if "cross" in os.environ.get("CONFIG_DEFAULT_FILE", ''):
cross_package_enabled = True
config_tmp_path = Path("build") / "config" / "config_tmp.mk"
sysroot_path_str = static_lib_path.as_posix().replace('"', r'\"')
config_tmp_content = (
f'CONFIG_TOOLCHAIN_SYSROOT="{sysroot_path_str}"\n'
)
if not config_tmp_path.exists() or config_tmp_path.read_text() != config_tmp_content:
config_tmp_path.parent.mkdir(parents=True, exist_ok=True)
config_tmp_path.write_text(config_tmp_content)
os.environ["SDK_PATH"] = str(sdk_path)
os.environ["EXT_COMPONENTS_PATH"] = str(sdk_path.parent / "ext_components")
env = SConscript(
str(sdk_path / "tools" / "scons" / "project.py"),
variant_dir=os.getcwd(),
duplicate=0,
)
# static_lib is only needed for cross-compilation, skip in SDL mode.
if cross_package_enabled:
update = False
if not static_lib_path.exists():
update = True
else:
try:
with open(str(static_lib_path / "version"), "r") as f:
if version != f.read().strip():
update = True
except Exception:
update = True
if update:
with open(env["PROJECT_TOOL_S"]) as f:
exec(f.read())
try:
import tarfile
tarfile.TarFile.extraction_filter = staticmethod(
tarfile.fully_trusted_filter
)
except AttributeError:
pass
down_url = (
"https://github.com/CardputerZero/M5CardputerZero-UserDemo/"
"releases/download/{}/sdk_bsp.tar.gz"
).format(version)
check_wget_down(down_url, "static_lib_{}.tar.gz".format(version))