Skip to content
This repository was archived by the owner on Aug 26, 2021. It is now read-only.

Commit 32c22d1

Browse files
committed
Updated dep
1 parent 9a6b350 commit 32c22d1

File tree

5 files changed

+20
-40
lines changed

5 files changed

+20
-40
lines changed

cmd/go2nix/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func main() {
2424
log.Fatalf("Couldn't load Go package: %v", err)
2525
}
2626

27-
deps, err := solver.Dependencies(goPkg)
27+
deps, err := solver.Dependencies(goPkg, gopath.GoPath())
2828
if err != nil {
2929
log.Fatalf("Couldn't solve package dependencies: %v", err)
3030
}

dep/solver.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,21 @@ package dep
22

33
import (
44
"fmt"
5+
"os"
56

67
"github.com/golang/dep"
7-
"github.com/golang/dep/gps"
88

99
"github.com/kamilchm/go2nix"
1010
)
1111

1212
type Solver struct{}
1313

14-
func (s *Solver) Dependencies(pkg go2nix.GoPackage) ([]go2nix.GoPackage, error) {
15-
ctx, err := dep.NewContext()
14+
func (s *Solver) Dependencies(pkg go2nix.GoPackage, goPath string) ([]go2nix.GoPackage, error) {
15+
wd, err := os.Getwd()
16+
if err != nil {
17+
return nil, fmt.Errorf("Couldn't get working dir: %v", err)
18+
}
19+
ctx, err := dep.NewContext(wd, []string{"GOPATH=" + goPath}, nil)
1620
if err != nil {
1721
return nil, fmt.Errorf("Couldn't create Go dep context: %v", err)
1822
}
@@ -22,19 +26,19 @@ func (s *Solver) Dependencies(pkg go2nix.GoPackage) ([]go2nix.GoPackage, error)
2226
return nil, fmt.Errorf("Couldn't load Go project: %v", err)
2327
}
2428

25-
return convertDeps(project.Lock.Projects()), nil
29+
return convertDeps(project), nil
2630
}
2731

28-
func convertDeps(gpsDeps []gps.LockedProject) (deps []go2nix.GoPackage) {
29-
for _, p := range gpsDeps {
32+
func convertDeps(depProject *dep.Project) (deps []go2nix.GoPackage) {
33+
for _, p := range depProject.Lock.Projects() {
3034
pkg := go2nix.GoPackage{
3135
Name: go2nix.ImportPath(p.Ident().ProjectRoot),
3236
Version: p.Version().String(),
3337
}
3438

35-
if v, ok := p.Version().(gps.PairedVersion); ok {
36-
pkg.Revision = v.Underlying().String()
37-
}
39+
//if v, ok := p.Version().(gps.PairedVersion); ok {
40+
// pkg.Revision = v.Underlying().String()
41+
//}
3842

3943
deps = append(deps, pkg)
4044
}

dep/solver_test.go

Lines changed: 0 additions & 28 deletions
This file was deleted.

go2nix.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ type NixPackage struct {
1818
}
1919

2020
type DepSolver interface {
21-
Dependencies(GoPackage) ([]GoPackage, error)
21+
Dependencies(GoPackage, string) ([]GoPackage, error)
2222
}
2323

2424
type PackageLoader interface {

gopath/package_loader.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
type PackageLoader struct{}
1313

1414
func (l *PackageLoader) Package(dir string) (go2nix.GoPackage, error) {
15-
goPath := os.Getenv("GOPATH")
15+
goPath := GoPath()
1616
if goPath == "" {
1717
return go2nix.GoPackage{}, fmt.Errorf("No GOPATH set, couldn't discover Go package")
1818
}
@@ -32,3 +32,7 @@ func (l *PackageLoader) Package(dir string) (go2nix.GoPackage, error) {
3232
return go2nix.GoPackage{}, fmt.Errorf("Current dir %v is outside of GOPATH(%v). "+
3333
"Couldn't get current package name", dir, goPath)
3434
}
35+
36+
func GoPath() string {
37+
return os.Getenv("GOPATH")
38+
}

0 commit comments

Comments
 (0)