~ruther/guix-local

c149fc769c65fce67d46a6c77fdfd6e269824cb0 — Sharlatan Hellseher 1 year, 5 months ago 1e4a22c
build-system/go: Add skip-build? option key.

Golang project's root may miss any .go files which makes build phase to
fail with error similar to:

    no Go files in /tmp/<...>/src/golang.org/x/mod

This change implements a SKIP-BUILD? key parameter which is, by default,
set to #f to invoke build procedure. It is taken from cargo-build-system

* guix/build-system/go.scm (go-build, go-cross-build): Add "skip-build?"
key parameter.
* guix/build/go-build-system.scm (build): Add "skip-build?" key
parameter and implement logic.

Change-Id: I3f41414868a7329cbe99324106427cdae4884d94
2 files changed, 21 insertions(+), 12 deletions(-)

M guix/build-system/go.scm
M guix/build/go-build-system.scm
M guix/build-system/go.scm => guix/build-system/go.scm +4 -0
@@ 203,6 203,7 @@ commit hash and its date rather than a proper release tag."
                   (import-path "")
                   (unpack-path "")
                   (build-flags ''())
                   (skip-build? #f)
                   (tests? #t)
                   (test-flags ''())
                   (test-subdirs ''("..."))


@@ 238,6 239,7 @@ commit hash and its date rather than a proper release tag."
                    #:import-path #$import-path
                    #:unpack-path #$unpack-path
                    #:build-flags #$build-flags
                    #:skip-build? #$skip-build?
                    #:tests? #$tests?
                    #:test-flags #$test-flags
                    #:test-subdirs #$test-subdirs


@@ 264,6 266,7 @@ commit hash and its date rather than a proper release tag."
                         (import-path "")
                         (unpack-path "")
                         (build-flags ''())
                         (skip-build? #f)
                         (tests? #f)              ; nothing can be done
                         (test-flags ''())
                         (test-subdirs ''("..."))


@@ 317,6 320,7 @@ commit hash and its date rather than a proper release tag."
                    #:import-path #$import-path
                    #:unpack-path #$unpack-path
                    #:build-flags #$build-flags
                    #:skip-build? #$skip-build?
                    #:tests? #$tests?
                    #:test-flags #$test-flags
                    #:test-subdirs #$test-subdirs

M guix/build/go-build-system.scm => guix/build/go-build-system.scm +17 -12
@@ 289,6 289,7 @@ unpacking."

(define* (build #:key
                build-flags
                skip-build?
                import-path
                (parallel-build? #t)
                (verbosity 1)


@@ 311,19 312,23 @@ unpacking."
    (setenv "GOMAXPROCS" (number->string njobs)))

  (with-throw-handler
    #t
      #t
    (lambda _
      (apply invoke "go" "install"
             ;; Respectively, strip the symbol table and debug information,
             ;; and the DWARF symbol table.
             "-ldflags=-s -w"
             ;; Remove all file system paths from the resulting executable.
             ;; Instead of absolute file system paths, the recorded file names
             ;; will begin either a module path@version (when using modules),
             ;; or a plain import path (when using the standard library, or
             ;; GOPATH).
             "-trimpath"
             `(,@build-flags ,import-path)))
      (if skip-build?
          (begin
            (format #t "Build is skipped, no go files in project's root.~%")
            #t)
          (apply invoke "go" "install"
                 ;; Respectively, strip the symbol table and debug
                 ;; information, and the DWARF symbol table.
                 "-ldflags=-s -w"
                 ;; Remove all file system paths from the resulting
                 ;; executable.  Instead of absolute file system paths, the
                 ;; recorded file names will begin either a module
                 ;; path@version (when using modules), or a plain import path
                 ;; (when using the standard library, or GOPATH).
                 "-trimpath"
                 `(,@build-flags ,import-path))))

    (lambda (key . args)
      (display (string-append "Building '" import-path "' failed.\n"