8000 Support non-cmake builds with an in-tree `experimental.h` by ethomson · Pull Request #6405 · libgit2/libgit2 · GitHub
[go: up one dir, main page]

Skip to content

Support non-cmake builds with an in-tree experimental.h #6405

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions cmake/ExperimentalFeatures.cmake
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
# Experimental feature support for libgit2 - developers can opt in to
# experimental functionality, like sha256 support. When experimental
# functionality is enabled, we set both a cmake flag *and* a compile
# definition. The cmake flag is used to generate `experimental.h`,
# which will be installed by a `make install`. But the compile definition
# is used by the libgit2 sources to detect the functionality at library
# build time. This allows us to have an in-tree `experimental.h` with
# *no* experiments enabled. This lets us support users who build without
# cmake and cannot generate the `experimental.h` file.

if(EXPERIMENTAL_SHA256)
add_feature_info("SHA256 API" ON "experimental SHA256 APIs")

set(EXPERIMENTAL 1)
set(GIT_EXPERIMENTAL_SHA256 1)
add_compile_definitions(GIT_EXPERIMENTAL_SHA256)
else()
add_feature_info("SHA256 API" OFF "experimental SHA256 APIs")
endif()
Expand Down
20 changes: 20 additions & 0 deletions include/git2/experimental.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright (C) the libgit2 contributors. All rights reserved.
*
* This file is part of libgit2, distributed under the GNU GPL v2 with
* a Linking Exception. For full terms see the included COPYING file.
*/

#ifndef INCLUDE_experimental_h__
#define INCLUDE_experimental_h__

/*
* This file exists to support users who build libgit2 with a bespoke
* build system and do not use our cmake configuration. Normally, cmake
* will create `experimental.h` from the `experimental.h.in` file and
* will include the generated file instead of this one. For non-cmake
* users, we bundle this `experimental.h` file which will be used
* instead.
*/

#endif
7 changes: 7 additions & 0 deletions src/libgit2/experimental.h.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/*
* Copyright (C) the libgit2 contributors. All rights reserved.
*
* This file is part of libgit2, distributed under the GNU GPL v2 with
* a Linking Exception. For full terms see the included COPYING file.
*/

#ifndef INCLUDE_experimental_h__
#define INCLUDE_experimental_h__

Expand Down
12 changes: 9 additions & 3 deletions tests/libgit2/core/oid.c
8000
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ void test_core_oid__streq_sha1(void)

void test_core_oid__streq_sha256(void)
{
#ifdef GIT_EXPERIMENTAL_SHA256
#ifndef GIT_EXPERIMENTAL_SHA256
cl_skip();
#else
cl_assert_equal_i(0, git_oid_streq(&id_sha256, str_oid_sha256));
cl_assert_equal_i(-1, git_oid_streq(&id_sha256, "deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef"));

Expand Down Expand Up @@ -90,7 +92,9 @@ void test_core_oid__strcmp_sha1(void)

void test_core_oid__strcmp_sha256(void)
{
#ifdef GIT_EXPERIMENTAL_SHA256
#ifndef GIT_EXPERIMENTAL_SHA256
cl_skip();
#else
cl_assert_equal_i(0, git_oid_strcmp(&id_sha256, str_oid_sha256));
cl_assert(git_oid_strcmp(&id_sha256, "deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef") < 0);

Expand Down Expand Up @@ -129,7 +133,9 @@ void test_core_oid__ncmp_sha1(void)

void test_core_oid__ncmp_sha256(void)
{
#ifdef GIT_EXPERIMENTAL_SHA256
#ifndef GIT_EXPERIMENTAL_SHA256
cl_skip();
#else
cl_assert(!git_oid_ncmp(&id_sha256, &idp_sha256, 0));
cl_assert(!git_oid_ncmp(&id_sha256, &idp_sha256, 1));
cl_assert(!git_oid_ncmp(&id_sha256, &idp_sha256, 2));
Expand Down
16 changes: 12 additions & 4 deletions tests/libgit2/odb/loose.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,9 @@ void test_odb_loose__exists_sha1(void)

void test_odb_loose__exists_sha256(void)
{
#ifdef GIT_EXPERIMENTAL_SHA256
#ifndef GIT_EXPERIMENTAL_SHA256
cl_skip();
#else
git_oid id, id2;
git_odb *odb;
git_odb_options odb_opts = GIT_ODB_OPTIONS_INIT;
Expand Down Expand Up @@ -201,7 +203,9 @@ void test_odb_loose__simple_reads_sha1(void)

void test_odb_loose__simple_reads_sha256(void)
{
#ifdef GIT_EXPERIMENTAL_SHA256
#ifndef GIT_EXPERIMENTAL_SHA256
cl_skip();
#else
test_read_object(&commit_sha256);
test_read_object(&tree_sha256);
test_read_object(&tag_sha256);
Expand Down Expand Up @@ -230,7 +234,9 @@ void test_odb_loose__streaming_reads_sha1(void)

void test_odb_loose__streaming_reads_sha256(void)
{
#ifdef GIT_EXPERIMENTAL_SHA256
#ifndef GIT_EXPERIMENTAL_SHA256
cl_skip();
#else
size_t blocksizes[] = { 1, 2, 4, 16, 99, 1024, 123456789 };
size_t i;

Expand Down Expand Up @@ -259,7 +265,9 @@ void test_odb_loose__read_header_sha1(void)

void test_odb_loose__read_header_sha256(void)
{
#ifdef GIT_EXPERIMENTAL_SHA256
#ifndef GIT_EXPERIMENTAL_SHA256
cl_skip();
#else
test_read_header(&commit_sha256);
test_read_header(&tree_sha256);
test_read_header(&tag_sha256);
Expand Down
0