OLD | NEW |
1 // Copyright 2016 The LUCI Authors. All rights reserved. | 1 // Copyright 2016 The LUCI Authors. All rights reserved. |
2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
4 | 4 |
5 package main | 5 package main |
6 | 6 |
7 import ( | 7 import ( |
8 "strings" | 8 "strings" |
9 | 9 |
10 "github.com/luci/luci-go/common/errors" | 10 "github.com/luci/luci-go/common/errors" |
(...skipping 18 matching lines...) Expand all Loading... |
29 dirs := make(map[string]struct{}) | 29 dirs := make(map[string]struct{}) |
30 build := make(map[string]string) | 30 build := make(map[string]string) |
31 for _, src := range comp.sources { | 31 for _, src := range comp.sources { |
32 if src.InitResult == nil { | 32 if src.InitResult == nil { |
33 continue | 33 continue |
34 } | 34 } |
35 | 35 |
36 for _, gopath := range src.InitResult.GoPath { | 36 for _, gopath := range src.InitResult.GoPath { |
37 // Make sure our Go package isn't a directory. | 37 // Make sure our Go package isn't a directory. |
38 if _, ok := dirs[gopath.GoPackage]; ok { | 38 if _, ok := dirs[gopath.GoPackage]; ok { |
39 » » » » return errors.Reason("GOPATH %(package)q is both
a package and directory"). | 39 » » » » return errors.Reason("GOPATH %q is both a packag
e and directory", gopath.GoPackage).Err() |
40 » » » » » D("package", gopath.GoPackage).Err() | |
41 } | 40 } |
42 | 41 |
43 // Check intermediate paths to make sure there isn't a d
eployment | 42 // Check intermediate paths to make sure there isn't a d
eployment |
44 // conflict. | 43 // conflict. |
45 pkgParts := splitGoPackage(gopath.GoPackage) | 44 pkgParts := splitGoPackage(gopath.GoPackage) |
46 for _, parentPkg := range pkgParts[:len(pkgParts)-1] { | 45 for _, parentPkg := range pkgParts[:len(pkgParts)-1] { |
47 if _, ok := build[parentPkg]; ok { | 46 if _, ok := build[parentPkg]; ok { |
48 » » » » » return errors.Reason("GOPATH %(package)q
is both a package and directory"). | 47 » » » » » return errors.Reason("GOPATH %q is both
a package and directory", parentPkg).Err() |
49 » » » » » » D("package", parentPkg).Err() | |
50 } | 48 } |
51 dirs[parentPkg] = struct{}{} | 49 dirs[parentPkg] = struct{}{} |
52 } | 50 } |
53 | 51 |
54 // Everything checks out, add this link. | 52 // Everything checks out, add this link. |
55 build[gopath.GoPackage] = src.pathTo(gopath.Path, "") | 53 build[gopath.GoPackage] = src.pathTo(gopath.Path, "") |
56 } | 54 } |
57 } | 55 } |
58 | 56 |
59 srcDir, err := root.EnsureDirectory("src") | 57 srcDir, err := root.EnsureDirectory("src") |
60 if err != nil { | 58 if err != nil { |
61 return err | 59 return err |
62 } | 60 } |
63 | 61 |
64 for pkg, src := range build { | 62 for pkg, src := range build { |
65 var ( | 63 var ( |
66 pkgComponents = strings.Split(pkg, "/") | 64 pkgComponents = strings.Split(pkg, "/") |
67 d = srcDir | 65 d = srcDir |
68 ) | 66 ) |
69 for _, comp := range pkgComponents[:len(pkgComponents)-1] { | 67 for _, comp := range pkgComponents[:len(pkgComponents)-1] { |
70 var err error | 68 var err error |
71 d, err = d.EnsureDirectory(comp) | 69 d, err = d.EnsureDirectory(comp) |
72 if err != nil { | 70 if err != nil { |
73 » » » » return errors.Annotate(err).Reason("could not cr
eate GOPATH parent directory [%(path)s]"). | 71 » » » » return errors.Annotate(err, "could not create GO
PATH parent directory [%s]", d).Err() |
74 » » » » » D("path", d).Err() | |
75 } | 72 } |
76 } | 73 } |
77 link := d.File(pkgComponents[len(pkgComponents)-1]) | 74 link := d.File(pkgComponents[len(pkgComponents)-1]) |
78 if err := link.SymlinkFrom(src, true); err != nil { | 75 if err := link.SymlinkFrom(src, true); err != nil { |
79 » » » return errors.Annotate(err).Reason("failed to create GOP
ATH link").Err() | 76 » » » return errors.Annotate(err, "failed to create GOPATH lin
k").Err() |
80 } | 77 } |
81 } | 78 } |
82 return nil | 79 return nil |
83 } | 80 } |
OLD | NEW |