Subject: bug#56322: [PATCH] gnu: ruby: regenerate parse.c

From: Remco van 't Veer <[email-masked]>
Date: Thu, 25 Aug 2022 12:45:10 +0200

* gnu/packages/ruby.scm (baseruby, ruby-2.7): Use bootstrap baseruby to regenerate parse.c
---
 gnu/packages/ruby.scm | 30 ++++++++++++++++++++++++++++--
 1 file changed, 28 insertions(+), 2 deletions(-)

diff --git a/gnu/packages/ruby.scm b/gnu/packages/ruby.scm
index e98814da6d..8de6cda257 100644
--- a/gnu/packages/ruby.scm
+++ b/gnu/packages/ruby.scm
@@ -161,7 +161,16 @@ (define-public ruby-2.7
                                   version ".tar.gz"))
               (sha256
                (base32
-                "0nxwkxh7snmjqf787qsp4i33mxd1rbf9yzyfiky5k230i680jhrh"))))
+                "0nxwkxh7snmjqf787qsp4i33mxd1rbf9yzyfiky5k230i680jhrh"))
+              (snippet `(begin
+                          ;; Remove bundled libffi
+                          (delete-file-recursively "ext/fiddle/libffi-3.2.1")
+                          ;; Trigger bootstap
+                          (delete-file "configure")
+                          (delete-file "aclocal.m4")
+                          ;; Trigger rebuild of parse.c from parse.y
+                          (delete-file "parse.c")
+                          #t))))
     (arguments
      `(#:test-target "test"
        #:configure-flags '("--enable-shared") ;dynamic linking
@@ -181,7 +190,24 @@ (define-public ruby-2.7
                                      "test/ruby/test_system.rb"
                                      "tool/rbinstall.rb")
                         (("/bin/sh")
-                         (which "sh"))) #t)))))))
+                         (which "sh"))) #t)))))
+    (native-inputs (list autoconf automake baseruby bison))))
+
+(define baseruby ;; used to build ruby by parser generator
+  (package
+    (inherit ruby-2.7)
+    (name "baseruby")
+    (source (origin
+              (inherit (package-source ruby-2.7))
+              ;; override snippet to not include deletion of bundled parse.c
+              (snippet `(begin
+                          ;; Remove bundled libffi
+                          (delete-file-recursively "ext/fiddle/libffi-3.2.1")
+                          ;; Trigger bootstap
+                          (delete-file "configure")
+                          (delete-file "aclocal.m4")
+                          #t))))
+    (native-inputs (list autoconf automake))))
 
 (define-public ruby-3.0
   (package
-- 
2.37.2