2022-06-30 16:06:12 +00:00
|
|
|
import os
|
2023-05-03 05:48:49 +00:00
|
|
|
import re
|
2024-03-20 16:32:53 +00:00
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
import webbrowser
|
2022-11-02 15:15:40 +00:00
|
|
|
|
2023-05-03 05:48:49 +00:00
|
|
|
import SCons
|
|
|
|
from SCons.Errors import StopError
|
|
|
|
from SCons.Subst import quote_spaces
|
2022-06-26 12:00:03 +00:00
|
|
|
|
|
|
|
WINPATHSEP_RE = re.compile(r"\\([^\"'\\]|$)")
|
|
|
|
|
2023-02-08 09:35:38 +00:00
|
|
|
# Used by default when globbing for files with GlobRecursive
|
|
|
|
# Excludes all files ending with ~, usually created by editors as backup files
|
|
|
|
GLOB_FILE_EXCLUSION = ["*~"]
|
|
|
|
|
2023-12-19 12:43:06 +00:00
|
|
|
# List of environment variables to proxy to child processes
|
|
|
|
FORWARDED_ENV_VARIABLES = [
|
|
|
|
# CI/CD variables
|
|
|
|
"WORKFLOW_BRANCH_OR_TAG",
|
|
|
|
"DIST_SUFFIX",
|
|
|
|
# Python & other tools
|
|
|
|
"HOME",
|
|
|
|
"APPDATA",
|
|
|
|
"PYTHONHOME",
|
|
|
|
"PYTHONNOUSERSITE",
|
|
|
|
"TMP",
|
|
|
|
"TEMP",
|
2024-02-26 12:16:19 +00:00
|
|
|
"USERPROFILE",
|
|
|
|
"LOCALAPPDATA",
|
2023-12-19 12:43:06 +00:00
|
|
|
# ccache
|
|
|
|
"CCACHE_DISABLE",
|
|
|
|
# Colors for tools
|
|
|
|
"TERM",
|
|
|
|
# Toolchain
|
|
|
|
"FBT_TOOLCHAIN_PATH",
|
|
|
|
"UFBT_HOME",
|
|
|
|
]
|
|
|
|
|
2022-06-26 12:00:03 +00:00
|
|
|
|
|
|
|
def tempfile_arg_esc_func(arg):
|
|
|
|
arg = quote_spaces(arg)
|
|
|
|
if SCons.Platform.platform_default() != "win32":
|
|
|
|
return arg
|
|
|
|
# GCC requires double Windows slashes, let's use UNIX separator
|
|
|
|
return WINPATHSEP_RE.sub(r"/\1", arg)
|
|
|
|
|
|
|
|
|
|
|
|
def wrap_tempfile(env, command):
|
|
|
|
env[command] = '${TEMPFILE("' + env[command] + '","$' + command + 'STR")}'
|
2022-06-30 16:06:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
def link_dir(target_path, source_path, is_windows):
|
|
|
|
# print(f"link_dir: {target_path} -> {source_path}")
|
|
|
|
if os.path.lexists(target_path) or os.path.exists(target_path):
|
|
|
|
os.unlink(target_path)
|
|
|
|
if is_windows:
|
|
|
|
# Crete junction
|
|
|
|
import _winapi
|
|
|
|
|
|
|
|
if not os.path.isdir(source_path):
|
2022-07-14 16:24:26 +00:00
|
|
|
raise StopError(f"Source directory {source_path} is not a directory")
|
2022-06-30 16:06:12 +00:00
|
|
|
|
|
|
|
if not os.path.exists(target_path):
|
|
|
|
_winapi.CreateJunction(source_path, target_path)
|
|
|
|
else:
|
|
|
|
os.symlink(source_path, target_path)
|
|
|
|
|
|
|
|
|
2022-07-04 16:53:04 +00:00
|
|
|
def single_quote(arg_list):
|
|
|
|
return " ".join(f"'{arg}'" if " " in arg else str(arg) for arg in arg_list)
|
2022-11-02 15:15:40 +00:00
|
|
|
|
|
|
|
|
2023-08-10 16:21:56 +00:00
|
|
|
def resolve_real_dir_node(node):
|
2022-11-02 15:15:40 +00:00
|
|
|
if isinstance(node, SCons.Node.FS.EntryProxy):
|
|
|
|
node = node.get()
|
|
|
|
|
|
|
|
for repo_dir in node.get_all_rdirs():
|
|
|
|
if os.path.exists(repo_dir.abspath):
|
2022-11-07 14:54:41 +00:00
|
|
|
return repo_dir
|
|
|
|
|
2023-08-10 16:21:56 +00:00
|
|
|
raise StopError(f"Can't find absolute path for {node.name} ({node})")
|
2022-11-10 11:55:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
def path_as_posix(path):
|
|
|
|
if SCons.Platform.platform_default() == "win32":
|
|
|
|
return path.replace(os.path.sep, os.path.altsep)
|
|
|
|
return path
|
2024-03-20 16:32:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
def open_browser_action(target, source, env):
|
|
|
|
if sys.platform == "darwin":
|
|
|
|
subprocess.run(["open", source[0].abspath])
|
|
|
|
else:
|
|
|
|
webbrowser.open(source[0].abspath)
|