Skip to content

Commit 6b2133b

Browse files
authored
Merge pull request libgit2#4235 from pks-t/pks/out-of-tree-builds
Out of tree builds
2 parents 6f02a4d + b6ed67c commit 6b2133b

File tree

4 files changed

+29
-18
lines changed

4 files changed

+29
-18
lines changed

CMakeLists.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -677,15 +677,16 @@ IF (BUILD_CLAR)
677677
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")
678678

679679
ADD_CUSTOM_COMMAND(
680-
OUTPUT ${CLAR_PATH}/clar.suite
681-
COMMAND ${PYTHON_EXECUTABLE} generate.py -f -xonline -xstress .
680+
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/clar.suite
681+
COMMAND ${PYTHON_EXECUTABLE} generate.py -o "${CMAKE_CURRENT_BINARY_DIR}" -f -xonline -xstress .
682682
DEPENDS ${SRC_TEST}
683683
WORKING_DIRECTORY ${CLAR_PATH}
684684
)
685+
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
685686

686687
SET_SOURCE_FILES_PROPERTIES(
687688
${CLAR_PATH}/clar.c
688-
PROPERTIES OBJECT_DEPENDS ${CLAR_PATH}/clar.suite)
689+
PROPERTIES OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/clar.suite)
689690

690691
ADD_EXECUTABLE(libgit2_clar ${SRC_H} ${SRC_GIT2} ${SRC_OS} ${SRC_CLAR} ${SRC_TEST} ${SRC_ZLIB} ${SRC_HTTP} ${SRC_REGEX} ${SRC_SSH} ${SRC_SHA1})
691692

tests/generate.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from __future__ import with_statement
1010
from string import Template
11-
import re, fnmatch, os, codecs, pickle
11+
import re, fnmatch, os, sys, codecs, pickle
1212

1313
class Module(object):
1414
class Template(object):
@@ -128,8 +128,9 @@ def refresh(self, path):
128128

129129
class TestSuite(object):
130130

131-
def __init__(self, path):
131+
def __init__(self, path, output):
132132
self.path = path
133+
self.output = output
133134

134135
def should_generate(self, path):
135136
if not os.path.isfile(path):
@@ -157,7 +158,7 @@ def find_modules(self):
157158
return modules
158159

159160
def load_cache(self):
160-
path = os.path.join(self.path, '.clarcache')
161+
path = os.path.join(self.output, '.clarcache')
161162
cache = {}
162163

163164
try:
@@ -170,7 +171,7 @@ def load_cache(self):
170171
return cache
171172

172173
def save_cache(self):
173-
path = os.path.join(self.path, '.clarcache')
174+
path = os.path.join(self.output, '.clarcache')
174175
with open(path, 'wb') as cache:
175176
pickle.dump(self.modules, cache)
176177

@@ -200,7 +201,7 @@ def callback_count(self):
200201
return sum(len(module.callbacks) for module in self.modules.values())
201202

202203
def write(self):
203-
output = os.path.join(self.path, 'clar.suite')
204+
output = os.path.join(self.output, 'clar.suite')
204205

205206
if not self.should_generate(output):
206207
return False
@@ -232,13 +233,18 @@ def write(self):
232233
parser = OptionParser()
233234
parser.add_option('-f', '--force', action="store_true", dest='force', default=False)
234235
parser.add_option('-x', '--exclude', dest='excluded', action='append', default=[])
236+
parser.add_option('-o', '--output', dest='output')
235237

236238
options, args = parser.parse_args()
237-
238-
for path in args or ['.']:
239-
suite = TestSuite(path)
240-
suite.load(options.force)
241-
suite.disable(options.excluded)
242-
if suite.write():
243-
print("Written `clar.suite` (%d tests in %d suites)" % (suite.callback_count(), suite.suite_count()))
239+
if len(args) > 1:
240+
print("More than one path given")
241+
sys.exit(1)
242+
243+
path = args.pop() if args else '.'
244+
output = options.output or path
245+
suite = TestSuite(path, output)
246+
suite.load(options.force)
247+
suite.disable(options.excluded)
248+
if suite.write():
249+
print("Written `clar.suite` (%d tests in %d suites)" % (suite.callback_count(), suite.suite_count()))
244250

tests/index/tests.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -856,11 +856,14 @@ void test_index_tests__change_icase_on_instance(void)
856856

857857
void test_index_tests__can_lock_index(void)
858858
{
859+
git_repository *repo;
859860
git_index *index;
860861
git_indexwriter one = GIT_INDEXWRITER_INIT,
861862
two = GIT_INDEXWRITER_INIT;
862863

863-
cl_git_pass(git_index_open(&index, TEST_INDEX_PATH));
864+
repo = cl_git_sandbox_init("testrepo.git");
865+
866+
cl_git_pass(git_repository_index(&index, repo));
864867
cl_git_pass(git_indexwriter_init(&one, index));
865868

866869
cl_git_fail_with(GIT_ELOCKED, git_indexwriter_init(&two, index));
@@ -873,4 +876,5 @@ void test_index_tests__can_lock_index(void)
873876
git_indexwriter_cleanup(&one);
874877
git_indexwriter_cleanup(&two);
875878
git_index_free(index);
879+
cl_git_sandbox_cleanup();
876880
}

tests/refs/crashes.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ void test_refs_crashes__double_free(void)
66
git_reference *ref, *ref2;
77
const char *REFNAME = "refs/heads/xxx";
88

9-
cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
9+
repo = cl_git_sandbox_init("testrepo.git");
1010
cl_git_pass(git_reference_symbolic_create(&ref, repo, REFNAME, "refs/heads/master", 0, NULL));
1111
cl_git_pass(git_reference_lookup(&ref2, repo, REFNAME));
1212
cl_git_pass(git_reference_delete(ref));
@@ -16,5 +16,5 @@ void test_refs_crashes__double_free(void)
1616
/* reference is gone from disk, so reloading it will fail */
1717
cl_git_fail(git_reference_lookup(&ref2, repo, REFNAME));
1818

19-
git_repository_free(repo);
19+
cl_git_sandbox_cleanup();
2020
}

0 commit comments

Comments
 (0)