Skip to content
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

git: new recipe #23828

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
12 changes: 12 additions & 0 deletions recipes/git/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
sources:
"2.45.1":
url: "https://github.com/git/git/archive/refs/tags/v2.45.1.tar.gz"
sha256: "d98c8f70d58f49f7546d59b25e25f2deae6999eb036a33b0fe6f5d07c33f67c6"
patches:
"2.45.1":
- patch_file: "patches/fix-expat-and-replace-pkgconfig-in-cmake.patch"
patch_description: "Use module mode for find_package(EXPAT) and don't use pkg_check_modules"
patch_type: "conan"
- patch_file: "patches/fix-macos-in-cmake.patch"
patch_description: "Fix handling of MacOS in upstream CMake"
patch_type: "portability"
111 changes: 111 additions & 0 deletions recipes/git/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.apple import is_apple_os
from conan.tools.build import cross_building
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rmdir
import os


required_conan_version = ">=1.54.0"

class PackageConan(ConanFile):
name = "git"
description = "Fast, scalable, distributed revision control system"
license = "GPL-2.0-only"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://git-scm.com/"
topics = ("scm", "version-control")
package_type = "application"
settings = "os", "arch", "compiler", "build_type"

def configure(self):
# C only
self.settings.compiler.rm_safe("libcxx")
self.settings.compiler.rm_safe("cppstd")

def layout(self):
cmake_layout(self, src_folder="src")

def export_sources(self):
export_conandata_patches(self)

def validate(self):
if cross_building(self):
raise ConanInvalidConfiguration(f"FIXME: {self.ref} (currently) does not support cross building.")

def requirements(self):
self.requires("expat/[>=2.6.2 <3]")
self.requires("libcurl/[>=7.78.0 <9]")
self.requires("libiconv/1.17")
self.requires("openssl/[>=1.1 <4]")
self.requires("zlib/[>=1.2.11 <2]")
if self.settings.os != "Windows":
# Git's CMake tries to pick this up only when PkgConfig is detected, so it
# likely expects it to not exist on Windows. It fails if it is injected.
self.requires("pcre2/10.43")

def build_requirements(self):
self.tool_requires("gettext/0.22.5")

def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)

def generate(self):
tc = CMakeToolchain(self)
tc.variables["BUILD_TESTING"] = False
# So `check_c_source_compiles` can work with multi-config generators
tc.variables["CMAKE_TRY_COMPILE_CONFIGURATION"] = self.settings.build_type
if is_apple_os(self):
# This isn't set properly in CMake.
# https://lore.kernel.org/git/[email protected]/T/
tc.preprocessor_definitions["USE_ST_TIMESPEC"] = "1"
# Forces Git to look relative to the binary for additional files.
tc.preprocessor_definitions["RUNTIME_PREFIX"] = "1"
# Allows the use of _NSGetExecutablePath to get the path of the running executable,
# used in tandem with RUNTIME_PREFIX.
tc.preprocessor_definitions["HAVE_NS_GET_EXECUTABLE_PATH"] = "1"
tc.generate()

deps = CMakeDeps(self)
deps.generate()

def build(self):
apply_conandata_patches(self)

cmake_directory = os.path.join(self.source_folder, "contrib", "buildsystems")

cmake = CMake(self)
cmake.configure(
build_script_folder=cmake_directory,
# USE_VCPKG is checked before project(), so it can't be injected from the toolchain.
cli_args=["-DUSE_VCPKG=OFF"],
)
cmake.build()

def package(self):
copy(self, "COPYING", self.source_folder, os.path.join(self.package_folder, "licenses"))
cmake = CMake(self)
cmake.install()
# Contains mainly perl scripts an examples, otherwise is actually rather small
rmdir(self, os.path.join(self.package_folder, "share"))
# Contains many executables which are near duplicates of `git`, presumably with pre-configured command line args.
# Greatly bloats the package size. These are also packaged on normal distributions, but often separately. Unsure of their purpose.
rmdir(self, os.path.join(self.package_folder, "libexec"))

def package_id(self):
# Just an application
del self.info.settings.compiler

def package_info(self):
self.cpp_info.frameworkdirs = []
self.cpp_info.libdirs = []
self.cpp_info.resdirs = []
self.cpp_info.includedirs = []

bin_folder = os.path.join(self.package_folder, "bin")

self.runenv_info.prepend_path("PATH", bin_folder)

# TODO: Legacy, to be removed in Conan 2.0
self.env_info.PATH.append(bin_folder)
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
From 2bb4de710f2b933654951f76adff680d14e62c25 Mon Sep 17 00:00:00 2001
From: Ahajha <[email protected]>
Date: Sun, 19 May 2024 03:34:54 -0400
Subject: [PATCH] Add Conan specific CMake changes

Expat needs to use module mode, since at time of writing expat's CMake uses `expat` for find mode and `EXPAT` for module mode. Git looks for the latter.
PkgConfig is only used within CMake for one dependency, so it's easier to just change it to use find_package than deal with PkgConfigDeps.
---
contrib/buildsystems/CMakeLists.txt | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt
index 804629c525..d499a1d1a3 100644
--- a/contrib/buildsystems/CMakeLists.txt
+++ b/contrib/buildsystems/CMakeLists.txt
@@ -151,7 +151,7 @@ include(CTest)

find_package(ZLIB REQUIRED)
find_package(CURL)
-find_package(EXPAT)
+find_package(EXPAT MODULE)
find_package(Iconv)

#Don't use libintl on Windows Visual Studio and Clang builds
@@ -159,12 +159,9 @@ if(NOT (WIN32 AND (CMAKE_C_COMPILER_ID STREQUAL "MSVC" OR CMAKE_C_COMPILER_ID ST
find_package(Intl)
endif()

-find_package(PkgConfig)
-if(PkgConfig_FOUND)
- pkg_check_modules(PCRE2 libpcre2-8)
- if(PCRE2_FOUND)
- add_compile_definitions(USE_LIBPCRE2)
- endif()
+find_package(PCRE2)
+if(PCRE2_FOUND)
+ add_compile_definitions(USE_LIBPCRE2)
endif()

if(NOT Intl_FOUND)
--
2.34.1

41 changes: 41 additions & 0 deletions recipes/git/all/patches/fix-macos-in-cmake.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
From 9bb18c5586920e4d6bb5381dfc7a8b90dfe59ddf Mon Sep 17 00:00:00 2001
From: Ahajha <[email protected]>
Date: Sun, 19 May 2024 03:39:44 -0400
Subject: [PATCH] Fix handling of MacOS in CMake

The CMake file does not fully work with MacOS, this provides two key changes:
1. Compile a set of files that originally were only compiled on Linux. This fixes missing symbol linker errors.
2. Remove the nonexistent `rt` library from being linked, and replace with the necessary Apple frameworks.
---
contrib/buildsystems/CMakeLists.txt | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt
index d499a1d1a3..d4ca16797a 100644
--- a/contrib/buildsystems/CMakeLists.txt
+++ b/contrib/buildsystems/CMakeLists.txt
@@ -282,7 +282,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
compat/strdup.c)
set(NO_UNIX_SOCKETS 1)

-elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
+else()
add_compile_definitions(PROCFS_EXECUTABLE_PATH="/proc/self/exe" HAVE_DEV_TTY )
list(APPEND compat_SOURCES unix-socket.c unix-stream-server.c compat/linux/procinfo.c)
endif()
@@ -745,7 +745,11 @@ if(WIN32)
message(FATAL_ERROR "Unhandled compiler: ${CMAKE_C_COMPILER_ID}")
endif()
elseif(UNIX)
- target_link_libraries(common-main pthread rt)
+ if (APPLE)
+ target_link_libraries(common-main pthread "-framework CoreFoundation" "-framework CoreServices")
+ else()
+ target_link_libraries(common-main pthread rt)
+ endif()
endif()

#git
--
2.34.1

39 changes: 39 additions & 0 deletions recipes/git/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from io import StringIO

from conan import ConanFile, conan_version
from conan.errors import ConanException
from conan.tools.build import can_run
from conan.tools.layout import basic_layout


class TestPackageConan(ConanFile):
generators = "VirtualBuildEnv", "VirtualRunEnv"
test_type = "explicit"

def layout(self):
basic_layout(self)

def build_requirements(self):
self.tool_requires(self.tested_reference_str)

@property
def _version(self):
if conan_version.major >= 2:
return self.dependencies.build["git"].ref.version
else:
return self.deps_cpp_info["git"].version

def build(self):
pass

def test(self):
if can_run(self):
buffer = StringIO()
self.run("git --version", buffer)
self.output.info(buffer.getvalue())
version_detected = buffer.getvalue().split()[-1].strip()
# The string can either be literally the version, or '<version>.GIT'
if str(self._version) not in version_detected:
raise ConanException(
f"git reported wrong version. Expected {self._version}, got {version_detected}."
)
3 changes: 3 additions & 0 deletions recipes/git/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"2.45.1":
folder: all
Loading