Skip to content

Commit 3d9e82f

Browse files
authored
Merge pull request libgit2#4935 from libgit2/ethomson/pcre
Use PCRE for our fallback regex engine when regcomp_l is unavailable
2 parents 954f535 + afb04a9 commit 3d9e82f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+47608
-12195
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ OPTION(DEBUG_POOL "Enable debug pool allocator" OFF)
6565
OPTION(ENABLE_WERROR "Enable compilation with -Werror" OFF)
6666
OPTION(USE_BUNDLED_ZLIB "Use the bundled version of zlib" OFF)
6767
OPTION(DEPRECATE_HARD "Do not include deprecated functions in the library" OFF)
68+
SET(REGEX_BACKEND "" CACHE STRING "Regular expression implementation. One of regcomp_l, pcre2, pcre, regcomp, or builtin.")
6869

6970
IF (UNIX AND NOT APPLE)
7071
OPTION(ENABLE_REPRODUCIBLE_BUILDS "Enable reproducible builds" OFF)

azure-pipelines.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
imageName: 'libgit2/trusty-amd64:latest'
1717
environmentVariables: |
1818
CC=gcc
19-
CMAKE_OPTIONS=-DUSE_HTTPS=OpenSSL -DDEPRECATE_HARD=ON
19+
CMAKE_OPTIONS=-DUSE_HTTPS=OpenSSL -DREGEX_BACKEND=builtin -DDEPRECATE_HARD=ON
2020
LEAK_CHECK=valgrind
2121
2222
- job: linux_amd64_trusty_gcc_mbedtls
@@ -55,7 +55,7 @@ jobs:
5555
imageName: 'libgit2/trusty-amd64:latest'
5656
environmentVariables: |
5757
CC=clang
58-
CMAKE_OPTIONS=-DUSE_HTTPS=mbedTLS -DSHA1_BACKEND=mbedTLS -DDEPRECATE_HARD=ON
58+
CMAKE_OPTIONS=-DUSE_HTTPS=mbedTLS -DSHA1_BACKEND=mbedTLS -DREGEX_BACKEND=pcre -DDEPRECATE_HARD=ON
5959
LEAK_CHECK=valgrind
6060
6161
- job: macos
@@ -71,7 +71,7 @@ jobs:
7171
TMPDIR: $(Agent.TempDirectory)
7272
PKG_CONFIG_PATH: /usr/local/opt/openssl/lib/pkgconfig
7373
LEAK_CHECK: leaks
74-
CMAKE_OPTIONS: -G Ninja -DDEPRECATE_HARD=ON
74+
CMAKE_OPTIONS: -G Ninja -DREGEX_BACKEND=regcomp_l -DDEPRECATE_HARD=ON
7575
SKIP_SSH_TESTS: true
7676

7777
- job: windows_vs_amd64

azure-pipelines/nightly.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
imageName: 'libgit2/trusty-amd64:latest'
1313
environmentVariables: |
1414
CC=gcc
15-
CMAKE_OPTIONS=-DUSE_HTTPS=OpenSSL -DDEPRECATE_HARD=ON
15+
CMAKE_OPTIONS=-DUSE_HTTPS=OpenSSL -DREGEX_BACKEND=builtin -DDEPRECATE_HARD=ON
1616
LEAK_CHECK=valgrind
1717
RUN_INVASIVE_TESTS=true
1818
@@ -54,7 +54,7 @@ jobs:
5454
imageName: 'libgit2/trusty-amd64:latest'
5555
environmentVariables: |
5656
CC=clang
57-
CMAKE_OPTIONS=-DUSE_HTTPS=mbedTLS -DSHA1_BACKEND=mbedTLS -DDEPRECATE_HARD=ON
57+
CMAKE_OPTIONS=-DUSE_HTTPS=mbedTLS -DSHA1_BACKEND=mbedTLS -DREGEX_BACKEND=pcre -DDEPRECATE_HARD=ON
5858
LEAK_CHECK=valgrind
5959
RUN_INVASIVE_TESTS=true
6060
@@ -71,7 +71,7 @@ jobs:
7171
TMPDIR: $(Agent.TempDirectory)
7272
PKG_CONFIG_PATH: /usr/local/opt/openssl/lib/pkgconfig
7373
LEAK_CHECK: leaks
74-
CMAKE_OPTIONS: -G Ninja -DDEPRECATE_HARD=ON
74+
CMAKE_OPTIONS: -G Ninja -DREGEX_BACKEND=regcomp_l -DDEPRECATE_HARD=ON
7575
RUN_INVASIVE_TESTS: true
7676
SKIP_SSH_TESTS: true
7777

cmake/Modules/FindPCRE.cmake

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Copyright (C) 2007-2009 LuaDist.
2+
# Created by Peter Kapec <kapecp@gmail.com>
3+
# Redistribution and use of this file is allowed according to the terms of the MIT license.
4+
# For details see the COPYRIGHT file distributed with LuaDist.
5+
# Note:
6+
# Searching headers and libraries is very simple and is NOT as powerful as scripts
7+
# distributed with CMake, because LuaDist defines directories to search for.
8+
# Everyone is encouraged to contact the author with improvements. Maybe this file
9+
# becomes part of CMake distribution sometimes.
10+
11+
# - Find pcre
12+
# Find the native PCRE headers and libraries.
13+
#
14+
# PCRE_INCLUDE_DIRS - where to find pcre.h, etc.
15+
# PCRE_LIBRARIES - List of libraries when using pcre.
16+
# PCRE_FOUND - True if pcre found.
17+
18+
# Look for the header file.
19+
FIND_PATH(PCRE_INCLUDE_DIR NAMES pcreposix.h)
20+
21+
# Look for the library.
22+
FIND_LIBRARY(PCRE_LIBRARY NAMES pcre)
23+
FIND_LIBRARY(PCRE_POSIX_LIBRARY NAMES pcreposix)
24+
25+
# Handle the QUIETLY and REQUIRED arguments and set PCRE_FOUND to TRUE if all listed variables are TRUE.
26+
INCLUDE(FindPackageHandleStandardArgs)
27+
FIND_PACKAGE_HANDLE_STANDARD_ARGS(PCRE DEFAULT_MSG PCRE_LIBRARY PCRE_POSIX_LIBRARY PCRE_INCLUDE_DIR)
28+
29+
# Copy the results to the output variables.
30+
IF(PCRE_FOUND)
31+
SET(PCRE_LIBRARIES ${PCRE_LIBRARY} ${PCRE_POSIX_LIBRARY})
32+
SET(PCRE_INCLUDE_DIRS ${PCRE_INCLUDE_DIR})
33+
ELSE(PCRE_FOUND)
34+
SET(PCRE_LIBRARIES)
35+
SET(PCRE_INCLUDE_DIRS)
36+
ENDIF(PCRE_FOUND)
37+
38+
MARK_AS_ADVANCED(PCRE_INCLUDE_DIRS PCRE_LIBRARIES)

cmake/Modules/FindPCRE2.cmake

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Copyright (C) 2007-2009 LuaDist.
2+
# Created by Peter Kapec <kapecp@gmail.com>
3+
# Redistribution and use of this file is allowed according to the terms of the MIT license.
4+
# For details see the COPYRIGHT file distributed with LuaDist.
5+
# Note:
6+
# Searching headers and libraries is very simple and is NOT as powerful as scripts
7+
# distributed with CMake, because LuaDist defines directories to search for.
8+
# Everyone is encouraged to contact the author with improvements. Maybe this file
9+
# becomes part of CMake distribution sometimes.
10+
11+
# - Find pcre
12+
# Find the native PCRE2 headers and libraries.
13+
#
14+
# PCRE2_INCLUDE_DIRS - where to find pcre.h, etc.
15+
# PCRE2_LIBRARIES - List of libraries when using pcre.
16+
# PCRE2_FOUND - True if pcre found.
17+
18+
# Look for the header file.
19+
FIND_PATH(PCRE2_INCLUDE_DIR NAMES pcre2posix.h)
20+
21+
# Look for the library.
22+
FIND_LIBRARY(PCRE2_LIBRARY NAMES pcre2-8)
23+
FIND_LIBRARY(PCRE2_POSIX_LIBRARY NAMES pcre2-posix)
24+
25+
# Handle the QUIETLY and REQUIRED arguments and set PCRE2_FOUND to TRUE if all listed variables are TRUE.
26+
INCLUDE(FindPackageHandleStandardArgs)
27+
FIND_PACKAGE_HANDLE_STANDARD_ARGS(PCRE2 DEFAULT_MSG PCRE2_LIBRARY PCRE2_POSIX_LIBRARY PCRE2_INCLUDE_DIR)
28+
29+
# Copy the results to the output variables.
30+
IF(PCRE2_FOUND)
31+
SET(PCRE2_LIBRARIES ${PCRE2_LIBRARY} ${PCRE2_POSIX_LIBRARY})
32+
SET(PCRE2_INCLUDE_DIRS ${PCRE2_INCLUDE_DIR})
33+
ELSE(PCRE2_FOUND)
34+
SET(PCRE2_LIBRARIES)
35+
SET(PCRE2_INCLUDE_DIRS)
36+
ENDIF(PCRE2_FOUND)
37+
38+
MARK_AS_ADVANCED(PCRE2_INCLUDE_DIRS PCRE2_LIBRARIES)

deps/pcre/CMakeLists.txt

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
INCLUDE(CheckIncludeFile)
2+
INCLUDE(CheckFunctionExists)
3+
INCLUDE(CheckTypeSize)
4+
5+
CHECK_INCLUDE_FILE(dirent.h HAVE_DIRENT_H)
6+
CHECK_INCLUDE_FILE(stdint.h HAVE_STDINT_H)
7+
CHECK_INCLUDE_FILE(inttypes.h HAVE_INTTYPES_H)
8+
CHECK_INCLUDE_FILE(sys/stat.h HAVE_SYS_STAT_H)
9+
CHECK_INCLUDE_FILE(sys/types.h HAVE_SYS_TYPES_H)
10+
CHECK_INCLUDE_FILE(unistd.h HAVE_UNISTD_H)
11+
CHECK_INCLUDE_FILE(windows.h HAVE_WINDOWS_H)
12+
13+
CHECK_FUNCTION_EXISTS(bcopy HAVE_BCOPY)
14+
CHECK_FUNCTION_EXISTS(memmove HAVE_MEMMOVE)
15+
CHECK_FUNCTION_EXISTS(strerror HAVE_STRERROR)
16+
CHECK_FUNCTION_EXISTS(strtoll HAVE_STRTOLL)
17+
CHECK_FUNCTION_EXISTS(strtoq HAVE_STRTOQ)
18+
CHECK_FUNCTION_EXISTS(_strtoi64 HAVE__STRTOI64)
19+
20+
CHECK_TYPE_SIZE("long long" LONG_LONG)
21+
CHECK_TYPE_SIZE("unsigned long long" UNSIGNED_LONG_LONG)
22+
23+
DISABLE_WARNINGS(unused-function)
24+
25+
# User-configurable options
26+
27+
SET(SUPPORT_PCRE8 1)
28+
SET(PCRE_LINK_SIZE "2")
29+
SET(PCRE_PARENS_NEST_LIMIT "250")
30+
SET(PCRE_MATCH_LIMIT "10000000")
31+
SET(PCRE_MATCH_LIMIT_RECURSION "MATCH_LIMIT")
32+
SET(PCRE_NEWLINE "LF")
33+
SET(NO_RECURSE 1)
34+
SET(PCRE_POSIX_MALLOC_THRESHOLD "10")
35+
SET(BSR_ANYCRLF 0)
36+
37+
IF (MINGW)
38+
OPTION(NON_STANDARD_LIB_PREFIX
39+
"ON=Shared libraries built in mingw will be named pcre.dll, etc., instead of libpcre.dll, etc."
40+
OFF)
41+
42+
OPTION(NON_STANDARD_LIB_SUFFIX
43+
"ON=Shared libraries built in mingw will be named libpcre-0.dll, etc., instead of libpcre.dll, etc."
44+
OFF)
45+
ENDIF(MINGW)
46+
47+
# Prepare build configuration
48+
49+
SET(pcre_have_long_long 0)
50+
SET(pcre_have_ulong_long 0)
51+
52+
IF(HAVE_LONG_LONG)
53+
SET(pcre_have_long_long 1)
54+
ENDIF(HAVE_LONG_LONG)
55+
56+
IF(HAVE_UNSIGNED_LONG_LONG)
57+
SET(pcre_have_ulong_long 1)
58+
ENDIF(HAVE_UNSIGNED_LONG_LONG)
59+
60+
SET(NEWLINE "")
61+
62+
IF(PCRE_NEWLINE STREQUAL "LF")
63+
SET(NEWLINE "10")
64+
ENDIF(PCRE_NEWLINE STREQUAL "LF")
65+
IF(PCRE_NEWLINE STREQUAL "CR")
66+
SET(NEWLINE "13")
67+
ENDIF(PCRE_NEWLINE STREQUAL "CR")
68+
IF(PCRE_NEWLINE STREQUAL "CRLF")
69+
SET(NEWLINE "3338")
70+
ENDIF(PCRE_NEWLINE STREQUAL "CRLF")
71+
IF(PCRE_NEWLINE STREQUAL "ANY")
72+
SET(NEWLINE "-1")
73+
ENDIF(PCRE_NEWLINE STREQUAL "ANY")
74+
IF(PCRE_NEWLINE STREQUAL "ANYCRLF")
75+
SET(NEWLINE "-2")
76+
ENDIF(PCRE_NEWLINE STREQUAL "ANYCRLF")
77+
78+
IF(NEWLINE STREQUAL "")
79+
MESSAGE(FATAL_ERROR "The PCRE_NEWLINE variable must be set to one of the following values: \"LF\", \"CR\", \"CRLF\", \"ANY\", \"ANYCRLF\".")
80+
ENDIF(NEWLINE STREQUAL "")
81+
82+
# Output files
83+
CONFIGURE_FILE(config.h.in
84+
${PROJECT_BINARY_DIR}/src/pcre/config.h
85+
@ONLY)
86+
87+
# Source code
88+
89+
SET(PCRE_HEADERS ${PROJECT_BINARY_DIR}/src/pcre/config.h)
90+
91+
SET(PCRE_SOURCES
92+
pcre_byte_order.c
93+
pcre_chartables.c
94+
pcre_compile.c
95+
pcre_config.c
96+
pcre_dfa_exec.c
97+
pcre_exec.c
98+
pcre_fullinfo.c
99+
pcre_get.c
100+
pcre_globals.c
101+
pcre_jit_compile.c
102+
pcre_maketables.c
103+
pcre_newline.c
104+
pcre_ord2utf8.c
105+
pcre_refcount.c
106+
pcre_string_utils.c
107+
pcre_study.c
108+
pcre_tables.c
109+
pcre_ucd.c
110+
pcre_valid_utf8.c
111+
pcre_version.c
112+
pcre_xclass.c
113+
)
114+
115+
SET(PCREPOSIX_HEADERS pcreposix.h)
116+
117+
SET(PCREPOSIX_SOURCES pcreposix.c)
118+
119+
# Fix static compilation with MSVC: https://bugs.exim.org/show_bug.cgi?id=1681
120+
# This code was taken from the CMake wiki, not from WebM.
121+
122+
# Build setup
123+
124+
ADD_DEFINITIONS(-DHAVE_CONFIG_H)
125+
126+
IF(MSVC)
127+
ADD_DEFINITIONS(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS)
128+
ENDIF(MSVC)
129+
130+
SET(CMAKE_INCLUDE_CURRENT_DIR 1)
131+
132+
SET(targets)
133+
134+
# Libraries
135+
# pcre
136+
INCLUDE_DIRECTORIES(${PROJECT_BINARY_DIR}/src/pcre)
137+
ADD_LIBRARY(pcre OBJECT ${PCRE_HEADERS} ${PCRE_SOURCES} ${PCREPOSIX_SOURCES})
138+
139+
# end CMakeLists.txt

deps/pcre/COPYING

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
PCRE LICENCE
2+
3+
Please see the file LICENCE in the PCRE distribution for licensing details.
4+
5+
End
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Redistribution and use in source and binary forms, with or without
2+
modification, are permitted provided that the following conditions
3+
are met:
4+
5+
1. Redistributions of source code must retain the copyright
6+
notice, this list of conditions and the following disclaimer.
7+
2. Redistributions in binary form must reproduce the copyright
8+
notice, this list of conditions and the following disclaimer in the
9+
documentation and/or other materials provided with the distribution.
10+
3. The name of the author may not be used to endorse or promote products
11+
derived from this software without specific prior written permission.
12+
13+
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14+
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15+
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16+
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18+
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22+
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

deps/pcre/cmake/FindEditline.cmake

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Modified from FindReadline.cmake (PH Feb 2012)
2+
3+
if(EDITLINE_INCLUDE_DIR AND EDITLINE_LIBRARY AND NCURSES_LIBRARY)
4+
set(EDITLINE_FOUND TRUE)
5+
else(EDITLINE_INCLUDE_DIR AND EDITLINE_LIBRARY AND NCURSES_LIBRARY)
6+
FIND_PATH(EDITLINE_INCLUDE_DIR readline.h
7+
/usr/include/editline
8+
/usr/include/edit/readline
9+
/usr/include/readline
10+
)
11+
12+
FIND_LIBRARY(EDITLINE_LIBRARY NAMES edit)
13+
include(FindPackageHandleStandardArgs)
14+
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Editline DEFAULT_MSG EDITLINE_INCLUDE_DIR EDITLINE_LIBRARY )
15+
16+
MARK_AS_ADVANCED(EDITLINE_INCLUDE_DIR EDITLINE_LIBRARY)
17+
endif(EDITLINE_INCLUDE_DIR AND EDITLINE_LIBRARY AND NCURSES_LIBRARY)
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# FIND_PACKAGE_HANDLE_STANDARD_ARGS(NAME (DEFAULT_MSG|"Custom failure message") VAR1 ... )
2+
# This macro is intended to be used in FindXXX.cmake modules files.
3+
# It handles the REQUIRED and QUIET argument to FIND_PACKAGE() and
4+
# it also sets the <UPPERCASED_NAME>_FOUND variable.
5+
# The package is found if all variables listed are TRUE.
6+
# Example:
7+
#
8+
# FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibXml2 DEFAULT_MSG LIBXML2_LIBRARIES LIBXML2_INCLUDE_DIR)
9+
#
10+
# LibXml2 is considered to be found, if both LIBXML2_LIBRARIES and
11+
# LIBXML2_INCLUDE_DIR are valid. Then also LIBXML2_FOUND is set to TRUE.
12+
# If it is not found and REQUIRED was used, it fails with FATAL_ERROR,
13+
# independent whether QUIET was used or not.
14+
# If it is found, the location is reported using the VAR1 argument, so
15+
# here a message "Found LibXml2: /usr/lib/libxml2.so" will be printed out.
16+
# If the second argument is DEFAULT_MSG, the message in the failure case will
17+
# be "Could NOT find LibXml2", if you don't like this message you can specify
18+
# your own custom failure message there.
19+
20+
MACRO(FIND_PACKAGE_HANDLE_STANDARD_ARGS _NAME _FAIL_MSG _VAR1 )
21+
22+
IF("${_FAIL_MSG}" STREQUAL "DEFAULT_MSG")
23+
IF (${_NAME}_FIND_REQUIRED)
24+
SET(_FAIL_MESSAGE "Could not find REQUIRED package ${_NAME}")
25+
ELSE (${_NAME}_FIND_REQUIRED)
26+
SET(_FAIL_MESSAGE "Could not find OPTIONAL package ${_NAME}")
27+
ENDIF (${_NAME}_FIND_REQUIRED)
28+
ELSE("${_FAIL_MSG}" STREQUAL "DEFAULT_MSG")
29+
SET(_FAIL_MESSAGE "${_FAIL_MSG}")
30+
ENDIF("${_FAIL_MSG}" STREQUAL "DEFAULT_MSG")
31+
32+
STRING(TOUPPER ${_NAME} _NAME_UPPER)
33+
34+
SET(${_NAME_UPPER}_FOUND TRUE)
35+
IF(NOT ${_VAR1})
36+
SET(${_NAME_UPPER}_FOUND FALSE)
37+
ENDIF(NOT ${_VAR1})
38+
39+
FOREACH(_CURRENT_VAR ${ARGN})
40+
IF(NOT ${_CURRENT_VAR})
41+
SET(${_NAME_UPPER}_FOUND FALSE)
42+
ENDIF(NOT ${_CURRENT_VAR})
43+
ENDFOREACH(_CURRENT_VAR)
44+
45+
IF (${_NAME_UPPER}_FOUND)
46+
IF (NOT ${_NAME}_FIND_QUIETLY)
47+
MESSAGE(STATUS "Found ${_NAME}: ${${_VAR1}}")
48+
ENDIF (NOT ${_NAME}_FIND_QUIETLY)
49+
ELSE (${_NAME_UPPER}_FOUND)
50+
IF (${_NAME}_FIND_REQUIRED)
51+
MESSAGE(FATAL_ERROR "${_FAIL_MESSAGE}")
52+
ELSE (${_NAME}_FIND_REQUIRED)
53+
IF (NOT ${_NAME}_FIND_QUIETLY)
54+
MESSAGE(STATUS "${_FAIL_MESSAGE}")
55+
ENDIF (NOT ${_NAME}_FIND_QUIETLY)
56+
ENDIF (${_NAME}_FIND_REQUIRED)
57+
ENDIF (${_NAME_UPPER}_FOUND)
58+
ENDMACRO(FIND_PACKAGE_HANDLE_STANDARD_ARGS)

0 commit comments

Comments
 (0)