Moved all the recipes that weren't actually recipes to addons.

This commit is contained in:
2024-08-04 13:11:10 +02:00
parent bbfec6c98a
commit 7d070c7e68
29 changed files with 63 additions and 43 deletions

View File

@@ -1,39 +0,0 @@
import os
import pathlib
import subprocess
import sys
from SCons.Script import *
_BUILT_STAMPFILE = '.spp_built'
def cook(env: Environment, project_root: str, config_args: 'list[str]' = [], build_args : 'list[str]' = [], install_args : 'list[str]' = []) -> dict:
config = env['BUILD_TYPE']
build_dir = os.path.join(project_root, f'build_{config}')
install_dir = os.path.join(project_root, f'install_{config}')
is_built = os.path.exists(os.path.join(install_dir, _BUILT_STAMPFILE))
if not is_built or env['UPDATE_REPOSITORIES']:
print(f'Building {project_root}, config {config}')
os.makedirs(build_dir, exist_ok=True)
opt_level = {
'debug': '-O0',
}.get(env['BUILD_TYPE'], '-O2')
debug_symbols = {
'release': ''
}.get(env['BUILD_TYPE'], '-g')
cflags = f'{opt_level} {debug_symbols}'
jobs = env.GetOption('num_jobs')
env = os.environ.copy()
env['CFLAGS'] = cflags
subprocess.run((os.path.join(project_root, 'configure'), '--prefix', install_dir, *config_args), cwd=build_dir, env=env, stdout=sys.stdout, stderr=sys.stderr, check=True)
subprocess.run(('make', f'-j{jobs}', *build_args), cwd=build_dir, stdout=sys.stdout, stderr=sys.stderr, check=True)
subprocess.run(('make', 'install', *install_args), cwd=build_dir, stdout=sys.stdout, stderr=sys.stderr, check=True)
pathlib.Path(install_dir, _BUILT_STAMPFILE).touch()
return {
'install_dir': install_dir,
'LIBPATH': [os.path.join(install_dir, 'lib')],
'CPPPATH': [os.path.join(install_dir, 'include')]
}

View File

@@ -1,47 +0,0 @@
import os
import pathlib
from SCons.Script import *
_BUILT_STAMPFILE = '.spp_built'
def cmd_quote(s: str) -> str:
escaped = s.replace('\\', '\\\\')
return f'"{escaped}"'
def cook(env: Environment, project_root: str, generate_args: 'list[str]' = [], build_args : 'list[str]' = [], install_args : 'list[str]' = []) -> dict:
config = env['BUILD_TYPE']
build_dir = os.path.join(project_root, f'build_{config}')
install_dir = os.path.join(project_root, f'install_{config}')
is_built = os.path.exists(os.path.join(install_dir, _BUILT_STAMPFILE))
if not is_built or env['UPDATE_REPOSITORIES']:
print(f'Building {project_root}, config {config}')
os.makedirs(build_dir, exist_ok=True)
build_type = {
'debug': 'Debug',
'release_debug': 'RelWithDebInfo',
'release': 'Release',
'profile': 'RelWithDebInfo'
}.get(env['BUILD_TYPE'], 'RelWithDebInfo')
def run_cmd(args):
env.Execute(' '.join([str(s) for s in args]))
# TODO: is this a problem?
# environ = os.environ.copy()
# environ['CXXFLAGS'] = ' '.join(f'-D{define}' for define in env['CPPDEFINES']) # TODO: who cares about windows?
run_cmd(['cmake', '-G', 'Ninja', '-B', build_dir, f'-DCMAKE_BUILD_TYPE={build_type}', f'-DCMAKE_INSTALL_PREFIX={cmd_quote(install_dir)}', '-DBUILD_TESTING=OFF', *generate_args, project_root])
run_cmd(['cmake', '--build', *build_args, cmd_quote(build_dir)])
run_cmd(['cmake', '--install', *install_args, cmd_quote(build_dir)])
pathlib.Path(install_dir, _BUILT_STAMPFILE).touch()
libpath = []
for lib_folder in ('lib', 'lib64'):
full_path = os.path.join(install_dir, lib_folder)
if os.path.exists(full_path):
libpath.append(full_path)
return {
'install_dir': install_dir,
'LIBPATH': libpath,
'CPPPATH': [os.path.join(install_dir, 'include')]
}

View File

@@ -2,9 +2,9 @@
from SCons.Script import *
def cook(env: Environment, git_ref: str = 'master', own_main: bool = False) -> dict:
repo = env.Cook('GitBranch', repo_name = 'catch2', remote_url = 'https://github.com/catchorg/Catch2.git', git_ref = git_ref)
repo = env.GitBranch(repo_name = 'catch2', remote_url = 'https://github.com/catchorg/Catch2.git', git_ref = git_ref)
checkout_root = repo['checkout_root']
build_result = env.Cook('CMakeProject', project_root=checkout_root)
build_result = env.CMakeProject(project_root=checkout_root)
lib_name = {
'debug': 'Catch2d'

View File

@@ -1,72 +0,0 @@
from enum import Enum
import hashlib
import pathlib
import tarfile
import zipfile
import urllib.request
from SCons.Script import *
class ArchiveType(Enum):
TAR_GZ = 0
ZIP = 1
def _detect_archive_type(url: str) -> ArchiveType:
if url.lower().endswith('.tar.gz'):
return ArchiveType.TAR_GZ
elif url.lower().endswith('.zip'):
return ArchiveType.ZIP
raise Exception('could not detect archive type from URL')
def _archive_type_ext(archive_type: ArchiveType) -> str:
if archive_type == ArchiveType.TAR_GZ:
return 'tar.gz'
elif archive_type == ArchiveType.ZIP:
return 'zip'
raise Exception('invalid archive type')
def _download_file(url: str, path: pathlib.Path) -> None:
if path.exists():
return
dl_path = path.with_suffix(f'{path.suffix}.tmp')
if dl_path.exists():
dl_path.unlink()
print(f'Downloading {url} to {dl_path}...')
urllib.request.urlretrieve(url, dl_path)
dl_path.rename(path)
def _extract_file(path: pathlib.Path, output_dir: str, archive_type: ArchiveType, skip_folders: int) -> None:
if archive_type == ArchiveType.TAR_GZ:
file = tarfile.open(str(path))
if skip_folders != 0:
def skip_filer(member: tarfile.TarInfo, path: str) -> tarfile.TarInfo:
name_parts = member.name.split('/')
if len(name_parts) <= skip_folders:
return None
return member.replace(name = '/'.join(name_parts[skip_folders:]))
file.extraction_filter = skip_filer
file.extractall(output_dir)
file.close()
elif archive_type == ArchiveType.ZIP:
file = zipfile.open(str(path))
file.extractall(output_dir)
file.close()
else:
raise Exception('invalid archive type')
def cook(env: Environment, repo_name: str, url: str, skip_folders: int = 0) -> dict:
archive_type = _detect_archive_type(url)
ext = _archive_type_ext(archive_type)
path = pathlib.Path(env['DOWNLOAD_DIR'], f'{hashlib.shake_128(url.encode("utf-8")).hexdigest(6)}.{ext}')
output_dir = pathlib.Path(env['CLONE_DIR'], 'download', repo_name)
stamp_file = pathlib.Path(output_dir, '.spp_extracted')
if not stamp_file.exists():
_download_file(url, path)
_extract_file(path, output_dir, archive_type, skip_folders)
stamp_file.touch()
return {
'extracted_root': str(output_dir)
}

View File

@@ -1,34 +0,0 @@
from git import Repo
from git.exc import GitError
import hashlib
import os
from SCons.Script import *
def cook(env: Environment, repo_name: str, remote_url: str, git_ref: str = "main") -> dict:
repo_dir = os.path.join(env['CLONE_DIR'], 'git', repo_name, '_bare')
try:
repo = Repo(repo_dir)
origin = repo.remotes['origin']
except GitError:
print(f'Initializing git repository at {repo_dir}.')
repo = Repo.init(repo_dir, bare=True)
origin = repo.create_remote('origin', remote_url)
worktree_dir = os.path.join(env['CLONE_DIR'], 'git', repo_name, hashlib.shake_128(git_ref.encode('utf-8')).hexdigest(6)) # TODO: commit hash would be better, right? -> not if it's a branch!
if not os.path.exists(worktree_dir):
print(f'Checking out into {worktree_dir}.')
origin.fetch(tags=True)
os.makedirs(worktree_dir)
repo.git.worktree('add', worktree_dir, git_ref)
elif env['UPDATE_REPOSITORIES']:
worktree_repo = Repo(worktree_dir)
if not worktree_repo.head.is_detached:
print(f'Updating git repository at {worktree_dir}')
worktree_origin = worktree_repo.remotes['origin']
worktree_origin.pull()
else:
print(f'Not updating git repository {worktree_dir} as it is not on a branch.')
return {
'checkout_root': worktree_dir
}

View File

@@ -2,9 +2,9 @@
from SCons.Script import *
def cook(env: Environment, git_ref = 'main') -> dict:
repo = env.Cook('GitBranch', repo_name = 'ImageMagick', remote_url = 'https://github.com/ImageMagick/ImageMagick.git', git_ref = git_ref)
repo = env.GitBranch(repo_name = 'ImageMagick', remote_url = 'https://github.com/ImageMagick/ImageMagick.git', git_ref = git_ref)
checkout_root = repo['checkout_root']
build_result = env.Cook('AutotoolsProject', checkout_root)
build_result = env.AutotoolsProject(checkout_root)
return {
'LIBPATH': build_result['LIBPATH'],
'CPPPATH': build_result['CPPPATH'],

View File

@@ -4,9 +4,9 @@ import platform
from SCons.Script import *
def cook(env: Environment, git_ref: str = "main") -> dict:
repo = env.Cook('GitBranch', repo_name = 'SDL', remote_url = 'https://github.com/libsdl-org/SDL.git', git_ref = git_ref)
repo = env.GitBranch(repo_name = 'SDL', remote_url = 'https://github.com/libsdl-org/SDL.git', git_ref = git_ref)
checkout_root = repo['checkout_root']
build_result = env.Cook('CMakeProject', project_root=checkout_root, generate_args = ['-DSDL_STATIC=ON', '-DSDL_SHARED=OFF'])
build_result = env.CMakeProject(project_root=checkout_root, generate_args = ['-DSDL_STATIC=ON', '-DSDL_SHARED=OFF'])
libs = []
if platform.system() == 'Windows':
if env['BUILD_TYPE'] == 'debug':

View File

@@ -4,9 +4,9 @@ from SCons.Script import *
def cook(env: Environment, remote: str = 'github', git_ref: str = 'main') -> dict:
if remote == 'mewin':
repo = env.Cook('GitBranch', repo_name = 'VulkanHeaders_mewin', remote_url = 'https://git.mewin.de/mewin/vulkan-headers.git', git_ref = git_ref)
repo = env.GitBranch(repo_name = 'VulkanHeaders_mewin', remote_url = 'https://git.mewin.de/mewin/vulkan-headers.git', git_ref = git_ref)
else:
repo = env.Cook('GitBranch', repo_name = 'VulkanHeaders', remote_url = 'https://github.com/KhronosGroup/Vulkan-Headers.git', git_ref = git_ref)
repo = env.GitBranch(repo_name = 'VulkanHeaders', remote_url = 'https://github.com/KhronosGroup/Vulkan-Headers.git', git_ref = git_ref)
checkout_root = repo['checkout_root']
return {
'CPPPATH': [os.path.join(checkout_root, 'include')]

View File

@@ -3,7 +3,7 @@ import os
from SCons.Script import *
def cook(env: Environment, git_ref: str = "master") -> dict:
repo = env.Cook('GitBranch', repo_name = 'argparse', remote_url = 'https://github.com/p-ranav/argparse.git', git_ref = git_ref)
repo = env.GitBranch(repo_name = 'argparse', remote_url = 'https://github.com/p-ranav/argparse.git', git_ref = git_ref)
checkout_root = repo['checkout_root']
return {
'CPPPATH': [os.path.join(checkout_root, 'include')]

View File

@@ -5,7 +5,7 @@ from SCons.Script import *
def cook(env: Environment, version: str = "1.85.0") -> dict:
# TODO: build binaries?
url = f'https://archives.boost.io/release/{version}/source/boost_{version.replace(".", "_")}.tar.gz'
repo = env.Cook('DownloadAndExtract', f'boost_{version}', url = url, skip_folders = 1)
repo = env.DownloadAndExtract(f'boost_{version}', url = url, skip_folders = 1)
checkout_root = repo['extracted_root']
return {
'CPPPATH': [checkout_root]

View File

@@ -2,7 +2,7 @@
from SCons.Script import *
def cook(env: Environment, git_ref: str = "master") -> dict:
repo = env.Cook('GitBranch', repo_name = 'cgltf', remote_url = 'https://github.com/jkuhlmann/cgltf.git', git_ref = git_ref)
repo = env.GitBranch(repo_name = 'cgltf', remote_url = 'https://github.com/jkuhlmann/cgltf.git', git_ref = git_ref)
checkout_root = repo['checkout_root']
return {
'CPPPATH': [checkout_root]

View File

@@ -2,9 +2,9 @@
from SCons.Script import *
def cook(env: Environment, git_ref: str = 'master') -> dict:
repo = env.Cook('GitBranch', repo_name = 'fmt', remote_url = 'https://github.com/fmtlib/fmt.git', git_ref = git_ref)
repo = env.GitBranch(repo_name = 'fmt', remote_url = 'https://github.com/fmtlib/fmt.git', git_ref = git_ref)
checkout_root = repo['checkout_root']
build_result = env.Cook('CMakeProject', project_root=checkout_root, generate_args = ['-DFMT_TEST=OFF'])
build_result = env.CMakeProject(project_root=checkout_root, generate_args = ['-DFMT_TEST=OFF'])
lib_name = {
'debug': 'fmtd'

View File

@@ -3,9 +3,9 @@ from SCons.Script import *
def cook(env: Environment, remote: str = 'github', git_ref: str = "master") -> dict:
if remote == 'mewin':
repo = env.Cook('GitBranch', repo_name = 'glm_mewin', remote_url = 'https://git.mewin.de/mewin/glm.git', git_ref = git_ref)
repo = env.GitBranch(repo_name = 'glm_mewin', remote_url = 'https://git.mewin.de/mewin/glm.git', git_ref = git_ref)
else:
repo = env.Cook('GitBranch', repo_name = 'glm', remote_url = 'https://github.com/g-truc/glm.git', git_ref = git_ref)
repo = env.GitBranch(repo_name = 'glm', remote_url = 'https://github.com/g-truc/glm.git', git_ref = git_ref)
checkout_root = repo['checkout_root']
return {

View File

@@ -12,9 +12,9 @@ _SCRIPT_STAMPFILE = '.spp_script_run'
def cook(env: Environment, remote: str = 'github', git_ref: str = '') -> dict:
if remote == 'mewin':
repo = env.Cook('GitBranch', repo_name = 'glslang_mewin', remote_url = 'https://git.mewin.de/mewin/glslang.git', git_ref = git_ref or 'master')
repo = env.GitBranch(repo_name = 'glslang_mewin', remote_url = 'https://git.mewin.de/mewin/glslang.git', git_ref = git_ref or 'master')
else:
repo = env.Cook('GitBranch', repo_name = 'glslang', remote_url = 'https://github.com/KhronosGroup/glslang.git', git_ref = git_ref or 'main')
repo = env.GitBranch(repo_name = 'glslang', remote_url = 'https://github.com/KhronosGroup/glslang.git', git_ref = git_ref or 'main')
checkout_root = repo['checkout_root']
# TODO: windows?

View File

@@ -3,7 +3,7 @@ from SCons.Script import *
import os
def cook(env: Environment, backends: list = [], git_ref: str = '') -> dict:
repo = env.Cook('GitBranch', repo_name = 'imgui', remote_url = 'https://github.com/ocornut/imgui.git', git_ref = git_ref or 'master')
repo = env.GitBranch(repo_name = 'imgui', remote_url = 'https://github.com/ocornut/imgui.git', git_ref = git_ref or 'master')
imgui_source_files = [
os.path.join(repo['checkout_root'], 'imgui.cpp'),

View File

@@ -3,6 +3,6 @@ import os
from SCons.Script import *
def cook(env: Environment, git_ref: str = "master") -> dict:
repo = env.Cook('GitBranch', repo_name = 'iwa', remote_url = 'https://git.mewin.de/mewin/iwa.git', git_ref = git_ref)
repo = env.GitBranch(repo_name = 'iwa', remote_url = 'https://git.mewin.de/mewin/iwa.git', git_ref = git_ref)
checkout_root = repo['checkout_root']
return SConscript(os.path.join(checkout_root, 'LibConf'), exports = ['env'])

View File

@@ -4,9 +4,9 @@ from SCons.Script import *
def cook(env: Environment, git_ref = 'master') -> dict:
if env['COMPILER_FAMILY'] not in ('gcc', 'clang'):
env.Error('libbacktrace requires gcc or clang.')
repo = env.Cook('GitBranch', repo_name = 'libbacktrace', remote_url = 'https://github.com/ianlancetaylor/libbacktrace.git', git_ref = git_ref)
repo = env.GitBranch(repo_name = 'libbacktrace', remote_url = 'https://github.com/ianlancetaylor/libbacktrace.git', git_ref = git_ref)
checkout_root = repo['checkout_root']
build_result = env.Cook('AutotoolsProject', checkout_root)
build_result = env.AutotoolsProject(checkout_root)
return {
'LIBPATH': build_result['LIBPATH'],
'CPPPATH': build_result['CPPPATH'],

View File

@@ -2,9 +2,9 @@
from SCons.Script import *
def cook(env: Environment, git_ref = 'main') -> dict:
repo = env.Cook('GitBranch', repo_name = 'libjpeg-turbo', remote_url = 'https://github.com/libjpeg-turbo/libjpeg-turbo.git', git_ref = git_ref)
repo = env.GitBranch(repo_name = 'libjpeg-turbo', remote_url = 'https://github.com/libjpeg-turbo/libjpeg-turbo.git', git_ref = git_ref)
checkout_root = repo['checkout_root']
build_result = env.Cook('CMakeProject', checkout_root)
build_result = env.CMakeProject(checkout_root)
return {
'CPPPATH': build_result['CPPPATH'],
'LIBS': [env.FindLib('jpeg', paths=build_result['LIBPATH'])],

View File

@@ -3,9 +3,9 @@ from SCons.Script import *
def cook(env: Environment, git_ref = 'master') -> dict:
lib_z = env.Cook('zlib')
repo = env.Cook('GitBranch', repo_name = 'libpng', remote_url = 'https://git.code.sf.net/p/libpng/code.git', git_ref = git_ref)
repo = env.GitBranch(repo_name = 'libpng', remote_url = 'https://git.code.sf.net/p/libpng/code.git', git_ref = git_ref)
checkout_root = repo['checkout_root']
build_result = env.Cook('AutotoolsProject', checkout_root)
build_result = env.AutotoolsProject(checkout_root)
return {
'CPPPATH': build_result['CPPPATH'],
'LIBS': [env.FindLib('png16', paths=build_result['LIBPATH'])],

View File

@@ -3,7 +3,7 @@ import os
from SCons.Script import *
def cook(env: Environment, git_ref: str = "master") -> dict:
repo = env.Cook('GitBranch', repo_name = 'magic_enum', remote_url = 'https://github.com/Neargye/magic_enum.git', git_ref = git_ref)
repo = env.GitBranch(repo_name = 'magic_enum', remote_url = 'https://github.com/Neargye/magic_enum.git', git_ref = git_ref)
checkout_root = repo['checkout_root']
return {
'CPPPATH': [os.path.join(checkout_root, 'include')]

View File

@@ -4,9 +4,9 @@ from SCons.Script import *
import os
def cook(env: Environment, git_ref = 'master') -> dict:
repo = env.Cook('GitBranch', repo_name = 'mecab', remote_url = 'https://github.com/taku910/mecab.git', git_ref = git_ref)
repo = env.GitBranch(repo_name = 'mecab', remote_url = 'https://github.com/taku910/mecab.git', git_ref = git_ref)
checkout_root = repo['checkout_root']
build_result = env.Cook('AutotoolsProject', os.path.join(checkout_root, 'mecab'))
build_result = env.AutotoolsProject(os.path.join(checkout_root, 'mecab'))
return {
'LIBPATH': build_result['LIBPATH'],
'CPPPATH': build_result['CPPPATH'],

View File

@@ -3,6 +3,6 @@ import os
from SCons.Script import *
def cook(env: Environment, git_ref: str = "master") -> dict:
repo = env.Cook('GitBranch', repo_name = 'mijin', remote_url = 'https://git.mewin.de/mewin/mijin2.git', git_ref = git_ref)
repo = env.GitBranch(repo_name = 'mijin', remote_url = 'https://git.mewin.de/mewin/mijin2.git', git_ref = git_ref)
checkout_root = repo['checkout_root']
return SConscript(os.path.join(checkout_root, 'LibConf'), exports = ['env'])

View File

@@ -3,7 +3,7 @@ import os
from SCons.Script import *
def cook(env: Environment, git_ref: str = 'master') -> dict:
repo = env.Cook('GitBranch', repo_name = 'mikktspace', remote_url = 'https://github.com/mmikk/MikkTSpace.git', git_ref = git_ref)
repo = env.GitBranch(repo_name = 'mikktspace', remote_url = 'https://github.com/mmikk/MikkTSpace.git', git_ref = git_ref)
lib_mikktspace = env.StaticLibrary(
CPPPATH = [repo['checkout_root']],
target = env['LIB_DIR'] + '/mikktspace',

View File

@@ -2,9 +2,9 @@
from SCons.Script import *
def cook(env: Environment, git_ref: str = 'v1.x', use_external_libfmt = False) -> dict:
repo = env.Cook('GitBranch', repo_name = 'spdlog', remote_url = 'https://github.com/gabime/spdlog.git', git_ref = git_ref)
repo = env.GitBranch(repo_name = 'spdlog', remote_url = 'https://github.com/gabime/spdlog.git', git_ref = git_ref)
checkout_root = repo['checkout_root']
build_result = env.Cook('CMakeProject', project_root=checkout_root)
build_result = env.CMakeProject(project_root=checkout_root)
lib_name = {
'debug': 'spdlogd'

View File

@@ -2,7 +2,7 @@
from SCons.Script import *
def cook(env: Environment, git_ref: str = "master") -> dict:
repo = env.Cook('GitBranch', repo_name = 'stb', remote_url = 'https://github.com/nothings/stb.git', git_ref = git_ref)
repo = env.GitBranch(repo_name = 'stb', remote_url = 'https://github.com/nothings/stb.git', git_ref = git_ref)
checkout_root = repo['checkout_root']
return {
'CPPPATH': [checkout_root]

View File

@@ -1,9 +1,9 @@
from SCons.Script import *
def cook(env: Environment, git_ref: str = "master") -> dict:
repo = env.Cook('GitBranch', repo_name = 'yaml-cpp', remote_url = 'https://github.com/jbeder/yaml-cpp', git_ref = git_ref)
repo = env.GitBranch(repo_name = 'yaml-cpp', remote_url = 'https://github.com/jbeder/yaml-cpp', git_ref = git_ref)
checkout_root = repo['checkout_root']
build_result = env.Cook('CMakeProject', project_root=checkout_root)
build_result = env.CMakeProject(project_root=checkout_root)
lib_name = {
'debug': 'yaml-cppd'
}.get(env['BUILD_TYPE'], 'yaml-cpp')

View File

@@ -3,9 +3,9 @@ import os
from SCons.Script import *
def cook(env: Environment, git_ref: str = 'master') -> dict:
repo = env.Cook('GitBranch', repo_name = 'zlib', remote_url = 'https://github.com/madler/zlib.git', git_ref = git_ref)
repo = env.GitBranch(repo_name = 'zlib', remote_url = 'https://github.com/madler/zlib.git', git_ref = git_ref)
extracted_root = repo['checkout_root']
build_result = env.Cook('CMakeProject', project_root=extracted_root)
build_result = env.CMakeProject(project_root=extracted_root)
return {
'CPPPATH': [os.path.join(build_result['install_dir'], 'install')],
'LIBS': [env.FindLib('z', paths=build_result['LIBPATH'])]