Commit d4e4d98c authored by Adam P. Goucher's avatar Adam P. Goucher

Progress indicator for lifelib compilation

parent 56bda762
Pipeline #41924013 passed with stages
in 6 minutes and 28 seconds
......@@ -5,3 +5,4 @@ rules/x*
dd0e0p
tempdir
cygwin
compiletime.txt
......@@ -3,6 +3,8 @@ import re
import sys
import os
import subprocess
import time
from . import genera
from ._version import __version__
......@@ -148,6 +150,20 @@ def run_tests():
print("Completed tests successfully.")
def obtain_arguments(soname, standard="C++11", optimisations=["-march=native", "-O3"],
options=["-Wall", "-Wextra"], **unused_kwargs):
so_args = ["-fPIC", "-shared", "-o", soname, "lifelib.cpp"]
if isinstance(standard, str):
standard = standard.lower()
if standard[0] != '-':
standard = "-std=" + standard
standard = [standard]
return standard + optimisations + options + so_args
def compile_rules(*rules, **kwargs):
if (len(rules) == 0):
......@@ -180,6 +196,17 @@ def compile_rules(*rules, **kwargs):
if recompile:
etime = 20.0
try:
with open(os.path.join(lifelib_dir, 'compiletime.txt'), 'r') as f:
for l in f:
l = l.strip()
if '.' in l:
etime = float(l)
except:
pass
try:
cwd = os.path.abspath(os.getcwd())
......@@ -188,13 +215,29 @@ def compile_rules(*rules, **kwargs):
generate_code(rules)
os.chdir(lifelib_dir)
print("Compiling lifelib shared object (this may take a while)...")
po = subprocess.Popen(get_compiler() + ["-std=c++11", "-march=native", "-O3",
"-Wall", "-Wextra", "-fPIC", "-shared", "-o", soname, "lifelib.cpp"],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
print("Compiling lifelib shared object (estimated time: %.1f seconds)..." % etime)
ccargs = get_compiler() + obtain_arguments(soname, **kwargs)
po = subprocess.Popen(ccargs, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
i = 0
imax = 64
sys.stdout.write('[' + (' ' * imax) + ']\r[')
while po.poll() is None:
time.sleep(etime / imax)
if (i < imax):
sys.stdout.write('=')
sys.stdout.flush()
i += 1
g_stdout, g_stderr = po.communicate()
status = po.returncode
char = '=' if (status == 0) else '!'
if (i < imax):
sys.stdout.write((char * (imax - i)))
sys.stdout.write(']\n')
if kwargs.get('compiler_output', (status != 0)):
sys.stderr.write("Compiler stdout: %s\n" % g_stdout)
......@@ -207,6 +250,11 @@ def compile_rules(*rules, **kwargs):
os.chdir(cwd)
etime = ((etime * i) / imax) + 0.5
with open(os.path.join(lifelib_dir, 'compiletime.txt'), 'w') as f:
f.write(str(etime))
reset_tree()
return soname
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment