From 15515f390c5e3316a7faf0cf85d661a297d45a50 Mon Sep 17 00:00:00 2001 From: Julien Schueller Date: Tue, 4 Jan 2022 13:50:02 +0100 Subject: [PATCH 1/4] PCRE2 Closes #2120 --- CMakeLists.txt | 10 ++++----- Doc/Manual/Preface.html | 6 +++--- Doc/Manual/Windows.html | 22 ++++++++++++-------- Source/Swig/misc.c | 41 ++++++++++++++++++++++++------------- Source/Swig/naming.c | 22 ++++++++++++-------- Tools/cmake/FindPCRE.cmake | 37 --------------------------------- Tools/cmake/FindPCRE2.cmake | 21 +++++++++++++++++++ Tools/mkwindows.sh | 2 +- Tools/nuget-install.cmd | 28 ------------------------- Tools/pcre-build.sh | 4 ++-- appveyor.yml | 15 ++++++++------ configure.ac | 19 +++++++++-------- 12 files changed, 106 insertions(+), 121 deletions(-) delete mode 100644 Tools/cmake/FindPCRE.cmake create mode 100644 Tools/cmake/FindPCRE2.cmake delete mode 100644 Tools/nuget-install.cmd diff --git a/CMakeLists.txt b/CMakeLists.txt index 8a195de54..21412aa7e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -73,11 +73,11 @@ if (MSVC) set (CMAKE_CXX_FLAGS "/EHsc ${CMAKE_CXX_FLAGS}") endif () -option (WITH_PCRE "Enable pcre" ON) +option (WITH_PCRE "Enable PCRE" ON) if (WITH_PCRE) - find_package (PCRE REQUIRED) + find_package (PCRE2 REQUIRED) set (HAVE_PCRE 1) - include_directories (${PCRE_INCLUDE_DIRS}) + include_directories (${PCRE2_INCLUDE_DIRS}) endif() if (WIN32) @@ -145,8 +145,8 @@ add_executable (swig ${PROJECT_BINARY_DIR}/Source/CParse/parser.c ${PROJECT_BINARY_DIR}/Source/CParse/parser.h ) -if (PCRE_FOUND) - target_link_libraries (swig ${PCRE_LIBRARIES}) +if (PCRE2_FOUND) + target_link_libraries (swig ${PCRE2_LIBRARIES}) endif () install (TARGETS swig DESTINATION bin) diff --git a/Doc/Manual/Preface.html b/Doc/Manual/Preface.html index 36a99bd1f..24e844c51 100644 --- a/Doc/Manual/Preface.html +++ b/Doc/Manual/Preface.html @@ -283,9 +283,9 @@ You must use GNU make to build a

PCRE needs to be installed on your system to build SWIG, in particular -pcre-config must be available. If you have PCRE headers and libraries but not -pcre-config itself or, alternatively, wish to override the compiler or linker -flags returned by pcre-config, you may set PCRE_LIBS and PCRE_CFLAGS variables +pcre2-config must be available. If you have PCRE headers and libraries but not +pcre2-config itself or, alternatively, wish to override the compiler or linker +flags returned by pcre-config, you may set PCRE2_LIBS and PCRE2_CFLAGS variables to be used instead. And if you don't have PCRE at all, the configure script will provide instructions for obtaining it.

diff --git a/Doc/Manual/Windows.html b/Doc/Manual/Windows.html index 0e4ffc3e2..5aef29460 100644 --- a/Doc/Manual/Windows.html +++ b/Doc/Manual/Windows.html @@ -239,7 +239,7 @@ For fully working build steps always check the Continuous Integration setups cur
  1. Install Nuget from https://www.nuget.org/downloads (v5.8.1 is used in this example, and installed to C:\Tools). Nuget is the package manager - for .NET, but allows us to easily install PCRE and other dependencies required by SWIG. + for .NET, but allows us to easily install CMake and other dependencies required by SWIG.
  2. Install CMake using the following command:
    C:\Tools\nuget install CMake-win64 -Version 3.15.5 -OutputDirectory C:\Tools\CMake
    @@ -251,8 +251,14 @@ For fully working build steps always check the Continuous Integration setups cur and save to a folder e.g. C:\Tools\Bison
  3. - Install PCRE using Nuget using the following command:
    C:\Tools\nuget install pcre -Version 8.33.0.1 -OutputDirectory C:\Tools\pcre
    . - Alternatively, use WITH_PCRE option to disable PCRE support if you are sure not to need it. + Install PCRE2 using the following commands: +
    +git clone https://github.com/PhilipHazel/pcre2.git
    +cd pcre2
    +cmake -G "Visual Studio 15 2017 Win64" -DCMAKE_INSTALL_PREFIX=C:/pcre .
    +cmake --build . --config Release --target install
    +
    +Alternatively, use WITH_PCRE option to disable PCRE support if you are sure not to need it.
  4. We will also need the SWIG source code. Either download a zipped archive from GitHub, or if git is installed clone the latest codebase @@ -272,10 +278,10 @@ For fully working build steps always check the Continuous Integration setups cur
     cd C:\swig
     SET PATH=C:\Tools\CMake\CMake-win64.3.15.5\bin;C:\Tools\bison\bison-win32.2.4.1.1\tools\native\bin;%PATH%
    -SET PCRE_ROOT=C:\Tools\pcre\pcre.8.33.0.1\build\native
    +SET PCRE_ROOT=C:/pcre
     SET PCRE_PLATFORM=x64
    -cmake -G "Visual Studio 15 2017 Win64" -DCMAKE_INSTALL_PREFIX="%CD:\=/%/install2" -DCMAKE_C_FLAGS="/DPCRE_STATIC" ^
    -  -DPCRE_INCLUDE_DIR=%PCRE_ROOT%/include -DPCRE_LIBRARY=%PCRE_ROOT%/lib/v110/%PCRE_PLATFORM%/Release/static/utf8/pcre8.lib .
    +cmake -G "Visual Studio 15 2017 Win64" -DCMAKE_INSTALL_PREFIX="%CD:\=/%/install2" -DCMAKE_C_FLAGS="/DPCRE2_STATIC" ^
    +  -DPCRE2_INCLUDE_DIR=%PCRE_ROOT%/include -DPCRE2_LIBRARY=%PCRE_ROOT%/lib/pcre2-8.lib .
     cmake --build . --config Release
     
     REM to test the exe
    @@ -311,7 +317,7 @@ Install the packages needed to build swig:
    -pacman -S git autoconf automake bison gcc make pcre-devel
    +pacman -S git autoconf automake bison gcc make pcre2-devel
     
    @@ -446,7 +452,7 @@ the autotools will fail miserably on those.
  5. The PCRE third party library needs to be built next. -Download the latest PCRE source tarball, such as pcre-8.10.tar.bz2, from +Download the latest PCRE source tarball, such as pcre2-10.39.tar.bz2, from PCRE and place in the /usr/src/swig directory. Build PCRE as a static library using the Tools/pcre-build.sh script as follows: diff --git a/Source/Swig/misc.c b/Source/Swig/misc.c index ef6fcc02f..1324f4d51 100644 --- a/Source/Swig/misc.c +++ b/Source/Swig/misc.c @@ -1312,7 +1312,8 @@ void Swig_offset_string(String *s, int number) { #ifdef HAVE_PCRE -#include +#define PCRE2_CODE_UNIT_WIDTH 8 +#include static int split_regex_pattern_subst(String *s, String **pattern, String **subst, const char **input) { @@ -1375,7 +1376,7 @@ static void copy_with_maybe_case_conversion(String *dst, const char *src, int le } } -String *replace_captures(int num_captures, const char *input, String *subst, int captures[], String *pattern, String *s) +String *replace_captures(int num_captures, const char *input, String *subst, size_t captures[], String *pattern, String *s) { int convertCase = 0, convertNextOnly = 0; String *result = NewStringEmpty(); @@ -1397,7 +1398,7 @@ String *replace_captures(int num_captures, const char *input, String *subst, int } else if (isdigit((unsigned char)*p)) { int group = *p++ - '0'; if (group < num_captures) { - int l = captures[group*2], r = captures[group*2 + 1]; + int l = (int)captures[group*2], r = (int)captures[group*2 + 1]; if (l != -1) { copy_with_maybe_case_conversion(result, input + l, r - l, &convertCase, convertNextOnly); } @@ -1449,26 +1450,31 @@ String *Swig_string_regex(String *s) { const int pcre_options = 0; String *res = 0; - pcre *compiled_pat = 0; - const char *pcre_error, *input; - int pcre_errorpos; + pcre2_code *compiled_pat = 0; + const char *input; + PCRE2_UCHAR pcre_error[256]; + int pcre_errornum; + size_t pcre_errorpos; String *pattern = 0, *subst = 0; - int captures[30]; - + size_t *captures = 0; + pcre2_match_data *match_data = 0; if (split_regex_pattern_subst(s, &pattern, &subst, &input)) { int rc; - compiled_pat = pcre_compile( - Char(pattern), pcre_options, &pcre_error, &pcre_errorpos, NULL); + compiled_pat = pcre2_compile( + (PCRE2_SPTR8)Char(pattern), PCRE2_ZERO_TERMINATED, pcre_options, &pcre_errornum, &pcre_errorpos, NULL); if (!compiled_pat) { + pcre2_get_error_message (pcre_errornum, pcre_error, sizeof pcre_error); Swig_error("SWIG", Getline(s), "PCRE compilation failed: '%s' in '%s':%i.\n", pcre_error, Char(pattern), pcre_errorpos); SWIG_exit(EXIT_FAILURE); } - rc = pcre_exec(compiled_pat, NULL, input, (int)strlen(input), 0, 0, captures, 30); + match_data = pcre2_match_data_create_from_pattern (compiled_pat, NULL); + rc = pcre2_match(compiled_pat, (PCRE2_SPTR8)input, PCRE2_ZERO_TERMINATED, 0, 0, match_data, NULL); + captures = pcre2_get_ovector_pointer (match_data); if (rc >= 0) { res = replace_captures(rc, input, subst, captures, pattern, s); - } else if (rc != PCRE_ERROR_NOMATCH) { + } else if (rc != PCRE2_ERROR_NOMATCH) { Swig_error("SWIG", Getline(s), "PCRE execution failed: error %d while matching \"%s\" using \"%s\".\n", rc, Char(pattern), input); SWIG_exit(EXIT_FAILURE); @@ -1477,12 +1483,19 @@ String *Swig_string_regex(String *s) { DohDelete(pattern); DohDelete(subst); - pcre_free(compiled_pat); + pcre2_code_free(compiled_pat); + pcre2_match_data_free(match_data); return res ? res : NewStringEmpty(); } String *Swig_pcre_version(void) { - return NewStringf("PCRE Version: %s", pcre_version()); + int len = pcre2_config(PCRE2_CONFIG_VERSION, NULL); + char *buf = malloc(len); + String *result; + pcre2_config(PCRE2_CONFIG_VERSION, buf); + result = NewStringf("PCRE Version: %s", buf); + free(buf); + return result; } #else diff --git a/Source/Swig/naming.c b/Source/Swig/naming.c index 871a9e5bb..a1a03819c 100644 --- a/Source/Swig/naming.c +++ b/Source/Swig/naming.c @@ -1092,26 +1092,32 @@ static DOH *get_lattr(Node *n, List *lattr) { } #ifdef HAVE_PCRE -#include +#define PCRE2_CODE_UNIT_WIDTH 8 +#include static int name_regexmatch_value(Node *n, String *pattern, String *s) { - pcre *compiled_pat; - const char *err; - int errpos; + pcre2_code *compiled_pat; + PCRE2_UCHAR err[256]; + int errornum; + size_t errpos; int rc; - compiled_pat = pcre_compile(Char(pattern), 0, &err, &errpos, NULL); + compiled_pat = pcre2_compile((PCRE2_SPTR8)Char(pattern), PCRE2_ZERO_TERMINATED, 0, &errornum, &errpos, NULL); if (!compiled_pat) { + pcre2_get_error_message (errornum, err, sizeof err); Swig_error("SWIG", Getline(n), "Invalid regex \"%s\": compilation failed at %d: %s\n", Char(pattern), errpos, err); SWIG_exit(EXIT_FAILURE); } - rc = pcre_exec(compiled_pat, NULL, Char(s), Len(s), 0, 0, NULL, 0); - pcre_free(compiled_pat); + pcre2_match_data *match_data = 0; + match_data = pcre2_match_data_create_from_pattern (compiled_pat, NULL); + rc = pcre2_match(compiled_pat, (PCRE2_SPTR8)Char(s), PCRE2_ZERO_TERMINATED, 0, 0, match_data, 0); + pcre2_code_free(compiled_pat); + pcre2_match_data_free(match_data); - if (rc == PCRE_ERROR_NOMATCH) + if (rc == PCRE2_ERROR_NOMATCH) return 0; if (rc < 0 ) { diff --git a/Tools/cmake/FindPCRE.cmake b/Tools/cmake/FindPCRE.cmake deleted file mode 100644 index dbbd60ada..000000000 --- a/Tools/cmake/FindPCRE.cmake +++ /dev/null @@ -1,37 +0,0 @@ -# Copyright (C) 2007-2009 LuaDist. -# Created by Peter Kapec -# Redistribution and use of this file is allowed according to the terms of the MIT license. -# For details see the COPYRIGHT file distributed with LuaDist. -# Note: -# Searching headers and libraries is very simple and is NOT as powerful as scripts -# distributed with CMake, because LuaDist defines directories to search for. -# Everyone is encouraged to contact the author with improvements. Maybe this file -# becomes part of CMake distribution sometimes. - -# - Find pcre -# Find the native PCRE headers and libraries. -# -# PCRE_INCLUDE_DIRS - where to find pcre.h, etc. -# PCRE_LIBRARIES - List of libraries when using pcre. -# PCRE_FOUND - True if pcre found. - -# Look for the header file. -FIND_PATH(PCRE_INCLUDE_DIR NAMES pcre.h) - -# Look for the library. -FIND_LIBRARY(PCRE_LIBRARY NAMES pcre) - -# Handle the QUIETLY and REQUIRED arguments and set PCRE_FOUND to TRUE if all listed variables are TRUE. -INCLUDE(FindPackageHandleStandardArgs) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(PCRE DEFAULT_MSG PCRE_LIBRARY PCRE_INCLUDE_DIR) - -# Copy the results to the output variables. -IF(PCRE_FOUND) - SET(PCRE_LIBRARIES ${PCRE_LIBRARY}) - SET(PCRE_INCLUDE_DIRS ${PCRE_INCLUDE_DIR}) -ELSE(PCRE_FOUND) - SET(PCRE_LIBRARIES) - SET(PCRE_INCLUDE_DIRS) -ENDIF(PCRE_FOUND) - -MARK_AS_ADVANCED(PCRE_INCLUDE_DIRS PCRE_LIBRARIES) diff --git a/Tools/cmake/FindPCRE2.cmake b/Tools/cmake/FindPCRE2.cmake new file mode 100644 index 000000000..08c216347 --- /dev/null +++ b/Tools/cmake/FindPCRE2.cmake @@ -0,0 +1,21 @@ +# - Find PCRE2 +# Perl Compatible Regular Expressions +# https://www.pcre.org/ + +# The following variables are set: +# PCRE2_FOUND - System has the PCRE library +# PCRE2_LIBRARIES - The PCRE library file +# PCRE2_INCLUDE_DIRS - The folder with the PCRE headers + +find_library(PCRE2_LIBRARY NAMES pcre2 pcre2-8) +find_path(PCRE2_INCLUDE_DIR pcre2.h) + +set (PCRE2_LIBRARIES ${PCRE2_LIBRARY}) +set (PCRE2_INCLUDE_DIRS ${PCRE2_INCLUDE_DIR}) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(PCRE2 DEFAULT_MSG PCRE2_LIBRARIES PCRE2_INCLUDE_DIRS) + +mark_as_advanced ( + PCRE2_LIBRARY + PCRE2_INCLUDE_DIR) diff --git a/Tools/mkwindows.sh b/Tools/mkwindows.sh index 5e4d2f0fd..4717e1ce6 100755 --- a/Tools/mkwindows.sh +++ b/Tools/mkwindows.sh @@ -84,7 +84,7 @@ export CXXFLAGS="$compileflags" swigbasename=swig-$version swigwinbasename=swigwin-$version tarball=$swigbasename.tar.gz -pcre_tarball=`ls pcre-*.tar.*` +pcre_tarball=`ls pcre2-*.tar.*` if ! test -f "$pcre_tarball"; then echo "Could not find PCRE tarball. Please download a PCRE source tarball from http://www.pcre.org" diff --git a/Tools/nuget-install.cmd b/Tools/nuget-install.cmd deleted file mode 100644 index eec7f8787..000000000 --- a/Tools/nuget-install.cmd +++ /dev/null @@ -1,28 +0,0 @@ -rem Workaround 'nuget install' not being reliable by retrying a few times -@echo off -rem initiate the retry number -set errorCode=1 -set retryNumber=0 -set maxRetries=5 - -:RESTORE -nuget install %* - -rem problem? -IF ERRORLEVEL %errorCode% GOTO :RETRY - -rem everything is fine! -@echo Installed nuget, retries: %reTryNumber% -GOTO :EXIT - -:RETRY -@echo Oops, nuget restore exited with code %errorCode% - let us try again! -set /a retryNumber=%retryNumber%+1 -IF %reTryNumber% LSS %maxRetries% (GOTO :RESTORE) -IF %retryNumber% EQU %maxRetries% (GOTO :ERR) - -:ERR -@echo Sorry, we tried restoring nuget packages for %maxRetries% times and all attempts were unsuccessful! -EXIT /B 1 - -:EXIT diff --git a/Tools/pcre-build.sh b/Tools/pcre-build.sh index 92f645da2..ffa7a69f8 100755 --- a/Tools/pcre-build.sh +++ b/Tools/pcre-build.sh @@ -37,8 +37,8 @@ fi echo "Looking for PCRE tarball..." rm -rf pcre -pcre_tarball=`ls pcre-*.tar*` -test -n "$pcre_tarball" || bail "Could not find tarball matching pattern: pcre-*.tar*" +pcre_tarball=`ls pcre2-*.tar*` +test -n "$pcre_tarball" || bail "Could not find tarball matching pattern: pcre2-*.tar*" test -f "$pcre_tarball" || bail "Could not find a single PCRE tarball. Found: $pcre_tarball" echo "Extracting tarball: $pcre_tarball" diff --git a/appveyor.yml b/appveyor.yml index 5eaa77b2f..6959346b2 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -123,15 +123,16 @@ install: } - if "%OSVARIANT%"=="" bash -c "cd /usr/bin && curl --retry 15 -s -L https://github.com/swig/cccl/archive/cccl-1.2.tar.gz | tar -xz --strip 1 cccl-cccl-1.2/cccl" - if "%OSVARIANT%"=="" call "%VCVARSBAT%" %VCVARSARG% -- if "%OSVARIANT%"=="" Tools\nuget-install.cmd pcre -Verbosity quiet -Version 8.33.0.1 -OutputDirectory C:\pcre -- if "%OSVARIANT%"=="" set PCRE_ROOT=C:/pcre/pcre.8.33.0.1/build/native +- if "%OSVARIANT%"=="" appveyor-retry appveyor DownloadFile https://github.com/PhilipHazel/pcre2/archive/refs/tags/pcre2-10.39.zip +- if "%OSVARIANT%"=="" 7z x pcre2-10.39.zip +- if "%OSVARIANT%"=="" set PCRE_ROOT=C:/pcre - if not "%OSVARIANT%"=="cygwin" set PATH=C:\Python%VER%%LANG_PLATFORM%;%PATH% - if "%OSVARIANT%"=="" bash -c "which cl.exe" - if "%OSVARIANT%"=="" bash -c "cl.exe /? 2>&1 | head -n 1" - if "%OSVARIANT%"=="" bash -c "which csc.exe" - if "%OSVARIANT%"=="" bash -c "csc.exe /? | head -n 1" -- if "%OSVARIANT%"=="cygwin" %CYGWINSETUP% --quiet-mode --packages python2-devel,libpcre-devel,libboost-devel > cygwin-install.txt || bash -c "cat cygwin-install.txt" -- if "%OSVARIANT%"=="mingw" bash -c "pacman --noconfirm --sync mingw%MBITS%/mingw-w64-%MARCH%-autotools mingw%MBITS%/mingw-w64-%MARCH%-pcre mingw%MBITS%/mingw-w64-%MARCH%-boost" +- if "%OSVARIANT%"=="cygwin" %CYGWINSETUP% --quiet-mode --packages python2-devel,libpcre2-devel,libboost-devel > cygwin-install.txt || bash -c "cat cygwin-install.txt" +- if "%OSVARIANT%"=="mingw" bash -c "pacman --noconfirm --sync mingw%MBITS%/mingw-w64-%MARCH%-autotools mingw%MBITS%/mingw-w64-%MARCH%-pcre2 mingw%MBITS%/mingw-w64-%MARCH%-boost" - if not "%WITHLANG%"=="" set SWIGWITHLANG==%WITHLANG% - if not "%WITHLANG%"=="" where %WITHLANG% - bash -c "which $CC" @@ -148,9 +149,11 @@ install: build_script: - set CCCL_OPTIONS=--cccl-muffle /W3 /EHsc - set CHECK_OPTIONS=CSHARPOPTIONS=-platform:%Platform% -- if "%BUILDSYSTEM%"=="cmake" cmake --version && cmake -G "Visual Studio 14 2015%VSARCH%" -DCMAKE_INSTALL_PREFIX="%CD:\=/%/install2" -DCMAKE_C_FLAGS="/WX /DPCRE_STATIC" -DCMAKE_CXX_FLAGS="/WX /DPCRE_STATIC" -DPCRE_INCLUDE_DIR=%PCRE_ROOT%/include -DPCRE_LIBRARY=%PCRE_ROOT%/lib/v110/%PCRE_PLATFORM%/Release/static/utf8/pcre8.lib -DBISON_EXECUTABLE=C:/cygwin/bin/bison.exe . && cmake --build . --config Release --target install && ctest --output-on-failure -V -C Release && appveyor exit +- if "%BUILDSYSTEM%"=="cmake" cd pcre2-pcre2-10.39 && cmake -G "Visual Studio 14 2015%VSARCH%" -DCMAKE_INSTALL_PREFIX="%PCRE_ROOT:\=/%" . && cmake --build . --config Release --target install && cd .. +- if "%BUILDSYSTEM%"=="cmake" cmake --version && cmake -G "Visual Studio 14 2015%VSARCH%" -DCMAKE_INSTALL_PREFIX="%CD:\=/%/install2" -DCMAKE_C_FLAGS="/WX /DPCRE_STATIC" -DCMAKE_CXX_FLAGS="/WX /DPCRE2_STATIC" -DPCRE2_INCLUDE_DIR=%PCRE_ROOT%/include -DPCRE2_LIBRARY=%PCRE_ROOT%/lib/pcre2-8-static.lib -DBISON_EXECUTABLE=C:/cygwin/bin/bison.exe . && cmake --build . --config Release --target install && ctest --output-on-failure -V -C Release && appveyor exit +- if "%OSVARIANT%"=="" bash -c "exec 0 Date: Thu, 20 Jan 2022 22:24:53 +0000 Subject: [PATCH 2/4] Few more PCRE to PCRE2 changes --- Doc/Manual/Preface.html | 8 ++++---- Doc/Manual/SWIG.html | 6 +++--- Doc/Manual/Windows.html | 10 +++++----- Source/Modules/main.cxx | 2 +- Source/Swig/misc.c | 2 +- Tools/mkwindows.sh | 2 +- Tools/pcre-build.sh | 26 +++++++++++++------------- configure.ac | 18 +++++++++--------- 8 files changed, 37 insertions(+), 37 deletions(-) diff --git a/Doc/Manual/Preface.html b/Doc/Manual/Preface.html index 24e844c51..41f21d48d 100644 --- a/Doc/Manual/Preface.html +++ b/Doc/Manual/Preface.html @@ -281,12 +281,12 @@ You must use GNU make to build a

    -PCRE +PCRE2 needs to be installed on your system to build SWIG, in particular -pcre2-config must be available. If you have PCRE headers and libraries but not +pcre2-config must be available. If you have PCRE2 headers and libraries but not pcre2-config itself or, alternatively, wish to override the compiler or linker -flags returned by pcre-config, you may set PCRE2_LIBS and PCRE2_CFLAGS variables -to be used instead. And if you don't have PCRE at all, the configure script +flags returned by pcre2-config, you may set PCRE2_LIBS and PCRE2_CFLAGS variables +to be used instead. And if you don't have PCRE2 at all, the configure script will provide instructions for obtaining it.

    diff --git a/Doc/Manual/SWIG.html b/Doc/Manual/SWIG.html index 876c0ac17..d39c0f372 100644 --- a/Doc/Manual/SWIG.html +++ b/Doc/Manual/SWIG.html @@ -208,7 +208,7 @@ General Options -oh <headfile> - Set name of C++ output header file for directors to <headfile> -outcurrentdir - Set default output dir to current dir instead of input file's path -outdir <dir> - Set language specific files output directory to <dir> - -pcreversion - Display PCRE version information + -pcreversion - Display PCRE2 version information -small - Compile in virtual elimination and compact mode -swiglib - Report location of SWIG library and exit -templatereduce - Reduce all the typedefs in templates @@ -2022,8 +2022,8 @@ and a more descriptive one, but the two functions are otherwise equivalent: String after (Perl-like) regex substitution operation. This function allows applying arbitrary regular expressions to the identifier names. The pattern part is a regular expression in Perl syntax (as supported - by the Perl Compatible Regular Expressions (PCRE)) - library and the subst string + by the Perl Compatible Regular Expressions) + (PCRE2 library) and the subst string can contain back-references of the form \N where N is a digit from 0 to 9, or one of the following escape sequences: \l, \L, \u, \U or \E. The back-references are replaced with the diff --git a/Doc/Manual/Windows.html b/Doc/Manual/Windows.html index 5aef29460..8bee04ae9 100644 --- a/Doc/Manual/Windows.html +++ b/Doc/Manual/Windows.html @@ -258,7 +258,7 @@ cd pcre2 cmake -G "Visual Studio 15 2017 Win64" -DCMAKE_INSTALL_PREFIX=C:/pcre . cmake --build . --config Release --target install
  6. -Alternatively, use WITH_PCRE option to disable PCRE support if you are sure not to need it. +Alternatively, use WITH_PCRE option to disable PCRE2 support if you are sure not to need it.
  7. We will also need the SWIG source code. Either download a zipped archive from GitHub, or if git is installed clone the latest codebase @@ -451,10 +451,10 @@ the autotools will fail miserably on those.
  8. -The PCRE third party library needs to be built next. -Download the latest PCRE source tarball, such as pcre2-10.39.tar.bz2, from -PCRE and place in the /usr/src/swig directory. -Build PCRE as a static library using the Tools/pcre-build.sh script as follows: +The PCRE2 third party library needs to be built next. +Download the latest PCRE2 source tarball, such as pcre2-10.39.tar.bz2, from +www.pcre.org and place in the /usr/src/swig directory. +Build PCRE2 as a static library using the Tools/pcre-build.sh script as follows:
     cd /usr/src/swig
    diff --git a/Source/Modules/main.cxx b/Source/Modules/main.cxx
    index d8f2ab6b4..1476ddba5 100644
    --- a/Source/Modules/main.cxx
    +++ b/Source/Modules/main.cxx
    @@ -137,7 +137,7 @@ static const char *usage4 = (const char *) "\
          -oh   - Set name of C++ output header file for directors to \n\
          -outcurrentdir  - Set default output dir to current dir instead of input file's path\n\
          -outdir    - Set language specific files output directory to \n\
    -     -pcreversion    - Display PCRE version information\n\
    +     -pcreversion    - Display PCRE2 version information\n\
          -small          - Compile in virtual elimination and compact mode\n\
          -swiglib        - Report location of SWIG library and exit\n\
          -templatereduce - Reduce all the typedefs in templates\n\
    diff --git a/Source/Swig/misc.c b/Source/Swig/misc.c
    index 1324f4d51..62a97875e 100644
    --- a/Source/Swig/misc.c
    +++ b/Source/Swig/misc.c
    @@ -1493,7 +1493,7 @@ String *Swig_pcre_version(void) {
       char *buf = malloc(len);
       String *result;
       pcre2_config(PCRE2_CONFIG_VERSION, buf);
    -  result = NewStringf("PCRE Version: %s", buf);
    +  result = NewStringf("PCRE2 Version: %s", buf);
       free(buf);
       return result;
     }
    diff --git a/Tools/mkwindows.sh b/Tools/mkwindows.sh
    index 4717e1ce6..ad96c9768 100755
    --- a/Tools/mkwindows.sh
    +++ b/Tools/mkwindows.sh
    @@ -87,7 +87,7 @@ tarball=$swigbasename.tar.gz
     pcre_tarball=`ls pcre2-*.tar.*`
     
     if ! test -f "$pcre_tarball"; then
    -  echo "Could not find PCRE tarball. Please download a PCRE source tarball from http://www.pcre.org"
    +  echo "Could not find PCRE2 tarball. Please download a PCRE2 source tarball from http://www.pcre.org"
       echo "and place in the same directory as the SWIG tarball."
       exit 1
     fi
    diff --git a/Tools/pcre-build.sh b/Tools/pcre-build.sh
    index ffa7a69f8..e986d682f 100755
    --- a/Tools/pcre-build.sh
    +++ b/Tools/pcre-build.sh
    @@ -4,17 +4,17 @@ pcre_subdir=pcre/pcre-swig-install
     pcre_install_dir=`pwd`/$pcre_subdir
     
     usage() {
    -  echo "Helper script to build PCRE as a static library from a tarball just for use during the"
    -  echo "SWIG build. It does not install PCRE for global use on your system."
    +  echo "Helper script to build PCRE2 as a static library from a tarball just for use during the"
    +  echo "SWIG build. It does not install PCRE2 for global use on your system."
       echo "Usage: pcre-build.sh [--help] [args]"
    -  echo "  args   - optional additional arguments passed on to the PCRE configure script (leave out"
    +  echo "  args   - optional additional arguments passed on to the PCRE2 configure script (leave out"
       echo "         unless you are an expert at configure)"
       echo "  --help - Display this help information."
       echo "Instructions:"
    -  echo "  - Download the latest PCRE source tarball from http://www.pcre.org and place in the"
    +  echo "  - Download the latest PCRE2 source tarball from http://www.pcre.org and place in the"
       echo "    directory that you will configure and build SWIG."
       echo "  - Run this script in the same directory that you intend to configure and build SWIG in."
    -  echo "    This will configure and build PCRE as a static library."
    +  echo "    This will configure and build PCRE2 as a static library."
       echo "  - Afterwards run the SWIG configure script which will then find and use the PCRE static"
       echo "    libraries in the $pcre_subdir subdirectory."
       exit 0
    @@ -35,21 +35,21 @@ if test -f "pcre-build.sh" ; then
       usage
     fi
     
    -echo "Looking for PCRE tarball..."
    +echo "Looking for PCRE2 tarball..."
     rm -rf pcre
     pcre_tarball=`ls pcre2-*.tar*`
     test -n "$pcre_tarball" || bail "Could not find tarball matching pattern: pcre2-*.tar*"
    -test -f "$pcre_tarball" || bail "Could not find a single PCRE tarball. Found: $pcre_tarball"
    +test -f "$pcre_tarball" || bail "Could not find a single PCRE2 tarball. Found: $pcre_tarball"
     
     echo "Extracting tarball: $pcre_tarball"
     tar -xf $pcre_tarball || bail "Could not untar $pcre_tarball"
     pcre_dir=`echo $pcre_tarball | sed -e "s/\.tar.*//"`
     echo "Configuring PCRE in directory: pcre"
     mv $pcre_dir pcre || bail "Could not create pcre directory"
    -cd pcre && ./configure --prefix=$pcre_install_dir --disable-shared $* || bail "PCRE configure failed"
    -echo "Building PCRE..."
    -${MAKE:-make} -s || bail "Could not build PCRE"
    -echo "Installing PCRE locally to $pcre_install_dir..."
    -${MAKE:-make} -s install || bail "Could not install PCRE"
    +cd pcre && ./configure --prefix=$pcre_install_dir --disable-shared $* || bail "PCRE2 configure failed"
    +echo "Building PCRE2..."
    +${MAKE:-make} -s || bail "Could not build PCRE2"
    +echo "Installing PCRE2 locally to $pcre_install_dir..."
    +${MAKE:-make} -s install || bail "Could not install PCRE2"
     echo ""
    -echo "The SWIG configure script can now be run, whereupon PCRE will automatically be detected and used from $pcre_install_dir/bin/pcre-config."
    +echo "The SWIG configure script can now be run, whereupon PCRE2 will automatically be detected and used from $pcre_install_dir/bin/pcre-config."
    diff --git a/configure.ac b/configure.ac
    index c5ae9fc03..209dba1b8 100644
    --- a/configure.ac
    +++ b/configure.ac
    @@ -48,16 +48,16 @@ fi
     dnl PCRE
     AC_ARG_WITH([pcre],
       [AS_HELP_STRING([--without-pcre],
    -                  [Disable support for regular expressions using PCRE])],
    +                  [Disable support for regular expressions using PCRE2])],
       [],
       [with_pcre=yes])
     
    -AC_MSG_CHECKING([whether to enable PCRE support])
    +AC_MSG_CHECKING([whether to enable PCRE2 support])
     AC_MSG_RESULT([$with_pcre])
     
     dnl To make configuring easier, check for a locally built PCRE using the Tools/pcre-build.sh script
     if test x"${with_pcre}" = xyes ; then
    -  AC_MSG_CHECKING([whether to use local PCRE])
    +  AC_MSG_CHECKING([whether to use local PCRE2])
       local_pcre_config=no
       if test -z $PCRE2_CONFIG; then
         if test -f `pwd`/pcre/pcre-swig-install/bin/pcre2-config; then
    @@ -71,20 +71,20 @@ AS_IF([test "x$with_pcre" != xno],
       [AX_PATH_GENERIC([pcre2],
         [], dnl Minimal version of PCRE we need -- accept any
         [], dnl custom sed script for version parsing is not needed
    -    [AC_DEFINE([HAVE_PCRE], [1], [Define if you have PCRE library])
    +    [AC_DEFINE([HAVE_PCRE], [1], [Define if you have PCRE2 library])
          LIBS="$LIBS $PCRE2_LIBS"
          CPPFLAGS="$CPPFLAGS $PCRE2_CFLAGS"
         ],
         [AC_MSG_FAILURE([
    -        Cannot find pcre2-config script from PCRE (Perl Compatible Regular Expressions)
    +        Cannot find pcre2-config script from PCRE2 (Perl Compatible Regular Expressions)
             library package. This dependency is needed for configure to complete,
             Either:
    -        - Install the PCRE developer package on your system (preferred approach).
    -        - Download the PCRE source tarball, build and install on your system
    +        - Install the PCRE2 developer package on your system (preferred approach).
    +        - Download the PCRE2 source tarball, build and install on your system
               as you would for any package built from source distribution.
    -        - Use the Tools/pcre-build.sh script to build PCRE just for SWIG to statically
    +        - Use the Tools/pcre-build.sh script to build PCRE2 just for SWIG to statically
               link against. Run 'Tools/pcre-build.sh --help' for instructions.
    -          (quite easy and does not require privileges to install PCRE on your system)
    +          (quite easy and does not require privileges to install PCRE2 on your system)
             - Use configure --without-pcre to disable regular expressions support in SWIG
               (not recommended).])
         ],
    
    From da8eb35a516c9afd5f59f6fc165cadbc41bf449b Mon Sep 17 00:00:00 2001
    From: William S Fulton 
    Date: Thu, 20 Jan 2022 22:47:03 +0000
    Subject: [PATCH 3/4] Call -pcreversion during appveyor testing
    
    ---
     CMakeLists.txt | 1 +
     appveyor.yml   | 1 +
     2 files changed, 2 insertions(+)
    
    diff --git a/CMakeLists.txt b/CMakeLists.txt
    index 21412aa7e..c5431293a 100644
    --- a/CMakeLists.txt
    +++ b/CMakeLists.txt
    @@ -160,6 +160,7 @@ include (CPack)
     # few tests
     enable_testing ()
     add_test (NAME cmd_version COMMAND swig -version)
    +add_test (NAME cmd_version COMMAND swig -pcreversion)
     add_test (NAME cmd_swiglib COMMAND swig -swiglib)
     add_test (NAME cmd_external_runtime COMMAND swig -external-runtime ext_rt.h)
     set_tests_properties(cmd_external_runtime PROPERTIES ENVIRONMENT "SWIG_LIB=${PROJECT_SOURCE_DIR}/Lib")
    diff --git a/appveyor.yml b/appveyor.yml
    index 6959346b2..5a57c5fa2 100644
    --- a/appveyor.yml
    +++ b/appveyor.yml
    @@ -160,6 +160,7 @@ build_script:
     test_script:
     - set CCCL_OPTIONS=--cccl-muffle /W3 /EHsc
     - .\swig.exe -version
    +- .\swig.exe -pcreversion
     - if not "%OSVARIANT%"=="" CCache\ccache-swig -V
     - bash -c "file ./swig.exe"
     - bash -c "make check-%SWIGLANG%-version"
    
    From 8939470b05bce6569672e0c5b2bb78b6699bc9e0 Mon Sep 17 00:00:00 2001
    From: William S Fulton 
    Date: Fri, 21 Jan 2022 19:22:11 +0000
    Subject: [PATCH 4/4] Add changes entry for PCRE2
    
    ---
     CHANGES.current | 12 ++++++++++++
     1 file changed, 12 insertions(+)
    
    diff --git a/CHANGES.current b/CHANGES.current
    index 89955d183..a9ba1ebaf 100644
    --- a/CHANGES.current
    +++ b/CHANGES.current
    @@ -7,6 +7,18 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
     Version 4.1.0 (in progress)
     ===========================
     
    +2022-01-21: wsfulton
    +            #2120 #2138 Replace legacy PCRE dependency with PCRE2.
    +            This requires changes for building SWIG from source. See updated
    +            html documentation in Preface.html and Windows.html. Updated
    +            instructions are also shown when running ./configure if PCRE2 is not
    +            found. Note that debian based systems can install PCRE2 using:
    +
    +              apt install libpcre2-dev
    +
    +            Note that https://github.com/swig/swig/wiki/Getting-Started also has
    +            updated information for building from source.
    +
     2022-01-19: olly
     	    [PHP] #2027 Automatically generate PHP type declarations for PHP 8.
     	    The generate code still compiles for PHP 7.x, but without type