Created
June 19, 2015 21:53
-
-
Save dcarney/ffb1bc29d90ebbed1c5c to your computer and use it in GitHub Desktop.
Vendors a set of go dependencies using 'gb-vendor', by reading the gb vendor manifest from another project.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// aids in moving deps from one gb project to another gb project: | |
// | |
// reads a gb vendor/manifest and uses the 'gb-vendor' plugin to vendor the | |
// same revision of each dependency into another gb-based project. | |
// | |
// Example: | |
// To vendor all the dependencies of the project at /go/src/github.com/username/foo | |
// into the new project at /path/to/gb/proj, run the following: | |
// | |
// $ go run gb2gb.go -src-manifest=/go/src/github.com/username/foo/vendor/manifest -dest=/path/to/gb/proj | |
// | |
package main | |
import ( | |
"encoding/json" | |
"flag" | |
"fmt" | |
"io/ioutil" | |
"os/exec" | |
) | |
var ( | |
gbSrcManifest string | |
gbDest string | |
) | |
type Dep struct { | |
ImportPath string `json:"importpath"` | |
Revision string `json:"revision"` | |
Repo string `json:"repository"` | |
} | |
func main() { | |
flag.StringVar(&gbSrcManifest, "src-manifest", "", "the path to the gb manifest to copy from") | |
flag.StringVar(&gbDest, "dest", "", "the project root for the gb project to copy to") | |
flag.Parse() | |
file, err := ioutil.ReadFile(gbSrcManifest) | |
if err != nil { | |
panic(err) | |
} | |
var manifest struct { | |
Deps []Dep `json:"dependencies"` | |
} | |
if err := json.Unmarshal(file, &manifest); err != nil { | |
panic(err) | |
} | |
for _, dep := range manifest.Deps { | |
fmt.Printf("vendoring pkg %s, rev %s...\n", dep.ImportPath, dep.Revision) | |
cmd := exec.Command("gb", "vendor", "fetch", "--revision", dep.Revision, dep.ImportPath) | |
cmd.Dir = gbDest | |
byts, err := cmd.CombinedOutput() | |
if err != nil { | |
fmt.Printf("ERROR: %s\n", string(byts)) | |
// don't panic or exit; just keep going if the dep was already vendored | |
} | |
fmt.Println(string(byts)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment