import json import os import re import requests from SCons.Script import * _VERSIONS_URL = 'https://api.github.com/repos/boostorg/boost/releases' _VERSION_PATTERN = re.compile(r'^boost-([0-9]+)\.([0-9]+)\.([0-9]+)$') def versions(env: Environment, update: bool = False): versions_file = os.path.join(env['DOWNLOAD_DIR'], 'boost_versions.json') if update or not os.path.exists(versions_file): req = requests.get(_VERSIONS_URL) versions_data = json.loads(req.text) result = [] for version_data in versions_data: match = _VERSION_PATTERN.match(version_data['name']) if not match: continue result.append((int(match.groups()[0]), int(match.groups()[1]), int(match.groups()[2]))) with open(versions_file, 'w') as f: json.dump(result, f) return result else: try: with open(versions_file, 'r') as f: return [tuple(v) for v in json.load(f)] except: print('boost_versions.json is empty or broken, redownloading.') return versions(env, update=True) def dependencies(env: Environment, version) -> 'dict': return {} def cook(env: Environment, version) -> dict: if env.get('BOOST_LIBS') is None: raise Exception('BOOST_LIBS not set. Set to a list of boost libs to link or "*" to link everything.') if version >= (1, 85, 0): url = f'https://github.com/boostorg/boost/releases/download/boost-{version[0]}.{version[1]}.{version[2]}/boost-{version[0]}.{version[1]}.{version[2]}-cmake.tar.gz' else: url = f'https://github.com/boostorg/boost/releases/download/boost-{version[0]}.{version[1]}.{version[2]}/boost-{version[0]}.{version[1]}.{version[2]}.tar.gz' repo = env.DownloadAndExtract(f'boost_{version[0]}.{version[1]}.{version[2]}', url = url, skip_folders = 1) checkout_root = repo['extracted_root'] build_result = env.CMakeProject(checkout_root) libs = [] if '*' in env['BOOST_LIBS']: lib_dir = build_result['LIBPATH'][0] for lib_file in os.listdir(lib_dir): fname = os.path.join(lib_dir, lib_file) if not os.path.isfile(fname): continue libs.append(fname) else: for lib in set(env['BOOST_LIBS']): if os.name == 'posix': libs.append(env.FindLib(f'boost_{lib}', paths=build_result['LIBPATH'])) elif os.name == 'nt': libs.append(env.FindLib(f'libboost_{lib}-*', paths=build_result['LIBPATH'], use_glob=True)) else: raise Exception('Boost not supported on this platform.') cpppath = { 'nt': [f'{build_result['CPPPATH'][0]}/boost-{version[0]}_{version[1]}'] }.get(os.name, build_result['CPPPATH']) return { 'CPPPATH': cpppath, 'LIBS': libs }