unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
blob 7554b76171ae2e919bdb147bb8fbc854d1bc6aa6 4888 bytes (raw)
name: guix/build/kconfig.scm 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
 
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2020 Stefan <stefan-guix@vodafonemail.de>
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

(define-module (guix build kconfig)
  #:use-module  (ice-9 rdelim)
  #:use-module  (srfi srfi-1)
  #:use-module  (srfi srfi-26)
  #:export (modify-defconfig))

;; Commentary:
;;
;; Builder-side code to modify configurations for the Kconfig build system as
;; used by Linux and U-Boot.
;;
;; Code:

(define (modify-defconfig defconfig configs)
  "This function can modify a given DEFCONFIG file by adding, changing or
removing the list of strings in CONFIGS.  This allows an easy customization of
Kconfig based projects like the kernel Linux or the bootloader 'Das U-Boot'.

These are examples for CONFIGS to add (or change) and remove
configurations to/from DEFCONFIG:

'(\"CONFIG_A=\\\"a\\\"\"
  \"CONFIG_B=0\"
  \"CONFIG_C=y\"
  \"CONFIG_D=m\"
  \"CONFIG_E=\"
  \"CONFIG_F\")"

  (define (config-string->pair config-string)
    "Parse a config-string like \"CONFIG_NET=y\" into a key-value pair.
Spaces get trimmed.
\"CONFIG_EXAMPLE=y\"  -> '(\"CONFIG_EXAMPLE\" . \"y\")
\"CONFIG_EXAMPLE=\\\"\\\"\" -> '(\"CONFIG_EXAMPLE\" . \"\").
\"CONFIG_EXAMPLE=\"  -> '(\"CONFIG_EXAMPLE\" . #f).
\"CONFIG_EXAMPLE\"   -> '(\"CONFIG_EXAMPLE\" . #f)."
    (let ((pair (map string-trim-both (string-split config-string #\=))))
      (case (length pair)
        ((2)
         (cons (string-append (first pair))
               (if (string-null? (second pair))
                   #f
                   (second pair))))
        (else (cons (first pair) #f)))))

  (define (pair->config-string pair)
    "Convert a PAIR back to a config-string."
    (let* ((key (car pair))
           (value (cdr pair)))
      (if value
          (string-append key "=" value)
          key)))

  (define (disable-pair pair blacklist)
    "Turn the key of a key-value PAIR into an disabled key, if listed in
BLACKLIST."
    (let* ((key (car pair)))
      (if (member key blacklist)
          (cons (string-append "# disabled " key)
                (cdr pair))
          pair)))

  (define (disable-config-string config-string blacklist)
    "Turn the CONFIG-STRING into a disabled one, if listed in BLACKLIST."
    (pair->config-string (disable-pair (config-string->pair config-string)
                                       blacklist)))

  (define (unset-pair pair)
    "Turn the key of a key-value PAIR into an unset key, if its value is #f."
    (let* ((key (car pair))
           (value (cdr pair)))
      (if value
          pair
          (cons (string-append "# unset " key) value))))

  (define (unset-config-string config-string)
    "Turn the CONFIG-STRING into a proper unset one, if there is no assignment"
    (pair->config-string (unset-pair (config-string->pair config-string))))

  (define (write-modified-lines input modify-line)
    "Write all lines from the INPUT after applying MODIFY-LINE to the
 current-output-port."
    (let loop ((line (read-line input)))
      (when (not (eof-object? line))
        (display (modify-line line))
        (newline)
        (loop (read-line input)))))

  (let* ((modified-defconfig (string-append defconfig ".mod"))
         ;; Generate a blacklist of config keys from configs.
         (blacklist (map (lambda (config-string)
                           (first (config-string->pair config-string)))
                         configs))
         (disable-config-string (cut disable-config-string <> blacklist)))
    ;; Write to modified-defconfig file first the configs, and second
    ;; the content of the defconfig file with disabled lines.
    (call-with-output-file modified-defconfig
      (lambda (output)
        (with-output-to-port output
          (lambda ()
            (call-with-input-string (string-join configs "\n")
              (lambda (input)
                (write-modified-lines input unset-config-string)))
            (false-if-exception
              (call-with-input-file defconfig
                (lambda (input)
                  (write-modified-lines input disable-config-string))))))))
    ;; Ensure the modified-defconfig file is used.
    (false-if-exception (delete-file defconfig))
    (rename-file modified-defconfig defconfig)))

debug log:

solving 7554b76171 ...
found 7554b76171 in https://yhetil.org/guix-patches/8DAC4983-25B2-4919-89F2-F08B5C781EC1@vodafonemail.de/

applying [1/1] https://yhetil.org/guix-patches/8DAC4983-25B2-4919-89F2-F08B5C781EC1@vodafonemail.de/
diff --git a/guix/build/kconfig.scm b/guix/build/kconfig.scm
new file mode 100644
index 0000000000..7554b76171

Checking patch guix/build/kconfig.scm...
Applied patch guix/build/kconfig.scm cleanly.

index at:
100644 7554b76171ae2e919bdb147bb8fbc854d1bc6aa6	guix/build/kconfig.scm

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).