Added test for a prebuilt static library and a declare_dependency that uses it.

pull/652/head
Jussi Pakkanen 9 years ago
parent 5942baa2d1
commit f3c793b9c1
  1. 65
      run_tests.py
  2. 0
      test cases/prebuilt/1 object/main.c
  3. 0
      test cases/prebuilt/1 object/meson.build
  4. 0
      test cases/prebuilt/1 object/source.c
  5. 3
      test cases/prebuilt/2 static/libdir/best.c
  6. 3
      test cases/prebuilt/2 static/libdir/best.h
  7. 5
      test cases/prebuilt/2 static/libdir/meson.build
  8. 7
      test cases/prebuilt/2 static/main.c
  9. 5
      test cases/prebuilt/2 static/meson.build

@ -308,7 +308,7 @@ def detect_tests_to_run():
all_tests = [] all_tests = []
all_tests.append(('common', gather_tests('test cases/common'), False)) all_tests.append(('common', gather_tests('test cases/common'), False))
all_tests.append(('failing', gather_tests('test cases/failing'), False)) all_tests.append(('failing', gather_tests('test cases/failing'), False))
all_tests.append(('prebuilt object', gather_tests('test cases/prebuilt object'), False)) all_tests.append(('prebuilt', gather_tests('test cases/prebuilt'), False))
all_tests.append(('platform-osx', gather_tests('test cases/osx'), False if mesonlib.is_osx() else True)) all_tests.append(('platform-osx', gather_tests('test cases/osx'), False if mesonlib.is_osx() else True))
all_tests.append(('platform-windows', gather_tests('test cases/windows'), False if mesonlib.is_windows() else True)) all_tests.append(('platform-windows', gather_tests('test cases/windows'), False if mesonlib.is_windows() else True))
@ -405,27 +405,51 @@ def check_format():
fullname = os.path.join(root, file) fullname = os.path.join(root, file)
check_file(fullname) check_file(fullname)
def generate_prebuilt_object(): def pbcompile(compiler, source, objectfile):
source = 'test cases/prebuilt object/1 basic/source.c' if compiler == 'cl':
objectbase = 'test cases/prebuilt object/1 basic/prebuilt.' cmd = [compiler, '/nologo', '/Fo'+objectfile, '/c', source]
if shutil.which('cl'):
objectfile = objectbase + 'obj'
cmd = ['cl', '/nologo', '/Fo'+objectfile, '/c', source]
else: else:
if mesonlib.is_windows(): cmd = [compiler, '-c', source, '-o', objectfile]
objectfile = objectbase + 'obj'
else:
objectfile = objectbase + 'o'
if shutil.which('cc'):
cmd = 'cc'
elif shutil.which('gcc'):
cmd = 'gcc'
else:
raise RuntimeError("Could not find C compiler.")
cmd = [cmd, '-c', source, '-o', objectfile]
subprocess.check_call(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) subprocess.check_call(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
def generate_pb_object(compiler, object_suffix):
source = 'test cases/prebuilt/1 object/source.c'
objectfile = 'test cases/prebuilt/1 object/prebuilt.' + object_suffix
pbcompile(compiler, source, objectfile)
return objectfile return objectfile
def generate_pb_static(compiler, object_suffix, static_suffix):
source = 'test cases/prebuilt/2 static/libdir/best.c'
objectfile = 'test cases/prebuilt/2 static/libdir/best.' + object_suffix
stlibfile = 'test cases/prebuilt/2 static/libdir/libbest.' + static_suffix
pbcompile(compiler, source, objectfile)
if compiler == 'cl':
linker = ['lib', '/NOLOGO', '/OUT:' + stlibfile, objectfile]
else:
linker = ['ar', 'csr', stlibfile, objectfile]
subprocess.check_call(linker)
os.unlink(objectfile)
return stlibfile
def generate_prebuilt():
static_suffix = 'a'
if shutil.which('cl'):
compiler = 'cl'
static_suffix = 'lib'
elif shutil.which('cc'):
compiler = 'cc'
elif shutil.which('gcc'):
compiler = 'gcc'
else:
raise RuntimeError("Could not find C compiler.")
if mesonlib.is_windows():
object_suffix = 'obj'
else:
object_suffix = 'o'
objectfile = generate_pb_object(compiler, object_suffix)
stlibfile = generate_pb_static(compiler, object_suffix, static_suffix)
return (objectfile, stlibfile)
if __name__ == '__main__': if __name__ == '__main__':
parser = argparse.ArgumentParser(description="Run the test suite of Meson.") parser = argparse.ArgumentParser(description="Run the test suite of Meson.")
parser.add_argument('extra_args', nargs='*', parser.add_argument('extra_args', nargs='*',
@ -439,12 +463,13 @@ if __name__ == '__main__':
if script_dir != '': if script_dir != '':
os.chdir(script_dir) os.chdir(script_dir)
check_format() check_format()
pbfile = generate_prebuilt_object() pbfiles = generate_prebuilt()
try: try:
run_tests(options.extra_args) run_tests(options.extra_args)
except StopException: except StopException:
pass pass
os.unlink(pbfile) for f in pbfiles:
os.unlink(f)
print('\nTotal passed tests:', passing_tests) print('\nTotal passed tests:', passing_tests)
print('Total failed tests:', failing_tests) print('Total failed tests:', failing_tests)
print('Total skipped tests:', skipped_tests) print('Total skipped tests:', skipped_tests)

@ -0,0 +1,3 @@
const char *msg() {
return "I am the best.";
}

@ -0,0 +1,3 @@
#pragma once
const char *msg();

@ -0,0 +1,5 @@
cc = meson.get_compiler('c')
stlib = cc.find_library('best', dirs : meson.current_source_dir())
best_dep = declare_dependency(dependencies : stlib,
include_directories : include_directories('.'))

@ -0,0 +1,7 @@
#include<stdio.h>
#include<best.h>
int main(int argc, char **argv) {
printf("%s\n", msg());
return 0;
}

@ -0,0 +1,5 @@
project('prebuilt static lib', 'c')
subdir('libdir')
test('static', executable('mainprog', 'main.c', dependencies : best_dep))
Loading…
Cancel
Save