diff options
author | Jussi Pakkanen <jpakkane@gmail.com> | 2013-01-12 13:53:19 +0200 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2013-01-12 13:53:19 +0200 |
commit | 8d038ef09ed709f7db95504f04b13678ecf79816 (patch) | |
tree | 1d37bc3bfb91ae56d78b85950683b860e9f8aec9 | |
parent | b6886b2c27f6b9b18acc1c6ac57d6d64039aa815 (diff) | |
download | meson-8d038ef09ed709f7db95504f04b13678ecf79816.zip meson-8d038ef09ed709f7db95504f04b13678ecf79816.tar.gz meson-8d038ef09ed709f7db95504f04b13678ecf79816.tar.bz2 |
Can install header files.
-rw-r--r-- | build.py | 4 | ||||
-rwxr-xr-x | environment.py | 3 | ||||
-rwxr-xr-x | interpreter.py | 49 | ||||
-rwxr-xr-x | shellgenerator.py | 39 | ||||
-rw-r--r-- | test cases/9 header install/builder.txt | 5 | ||||
-rw-r--r-- | test cases/9 header install/rootdir.h | 3 | ||||
-rw-r--r-- | test cases/9 header install/subdir.h | 3 |
7 files changed, 87 insertions, 19 deletions
@@ -25,6 +25,7 @@ class Build: self.targets = {} self.compilers = [] self.tests = [] + self.headers = [] self.static_linker = self.environment.detect_static_linker() def get_project(self): @@ -35,3 +36,6 @@ class Build: def get_tests(self): return self.tests + + def get_headers(self): + return self.headers diff --git a/environment.py b/environment.py index 93027f7..baf0861 100755 --- a/environment.py +++ b/environment.py @@ -242,6 +242,9 @@ class Environment(): def get_bindir(self): return self.options.bindir + + def get_includedir(self): + return self.options.includedir # This should be an InterpreterObject. Fix it. class PkgConfigDependency(): diff --git a/interpreter.py b/interpreter.py index dad45ee..b38bbbc 100755 --- a/interpreter.py +++ b/interpreter.py @@ -29,22 +29,45 @@ class InvalidArguments(InterpreterException): class InterpreterObject(): - def method_call(self, method_name): - raise InvalidCode('Object does not have method %s.' % method_name) + def __init__(self): + self.methods = {} + + def method_call(self, method_name, args): + if method_name in self.methods: + return self.methods[method_name](args) + raise InvalidCode('Unknown method "%s" in object.' % method_name) + +class Headers(InterpreterObject): + + def __init__(self, sources): + InterpreterObject.__init__(self) + self.sources = sources + self.methods.update({'set_subdir' : self.set_subdir}) + self.subdir = '' + + def set_subdir(self, args): + self.subdir = args[0] + + def get_subdir(self): + return self.subdir + + def get_sources(self): + return self.sources class BuildTarget(InterpreterObject): def __init__(self, name, sources): + InterpreterObject.__init__(self) self.name = name self.sources = sources self.external_deps = [] - self.methods = {'add_dep': self.add_dep_method, + self.methods.update({'add_dep': self.add_dep_method, 'link' : self.link_method, - 'install': self.install} + 'install': self.install}) self.link_targets = [] self.filename = 'no_name' self.need_install = False - + def get_filename(self): return self.filename @@ -78,11 +101,6 @@ class BuildTarget(InterpreterObject): raise InvalidArguments('Link target is not library.') self.link_targets.append(target) - def method_call(self, method_name, args): - if method_name in self.methods: - return self.methods[method_name](args) - raise InvalidCode('Unknown method "%s" in BuildTarget.' % method_name) - def install(self, args): if len(args) != 0: raise InvalidArguments('Install() takes no arguments.') @@ -142,7 +160,8 @@ class Interpreter(): 'find_dep' : self.func_find_dep, 'static_library' : self.func_static_lib, 'shared_library' : self.func_shared_lib, - 'add_test' : self.func_add_test + 'add_test' : self.func_add_test, + 'headers' : self.func_headers } def sanity_check_ast(self): @@ -233,6 +252,14 @@ class Interpreter(): t = Test(args[0], args[1]) self.build.tests.append(t) print('Adding test "%s"' % args[0]) + + def func_headers(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))) + h = Headers(args) + self.build.headers.append(h) + return h def build_target(self, node, args, targetclass): for a in args: diff --git a/shellgenerator.py b/shellgenerator.py index ee2eabd..79dab1a 100755 --- a/shellgenerator.py +++ b/shellgenerator.py @@ -71,15 +71,40 @@ echo This is experimental and most likely will not work! echo Run compile.sh before this or bad things will happen. """ % self.build.get_project() outfile = self.create_shfile(outfilename, message) - self.generate_install(outfile) + self.generate_target_install(outfile) + self.generate_header_install(outfile) outfile.close() - - def generate_install(self, outfile): + + def make_subdir(self, outfile, dir): + cmdlist = ['mkdir', '-p', dir] + outfile.write(' '.join(shell_quote(cmdlist)) + '\n') + + def copy_file(self, outfile, filename, outdir): + cpcommand = ['cp', filename, outdir] + cpcommand = ' '.join(shell_quote(cpcommand)) + '\n' + outfile.write(cpcommand) + + def generate_header_install(self, outfile): + prefix = self.environment.get_prefix() + incroot = os.path.join(prefix, self.environment.get_includedir()) + headers = self.build.get_headers() + if len(headers) != 0: + outfile.write('\necho Installing headers.\n') + else: + outfile.write('\necho This project has no headers to install.') + for h in headers: + outdir = os.path.join(incroot, h.get_subdir()) + self.make_subdir(outfile, outdir) + for f in h.get_sources(): + abspath = os.path.join(self.environment.get_source_dir(), f) + self.copy_file(outfile, abspath, outdir) + + def generate_target_install(self, outfile): prefix = self.environment.get_prefix() libdir = os.path.join(prefix, self.environment.get_libdir()) bindir = os.path.join(prefix, self.environment.get_bindir()) - outfile.write("mkdir -p '%s'\n" % libdir) - outfile.write("mkdir -p '%s'\n" % bindir) + self.make_subdir(outfile, libdir) + self.make_subdir(outfile, bindir) for tmp in self.build.get_targets().items(): (name, t) = tmp if t.should_install(): @@ -88,9 +113,7 @@ echo Run compile.sh before this or bad things will happen. else: outdir = libdir outfile.write('echo Installing "%s".\n' % name) - cpcommand = ['cp', self.get_target_filename(t), outdir] - cpcommand = ' '.join(shell_quote(cpcommand)) + '\n' - outfile.write(cpcommand) + self.copy_file(outfile, self.get_target_filename(t), outdir) def generate_tests(self, outfile): for t in self.build.get_tests(): diff --git a/test cases/9 header install/builder.txt b/test cases/9 header install/builder.txt new file mode 100644 index 0000000..af238ab --- /dev/null +++ b/test cases/9 header install/builder.txt @@ -0,0 +1,5 @@ +project('header install', 'c') + +h1 = headers('rootdir.h') +h2 = headers('subdir.h') +h2.set_subdir('subdir') diff --git a/test cases/9 header install/rootdir.h b/test cases/9 header install/rootdir.h new file mode 100644 index 0000000..72fb132 --- /dev/null +++ b/test cases/9 header install/rootdir.h @@ -0,0 +1,3 @@ +/* This header goes to include dir root. */ + +int root_func(); diff --git a/test cases/9 header install/subdir.h b/test cases/9 header install/subdir.h new file mode 100644 index 0000000..17f768e --- /dev/null +++ b/test cases/9 header install/subdir.h @@ -0,0 +1,3 @@ +/* This file goes to subdirectory of include root. */ + +int subdir_func(); |