From 1892e92a93c4a261fa030118b66cd7bbb02bf62f Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Tue, 1 Jan 2013 20:08:03 +0200 Subject: [PATCH] Put temporary stuff in a scratch directory. --- builder.py | 2 +- environment.py | 5 +++++ interpreter.py | 11 +++++++---- test cases/1 trivial/builder.txt | 1 + 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/builder.py b/builder.py index 95bd8d9a3..1ff451428 100755 --- a/builder.py +++ b/builder.py @@ -67,7 +67,7 @@ class Builder(): raise interpreter.InvalidCode('Builder file is empty.') assert(isinstance(code, str)) 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.generate() diff --git a/environment.py b/environment.py index 2fbe652cf..786607e88 100755 --- a/environment.py +++ b/environment.py @@ -108,6 +108,8 @@ class Environment(): def __init__(self, source_dir, build_dir): self.source_dir = source_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_cxx = ['c++'] @@ -124,6 +126,9 @@ class Environment(): if evar in os.environ: return os.environ[evar].split() return self.default_c + + def get_scratch_dir(self): + return self.scratch_dir def get_cxx_compiler(self): evar = 'CXX' diff --git a/interpreter.py b/interpreter.py index e35c20302..4d28ce682 100755 --- a/interpreter.py +++ b/interpreter.py @@ -66,14 +66,15 @@ class Executable(BuildTarget): class Interpreter(): - def __init__(self, code): + def __init__(self, code, scratch_dir): self.ast = parser.build_ast(code) self.sanity_check_ast() self.project = None self.compilers = [] self.executables = {} self.variables = {} - + self.scratch_dir = scratch_dir + def get_project(self): return self.project @@ -136,7 +137,9 @@ class Interpreter(): raise InvalidCode('Function language() can only be called once (line %d).' % node.lineno()) lang = args[0] 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: raise InvalidCode('Tried to use unknown language "%s".' % lang) @@ -231,5 +234,5 @@ if __name__ == '__main__': dep = find_dep('gtk+-3.0') prog.add_dep(dep) """ - i = Interpreter(code) + i = Interpreter(code, '.') i.run() diff --git a/test cases/1 trivial/builder.txt b/test cases/1 trivial/builder.txt index a499cf7ee..fdd1c6245 100644 --- a/test cases/1 trivial/builder.txt +++ b/test cases/1 trivial/builder.txt @@ -1,2 +1,3 @@ project('trivial test') +language('c')