diff --git a/SConscript b/SConscript index 3054a82..f5bf805 100644 --- a/SConscript +++ b/SConscript @@ -140,12 +140,19 @@ AddOption( default = 'auto' ) +AddOption( + '--update_repositories', + dest = 'update_repositories', + action = 'store_true' +) + build_type = GetOption('build_type') unity_mode = GetOption('unity_mode') variant = GetOption('variant') enable_asan = GetOption('enable_asan') config_file = GetOption('config_file') compiler = GetOption('compiler') +update_repositories = GetOption('update_repositories') default_CC = { 'gcc': 'gcc', @@ -170,6 +177,7 @@ env = Environment(tools = ['default', 'compilation_db', 'unity_build'], variable env['RECIPES_FOLDERS'] = [Dir('recipes')] env['SYSTEM_CACHE_DIR'] = os.path.join(_find_system_cache_dir(), 'spp_cache') env['CLONE_DIR'] = os.path.join(env['SYSTEM_CACHE_DIR'], 'cloned') +env['UPDATE_REPOSITORIES'] = update_repositories print(f'Detected system cache directory: {env["SYSTEM_CACHE_DIR"]}') try: diff --git a/recipes/GitBranch/recipe.py b/recipes/GitBranch/recipe.py index 03bed71..a23be8b 100644 --- a/recipes/GitBranch/recipe.py +++ b/recipes/GitBranch/recipe.py @@ -11,15 +11,23 @@ def cook(env: Environment, repo_name: str, remote_url: str, git_ref: str = "main repo = Repo(repo_dir) origin = repo.remotes['origin'] except GitError: - print(f'Initializing git repository for SDL at {repo_dir}.') + 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? + 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() 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 } diff --git a/recipes/criterion/recipe.py b/recipes/criterion/recipe.py new file mode 100644 index 0000000..c394c8e --- /dev/null +++ b/recipes/criterion/recipe.py @@ -0,0 +1,35 @@ + +import os +import subprocess +import sys +from SCons.Script import * + +def cook(env: Environment, git_ref: str = "master") -> dict: + repo = env.Cook('GitBranch', repo_name = 'criterion', remote_url = 'https://github.com/Snaipe/Criterion.git', git_ref = git_ref) + checkout_root = repo['checkout_root'] + + config = env['BUILD_TYPE'] + build_dir = os.path.join(checkout_root, f'build_{config}') + install_dir = os.path.join(checkout_root, f'install_{config}') + lib_fname = 'libcriterion.a' # TODO: who cares about windows? + is_built = os.path.exists(os.path.join(install_dir, 'lib', lib_fname)) # TODO! + if not is_built: + print(f'Building Criterion, config {config}') + os.makedirs(build_dir, exist_ok=True) + build_type = { + 'debug': 'debug', + 'release_debug': 'debugoptimized', + 'release': 'release', + 'profile': 'debugoptimized' + }.get(env['BUILD_TYPE'], 'debugoptimized') + subprocess.run(['meson', 'setup', '--prefix', install_dir, '--buildtype', build_type, build_dir, checkout_root], stdout=sys.stdout, stderr=sys.stderr, check=True) + subprocess.run(['meson', 'install', '-C', build_dir], stdout=sys.stdout, stderr=sys.stderr, check=True) + + + lib_name = 'criterion' + return { + 'LIBPATH': [os.path.join(install_dir, 'lib')], + 'CPPPATH': [os.path.join(install_dir, 'include')], + 'LIBS': [lib_name] + } +