diff --git a/SConstruct b/SConstruct index c37a309..f5c8652 100644 --- a/SConstruct +++ b/SConstruct @@ -5,8 +5,8 @@ env = SConscript('external/scons-plus-plus/SConscript', exports = ['config']) env.Append(CPPPATH = [Dir('private'), Dir('public')]) # add the default recipe repository -env.RecipeRepo('mewin-stable', 'https://git.mewin.de/mewin/spp_recipes.git', 'stable') -# env.RecipeRepo('mewin-testing', 'https://git.mewin.de/mewin/spp_recipes.git', 'testing') +env.RecipeRepo('mewin', 'https://git.mewin.de/mewin/spp_recipes.git', 'stable') +# env.RecipeRepo('mewin', 'https://git.mewin.de/mewin/spp_recipes.git', 'testing') # app env = env.Module('private/@MODULE_FOLDER_NAME@/SModule') diff --git a/external/scons-plus-plus/SConscript b/external/scons-plus-plus/SConscript new file mode 100644 index 0000000..7efb974 --- /dev/null +++ b/external/scons-plus-plus/SConscript @@ -0,0 +1,80 @@ +""" +SCons++ Bootstrapper +""" + + +import os +from pathlib import Path +import shutil +import subprocess +import sys +from SCons.Environment import Environment + + +Import('config') + + +_SPP_FOLDER_NAME = 'scons-plus-plus' +_SPP_DEFAULT_REPOSITORY = 'https://git.mewin.de/mewin/scons-plus-plus.git' +_SPP_DEFAULT_BRANCH = 'master' + + +spp_root: Path +spp_repository: str +spp_branch: str + +def _main() -> Environment: + global spp_root, spp_repository, spp_branch + + spp_root = config.get('SPP_ROOT') + if spp_root is None: + spp_root = _get_default_spp_root() + elif not isinstance(spp_root, Path): + spp_root = Path(str(spp_root)) + spp_root = spp_root.absolute() + + spp_repository = config.get('SPP_REPOSITORY', _SPP_DEFAULT_REPOSITORY) + spp_branch = config.get('SPP_BRANCH', _SPP_DEFAULT_BRANCH) + + print(f'Using SCons++ root at: {spp_root}') + + if not spp_root.exists(): + print('SCons++ does not yet exist, downloading it.') + _install_spp() + + spp_script = spp_root / 'SConscript' + if not spp_script.exists(): + _printerr(f'SCons++ main script not found at {spp_script}!') + sys.exit(1) + return SConscript(spp_script, exports=['config']) + +def _get_default_spp_root() -> Path: + if os.name == 'posix': + # follow XDG specification -> first try $XDG_DATA_HOME, then $HOME/.local/share + data_home = os.environ.get('XDG_DATA_HOME') + if data_home is not None: + return Path(data_home, _SPP_FOLDER_NAME) + home = os.environ.get('HOME') + if home is not None: + return Path(home, '.local', 'share', _SPP_FOLDER_NAME) + elif os.name == 'nt': + # just use LocalAppData, which should always be set on Windows + return Path(os.environ['LocalAppData'], _SPP_FOLDER_NAME) + print(f'Could not detect SCons++ root directory, falling back to ./{_SPP_FOLDER_NAME}.') + return Path(_SPP_FOLDER_NAME) + +def _install_spp() -> None: + git_exe = shutil.which('git') + if git_exe is None: + _printerr('No git executable found, cannot install SCons++.') + sys.exit(1) + _exec_checked((git_exe, 'clone', '-b', spp_branch, '--progress', spp_repository, spp_root)) + +def _exec_checked(args: Sequence[str], **kwargs) -> None: + subprocess.run(args, stdout=sys.stdout, stderr=sys.stderr, check=True, **kwargs) + +def _printerr(*args) -> None: + print(*args, file=sys.stderr) + +env = _main() +Return('env') diff --git a/tools/init_project.py b/tools/init_project.py index 8807fc2..307d2b9 100644 --- a/tools/init_project.py +++ b/tools/init_project.py @@ -28,36 +28,6 @@ def verify_tools() -> None: if not success: raise RuntimeError('one or more required tools could not be found') -def download_spp() -> None: - _logger.debug('Checking if Scons++ is checked out...') - output = exec_get_output(['git', 'submodule', 'status', 'external/scons-plus-plus']) - if output[0] in ('+', ' '): - return - assert output[0] == '-' - _logger.info('SCons++ not checkout out yet, doing it now.') - exec_checked(['git', 'submodule', 'init']) - exec_checked(['git', 'submodule', 'update', 'external/scons-plus-plus']) - -def update_spp() -> None: - _logger.debug('Updating SCons++ submodule...') - os.chdir(_root / 'external/scons-plus-plus') - try: - exec_checked(['git', 'fetch', 'origin', 'master']) - exec_checked(['git', 'checkout', 'master']) - exec_checked(['git', 'pull']) - finally: - os.chdir(_root) - output = exec_get_output(['git', 'status', '--porcelain']) - if output.strip() == '': - return - _logger.info('Changes in SCons++ detected, creating commit.') - exec_checked(['git', 'commit', '-m', 'Updated Scons++', 'external/scons-plus-plus']) - -def verify_unchanged() -> None: - output = exec_get_output(['git', 'status', '--porcelain']) - if output != '': - raise RuntimeError('There are uncommitted changes. Commit, stash or revert them before running this script.') - def setup_project() -> None: project_name = '' while project_name == '': @@ -111,9 +81,6 @@ def script_main(): global _root _root = get_root() verify_tools() - download_spp() - update_spp() - verify_unchanged() setup_project() setup_git_remote()