Now can create internal dependencies to simplify subproject usage.

pull/155/head
Jussi Pakkanen 10 years ago
parent ee0fee2111
commit 6d744b13ff
  1. 13
      build.py
  2. 7
      dependencies.py
  3. 42
      interpreter.py
  4. 4
      test cases/common/85 internal dependency/meson.build
  5. 5
      test cases/common/85 internal dependency/proj1/include/proj1.h
  6. 11
      test cases/common/85 internal dependency/proj1/meson.build
  7. 6
      test cases/common/85 internal dependency/proj1/proj1f1.c
  8. 6
      test cases/common/85 internal dependency/proj1/proj1f2.c
  9. 6
      test cases/common/85 internal dependency/proj1/proj1f3.c
  10. 10
      test cases/common/85 internal dependency/src/main.c
  11. 2
      test cases/common/85 internal dependency/src/meson.build

@ -421,11 +421,16 @@ class BuildTarget():
for dep in deps:
if hasattr(dep, 'held_object'):
dep = dep.held_object
if not isinstance(dep, dependencies.Dependency):
raise InvalidArguments('Argument is not an external dependency')
self.external_deps.append(dep)
if isinstance(dep, dependencies.Dependency):
if isinstance(dep, dependencies.InternalDependency):
self.sources += dep.sources
self.add_include_dirs(dep.include_directories)
for l in dep.libraries:
self.link(l)
elif isinstance(dep, dependencies.Dependency):
self.external_deps.append(dep)
self.process_sourcelist(dep.get_sources())
else:
raise InvalidArguments('Argument is not an external dependency')
def get_external_deps(self):
return self.external_deps

@ -58,6 +58,13 @@ class Dependency():
def need_threads(self):
return False
class InternalDependency():
def __init__(self, incdirs, libraries, sources):
super().__init__()
self.include_directories = incdirs
self.libraries = libraries
self.sources = sources
class PkgConfigDependency(Dependency):
pkgconfig_found = None

@ -22,7 +22,6 @@ import optinterpreter
import wrap
import mesonlib
import os, sys, platform, subprocess, shutil, uuid, re
from mesonlib import File
from functools import wraps
import importlib
@ -44,6 +43,14 @@ def check_stringlist(a, msg='Arguments must be strings.'):
if not all(isinstance(s, str) for s in a):
raise InvalidArguments(msg)
def noPosargs(f):
@wraps(f)
def wrapped(self, node, args, kwargs):
if len(args) != 0:
raise InvalidArguments('Function does not take positional arguments.')
return f(self, node, args, kwargs)
return wrapped
def noKwargs(f):
@wraps(f)
def wrapped(self, node, args, kwargs):
@ -215,6 +222,15 @@ class DependencyHolder(InterpreterObject):
def found_method(self, args, kwargs):
return self.held_object.found()
class InternalDependencyHolder(InterpreterObject):
def __init__(self, dep):
InterpreterObject.__init__(self)
self.held_object = dep
self.methods.update({'found' : self.found_method})
def found_method(self, args, kwargs):
return True
class ExternalProgramHolder(InterpreterObject):
def __init__(self, ep):
InterpreterObject.__init__(self)
@ -827,6 +843,7 @@ class Interpreter():
'set_variable' : self.func_set_variable,
'import' : self.func_import,
'files' : self.func_files,
'declare_dependency': self.func_declare_dependency,
}
def module_method_callback(self, invalues):
@ -930,7 +947,22 @@ class Interpreter():
@stringArgs
@noKwargs
def func_files(self, node, args, kwargs):
return [File.from_source_file(self.environment.source_dir, self.subdir, fname) for fname in args]
return [mesonlib.File.from_source_file(self.environment.source_dir, self.subdir, fname) for fname in args]
@noPosargs
def func_declare_dependency(self, node, args, kwargs):
incs = kwargs.get('include_directories', [])
if not isinstance(incs, list):
incs = [incs]
libs = kwargs.get('link_with', [])
if not isinstance(libs, list):
libs = [libs]
sources = kwargs.get('sources', [])
if not isinstance(sources, list):
sources = [sources]
sources = self.source_strings_to_files(self.flatten(sources))
dep = dependencies.InternalDependency(incs, libs, sources)
return InternalDependencyHolder(dep)
def set_variable(self, varname, variable):
if variable is None:
@ -1571,13 +1603,13 @@ class Interpreter():
def source_strings_to_files(self, sources):
results = []
for s in sources:
if isinstance(s, File) or isinstance(s, GeneratedListHolder) or \
if isinstance(s, mesonlib.File) or isinstance(s, GeneratedListHolder) or \
isinstance(s, CustomTargetHolder):
pass
elif isinstance(s, str):
s = File.from_source_file(self.environment.source_dir, self.subdir, s)
s = mesonlib.File.from_source_file(self.environment.source_dir, self.subdir, s)
else:
raise InterpreterException("Argument list is invalid.")
raise InterpreterException("Source item is not string or File-type object.")
results.append(s)
return results

@ -0,0 +1,4 @@
project('internal dependency', 'c')
subdir('proj1')
subdir('src')

@ -0,0 +1,5 @@
#pragma once
void proj1_func1();
void proj1_func2();
void proj1_func3();

@ -0,0 +1,11 @@
incdirs = include_directories('include')
p1lib = static_library('proj1', 'proj1f1.c',
include_directories : incdirs
)
indirect_source = files('proj1f2.c')
proj1_dep = declare_dependency(include_directories : incdirs,
link_with : p1lib,
sources : ['proj1f3.c', indirect_source])

@ -0,0 +1,6 @@
#include<proj1.h>
#include<stdio.h>
void proj1_func1() {
printf("In proj1_func1.\n");
}

@ -0,0 +1,6 @@
#include<proj1.h>
#include<stdio.h>
void proj1_func2() {
printf("In proj1_func2.\n");
}

@ -0,0 +1,6 @@
#include<proj1.h>
#include<stdio.h>
void proj1_func3() {
printf("In proj1_func3.\n");
}

@ -0,0 +1,10 @@
#include<stdio.h>
#include<proj1.h>
int main(int argc, char **argv) {
printf("Now calling into library.\n");
proj1_func1();
proj1_func2();
proj1_func3();
return 0;
}

@ -0,0 +1,2 @@
exe = executable('projtest', 'main.c', dependencies : proj1_dep)
test('projtest', exe)
Loading…
Cancel
Save