Commit 6b2133b4e9f7f17844254d333428e7367c71fe37

Patrick Steinhardt 2017-06-27T12:46:15

Merge pull request #4235 from pks-t/pks/out-of-tree-builds Out of tree builds

diff --git a/CMakeLists.txt b/CMakeLists.txt
index da7acfb..d3f5a99 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -677,15 +677,16 @@ IF (BUILD_CLAR)
 	SET(SRC_CLAR "${CLAR_PATH}/main.c" "${CLAR_PATH}/clar_libgit2.c" "${CLAR_PATH}/clar_libgit2_trace.c" "${CLAR_PATH}/clar_libgit2_timer.c" "${CLAR_PATH}/clar.c")
 
 	ADD_CUSTOM_COMMAND(
-		OUTPUT ${CLAR_PATH}/clar.suite
-		COMMAND ${PYTHON_EXECUTABLE} generate.py -f -xonline -xstress .
+		OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/clar.suite
+		COMMAND ${PYTHON_EXECUTABLE} generate.py -o "${CMAKE_CURRENT_BINARY_DIR}" -f -xonline -xstress .
 		DEPENDS ${SRC_TEST}
 		WORKING_DIRECTORY ${CLAR_PATH}
 	)
+	INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
 
 	SET_SOURCE_FILES_PROPERTIES(
 		${CLAR_PATH}/clar.c
-		PROPERTIES OBJECT_DEPENDS ${CLAR_PATH}/clar.suite)
+		PROPERTIES OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/clar.suite)
 
 	ADD_EXECUTABLE(libgit2_clar ${SRC_H} ${SRC_GIT2} ${SRC_OS} ${SRC_CLAR} ${SRC_TEST} ${SRC_ZLIB} ${SRC_HTTP} ${SRC_REGEX} ${SRC_SSH} ${SRC_SHA1})
 
diff --git a/tests/generate.py b/tests/generate.py
index 587efb5..6a6228f 100644
--- a/tests/generate.py
+++ b/tests/generate.py
@@ -8,7 +8,7 @@
 
 from __future__ import with_statement
 from string import Template
-import re, fnmatch, os, codecs, pickle
+import re, fnmatch, os, sys, codecs, pickle
 
 class Module(object):
     class Template(object):
@@ -128,8 +128,9 @@ class Module(object):
 
 class TestSuite(object):
 
-    def __init__(self, path):
+    def __init__(self, path, output):
         self.path = path
+        self.output = output
 
     def should_generate(self, path):
         if not os.path.isfile(path):
@@ -157,7 +158,7 @@ class TestSuite(object):
         return modules
 
     def load_cache(self):
-        path = os.path.join(self.path, '.clarcache')
+        path = os.path.join(self.output, '.clarcache')
         cache = {}
 
         try:
@@ -170,7 +171,7 @@ class TestSuite(object):
         return cache
 
     def save_cache(self):
-        path = os.path.join(self.path, '.clarcache')
+        path = os.path.join(self.output, '.clarcache')
         with open(path, 'wb') as cache:
             pickle.dump(self.modules, cache)
 
@@ -200,7 +201,7 @@ class TestSuite(object):
         return sum(len(module.callbacks) for module in self.modules.values())
 
     def write(self):
-        output = os.path.join(self.path, 'clar.suite')
+        output = os.path.join(self.output, 'clar.suite')
 
         if not self.should_generate(output):
             return False
@@ -232,13 +233,18 @@ if __name__ == '__main__':
     parser = OptionParser()
     parser.add_option('-f', '--force', action="store_true", dest='force', default=False)
     parser.add_option('-x', '--exclude', dest='excluded', action='append', default=[])
+    parser.add_option('-o', '--output', dest='output')
 
     options, args = parser.parse_args()
-
-    for path in args or ['.']:
-        suite = TestSuite(path)
-        suite.load(options.force)
-        suite.disable(options.excluded)
-        if suite.write():
-            print("Written `clar.suite` (%d tests in %d suites)" % (suite.callback_count(), suite.suite_count()))
+    if len(args) > 1:
+        print("More than one path given")
+        sys.exit(1)
+
+    path = args.pop() if args else '.'
+    output = options.output or path
+    suite = TestSuite(path, output)
+    suite.load(options.force)
+    suite.disable(options.excluded)
+    if suite.write():
+        print("Written `clar.suite` (%d tests in %d suites)" % (suite.callback_count(), suite.suite_count()))
 
diff --git a/tests/index/tests.c b/tests/index/tests.c
index 1498196..ea8335b 100644
--- a/tests/index/tests.c
+++ b/tests/index/tests.c
@@ -856,11 +856,14 @@ void test_index_tests__change_icase_on_instance(void)
 
 void test_index_tests__can_lock_index(void)
 {
+	git_repository *repo;
 	git_index *index;
 	git_indexwriter one = GIT_INDEXWRITER_INIT,
 		two = GIT_INDEXWRITER_INIT;
 
-	cl_git_pass(git_index_open(&index, TEST_INDEX_PATH));
+	repo = cl_git_sandbox_init("testrepo.git");
+
+	cl_git_pass(git_repository_index(&index, repo));
 	cl_git_pass(git_indexwriter_init(&one, index));
 
 	cl_git_fail_with(GIT_ELOCKED, git_indexwriter_init(&two, index));
@@ -873,4 +876,5 @@ void test_index_tests__can_lock_index(void)
 	git_indexwriter_cleanup(&one);
 	git_indexwriter_cleanup(&two);
 	git_index_free(index);
+	cl_git_sandbox_cleanup();
 }
diff --git a/tests/refs/crashes.c b/tests/refs/crashes.c
index 7a10411..228f479 100644
--- a/tests/refs/crashes.c
+++ b/tests/refs/crashes.c
@@ -6,7 +6,7 @@ void test_refs_crashes__double_free(void)
 	git_reference *ref, *ref2;
 	const char *REFNAME = "refs/heads/xxx";
 
-	cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
+	repo = cl_git_sandbox_init("testrepo.git");
 	cl_git_pass(git_reference_symbolic_create(&ref, repo, REFNAME, "refs/heads/master", 0, NULL));
 	cl_git_pass(git_reference_lookup(&ref2, repo, REFNAME));
 	cl_git_pass(git_reference_delete(ref));
@@ -16,5 +16,5 @@ void test_refs_crashes__double_free(void)
 	/* reference is gone from disk, so reloading it will fail */
 	cl_git_fail(git_reference_lookup(&ref2, repo, REFNAME));
 
-	git_repository_free(repo);
+	cl_git_sandbox_cleanup();
 }