Commit e7379f33 by Vicent Marti

Link tests with the raw objects

Fix the test building issues once for all; each test is linked
with the raw objects of the library, not with any compiled version. That
way we make sure the tests always run, and are always linked with the
latest and most up-to-date version of the code.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
parent 9f54fe48
...@@ -74,15 +74,15 @@ def build(bld): ...@@ -74,15 +74,15 @@ def build(bld):
# command '[build|clean|install|uninstall]-static' # command '[build|clean|install|uninstall]-static'
if bld.variant == 'static': if bld.variant == 'static':
build_library(bld, 'cstlib') build_library(bld, 'static')
# command '[build|clean|install|uninstall]-shared' # command '[build|clean|install|uninstall]-shared'
elif bld.variant == 'shared': elif bld.variant == 'shared':
build_library(bld, 'cshlib') build_library(bld, 'shared')
# command '[build|clean]-tests' # command '[build|clean]-tests'
elif bld.variant == 'tests': elif bld.variant == 'tests':
build_library(bld, 'cshlib') build_library(bld, 'objects')
build_tests(bld) build_tests(bld)
# command 'build|clean|install|uninstall': by default, run # command 'build|clean|install|uninstall': by default, run
...@@ -91,9 +91,15 @@ def build(bld): ...@@ -91,9 +91,15 @@ def build(bld):
from waflib import Options from waflib import Options
Options.commands = [bld.cmd + '-shared', bld.cmd + '-static'] + Options.commands Options.commands = [bld.cmd + '-shared', bld.cmd + '-static'] + Options.commands
def build_library(bld, lib_str): def build_library(bld, build_type):
directory = bld.path
BUILD = {
'shared' : bld.shlib,
'static' : bld.stlib,
'objects' : bld.objects
}
directory = bld.path
sources = directory.ant_glob('src/*.c') sources = directory.ant_glob('src/*.c')
# Compile platform-dependant code # Compile platform-dependant code
...@@ -106,15 +112,12 @@ def build_library(bld, lib_str): ...@@ -106,15 +112,12 @@ def build_library(bld, lib_str):
sources.append('src/ppc/sha1.c') sources.append('src/ppc/sha1.c')
else: else:
sources.append('src/block-sha1/sha1.c') sources.append('src/block-sha1/sha1.c')
features = ['c', lib_str]
#------------------------------ #------------------------------
# Build the main library # Build the main library
#------------------------------ #------------------------------
# either as static or shared; # either as static or shared;
bld(features=features, BUILD[build_type](
source=sources, source=sources,
target='git2', target='git2',
includes='src', includes='src',
...@@ -123,7 +126,7 @@ def build_library(bld, lib_str): ...@@ -123,7 +126,7 @@ def build_library(bld, lib_str):
) )
# On Unix systems, build the Pkg-config entry file # On Unix systems, build the Pkg-config entry file
if bld.env.PLATFORM == 'unix': if bld.env.PLATFORM == 'unix' and bld.is_install:
bld(rule="""sed -e 's#@prefix@#$(prefix)#' -e 's#@libdir@#$(libdir)#' < ${SRC} > ${TGT}""", bld(rule="""sed -e 's#@prefix@#$(prefix)#' -e 's#@libdir@#$(libdir)#' < ${SRC} > ${TGT}""",
source='libgit2.pc.in', source='libgit2.pc.in',
target='libgit2.pc', target='libgit2.pc',
...@@ -167,7 +170,6 @@ def build_tests(bld): ...@@ -167,7 +170,6 @@ def build_tests(bld):
includes=['src', 'tests'], includes=['src', 'tests'],
defines=['TEST_TOC="%s.toc"' % test_name, 'TEST_RESOURCES="%s"' % resources_path], defines=['TEST_TOC="%s.toc"' % test_name, 'TEST_RESOURCES="%s"' % resources_path],
install_path=None, install_path=None,
shlibpath=[directory.find_node('build/tests/').abspath()],
use=['test_helper', 'git2'] + ALL_LIBS # link with all the libs we know use=['test_helper', 'git2'] + ALL_LIBS # link with all the libs we know
# libraries which are not enabled won't link # libraries which are not enabled won't link
) )
...@@ -200,28 +202,14 @@ class _run_tests(Context): ...@@ -200,28 +202,14 @@ class _run_tests(Context):
fun = 'run_tests' fun = 'run_tests'
def run_tests(ctx): def run_tests(ctx):
import shutil, tempfile, sys, os import shutil, tempfile
failed = False failed = False
test_folder = tempfile.mkdtemp() test_folder = tempfile.mkdtemp()
build_folder = ctx.path.find_node('build/tests/')
test_glob = 'build/tests/t????-*' test_glob = 'build/tests/t????-*'
environ = os.environ.copy()
environ_tail = ""
if sys.platform == 'win32':
test_glob += '.exe'
environ_var, environ_separator = 'PATH', ';'
else:
environ_var, environ_separator = 'LD_LIBRARY_PATH', ':'
if environ_var in environ:
environ_tail = environ_separator + environ[environ_var]
environ[environ_var] = build_folder.abspath() + environ_tail
for test in ctx.path.ant_glob(test_glob): for test in ctx.path.ant_glob(test_glob):
if ctx.exec_command(test.abspath(), cwd=test_folder, env=environ) != 0: if ctx.exec_command(test.abspath(), cwd=test_folder) != 0:
failed = True failed = True
break break
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment