Include directories work.

pull/15/head
Jussi Pakkanen 12 years ago
parent 5269885f16
commit 5c0d1cc7c0
  1. 40
      interpreter.py
  2. 6
      shellgenerator.py
  3. 4
      test cases/21 includedir/builder.txt
  4. 6
      test cases/21 includedir/include/func.h
  5. 3
      test cases/21 includedir/src/builder.txt
  6. 5
      test cases/21 includedir/src/func.c
  7. 5
      test cases/21 includedir/src/prog.c

@ -38,8 +38,22 @@ class InterpreterObject():
return self.methods[method_name](args)
raise InvalidCode('Unknown method "%s" in object.' % method_name)
class IncludeDirs(InterpreterObject):
def __init__(self, curdir, dirs):
InterpreterObject.__init__(self)
self.curdir = curdir
self.incdirs = dirs
# Fixme: check that the directories actually exist.
# Also that they don't contain ".." or somesuch.
def get_curdir(self):
return self.curdir
def get_incdirs(self):
return self.incdirs
class Headers(InterpreterObject):
def __init__(self, sources):
InterpreterObject.__init__(self)
self.sources = sources
@ -112,10 +126,12 @@ class BuildTarget(InterpreterObject):
self.subdir = subdir
self.sources = sources
self.external_deps = []
self.include_dirs = []
self.methods.update({'add_dep': self.add_dep_method,
'link' : self.link_method,
'install': self.install_method,
'pch' : self.pch_method
'pch' : self.pch_method,
'add_include_dirs': self.add_include_dirs_method,
})
self.link_targets = []
self.filename = 'no_name'
@ -146,6 +162,9 @@ class BuildTarget(InterpreterObject):
def get_pch(self):
return self.pch
def get_include_dirs(self):
return self.include_dirs
def add_external_dep(self, dep):
if not isinstance(dep, environment.PkgConfigDependency):
raise InvalidArguments('Argument is not an external dependency')
@ -175,6 +194,11 @@ class BuildTarget(InterpreterObject):
for a in args:
self.pch.append(a)
def add_include_dirs_method(self, args):
for a in args:
if not isinstance(a, IncludeDirs):
raise InvalidArguments('Include directory to be added is not an include directory object.')
self.include_dirs += args
class Executable(BuildTarget):
def __init__(self, name, subdir, sources, environment):
@ -236,9 +260,10 @@ class Interpreter():
'man' : self.func_man,
'subdir' : self.func_subdir,
'data' : self.func_data,
'configure_file' : self.func_configure_file
'configure_file' : self.func_configure_file,
'include_directories' : self.func_include_directories,
}
def get_variables(self):
return self.variables
@ -396,6 +421,13 @@ class Interpreter():
c = ConfigureFile(self.subdir, args[0], args[1])
self.build.configure_files.append(c)
def func_include_directories(self, node, args):
for a in args:
if not isinstance(a, str):
raise InvalidArguments('Line %d: Argument %s is not a string.' % (node.lineno(), str(a)))
i = IncludeDirs(self.subdir, args)
return i
def flatten(self, args):
result = []
for a in args:

@ -236,6 +236,12 @@ echo Run compile.sh before this or bad things will happen.
abs_src = os.path.join(self.environment.get_source_dir(), target.get_source_subdir(), src)
abs_obj = os.path.join(self.get_target_dir(target), src)
abs_obj += '.' + self.environment.get_object_suffix()
for i in target.get_include_dirs():
basedir = i.get_curdir()
for d in i.get_incdirs():
fulldir = os.path.join(self.environment.get_source_dir(), basedir, d)
arg = compiler.get_include_arg(fulldir)
commands.append(arg)
commands += self.get_pch_include_args(compiler, target)
commands.append(abs_src)
commands += compiler.get_output_flags()

@ -0,0 +1,4 @@
project('include dir test', 'c')
inc = include_directories('include')
subdir('src')

@ -0,0 +1,6 @@
#ifndef FUNC_H__
#define FUNC_H__
int func();
#endif

@ -0,0 +1,3 @@
exe = executable('prog', 'prog.c', 'func.c')
exe.add_include_dirs(inc)
add_test('inc test', exe)

@ -0,0 +1,5 @@
#include "func.h"
int func() {
return 0;
}

@ -0,0 +1,5 @@
#include "func.h"
int main(int argc, char **argv) {
return func();
}
Loading…
Cancel
Save