regenerate.py
Go to the documentation of this file.00001
00002
00003 import os, sys, re, shutil, time
00004 from glob import glob
00005
00006 do_print = False
00007 filenames = []
00008 flags = []
00009 args = sys.argv[1:]
00010 for arg in args:
00011 if arg == "print":
00012 do_print = True
00013 elif arg.endswith(".ufl"):
00014 assert os.path.exists(arg)
00015 filenames.append(arg)
00016 elif os.path.isdir(arg):
00017 filenames.extend(glob(os.path.join(arg, "*.ufl")))
00018 else:
00019 flags.append(arg)
00020
00021 if not filenames:
00022 filenames = glob(os.path.join("ufl", "*.ufl"))
00023 filenames = sorted(filenames)
00024
00025 flags = " ".join(flags)
00026
00027 def basename(fn):
00028 n = os.path.basename(fn)
00029 b, e = os.path.splitext(n)
00030 return b
00031
00032
00033 try:
00034 os.mkdir("generated_code")
00035 except:
00036 pass
00037
00038 timing = []
00039 codepaths = []
00040 fails = []
00041 for fn in filenames:
00042 print
00043 print "--- Handling file", fn
00044 output = "generated_code/%s" % basename(fn)
00045
00046
00047 shutil.rmtree(output, ignore_errors=True)
00048
00049
00050 cmd = "sfc %s -o%s %s" % (flags, output, fn)
00051 t = -time.time()
00052 ok = os.system(cmd)
00053 t += time.time()
00054 if ok != 0:
00055 fails.append(fn)
00056 else:
00057 codepaths.append(output)
00058 timing.append("%8.1f seconds to compile %s." % (t, fn))
00059
00060
00061 if do_print:
00062 for p in codepaths:
00063 files = glob(os.path.join(p, "*integral*.cpp"))
00064 cmd = "print_tabulate_tensors %s" % " ".join(files)
00065 ok = os.system(cmd)
00066 if ok != 0:
00067 print "Failed to print tabulate_tensor for ", p
00068 print "cmd =", cmd
00069
00070
00071 if timing:
00072 print
00073 print "--- Timing of each sfc run:"
00074 print "\n".join(timing)
00075
00076 if fails:
00077 print
00078 print "--- The following files failed:"
00079 print "\n".join(fails)
00080 print
00081