Skip to content

Instantly share code, notes, and snippets.

@sbinet
Last active January 24, 2017 15:06
Show Gist options
  • Save sbinet/cfa02fa3700e5eba7b42ad4613212b6b to your computer and use it in GitHub Desktop.
Save sbinet/cfa02fa3700e5eba7b42ad4613212b6b to your computer and use it in GitHub Desktop.
package main
import (
"flag"
"fmt"
"io/ioutil"
"log"
"os"
"os/exec"
"path/filepath"
"strings"
)
const dir = "gonum.org/v1"
var (
verbose = flag.Bool("v", false, "enable verbose output")
filter = flag.Bool("filter-branch", false, "enable filter-branch (rewrites history)")
)
func main() {
flag.Parse()
var err error
err = os.RemoveAll("./gonum.org")
if err != nil {
log.Fatal(err)
}
err = os.MkdirAll(dir, 0755)
if err != nil {
log.Fatal(err)
}
run("git", "init")
err = ioutil.WriteFile(filepath.Join(dir, "LICENSE"), []byte(LICENSE), 0644)
if err != nil {
log.Fatal(err)
}
run("git", "add", "LICENSE")
run("git", "commit", "-m", "gonum: add LICENSE")
for _, n := range repos {
pkg := "github.com/gonum/" + n
fmt.Printf("slurping %v...\n", pkg)
run("git", "clone", "-q", "git://"+pkg, "../"+n)
if *filter {
cmd := exec.Command("git", "filter-branch", "--index-filter", fmt.Sprintf(`
git ls-files -s | sed "s,\t,&"%s"/," |
GIT_INDEX_FILE=$GIT_INDEX_FILE.new git update-index --index-info &&
mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE
`, n),
"HEAD",
)
cmd.Dir = filepath.Join(dir, "../"+n)
if *verbose {
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
}
err = cmd.Run()
if err != nil {
log.Fatal(err)
}
}
run(
"git", "subtree", "add", "-q",
"-m", n+": import from "+pkg,
"--prefix="+n,
"../"+n,
"master",
)
err = os.RemoveAll(filepath.Join(dir, "../"+n))
if err != nil {
log.Fatal(err)
}
}
fmt.Printf("removing cgo-wrappers...\n")
run("git", "rm", "-fr", "lapack/cgo")
run("git", "rm", "-fr", "blas/cgo")
run("git", "rm", "-fr", "blas/cblas64")
run("git", "rm", "-fr", "blas/cblas128")
run("git", "rm", "-fr", "matrix/mat64/cblas_test.go")
fmt.Printf("updating import paths...\n")
for _, n := range repos {
run(
"find", ".", "-type", "f", "-exec", "sed", "-i", "-e",
"s|github.com/gonum/"+n+"|"+dir+"/"+n+"|g",
"{}", ";",
)
}
run("goimports", "-w", ".")
fmt.Printf("commiting everything...\n")
run("git", "commit", "-am", "all: migrate to "+dir)
fmt.Printf("make sure everything compiles...\n")
run("go", "get", "./...")
}
func run(cmd string, args ...string) {
exe := exec.Command(cmd, args...)
exe.Dir = "./" + dir
if *verbose {
exe.Stdout = os.Stdout
exe.Stderr = os.Stderr
fmt.Printf("## %s\n", strings.Join(exe.Args, " "))
}
err := exe.Run()
if err != nil {
log.Fatalf("command %q failed: %v\n", strings.Join(exe.Args, " "), err)
}
}
var repos = []string{
"blas",
"diff",
"floats",
"graph",
//"hdf5", // cgo-based: discard
"integrate",
"internal",
"lapack",
"mathext",
"matrix",
"optimize",
"stat",
"unit",
}
const LICENSE = `Copyright ©2013 The gonum Authors. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the gonum project nor the names of its authors and
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
`
$> go run ./mig-gonum.go
slurping github.com/gonum/blas...
slurping github.com/gonum/diff...
slurping github.com/gonum/floats...
slurping github.com/gonum/graph...
slurping github.com/gonum/integrate...
slurping github.com/gonum/internal...
slurping github.com/gonum/lapack...
slurping github.com/gonum/mathext...
slurping github.com/gonum/matrix...
slurping github.com/gonum/optimize...
slurping github.com/gonum/stat...
slurping github.com/gonum/unit...
removing cgo-wrappers...
updating import paths...
commiting everything...
make sure everything compiles...
$> (cd gonum.org/v1/; ls; go get ./...)
blas diff floats graph integrate internal lapack LICENSE mathext matrix optimize stat unit
$> tree -d gonum.org/
gonum.org/
└── v1
├── blas
│   ├── blas32
│   ├── blas64
│   ├── native
│   │   └── internal
│   │   └── math32
│   └── testblas
│   └── benchautogen
├── diff
│   └── fd
├── floats
├── graph
│   ├── community
│   ├── encoding
│   │   └── dot
│   ├── ex
│   │   └── fdpclust
│   ├── graphs
│   │   └── gen
│   ├── internal
│   │   ├── linear
│   │   ├── ordered
│   │   └── set
│   ├── network
│   ├── path
│   │   ├── dynamic
│   │   └── internal
│   │   └── testgraphs
│   ├── simple
│   ├── topo
│   └── traverse
├── integrate
│   └── quad
│   └── internal
├── internal
│   ├── asm
│   │   ├── c128
│   │   ├── c64
│   │   ├── f32
│   │   └── f64
│   └── binding
├── lapack
│   ├── internal
│   │   └── testdata
│   │   ├── dlahr2test
│   │   ├── dlaqr5test
│   │   ├── dlasqtest
│   │   ├── dsterftest
│   │   └── netlib
│   ├── lapack64
│   ├── native
│   └── testlapack
│   └── testdata
├── mathext
│   └── internal
│   ├── amos
│   │   └── amoslib
│   ├── cephes
│   └── gonum
├── matrix
│   ├── cmat128
│   ├── conv
│   └── mat64
├── optimize
│   ├── convex
│   │   └── lp
│   └── functions
├── stat
│   ├── combin
│   ├── distmat
│   ├── distmv
│   ├── distuv
│   ├── samplemv
│   └── sampleuv
└── unit
└── autogen
77 directories
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment