Skip to content

Commit

Permalink
Merge e543da6 into f3ee1f4
Browse files Browse the repository at this point in the history
  • Loading branch information
kortschak committed Mar 14, 2019
2 parents f3ee1f4 + e543da6 commit 74042d9
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 10 deletions.
27 changes: 22 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ language: go

# Versions of go that are explicitly supported by gonum.
go:
- 1.9.x
- 1.10.x
- 1.12.x
- 1.11.x
- 1.10.x
- master

go_import_path: gonum.org/v1/netlib
Expand All @@ -16,14 +16,24 @@ os:
- osx

env:
matrix:
global:
- GO111MODULE=on
matrix:
- BLAS_LIB=OpenBLAS
# Does not currently link correctly. Note that there is an issue with drotgm in ATLAS.
# - BLAS_LIB=ATLAS
# If we can get multiarch builds on travis.
# There are some issues with the Accellerate implementation.
#- BLAS_LIB=Accellerate

cache:
directories:
- $HOME/.cache/go-build
- $HOME/gopath/pkg/mod

git:
depth: 1

matrix:
fast_finish: true
allow_failures:
Expand All @@ -39,6 +49,8 @@ matrix:
env: BLAS_LIB=OpenBLAS

before_install:
# Required for code get checks.
- go get -u gonum.org/v1/gonum/...
# Required for imports check.
- go get gonum.org/v1/tools/cmd/check-imports
# Required for copyright header check.
Expand All @@ -56,7 +68,12 @@ install:
script:
- ${TRAVIS_BUILD_DIR}/.travis/check-imports.sh
- ${TRAVIS_BUILD_DIR}/.travis/check-copyright.sh
- ${TRAVIS_BUILD_DIR}/.travis/check-generate.sh
- go list -m gonum.org/v1/gonum || true
- pwd
- cat ./blas/netlib/generate_errors.go
- GO111MODULE=off go build ./blas/netlib/generate_errors.go
- ./generate_errors
- git reset --hard
- source ${TRAVIS_BUILD_DIR}/.travis/$TRAVIS_OS_NAME/$BLAS_LIB/test.sh
- test -z "$(gofmt -d .)"
# This is run last since it alters the tree.
- ${TRAVIS_BUILD_DIR}/.travis/check-generate.sh
31 changes: 29 additions & 2 deletions blas/netlib/generate_blas.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import (
"go/format"
"io/ioutil"
"log"
"os"
"os/exec"
"path/filepath"
"strings"
"text/template"

Expand All @@ -25,7 +28,8 @@ import (

const (
header = "cblas.h"
documentation = "../../../gonum/blas/gonum"
srcModule = "gonum.org/v1/gonum"
documentation = "blas/gonum"
target = "blas.go"

typ = "Implementation"
Expand Down Expand Up @@ -132,7 +136,7 @@ func main() {
}
var docs map[string]map[string][]*ast.Comment
if cribDocs {
docs, err = binding.DocComments(documentation)
docs, err = binding.DocComments(pathTo(srcModule, documentation))
if err != nil {
log.Fatal(err)
}
Expand Down Expand Up @@ -802,6 +806,29 @@ func ldToPanicString(ld string) string {
}
}

// pathTo returns the path to package within the given module. If running
// in module mode, this will look within the module in $GOPATH/pkg/mod
// at the correct version, otherwise it will find the version installed
// at $GOPATH/src/module/pkg.
func pathTo(module, pkg string) string {
gopath, ok := os.LookupEnv("GOPATH")
if !ok {
panic("no $GOPATH")
}

cmd := exec.Command("go", "list", "-m", module)
var buf, stderr bytes.Buffer
cmd.Stdout = &buf
cmd.Stderr = &stderr
err := cmd.Run()
if err != nil {
log.Printf("module aware go list failed with stderr output %q: %v", stderr.String(), err)
return filepath.Join(gopath, "src", module, pkg)
}
version := strings.TrimSpace(strings.Join(strings.Split(buf.String(), " "), "@"))
return filepath.Join(gopath, "pkg", "mod", version, pkg)
}

const handwritten = `// Code generated by "go generate gonum.org/v1/netlib/blas/netlib" from {{.}}; DO NOT EDIT.
// Copyright ©2014 The Gonum Authors. All rights reserved.
Expand Down
36 changes: 33 additions & 3 deletions lapack/netlib/generate_errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,29 @@
package main

import (
"bytes"
"errors"
"fmt"
"go/ast"
"go/parser"
"go/printer"
"go/token"
"log"
"os"
"os/exec"
"path/filepath"
"strings"
)

const errorFile = "../../../gonum/lapack/gonum/errors.go"
const (
srcModule = "gonum.org/v1/gonum"
errorFile = "lapack/gonum/errors.go"
)

func main() {
path, err := filepath.Abs(errorFile)
path, err := pathTo(srcModule, errorFile)
if err != nil {
log.Fatalf("no absolute path for %q: %v", errorFile, err)
log.Fatalf("no GOPATH for %q: %v", errorFile, err)
}

fset := token.NewFileSet()
Expand Down Expand Up @@ -60,6 +67,29 @@ func main() {
fmt.Fprintln(o)
}

// pathTo returns the path to file within the given module. If running
// in module mode, this will look within the module in $GOPATH/pkg/mod
// at the correct version, otherwise it will find the version installed
// at $GOPATH/src/module/file.
func pathTo(module, file string) (string, error) {
gopath, ok := os.LookupEnv("GOPATH")
if !ok {
return "", errors.New("no $GOPATH")
}

cmd := exec.Command("go", "list", "-m", module)
var buf, stderr bytes.Buffer
cmd.Stdout = &buf
cmd.Stderr = &stderr
err := cmd.Run()
if err != nil {
log.Printf("module aware go list failed with stderr output %q: %v", stderr.String(), err)
return filepath.Join(gopath, "src", module, file), nil
}
version := strings.TrimSpace(strings.Join(strings.Split(buf.String(), " "), "@"))
return filepath.Join(gopath, "pkg", "mod", version, file), nil
}

const (
header = `// Code generated by "go generate gonum.org/v1/netlib/lapack/netlib”; DO NOT EDIT.
`
Expand Down

0 comments on commit 74042d9

Please sign in to comment.