Created
May 30, 2016 18:11
-
-
Save selaux/f1eb93fde855ed12ac6973171da1ae56 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import re | |
from shutil import copy2 as copy | |
from io import BytesIO | |
from subprocess import run, PIPE | |
from functools import partial | |
MAX_ITERS = 100000 | |
MAKE_CMD = partial(run, ['make', '-j1'], stderr=PIPE) | |
BUILD_BOOST_BASE = './_build/lib-boost/' | |
INCLUDE_BASE = 'boost' | |
BOOST_BASE = os.path.expanduser(os.path.expandvars('~/Downloads/boost_1_61_0/')) | |
def copy_missing_boost_header(missing): | |
target = os.path.join(BUILD_BOOST_BASE, missing) | |
target_directory = os.path.dirname(target) | |
boost_file = BOOST_BASE + missing | |
if not os.path.exists(boost_file): | |
print('Source file does not exist: {0}'.format(boost_file)) | |
return False | |
if not os.path.exists(target): | |
print('Copying', boost_file, 'to', target) | |
try: | |
os.stat(target_directory) | |
except: | |
print('Creating', target_directory) | |
os.makedirs(target_directory) | |
copy(boost_file, target) | |
return True | |
return False | |
REGEX_1 = 'No\srule\sto\smake\starget\s\'(.*\.[a-z]+)\',' | |
REGEX_2 = 'fatal error: (.*\.[a-z]+): No such file or directory' | |
for _ in range(MAX_ITERS): | |
fp = MAKE_CMD() | |
if fp.returncode == 0: | |
print("Too many iterations something went wrong") | |
break | |
match = re.search(REGEX_1, fp.stderr.decode('utf8')) or re.search(REGEX_2, fp.stderr.decode('utf8')) | |
missing = match.group(1) | |
missing = missing[17:] if missing.startswith('_build') else missing | |
copy_missing_boost_header(missing) | |
fp = MAKE_CMD() | |
# Do Some Integrity Checking of includes in boost directory | |
REGEX_1 = '#\s*include\s*[<"]({0}/[^\s]+\.[^\s]+)[">]'.format(INCLUDE_BASE) | |
def check_integrity(): | |
clean = True | |
for root, subdirs, files in os.walk(os.path.join(BUILD_BOOST_BASE, INCLUDE_BASE)): | |
for fn in files: | |
with open(root + '/' + fn) as f: | |
content = f.read() | |
matches = list(re.finditer(REGEX_1, content)) | |
for match in matches: | |
if copy_missing_boost_header(match.group(1)): | |
clean = False | |
return clean | |
for _ in range(MAX_ITERS): | |
if check_integrity(): | |
print("Too many iterations something went wrong") | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment