renpy-build-system.scm 4.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. (define* (install #:key inputs outputs game (output "out") #:allow-other-keys)
  40. (let* ((out (assoc-ref outputs output))
  41. (json-dump (call-with-input-file (string-append game
  42. "/renpy-build.json")
  43. read-json))
  44. (build (assoc-ref json-dump "build"))
  45. (executable-name (assoc-ref build "executable_name"))
  46. (directory-name (assoc-ref build "directory_name")))
  47. (let ((launcher (string-append out "/bin/" executable-name))
  48. (data (string-append out "/share/renpy/" directory-name)))
  49. (mkdir-p (string-append out "/bin"))
  50. (copy-recursively game data)
  51. ;; We don't actually want the metadata to be dumped in the output
  52. ;; directory
  53. (delete-file (string-append data "/renpy-build.json"))
  54. (call-with-output-file launcher
  55. (lambda (port)
  56. (format port "#!~a~%~a ~s \"$@\""
  57. (search-input-file inputs "/bin/sh")
  58. (search-input-file inputs "/bin/renpy")
  59. data)))
  60. (chmod launcher #o755))))
  61. (define* (install-desktop-file #:key inputs outputs game (output "out")
  62. #:allow-other-keys)
  63. (let* ((out (assoc-ref outputs output))
  64. (json-dump (call-with-input-file (string-append game
  65. "/renpy-build.json")
  66. read-json))
  67. (build (assoc-ref json-dump "build"))
  68. (directory-name (assoc-ref build "directory_name"))
  69. (executable-name (assoc-ref build "executable_name")))
  70. (make-desktop-entry-file
  71. (string-append out "/share/applications/" executable-name ".desktop")
  72. #:name (assoc-ref json-dump "name")
  73. #:generic-name (assoc-ref build "display_name")
  74. #:exec (format #f "~a ~s"
  75. (search-input-file inputs "/bin/renpy")
  76. (string-append out "/share/renpy/" directory-name))
  77. #:categories '("Game" "Visual Novel"))))
  78. (define %standard-phases
  79. (modify-phases gnu:%standard-phases
  80. (add-after 'unpack 'enable-bytecode-determinism
  81. (assoc-ref python:%standard-phases 'enable-bytecode-determinism))
  82. (delete 'bootstrap)
  83. (delete 'configure)
  84. (replace 'build build)
  85. (delete 'check)
  86. (replace 'install install)
  87. (add-after 'install 'install-desktop-file install-desktop-file)))
  88. (define* (renpy-build #:key inputs (phases %standard-phases)
  89. #:allow-other-keys #:rest args)
  90. "Build the given Ren'py package, applying all of PHASES in order."
  91. (apply gnu:gnu-build #:inputs inputs #:phases phases args))