diff --git a/SConscript b/SConscript index 4b7ce77..075911b 100644 --- a/SConscript +++ b/SConscript @@ -4,9 +4,11 @@ import os def _cook(env: Environment, recipe_name: str, *args, **kwargs): import importlib.util + source_file = None for folder in env['RECIPES_FOLDERS']: - source_file = f'{folder.abspath}/{recipe_name}/recipe.py' - if os.path.exists(source_file): + try_source_file = f'{folder.abspath}/{recipe_name}/recipe.py' + if os.path.exists(try_source_file): + source_file = try_source_file break if not source_file: raise Exception(f'Could not find recipe {recipe_name}.') @@ -34,6 +36,9 @@ def _inject_dependency(dependency, kwargs: dict) -> None: _inject_list(kwargs, dependency, 'CPPDEFINES') _inject_list(kwargs, dependency, 'LIBPATH') _inject_list(kwargs, dependency, 'LIBS') + if 'DEPENDENCIES' in dependency: + for inner_dependency in dependency['DEPENDENCIES']: + _inject_dependency(inner_dependency, kwargs) def _rglob(env: Environment, root_path: str, pattern: str, **kwargs): result_nodes = [] diff --git a/recipes/AutotoolsProject/recipe.py b/recipes/AutotoolsProject/recipe.py new file mode 100644 index 0000000..af420c9 --- /dev/null +++ b/recipes/AutotoolsProject/recipe.py @@ -0,0 +1,39 @@ + +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')] + } + diff --git a/recipes/libbacktrace/recipe.py b/recipes/libbacktrace/recipe.py new file mode 100644 index 0000000..8733feb --- /dev/null +++ b/recipes/libbacktrace/recipe.py @@ -0,0 +1,12 @@ + +from SCons.Script import * + +def cook(env: Environment) -> dict: + repo = env.Cook('GitBranch', repo_name = 'libbacktrace', remote_url = 'https://github.com/ianlancetaylor/libbacktrace.git', git_ref = 'master') + checkout_root = repo['checkout_root'] + build_result = env.Cook('AutotoolsProject', checkout_root) + return { + 'LIBPATH': build_result['LIBPATH'], + 'CPPPATH': build_result['CPPPATH'], + 'LIBS': ['backtrace'] + }