add build directory to ivy_to_cpp

This commit is contained in:
Ken McMillan 2018-11-26 17:45:15 -08:00
Родитель e0c9fec740
Коммит 592e27f039
2 изменённых файлов: 22 добавлений и 4 удалений

Просмотреть файл

@ -4915,6 +4915,7 @@ def main_int(is_ivyc):
with im.module.copy():
with iu.ErrorPrinter():
import os
if isolate:
if len(isolates) > 1:
print "Compiling isolate {}...".format(isolate)
@ -4948,15 +4949,15 @@ def main_int(is_ivyc):
header,impl = module_to_cpp_class(classname,basename)
# print header
# print impl
f = open(outfile(basename+'.h'),'w')
builddir = 'build' if os.path.exists('build') else '.'
f = open(outfile(builddir+'/'+basename+'.h'),'w')
f.write(header)
f.close()
f = open(outfile(basename+'.cpp'),'w')
f = open(outfile(builddir+'/'+basename+'.cpp'),'w')
f.write(impl)
f.close()
if opt_build.get():
import platform
import os
libpath = os.path.join(os.path.dirname(os.path.dirname(__file__)),'lib')
specfilename = os.path.join(libpath,'specs')
if os.path.isfile(specfilename):
@ -5018,7 +5019,8 @@ def main_int(is_ivyc):
cmd += ' -pthread'
print cmd
sys.stdout.flush()
status = os.system(cmd)
with iu.WorkingDir(builddir):
status = os.system(cmd)
if status:
exit(1)

Просмотреть файл

@ -226,6 +226,22 @@ class SourceFile(object):
filename = None
class WorkingDir(object):
""" Context Manager that temporarily sets the working directory.
"""
def __init__(self,fname):
self.fname = fname
def __enter__(self):
self.oldf = os.getcwd()
os.chdir(self.fname)
return self
def __exit__(self,exc_type, exc_val, exc_tb):
os.chdir(self.oldf)
return False # don't block any exceptions
def Location(filename=None,line=None):
return LocationTuple([filename,line])