Start work on descending to subdirectories.

pull/15/head
Jussi Pakkanen 12 years ago
parent 5969b1ed33
commit 79c9e1e172
  1. 5
      builder.py
  2. 2
      environment.py
  3. 15
      interpreter.py

@ -30,7 +30,6 @@ parser.add_option('--datadir', default='share', dest='datadir')
parser.add_option('--mandir' , default='share/man', dest='mandir')
class BuilderApp():
builder_filename = 'builder.txt'
def __init__(self, dir1, dir2, options):
(self.source_dir, self.build_dir) = self.validate_dirs(dir1, dir2)
@ -39,7 +38,7 @@ class BuilderApp():
self.options = options
def has_builder_file(self, dirname):
fname = os.path.join(dirname, BuilderApp.builder_filename)
fname = os.path.join(dirname, environment.builder_filename)
try:
ifile = open(fname, 'r')
ifile.close()
@ -66,7 +65,7 @@ class BuilderApp():
raise RuntimeError('Neither directory contains a builder file %s.' % BuilderApp.builder_filename)
def generate(self):
code = open(os.path.join(self.source_dir, BuilderApp.builder_filename)).read()
code = open(os.path.join(self.source_dir, environment.builder_filename)).read()
if len(code.strip()) == 0:
raise interpreter.InvalidCode('Builder file is empty.')
assert(isinstance(code, str))

@ -16,6 +16,8 @@
import subprocess, os.path
builder_filename = 'builder.txt'
class EnvironmentException(Exception):
def __init(self, *args, **kwargs):
Exception.__init__(self, *args, **kwargs)

@ -17,6 +17,7 @@
import parser
import nodes
import environment
import os
class InterpreterException(Exception):
pass
@ -168,6 +169,7 @@ class Interpreter():
self.variables = {}
self.environment = build.environment
self.build_func_dict()
self.subdir = ''
def build_func_dict(self):
self.funcs = {'project' : self.func_project,
@ -178,7 +180,8 @@ class Interpreter():
'shared_library' : self.func_shared_lib,
'add_test' : self.func_add_test,
'headers' : self.func_headers,
'man' : self.func_man
'man' : self.func_man,
'subdir' : self.func_subdir
}
def sanity_check_ast(self):
@ -286,6 +289,16 @@ class Interpreter():
self.build.man.append(m)
return m
def func_subdir(self, node, args):
self.validate_arguments(args, 1, [str])
prev_subdir = self.subdir
self.subdir = os.path.join(prev_subdir, args[0])
buildfilename = os.path.join(self.subdir, environment.builder_filename)
code = open(os.path.join(self.environment.get_source_dir(), buildfilename)).read()
assert(isinstance(code, str))
print('Going to subdirectory "%s".' % self.subdir)
self.subdir = prev_subdir
def build_target(self, node, args, targetclass):
for a in args:
if not isinstance(a, str):

Loading…
Cancel
Save