Put temporary stuff in a scratch directory.

pull/15/head
Jussi Pakkanen 12 years ago
parent 16aa9b16b2
commit 1892e92a93
  1. 2
      builder.py
  2. 5
      environment.py
  3. 11
      interpreter.py
  4. 1
      test cases/1 trivial/builder.txt

@ -67,7 +67,7 @@ class Builder():
raise interpreter.InvalidCode('Builder file is empty.') raise interpreter.InvalidCode('Builder file is empty.')
assert(isinstance(code, str)) assert(isinstance(code, str))
env = environment.Environment(self.source_dir, self.build_dir) env = environment.Environment(self.source_dir, self.build_dir)
intr = interpreter.Interpreter(code) intr = interpreter.Interpreter(code, env.get_scratch_dir())
g = shellgenerator.ShellGenerator(intr, env) g = shellgenerator.ShellGenerator(intr, env)
g.generate() g.generate()

@ -108,6 +108,8 @@ class Environment():
def __init__(self, source_dir, build_dir): def __init__(self, source_dir, build_dir):
self.source_dir = source_dir self.source_dir = source_dir
self.build_dir = build_dir self.build_dir = build_dir
self.scratch_dir = os.path.join(build_dir, 'builder-private')
os.makedirs(self.scratch_dir, exist_ok=True)
self.default_c = ['cc'] self.default_c = ['cc']
self.default_cxx = ['c++'] self.default_cxx = ['c++']
@ -124,6 +126,9 @@ class Environment():
if evar in os.environ: if evar in os.environ:
return os.environ[evar].split() return os.environ[evar].split()
return self.default_c return self.default_c
def get_scratch_dir(self):
return self.scratch_dir
def get_cxx_compiler(self): def get_cxx_compiler(self):
evar = 'CXX' evar = 'CXX'

@ -66,14 +66,15 @@ class Executable(BuildTarget):
class Interpreter(): class Interpreter():
def __init__(self, code): def __init__(self, code, scratch_dir):
self.ast = parser.build_ast(code) self.ast = parser.build_ast(code)
self.sanity_check_ast() self.sanity_check_ast()
self.project = None self.project = None
self.compilers = [] self.compilers = []
self.executables = {} self.executables = {}
self.variables = {} self.variables = {}
self.scratch_dir = scratch_dir
def get_project(self): def get_project(self):
return self.project return self.project
@ -136,7 +137,9 @@ class Interpreter():
raise InvalidCode('Function language() can only be called once (line %d).' % node.lineno()) raise InvalidCode('Function language() can only be called once (line %d).' % node.lineno())
lang = args[0] lang = args[0]
if lang.lower() == 'c': if lang.lower() == 'c':
self.compilers.append(environment.detect_c_compiler('gcc')) comp = environment.detect_c_compiler('gcc')
comp.sanity_check(self.scratch_dir)
self.compilers.append(comp)
else: else:
raise InvalidCode('Tried to use unknown language "%s".' % lang) raise InvalidCode('Tried to use unknown language "%s".' % lang)
@ -231,5 +234,5 @@ if __name__ == '__main__':
dep = find_dep('gtk+-3.0') dep = find_dep('gtk+-3.0')
prog.add_dep(dep) prog.add_dep(dep)
""" """
i = Interpreter(code) i = Interpreter(code, '.')
i.run() i.run()

@ -1,2 +1,3 @@
project('trivial test') project('trivial test')
language('c')

Loading…
Cancel
Save