renpy-build-system.scm 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2021 Liliana Marie Prikler <liliana.prikler@gmail.com>
  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 renpy-build-system)
  19. #:use-module ((guix build gnu-build-system) #:prefix gnu:)
  20. #:use-module ((guix build python-build-system) #:prefix python:)
  21. #:use-module (guix build json)
  22. #:use-module (guix build utils)
  23. #:use-module (ice-9 match)
  24. #:use-module (ice-9 ftw)
  25. #:use-module (srfi srfi-1)
  26. #:use-module (srfi srfi-26)
  27. #:export (%standard-phases
  28. renpy-build))
  29. (define* (build #:key game #:allow-other-keys)
  30. (for-each make-file-writable
  31. (find-files game (lambda (pred stat)
  32. (eq? (stat:type stat) 'directory))))
  33. (invoke "renpy"
  34. "--json-dump" (string-append game "/renpy-build.json")
  35. game
  36. ;; should be "compile", but renpy wants to compile itself really
  37. ;; badly if we do
  38. "quit")
  39. #t)
  40. (define* (install #:key outputs game (output "out") #:allow-other-keys)
  41. (let* ((out (assoc-ref outputs output))
  42. (json-dump (call-with-input-file (string-append game
  43. "/renpy-build.json")
  44. read-json))
  45. (build (assoc-ref json-dump "build"))
  46. (executable-name (assoc-ref build "executable_name"))
  47. (directory-name (assoc-ref build "directory_name")))
  48. (let ((launcher (string-append out "/bin/" executable-name))
  49. (data (string-append out "/share/renpy/" directory-name)))
  50. (mkdir-p (string-append out "/bin"))
  51. (copy-recursively game data)
  52. ;; We don't actually want the metadata to be dumped in the output
  53. ;; directory
  54. (delete-file (string-append data "/renpy-build.json"))
  55. (call-with-output-file launcher
  56. (lambda (port)
  57. (format port "#!~a~%~a ~s \"$@\""
  58. (which "bash")
  59. (which "renpy")
  60. data)))
  61. (chmod launcher #o755)))
  62. #t)
  63. (define* (install-desktop-file #:key outputs game (output "out")
  64. #:allow-other-keys)
  65. (let* ((out (assoc-ref outputs output))
  66. (json-dump (call-with-input-file (string-append game
  67. "/renpy-build.json")
  68. read-json))
  69. (build (assoc-ref json-dump "build"))
  70. (directory-name (assoc-ref build "directory_name"))
  71. (executable-name (assoc-ref build "executable_name")))
  72. (make-desktop-entry-file
  73. (string-append out "/share/applications/" executable-name ".desktop")
  74. #:name (assoc-ref json-dump "name")
  75. #:generic-name (assoc-ref build "display_name")
  76. #:exec (format #f "~a ~s"
  77. (which "renpy")
  78. (string-append out "/share/renpy/" directory-name))
  79. #:categories '("Game" "Visual Novel")))
  80. #t)
  81. (define %standard-phases
  82. (modify-phases gnu:%standard-phases
  83. (add-after 'unpack 'enable-bytecode-determinism
  84. (assoc-ref python:%standard-phases 'enable-bytecode-determinism))
  85. (delete 'bootstrap)
  86. (delete 'configure)
  87. (replace 'build build)
  88. (delete 'check)
  89. (replace 'install install)
  90. (add-after 'install 'install-desktop-file install-desktop-file)))
  91. (define* (renpy-build #:key inputs (phases %standard-phases)
  92. #:allow-other-keys #:rest args)
  93. "Build the given Ren'py package, applying all of PHASES in order."
  94. (apply gnu:gnu-build #:inputs inputs #:phases phases args))