Skip to content

Commit 9286e59

Browse files
authored
Merge pull request libgit2#6405 from libgit2/ethomson/experimental
Support non-cmake builds with an in-tree `experimental.h`
2 parents d78fad1 + c117246 commit 9286e59

File tree

5 files changed

+59
-7
lines changed

5 files changed

+59
-7
lines changed

cmake/ExperimentalFeatures.cmake

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
1+
# Experimental feature support for libgit2 - developers can opt in to
2+
# experimental functionality, like sha256 support. When experimental
3+
# functionality is enabled, we set both a cmake flag *and* a compile
4+
# definition. The cmake flag is used to generate `experimental.h`,
5+
# which will be installed by a `make install`. But the compile definition
6+
# is used by the libgit2 sources to detect the functionality at library
7+
# build time. This allows us to have an in-tree `experimental.h` with
8+
# *no* experiments enabled. This lets us support users who build without
9+
# cmake and cannot generate the `experimental.h` file.
10+
111
if(EXPERIMENTAL_SHA256)
212
add_feature_info("SHA256 API" ON "experimental SHA256 APIs")
313

414
set(EXPERIMENTAL 1)
515
set(GIT_EXPERIMENTAL_SHA256 1)
16+
add_compile_definitions(GIT_EXPERIMENTAL_SHA256)
617
else()
718
add_feature_info("SHA256 API" OFF "experimental SHA256 APIs")
819
endif()

include/git2/experimental.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright (C) the libgit2 contributors. All rights reserved.
3+
*
4+
* This file is part of libgit2, distributed under the GNU GPL v2 with
5+
* a Linking Exception. For full terms see the included COPYING file.
6+
*/
7+
8+
#ifndef INCLUDE_experimental_h__
9+
#define INCLUDE_experimental_h__
10+
11+
/*
12+
* This file exists to support users who build libgit2 with a bespoke
13+
* build system and do not use our cmake configuration. Normally, cmake
14+
* will create `experimental.h` from the `experimental.h.in` file and
15+
* will include the generated file instead of this one. For non-cmake
16+
* users, we bundle this `experimental.h` file which will be used
17+
* instead.
18+
*/
19+
20+
#endif

src/libgit2/experimental.h.in

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
/*
2+
* Copyright (C) the libgit2 contributors. All rights reserved.
3+
*
4+
* This file is part of libgit2, distributed under the GNU GPL v2 with
5+
* a Linking Exception. For full terms see the included COPYING file.
6+
*/
7+
18
#ifndef INCLUDE_experimental_h__
29
#define INCLUDE_experimental_h__
310

tests/libgit2/core/oid.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ void test_core_oid__streq_sha1(void)
5252

5353
void test_core_oid__streq_sha256(void)
5454
{
55-
#ifdef GIT_EXPERIMENTAL_SHA256
55+
#ifndef GIT_EXPERIMENTAL_SHA256
56+
cl_skip();
57+
#else
5658
cl_assert_equal_i(0, git_oid_streq(&id_sha256, str_oid_sha256));
5759
cl_assert_equal_i(-1, git_oid_streq(&id_sha256, "deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef"));
5860

@@ -90,7 +92,9 @@ void test_core_oid__strcmp_sha1(void)
9092

9193
void test_core_oid__strcmp_sha256(void)
9294
{
93-
#ifdef GIT_EXPERIMENTAL_SHA256
95+
#ifndef GIT_EXPERIMENTAL_SHA256
96+
cl_skip();
97+
#else
9498
cl_assert_equal_i(0, git_oid_strcmp(&id_sha256, str_oid_sha256));
9599
cl_assert(git_oid_strcmp(&id_sha256, "deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef") < 0);
96100

@@ -129,7 +133,9 @@ void test_core_oid__ncmp_sha1(void)
129133

130134
void test_core_oid__ncmp_sha256(void)
131135
{
132-
#ifdef GIT_EXPERIMENTAL_SHA256
136+
#ifndef GIT_EXPERIMENTAL_SHA256
137+
cl_skip();
138+
#else
133139
cl_assert(!git_oid_ncmp(&id_sha256, &idp_sha256, 0));
134140
cl_assert(!git_oid_ncmp(&id_sha256, &idp_sha256, 1));
135141
cl_assert(!git_oid_ncmp(&id_sha256, &idp_sha256, 2));

tests/libgit2/odb/loose.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,9 @@ void test_odb_loose__exists_sha1(void)
160160

161161
void test_odb_loose__exists_sha256(void)
162162
{
163-
#ifdef GIT_EXPERIMENTAL_SHA256
163+
#ifndef GIT_EXPERIMENTAL_SHA256
164+
cl_skip();
165+
#else
164166
git_oid id, id2;
165167
git_odb *odb;
166168
git_odb_options odb_opts = GIT_ODB_OPTIONS_INIT;
@@ -201,7 +203,9 @@ void test_odb_loose__simple_reads_sha1(void)
201203

202204
void test_odb_loose__simple_reads_sha256(void)
203205
{
204-
#ifdef GIT_EXPERIMENTAL_SHA256
206+
#ifndef GIT_EXPERIMENTAL_SHA256
207+
cl_skip();
208+
#else
205209
test_read_object(&commit_sha256);
206210
test_read_object(&tree_sha256);
207211
test_read_object(&tag_sha256);
@@ -230,7 +234,9 @@ void test_odb_loose__streaming_reads_sha1(void)
230234

231235
void test_odb_loose__streaming_reads_sha256(void)
232236
{
233-
#ifdef GIT_EXPERIMENTAL_SHA256
237+
#ifndef GIT_EXPERIMENTAL_SHA256
238+
cl_skip();
239+
#else
234240
size_t blocksizes[] = { 1, 2, 4, 16, 99, 1024, 123456789 };
235241
size_t i;
236242

@@ -259,7 +265,9 @@ void test_odb_loose__read_header_sha1(void)
259265

260266
void test_odb_loose__read_header_sha256(void)
261267
{
262-
#ifdef GIT_EXPERIMENTAL_SHA256
268+
#ifndef GIT_EXPERIMENTAL_SHA256
269+
cl_skip();
270+
#else
263271
test_read_header(&commit_sha256);
264272
test_read_header(&tree_sha256);
265273
test_read_header(&tag_sha256);

0 commit comments

Comments
 (0)