func buildCabinet(repo *graph.Repository, id string) error { // Build the cabinet data head, err := repo.Head() if err != nil { return fmt.Errorf("build: get repo head: %s", err) } data := &CabFile{ Repo: repo.String(), Created: time.Now(), Head: head, } deps, err := Deps.RepoDeps(repo) if err != nil { return fmt.Errorf("build: scan dependencies: %s", err) } for _, dep := range deps { rv, err := NewRepoVersion(dep) if err != nil { return fmt.Errorf("build: %s", err) } data.Deps = append(data.Deps, rv) } if *cabTest { // Test the packages in the repository test := exec.Command("go", "test", repo.String()) test.Dir = os.TempDir() test.Stdout = os.Stdout test.Stderr = os.Stderr if err := test.Run(); err != nil { return fmt.Errorf("build: `go test` failed: %s", err) } } // Make the $REPO/.rx directory repoRx := filepath.Join(repo.Root, ".rx") if err := os.MkdirAll(repoRx, 0755); err != nil { return fmt.Errorf("build: create .rx: %s", err) } filename := filepath.Join(repoRx, "cabinet-"+id) // Open the file, but fail if it already exists file, err := os.OpenFile(filename, os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0644) if err != nil { return fmt.Errorf("build: open cabinet: %s", err) } defer file.Close() if err := gob.NewEncoder(file).Encode(data); err != nil { return fmt.Errorf("build: encoding cabinet: %s", err) } log.Printf("Cabinet written to %q", filename) return nil }
// NewRepoVersion creates a repo version object suitable for storing into cabinets, etc. func NewRepoVersion(repo *graph.Repository) (*RepoVersion, error) { head, err := repo.Head() if err != nil { return nil, fmt.Errorf("get %s head: %s", repo, err) } return &RepoVersion{ Pattern: repo.String(), Packages: repo.Packages, Head: head, }, nil }