trivial.scm 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2012, 2013, 2014, 2018 Ludovic Courtès <ludo@gnu.org>
  3. ;;;
  4. ;;; This file is part of GNU Guix.
  5. ;;;
  6. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  7. ;;; under the terms of the GNU General Public License as published by
  8. ;;; the Free Software Foundation; either version 3 of the License, or (at
  9. ;;; your option) any later version.
  10. ;;;
  11. ;;; GNU Guix is distributed in the hope that it will be useful, but
  12. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;;; GNU General Public License for more details.
  15. ;;;
  16. ;;; You should have received a copy of the GNU General Public License
  17. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  18. (define-module (guix build-system trivial)
  19. #:use-module (guix store)
  20. #:use-module (guix utils)
  21. #:use-module (guix derivations)
  22. #:use-module (guix packages)
  23. #:use-module (guix build-system)
  24. #:use-module (ice-9 match)
  25. #:export (trivial-build-system))
  26. (define (guile-for-build store guile system)
  27. (match guile
  28. ((? package?)
  29. (package-derivation store guile system #:graft? #f))
  30. (#f ; the default
  31. (let* ((distro (resolve-interface '(gnu packages commencement)))
  32. (guile (module-ref distro 'guile-final)))
  33. (package-derivation store guile system #:graft? #f)))))
  34. (define* (lower name
  35. #:key source inputs native-inputs outputs system target
  36. guile builder modules allowed-references)
  37. "Return a bag for NAME."
  38. (bag
  39. (name name)
  40. (system system)
  41. (target target)
  42. (host-inputs `(,@(if source
  43. `(("source" ,source))
  44. '())
  45. ,@inputs))
  46. (build-inputs native-inputs)
  47. (outputs outputs)
  48. (build (if target trivial-cross-build trivial-build))
  49. (arguments `(#:guile ,guile
  50. #:builder ,builder
  51. #:modules ,modules
  52. #:allowed-references ,allowed-references))))
  53. (define* (trivial-build store name inputs
  54. #:key
  55. outputs guile system builder (modules '())
  56. search-paths allowed-references)
  57. "Run build expression BUILDER, an expression, for SYSTEM. SOURCE is
  58. ignored."
  59. (define canonicalize-reference
  60. (match-lambda
  61. ((? package? p)
  62. (derivation->output-path (package-derivation store p system
  63. #:graft? #f)))
  64. (((? package? p) output)
  65. (derivation->output-path (package-derivation store p system
  66. #:graft? #f)
  67. output))
  68. ((? string? output)
  69. output)))
  70. (build-expression->derivation store name builder
  71. #:inputs inputs
  72. #:system system
  73. #:outputs outputs
  74. #:modules modules
  75. #:allowed-references
  76. (and allowed-references
  77. (map canonicalize-reference
  78. allowed-references))
  79. #:guile-for-build
  80. (guile-for-build store guile system)))
  81. (define* (trivial-cross-build store name
  82. #:key
  83. target native-drvs target-drvs
  84. outputs guile system builder (modules '())
  85. search-paths native-search-paths
  86. allowed-references)
  87. "Run build expression BUILDER, an expression, for SYSTEM. SOURCE is
  88. ignored."
  89. (define canonicalize-reference
  90. (match-lambda
  91. ((? package? p)
  92. (derivation->output-path (package-cross-derivation store p system)))
  93. (((? package? p) output)
  94. (derivation->output-path (package-cross-derivation store p system)
  95. output))
  96. ((? string? output)
  97. output)))
  98. (build-expression->derivation store name builder
  99. #:inputs (append native-drvs target-drvs)
  100. #:system system
  101. #:outputs outputs
  102. #:modules modules
  103. #:allowed-references
  104. (and allowed-references
  105. (map canonicalize-reference
  106. allowed-references))
  107. #:guile-for-build
  108. (guile-for-build store guile system)))
  109. (define trivial-build-system
  110. (build-system
  111. (name 'trivial)
  112. (description
  113. "Trivial build system, to run arbitrary Scheme build expressions")
  114. (lower lower)))