Subject: [PATCH vREVISION] gnu: Add redo-apenwarr.

From: Massimo Zaniboni <[email-masked]>
Date: Thu, 16 May 2024 23:01:16 +0200

* gnu/packages/build-tools.scm (redo-apenwarr): New variable.

Change-Id: Ied142a7dc3e9baf9babdeff046f350e647a7a5cc
---
 gnu/packages/build-tools.scm | 115 +++++++++++++++++++++++++++++++++++
 1 file changed, 115 insertions(+)

diff --git a/gnu/packages/build-tools.scm b/gnu/packages/build-tools.scm
index daaf450e70..5f575c8aff 100644
--- a/gnu/packages/build-tools.scm
+++ b/gnu/packages/build-tools.scm
@@ -15,6 +15,7 @@
 ;;; Copyright © 2021 qblade <[email-masked]>
 ;;; Copyright © 2021, 2023 Maxim Cournoyer <[email-masked]>
 ;;; Copyright © 2022, 2023 Juliana Sims <[email-masked]>
+;;; Copyright © 2024 Massimo Zaniboni <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -464,6 +465,120 @@ (define-public premake5
 scripted definition of a software project and outputs @file{Makefile}s or
 other lower-level build files.")))
 
+(define-public redo-apenwarr
+  (let ((origin-url "https://github.com/apenwarr/redo")
+        (origin-date "2021-07-27 20:48:36 -0700")
+        (origin-version "0.42d")
+        (origin-commit "7f00abc36be15f398fa3ecf9f4e5283509c34a00"))
+    (package
+      (name "redo-apenwarr")
+      (version origin-version)
+      (source
+       (origin
+         (method git-fetch)
+         (uri (git-reference
+               (url origin-url)
+               (commit (string-append "redo-" version))))
+         (file-name (git-file-name name version))
+         (sha256
+          (base32 "0z78fmkb85k9hnpvh0pgi8cahljjgnr6j7mb614cykvpa3xsyl0p"))))
+      (build-system gnu-build-system)
+      (arguments
+       (list
+        #:test-target "test"
+        #:make-flags #~(list (string-append "DESTDIR="
+                                            #$output) "PREFIX=/")
+        #:phases #~(modify-phases %standard-phases
+                     (delete 'configure)
+                     (add-before 'build 'patch-shell-scripts
+                       (lambda _
+                         ;; The building tool queries the Git repository,
+                         ;; for retrieving info about the commit hash and date,
+                         ;; but this information is not anymore present in the
+                         ;; source code downloaded from Guix.
+                         ;; So this information will be generated manually here,
+                         ;; using the data specified in the `origin-*' params.
+                         (substitute* '("redo/version/gitvars.pre")
+                           (("\\$Format:%H\\$")
+                            #$origin-commit)
+                           (("\\$Format:%d\\$")
+                            (format #f "(HEAD -> main, tag: redo-~a)"
+                                    #$origin-version))
+                           (("\\$Format:%ci\\$")
+                            #$origin-date))
+
+                         ;; redo-apenwarr can generate support scripts having
+                         ;; shebangs headers. We will patch these scripts
+                         ;; for using the `sh' in the store.
+                         (substitute* '("bin/default.do"
+                                        "t/203-make/whichmake.do"
+                                        "redo/py.do"
+                                        "redoconf/link.od"
+                                        "redoconf/run.od"
+                                        "redoconf/link-shlib.od"
+                                        "redoconf/_compile.od"
+                                        "redoconf/compile.od"
+                                        "minimal/do")
+                           (("#!/bin/sh")
+                            (string-append "#!"
+                                           #$(file-append bash "/bin/sh"))))
+
+                         ;; Use `pwd' on the store.
+                         (substitute* '("t/all.do" "t/105-sympath/all.do"
+                                        "t/110-compile/hello.o.do"
+                                        "minimal/do" "minimal/do.test" "do")
+                           (("/bin/pwd")
+                            #$(file-append coreutils "/bin/pwd"))
+                           (("/bin/ls")
+                            #$(file-append coreutils "/bin/ls")))
+
+                         ;; Use `perl' on the store.
+                         (substitute* '("t/200-shell/nonshelltest.do")
+                           (("/usr/bin/env perl")
+                            #$(file-append perl "/bin/perl")))
+
+                         ;; Use `gcc' compiler, because Guix has no default `cc' compiler.
+                         (substitute* '("docs/cookbook/hello/hello.do"
+                                        "t/110-compile/LD.do"
+                                        "t/110-compile/CC.do"
+                                        "t/110-compile/yellow.o.do"
+                                        "t/111-example/CC.do"
+                                        "t/111-example/hello.do")
+                           (("^([ \t]*)cc " dummy starting-spaces)
+                            (string-append starting-spaces
+                                           #$(file-append gcc "/bin/gcc") " ")))
+
+                         (substitute* '("t/110-compile/all.do"
+                                        "t/111-example/all.do")
+                           ((" type cc ")
+                            " type gcc "))
+
+                         (substitute* '("docs/cookbook/c/flagtest.o.od")
+                           (("^CC=\"\\$CC\"")
+                            (string-append "CC=\""
+                                           #$(file-append gcc "/bin/gcc") "\""))))))))
+      (inputs (list coreutils bash python-wrapper))
+      (native-inputs (list ;Used from the building script,
+                           ;; for checking the existences of coreutils on the path.
+                           which
+
+                           ;; Required only for the tests.
+                           perl
+                           git
+                           gcc))
+      (synopsis
+       "Build tool where dependencies are parts of the building instructions")
+      (description
+       "@code{redo-apenwarr} is a build tool where each target file is produced by
+a normal shell script, but with additional commands for specifying
+its dependencies.  In tools like @code{make}, dependencies are specified
+upfront (i.e. bottom-up), while in @code{redo-apenwarr} they are
+generated dynamically during build script execution (i.e. top-down).
+Rebuilds are incremental, i.e. only target files with changed dependencies
+will be rebuilt.")
+      (home-page "https://github.com/apenwarr/redo")
+      (license license:asl2.0))))
+
 (define-public scons
   (package
     (name "scons")

base-commit: 5a624adfd7b14c3717237d137bd0766c77f0f570
-- 
2.41.0