[packages/rapidyaml] - add patches and no-download script from fedora
baggins
baggins at pld-linux.org
Sat Oct 24 00:46:56 CEST 2026
commit 9c29a45ccc1e5d768d1253df37aeb8b4076255ee
Author: Jan Rękorajski <baggins at pld-linux.org>
Date: Sat Oct 24 00:46:33 2026 +0200
- add patches and no-download script from fedora
653.patch | 327 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
662.patch | 27 +++++
patch-no-download | 91 +++++++++++++++
rapidyaml.spec | 26 +++++
4 files changed, 471 insertions(+)
---
diff --git a/rapidyaml.spec b/rapidyaml.spec
index fe9fa25..ddb8339 100644
--- a/rapidyaml.spec
+++ b/rapidyaml.spec
@@ -10,6 +10,9 @@ License: MIT
Group: Libraries
Source0: https://github.com/biojppm/rapidyaml/archive/v%{version}/%{name}-%{version}.tar.gz
# Source0-md5: 405851934758fac31bf128b6b59bd7d8
+Source10: patch-no-download
+Patch0: 653.patch
+Patch1: 662.patch
URL: https://github.com/biojppm/rapidyaml
BuildRequires: cmake
BuildRequires: ninja
@@ -52,6 +55,29 @@ Dokumentacja API biblioteki %{name}.
%prep
%setup -q
+%patch -P0 -p1
+%patch -P1 -p1
+
+# Patch out download of gtest:
+%{SOURCE10} proj/c4proj/c4Project.cmake '^ if\(_GTEST\)' '^ endif'
+
+# Patch out download of c4fs:
+%{SOURCE10} ext/testbm.cmake 'c4_download_remote_proj\(c4fs' '\)$'
+%{SOURCE10} ext/testbm.cmake 'c4_add_library\(c4fs' '\)$'
+%{SOURCE10} ext/testbm.cmake 'ryml_testbm_link_with_c4core\(c4fs' '\)$'
+
+# Patch out download of c4log:
+%{SOURCE10} ext/testbm.cmake 'c4_download_remote_proj\(c4log' '\)$'
+%{SOURCE10} ext/testbm.cmake 'c4_add_library\(c4log' '\)$'
+%{SOURCE10} ext/testbm.cmake 'ryml_testbm_link_with_c4core\(c4log' '\)$'
+
+# Patch out download of yaml-test-suite:
+%{SOURCE10} test/CMakeLists.txt \
+ 'c4_download_remote_proj\(yaml-test-suite' '\)$'
+sed --regexp-extended --in-place \
+ 's@([[:blank:]]*)set\(tsdir.*\).*@&\nset\(suite_dir test/extern/yaml-test-suite\)\1@' \
+ 'test/CMakeLists.txt'
+mkdir --parents 'test/extern/'
%build
%cmake -B build \
diff --git a/653.patch b/653.patch
new file mode 100644
index 0000000..133713b
--- /dev/null
+++ b/653.patch
@@ -0,0 +1,327 @@
+From c86f9336abdc1672f674bed4909ea429d96ea8ee Mon Sep 17 00:00:00 2001
+From: Joao Paulo Magalhaes <dev at jpmag.me>
+Date: Thu, 30 Jul 2026 17:35:04 +0100
+Subject: [PATCH] cmake: fix tests with RYML_SYSTEM_C4CORE
+
+---
+ .github/workflows/install.yml | 64 +++++++++++++++++++++++++++++++++++
+ .github/workflows/install.ys | 61 +++++++++++++++++++++++++++++----
+ changelog/current.md | 1 +
+ ext/testbm.cmake | 28 +++++++++------
+ samples/custom_c4core/run.sh | 2 +-
+ test/CMakeLists.txt | 8 ++---
+ tools/CMakeLists.txt | 2 +-
+ 7 files changed, 143 insertions(+), 23 deletions(-)
+
+diff --git a/.github/workflows/install.yml b/.github/workflows/install.yml
+index f35aa5dcd..2a1e4b054 100644
+--- a/.github/workflows/install.yml
++++ b/.github/workflows/install.yml
+@@ -213,3 +213,67 @@ jobs:
+ run: |
+ cd $BDIR/test
+ ctest -C ${{matrix.bt}} --output-on-failure
++ sysc4core:
++ name: sysc4core/${{matrix.name}}
++ continue-on-error: false
++ runs-on: ${{matrix.os}}
++ strategy:
++ fail-fast: false
++ matrix:
++ include:
++ - name: gcc
++ os: ubuntu-24.04
++ gen: -DCMAKE_CXX_COMPILER=g++
++ bt: Debug
++ rel: lib/cmake/c4core
++ - name: clang
++ os: ubuntu-24.04
++ gen: -DCMAKE_CXX_COMPILER=clang++
++ bt: Debug
++ rel: lib/cmake/c4core
++ - name: xcode
++ os: macos-15-intel
++ gen: -G Xcode -DCMAKE_OSX_ARCHITECTURES=x86_64
++ bt: Debug
++ rel: lib/cmake/c4core
++ - name: vs2026
++ os: windows-latest
++ gen: -G 'Visual Studio 18 2026' -A x64
++ bt: Debug
++ rel: cmake
++ steps:
++ - name: checkout
++ uses: actions/checkout at v6
++ - name: checkout c4core
++ run: make -C ext c4core
++ - name: config c4core
++ run: |
++ cmake -S ext/c4core -B ext/c4core/build \
++ -D CMAKE_INSTALL_PREFIX=`pwd`/ext/c4core/install \
++ ${{matrix.gen}}
++ - name: build c4core
++ run: |
++ cmake --build ext/c4core/build --target c4core --parallel
++ - name: install c4core
++ run: |
++ cmake --build ext/c4core/build --target install
++ - name: '--------------------------------------'
++ run: echo
++ - name: configure ryml
++ run: |
++ cmake -S . -B build \
++ -D c4core_DIR=`pwd`/ext/c4core/install/${{matrix.rel}} \
++ -D RYML_SYSTEM_C4CORE=ON \
++ -D RYML_BUILD_TESTS=ON \
++ ${{matrix.gen}} \
++ -D CMAKE_BUILD_TYPE=${{matrix.bt}}
++ - name: build ryml
++ run: |
++ cmake --build build --target ryml --parallel --config ${{matrix.bt}}
++ - name: build tests
++ run: |
++ cmake --build build --target ryml-test-build --parallel --config ${{matrix.bt}}
++ - name: run tests
++ run: |
++ export CTEST_PARALLEL_LEVEL=`nproc`
++ cmake --build build --target ryml-test-run --config ${{matrix.bt}}
+diff --git a/.github/workflows/install.ys b/.github/workflows/install.ys
+index c0552af5e..305eba91e 100644
+--- a/.github/workflows/install.ys
++++ b/.github/workflows/install.ys
+@@ -11,6 +11,8 @@ env:
+ NUM_JOBS_BUILD: # 4
+
+ jobs:
++
++ #---------------------------
+ install_tests:
+ if: |
+ (!contains(github.event.head_commit.message, 'skip all')) ||
+@@ -19,32 +21,26 @@ jobs:
+ name: ${{matrix.name}}/${{matrix.bt}}
+ continue-on-error: true
+ runs-on: ${{matrix.os}}
+-
+ strategy:
+ fail-fast: false
+ matrix:
+ include:
+-
+ - {name: find_package/linux, sdir: test/test_install, os: ubuntu-24.04, cxx: g++-16, gen: -DCMAKE_CXX_COMPILER=g++-16, tgt: all, bt: Debug, vars: -Dryml_DIR=$GITHUB_WORKSPACE/$PDIR/lib/cmake/ryml -DRYML_TEST_INSTALL_PACKAGE_MODE=ON}
+ - {name: find_package/linux/libcxx, sdir: test/test_install, os: ubuntu-24.04, cxx: clang++-18, gen: -DCMAKE_CXX_COMPILER=clang++-18, tgt: all, bt: Debug, vars: -Dryml_DIR=$GITHUB_WORKSPACE/$PDIR/lib/cmake/ryml -DRYML_TEST_INSTALL_PACKAGE_MODE=ON, commonvars: -DRYML_USE_LIBCXX=ON}
+ - {name: find_package/macos, sdir: test/test_install, os: macos-15-intel, cxx: xcode, gen: -G Xcode -DCMAKE_OSX_ARCHITECTURES=x86_64, tgt: ALL_BUILD, bt: Debug, vars: -Dryml_DIR=$GITHUB_WORKSPACE/$PDIR/lib/cmake/ryml -DRYML_TEST_INSTALL_PACKAGE_MODE=ON}
+ - {name: find_package/win, sdir: test/test_install, os: windows-latest, cxx: vs2026, gen: -G 'Visual Studio 18 2026' -A x64, tgt: ALL_BUILD, bt: Debug, vars: -Dryml_DIR=$GITHUB_WORKSPACE/$PDIR/cmake -DRYML_TEST_INSTALL_PACKAGE_MODE=ON}
+-
+ - {name: find_library/linux, sdir: test/test_install, os: ubuntu-24.04, cxx: g++-16, gen: -DCMAKE_CXX_COMPILER=g++-16, tgt: all, bt: Debug, vars: -DCMAKE_PREFIX_PATH=$GITHUB_WORKSPACE/$PDIR -DRYML_TEST_INSTALL_PACKAGE_MODE=OFF}
+ - {name: find_library/linux/libcxx, sdir: test/test_install, os: ubuntu-24.04, cxx: clang++-18, gen: -DCMAKE_CXX_COMPILER=clang++-18, tgt: all, bt: Debug, vars: -DCMAKE_PREFIX_PATH=$GITHUB_WORKSPACE/$PDIR -DRYML_TEST_INSTALL_PACKAGE_MODE=OFF, commonvars: -DRYML_USE_LIBCXX=ON}
+ - {name: find_library/macos, sdir: test/test_install, os: macos-15-intel, cxx: xcode, gen: -G Xcode -DCMAKE_OSX_ARCHITECTURES=x86_64, tgt: ALL_BUILD, bt: Debug, vars: -DCMAKE_PREFIX_PATH=$GITHUB_WORKSPACE/$PDIR -DRYML_TEST_INSTALL_PACKAGE_MODE=OFF}
+ - {name: find_library/win, sdir: test/test_install, os: windows-latest, cxx: vs2026, gen: -G 'Visual Studio 18 2026' -A x64, tgt: ALL_BUILD, bt: Debug, vars: -DCMAKE_PREFIX_PATH=$GITHUB_WORKSPACE/$PDIR -DRYML_TEST_INSTALL_PACKAGE_MODE=OFF}
+-
+ - {name: singleheader/linux, sdir: test/test_singleheader, os: ubuntu-24.04, cxx: g++-16, gen: -DCMAKE_CXX_COMPILER=g++-16, tgt: all, bt: Debug}
+ - {name: singleheader/linux/libcxx, sdir: test/test_singleheader, os: ubuntu-24.04, cxx: clang++-18, gen: -DCMAKE_CXX_COMPILER=clang++-18, tgt: all, bt: Debug, commonvars: -DRYML_USE_LIBCXX=ON}
+ - {name: singleheader/macos, sdir: test/test_singleheader, os: macos-15-intel, cxx: xcode, gen: -G Xcode -DCMAKE_OSX_ARCHITECTURES=x86_64, tgt: ALL_BUILD, bt: Debug}
+ - {name: singleheader/win, sdir: test/test_singleheader, os: windows-latest, cxx: vs2026, gen: -G 'Visual Studio 18 2026' -A x64, tgt: ALL_BUILD, bt: Debug}
+-
+ - {name: singlesource/linux, sdir: test/test_singlesource, os: ubuntu-24.04, cxx: g++-16, gen: -DCMAKE_CXX_COMPILER=g++-16, tgt: all, bt: Debug}
+ - {name: singlesource/linux/libcxx, sdir: test/test_singlesource, os: ubuntu-24.04, cxx: clang++-18, gen: -DCMAKE_CXX_COMPILER=clang++-18, tgt: all, bt: Debug, commonvars: -DRYML_USE_LIBCXX=ON}
+ - {name: singlesource/macos, sdir: test/test_singlesource, os: macos-15-intel, cxx: xcode, gen: -G Xcode -DCMAKE_OSX_ARCHITECTURES=x86_64, tgt: ALL_BUILD, bt: Debug}
+ - {name: singlesource/win, sdir: test/test_singlesource, os: windows-latest, cxx: vs2026, gen: -G 'Visual Studio 18 2026' -A x64, tgt: ALL_BUILD, bt: Debug}
+-
+ env:
+ CXX_: ${{matrix.cxx}}
+ BT: ${{matrix.bt}}
+@@ -52,7 +48,6 @@ jobs:
+ BDIR: build/${{matrix.name}}-${{matrix.bt}}
+ IDIR: install/${{matrix.name}}-${{matrix.bt}}
+ PDIR: prefix/${{matrix.name}}-${{matrix.bt}}
+-
+ steps:
+ - name: checkout
+ uses: actions/checkout at v6
+@@ -101,3 +96,55 @@ jobs:
+ run: |
+ cd $BDIR/test
+ ctest -C ${{matrix.bt}} --output-on-failure
++
++
++ #---------------------------
++ sysc4core:
++ name: sysc4core/${{matrix.name}}
++ continue-on-error: false
++ runs-on: ${{matrix.os}}
++ strategy:
++ fail-fast: false
++ matrix:
++ include:
++ - {name: gcc, os: ubuntu-24.04, gen: -DCMAKE_CXX_COMPILER=g++, bt: Debug, rel: lib/cmake/c4core }
++ - {name: clang, os: ubuntu-24.04, gen: -DCMAKE_CXX_COMPILER=clang++, bt: Debug, rel: lib/cmake/c4core }
++ - {name: xcode, os: macos-15-intel, gen: -G Xcode -DCMAKE_OSX_ARCHITECTURES=x86_64, bt: Debug, rel: lib/cmake/c4core }
++ - {name: vs2026, os: windows-latest, gen: -G 'Visual Studio 18 2026' -A x64, bt: Debug, rel: cmake }
++ steps:
++ - name: checkout
++ uses: actions/checkout at v6
++ - name: checkout c4core
++ run: make -C ext c4core
++ - name: config c4core
++ run: |
++ cmake -S ext/c4core -B ext/c4core/build \
++ -D CMAKE_INSTALL_PREFIX=`pwd`/ext/c4core/install \
++ ${{matrix.gen}}
++ - name: build c4core
++ run: |
++ cmake --build ext/c4core/build --target c4core --parallel
++ - name: install c4core
++ run: |
++ cmake --build ext/c4core/build --target install
++ - name: "--------------------------------------"
++ run: echo
++ - name: configure ryml
++ run: |
++ cmake -S . -B build \
++ -D c4core_DIR=`pwd`/ext/c4core/install/${{matrix.rel}} \
++ -D RYML_SYSTEM_C4CORE=ON \
++ -D RYML_BUILD_TESTS=ON \
++ ${{matrix.gen}} \
++ -D CMAKE_BUILD_TYPE=${{matrix.bt}}
++ - name: build ryml
++ run: |
++ cmake --build build --target ryml --parallel --config ${{matrix.bt}}
++ - name: build tests
++ run: |
++ cmake --build build --target ryml-test-build --parallel --config ${{matrix.bt}}
++ - name: run tests
++ run: |
++ export CTEST_PARALLEL_LEVEL=`nproc`
++ cmake --build build --target ryml-test-run --config ${{matrix.bt}}
++
+diff --git a/changelog/current.md b/changelog/current.md
+index e69de29bb..759aabc0e 100644
+--- a/changelog/current.md
++++ b/changelog/current.md
+@@ -0,0 +1 @@
++- [PR#653](https://github.com/biojppm/rapidyaml/pull/653) cmake: fix tests with RYML_SYSTEM_C4CORE (fixes [#651](https://github.com/biojppm/rapidyaml/issues/651))
+diff --git a/ext/testbm.cmake b/ext/testbm.cmake
+index 6622f7dcb..096396513 100644
+--- a/ext/testbm.cmake
++++ b/ext/testbm.cmake
+@@ -1,5 +1,21 @@
+ # these are used both for testing and benchmarking
+
++function(ryml_testbm_link_with_c4core target)
++ if(RYML_SYSTEM_C4CORE)
++ target_link_libraries(${target} PUBLIC c4core::c4core)
++ elseif(NOT RYML_STANDALONE)
++ target_link_libraries(${target} PUBLIC c4core)
++ else() # RYML_STANDALONE
++ target_link_libraries(${target} PUBLIC ryml) # link with ryml to get c4core
++ ryml_add_c4core_dev_to_target(${target})
++ target_include_directories(${target} PUBLIC
++ ${CMAKE_CURRENT_LIST_DIR}/c4core.src
++ ${CMAKE_CURRENT_LIST_DIR}/c4core.dev
++ )
++ endif()
++endfunction()
++
++
+ set(C4FS_DIR ${CMAKE_CURRENT_BINARY_DIR}/subprojects/c4fs)
+ c4_download_remote_proj(c4fs C4FS_DIR
+ GIT_REPOSITORY https://github.com/biojppm/c4fs
+@@ -9,15 +25,11 @@ c4_add_library(c4fs LIBRARY_TYPE STATIC
+ ${C4FS_DIR}/src/c4/fs/fs.hpp
+ ${C4FS_DIR}/src/c4/fs/fs.cpp
+ INC_DIRS
+- ${CMAKE_CURRENT_LIST_DIR}/c4core.src
+- ${CMAKE_CURRENT_LIST_DIR}/c4core.dev
+ ${C4FS_DIR}/src
+- LIBS
+- ryml # link with ryml to get c4core
+ FOLDER
+ ext
+ )
+-ryml_add_c4core_dev_to_target(c4fs)
++ryml_testbm_link_with_c4core(c4fs)
+ if(WIN32 AND BUILD_SHARED_LIBS)
+ target_compile_definitions(c4fs PUBLIC C4FS_SHARED
+ $<BUILD_INTERFACE:C4FS_EXPORTS>
+@@ -34,15 +46,11 @@ c4_add_library(c4log
+ ${C4LOG_DIR}/src/c4/log/log.hpp
+ ${C4LOG_DIR}/src/c4/log/log.cpp
+ INC_DIRS
+- ${CMAKE_CURRENT_LIST_DIR}/c4core.src
+- ${CMAKE_CURRENT_LIST_DIR}/c4core.dev
+ ${C4LOG_DIR}/src
+- LIBS
+- ryml # link with ryml to get c4core
+ FOLDER
+ ext
+ )
+-ryml_add_c4core_dev_to_target(c4log)
++ryml_testbm_link_with_c4core(c4log)
+ if(WIN32 AND BUILD_SHARED_LIBS)
+ target_compile_definitions(c4log PUBLIC C4LOG_SHARED
+ $<BUILD_INTERFACE:C4LOG_EXPORTS>
+diff --git a/samples/custom_c4core/run.sh b/samples/custom_c4core/run.sh
+index 0e6e03583..813625912 100755
+--- a/samples/custom_c4core/run.sh
++++ b/samples/custom_c4core/run.sh
+@@ -17,7 +17,7 @@ if [ "$c4core_tag" == "." ] || [ -z "$c4core_tag" ] ; then
+ c4core_tag=$(cat ../../ext/c4core.mk \
+ | grep C4CORE_TAG \
+ | grep = \
+- | sed 's/.*=\s*\([0-9a-fA-F]*\)/\1/g')
++ | sed 's/.*=\s*\(.*\)/\1/g')
+ fi
+
+ # make sure to run from where this file is
+diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
+index 845eb6229..579545ab3 100644
+--- a/test/CMakeLists.txt
++++ b/test/CMakeLists.txt
+@@ -114,7 +114,7 @@ c4_add_library(ryml-_testlib LIBRARY_TYPE STATIC
+ LIBS ryml c4fs gtest
+ FOLDER test)
+ ryml_setup_test_target_props(ryml-_testlib)
+-ryml_add_c4core_dev_to_target(ryml-_testlib)
++ryml_testbm_link_with_c4core(ryml-_testlib)
+ c4_add_library(ryml-_testmain LIBRARY_TYPE OBJECT
+ SOURCES test_lib/test_main.cpp test_lib/test_main.hpp
+ LIBS ryml
+@@ -128,7 +128,7 @@ function(ryml_add_test test_name)
+ SOURCES test_${test_name}.cpp
+ LIBS ryml-_testlib ryml-_testmain
+ FOLDER test)
+- ryml_add_c4core_dev_to_target(${t})
++ ryml_testbm_link_with_c4core(${t})
+ if(RYML_SAVE_TEST_YAML)
+ target_sources(${t} PRIVATE test_lib/test_save.cpp)
+ endif()
+@@ -147,7 +147,7 @@ c4_add_library(ryml-_testgroup LIBRARY_TYPE STATIC
+ LIBS ryml ryml-_testlib c4fs
+ FOLDER test)
+ ryml_setup_test_target_props(ryml-_testgroup)
+-ryml_add_c4core_dev_to_target(ryml-_testgroup)
++ryml_testbm_link_with_c4core(ryml-_testgroup)
+ function(ryml_add_test_case_group name)
+ ryml_add_test(${name} ${ARGN})
+ target_link_libraries(ryml-test-${name} PUBLIC ryml-_testgroup)
+@@ -399,7 +399,7 @@ if(RYML_TEST_SUITE)
+ LIBS ryml-_testlib ryml-_testmain c4log
+ INC_DIRS ${CMAKE_CURRENT_LIST_DIR}/../src_extra
+ FOLDER test)
+- ryml_add_c4core_dev_to_target(ryml-test-suite)
++ ryml_testbm_link_with_c4core(ryml-test-suite)
+ add_dependencies(ryml-test-build ryml-test-suite)
+
+ ryml_get_target_exe(ryml-test-suite tgt)
+diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt
+index 9a3c3b277..126485e2c 100644
+--- a/tools/CMakeLists.txt
++++ b/tools/CMakeLists.txt
+@@ -6,5 +6,5 @@ c4_add_executable(ryml-parse-emit
+ INC_DIRS ../test
+ LIBS ryml c4fs
+ FOLDER tools)
+-ryml_add_c4core_dev_to_target(ryml-parse-emit)
++ryml_testbm_link_with_c4core(ryml-parse-emit)
+ ryml_maybe_dump_test_yaml(ryml-parse-emit)
diff --git a/662.patch b/662.patch
new file mode 100644
index 0000000..8f9e13d
--- /dev/null
+++ b/662.patch
@@ -0,0 +1,27 @@
+From b4d80b0e89bde09ec7d6333777fcf17405a532bd Mon Sep 17 00:00:00 2001
+From: "Benjamin A. Beasley" <code at musicinmybrain.net>
+Date: Sat, 5 Sep 2026 08:01:18 +0100
+Subject: [PATCH] Fix `c4_install_exports` call with system `c4core`
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+Fixes #659. Based on a suggestion by Sébastien Noel (@twolife) in a
+comment on that issue.
+---
+ CMakeLists.txt | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/CMakeLists.txt b/CMakeLists.txt
+index 285dc9937..b482a75ea 100644
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -200,7 +200,7 @@ endif()
+
+ if(RYML_INSTALL)
+ c4_install_target(ryml)
+- if(RYML_STANDALONE OR RYML_SYSTEM_C4CORE)
++ if(RYML_STANDALONE AND NOT RYML_SYSTEM_C4CORE)
+ c4_install_exports()
+ else()
+ c4_install_exports(DEPENDENCIES c4core)
diff --git a/patch-no-download b/patch-no-download
new file mode 100755
index 0000000..395e4c3
--- /dev/null
+++ b/patch-no-download
@@ -0,0 +1,91 @@
+#!/usr/bin/python3
+from argparse import ArgumentParser, FileType
+from enum import Enum, auto
+from os import fstat, utime
+from re import compile
+from shutil import copyfileobj
+from sys import stdout
+from tempfile import TemporaryFile
+
+
+class State(Enum):
+ SEARCH = auto()
+ SKIP = auto()
+ DUMP = auto()
+
+
+parser = ArgumentParser(
+ description="Patch out a c4project-style dependency download"
+)
+parser.add_argument(
+ "sourcefile",
+ metavar="SOURCEFILE",
+ type=FileType("r+"),
+ help="Path to the source file on which to operate",
+)
+parser.add_argument(
+ "first",
+ metavar="PATTERN",
+ type=compile,
+ help=(
+ "A Python regular expression matching the first line of the block "
+ "to be patched out"
+ ),
+)
+parser.add_argument(
+ "last",
+ metavar="PATTERN",
+ type=compile,
+ help=(
+ "A Python regular expression matching the first line of the block "
+ "to be patched out"
+ ),
+)
+args = parser.parse_args()
+
+with (
+ args.sourcefile as before,
+ TemporaryFile(mode="w+") as after,
+ TemporaryFile(mode="w+") as skipped,
+):
+ st = fstat(before.fileno())
+ times = st.st_atime_ns, st.st_mtime_ns
+ state = State.SEARCH
+ n = 0
+ for line in before:
+ if state == State.SEARCH:
+ if args.first.search(line) is None:
+ after.write(line)
+ continue
+ state = State.SKIP
+ if state == State.SKIP:
+ skipped.write(line)
+ n += 1
+ if args.last.search(line) is not None:
+ state = State.DUMP
+ continue
+ if state == State.DUMP:
+ after.write(line)
+ if state == State.SEARCH:
+ raise SystemExit(
+ f"No match for {args.first.pattern!r} in {before.name}"
+ )
+ elif state == State.SKIP:
+ raise SystemExit(
+ (
+ f"No match for {args.last.pattern!r} after "
+ f"{args.first.pattern!r} in {before.name}"
+ )
+ )
+ skipped.seek(0)
+ after.seek(0)
+ before.seek(0)
+ before.truncate()
+ copyfileobj(after, before)
+ print(f"Patched out {n} line{'' if n == 1 else 's'} in {before.name}:")
+ bar = "=" * 78
+ print(bar)
+ copyfileobj(skipped, stdout)
+ print(bar)
+
+utime(args.sourcefile.name, ns=times)
================================================================
---- gitweb:
http://git.pld-linux.org/gitweb.cgi/packages/rapidyaml.git/commitdiff/9c29a45ccc1e5d768d1253df37aeb8b4076255ee
More information about the pld-cvs-commit
mailing list