123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- (define-module (guix build-system go)
- #:use-module (guix utils)
- #:use-module (guix gexp)
- #:use-module (guix store)
- #:use-module (guix monads)
- #:use-module (guix search-paths)
- #:use-module (guix build-system)
- #:use-module (guix build-system gnu)
- #:use-module (guix packages)
- #:use-module (ice-9 match)
- #:use-module (ice-9 regex)
- #:export (%go-build-system-modules
- go-build
- go-build-system
- go-pseudo-version?
- go-version->git-ref))
- (define %go-pseudo-version-rx
-
-
- (make-regexp (string-append
- "([0-9]{14}-)"
- "([0-9A-Fa-f]{12})"
- "(\\+incompatible)?$")))
- (define (go-version->git-ref version)
- "Parse VERSION, a \"pseudo-version\" as defined at
- <https://golang.org/ref/mod#pseudo-versions>, and extract the commit hash from
- it, defaulting to full VERSION (stripped from the \"+incompatible\" suffix if
- present) if a pseudo-version pattern is not recognized."
-
-
-
-
-
- (let* ((version
-
-
-
-
-
- (if (string-suffix? "+incompatible" version)
- (string-drop-right version 13)
- version))
- (match (regexp-exec %go-pseudo-version-rx version)))
- (if match
- (match:substring match 2)
- version)))
- (define (go-pseudo-version? version)
- "True if VERSION is a Go pseudo-version, i.e., a version string made of a
- commit hash and its date rather than a proper release tag."
- (regexp-exec %go-pseudo-version-rx version))
- (define %go-build-system-modules
-
- `((guix build go-build-system)
- (guix build union)
- ,@%gnu-build-system-modules))
- (define (default-go)
-
- (let ((go (resolve-interface '(gnu packages golang))))
- (module-ref go 'go)))
- (define* (lower name
- #:key source inputs native-inputs outputs system target
- (go (default-go))
- #:allow-other-keys
- #:rest arguments)
- "Return a bag for NAME."
- (define private-keywords
- '(#:target #:go #:inputs #:native-inputs))
- (and (not target)
- (bag
- (name name)
- (system system)
- (host-inputs `(,@(if source
- `(("source" ,source))
- '())
- ,@inputs
- ;; Keep the standard inputs of 'gnu-build-system'.
- ,@(standard-packages)))
- (build-inputs `(("go" ,go)
- ,@native-inputs))
- (outputs outputs)
- (build go-build)
- (arguments (strip-keyword-arguments private-keywords arguments)))))
- (define* (go-build name inputs
- #:key
- source
- (phases '%standard-phases)
- (outputs '("out"))
- (search-paths '())
- (install-source? #t)
- (import-path "")
- (unpack-path "")
- (build-flags ''())
- (tests? #t)
- (allow-go-reference? #f)
- (system (%current-system))
- (guile #f)
- (imported-modules %go-build-system-modules)
- (modules '((guix build go-build-system)
- (guix build union)
- (guix build utils))))
- (define builder
- (with-imported-modules imported-modules
- #~(begin
- (use-modules #$@modules)
- (go-build #:name #$name
- #:source #+source
- #:system #$system
- #:phases #$phases
- #:outputs #$(outputs->gexp outputs)
- #:search-paths '#$(sexp->gexp
- (map search-path-specification->sexp
- search-paths))
- #:install-source? #$install-source?
- #:import-path #$import-path
- #:unpack-path #$unpack-path
- #:build-flags #$build-flags
- #:tests? #$tests?
- #:allow-go-reference? #$allow-go-reference?
- #:inputs #$(input-tuples->gexp inputs)))))
- (mlet %store-monad ((guile (package->derivation (or guile (default-guile))
- system #:graft? #f)))
- (gexp->derivation name builder
- #:system system
- #:guile-for-build guile)))
- (define go-build-system
- (build-system
- (name 'go)
- (description
- "Build system for Go programs")
- (lower lower)))
|