@@ -74,24 +74,20 @@ type upstream struct {
74
74
repoDeps []string // the repository paths of all dependencies (e.g. github.com/zyedidia/glob)
75
75
}
76
76
77
- func (u * upstream ) get (gopath , repo string ) error {
77
+ func (u * upstream ) get (gopath , repo , rev string ) error {
78
78
done := make (chan struct {})
79
79
defer close (done )
80
80
go progressSize ("go get" , filepath .Join (gopath , "src" ), done )
81
81
82
- // As per https://groups.google.com/forum/#!topic/golang-nuts/N5apfenE4m4,
83
- // the arguments to “go get” are packages, not repositories. Hence, we
84
- // specify “gopkg/...” in order to cover all packages.
85
- // As a concrete example, github.com/jacobsa/util is a repository we want
86
- // to package into a single Debian package, and using “go get -d
87
- // github.com/jacobsa/util” fails because there are no buildable go files
88
- // in the top level of that repository.
89
- cmd := exec .Command ("go" , "get" , "-d" , "-t" , repo + "/..." )
90
- cmd .Stderr = os .Stderr
91
- cmd .Env = append ([]string {
92
- fmt .Sprintf ("GOPATH=%s" , gopath ),
93
- }, passthroughEnv ()... )
94
- return cmd .Run ()
82
+ rr , err := vcs .RepoRootForImportPath (repo , false )
83
+ if err != nil {
84
+ return err
85
+ }
86
+ dir := filepath .Join (gopath , "src" , rr .Root )
87
+ if rev != "" {
88
+ return rr .VCS .CreateAtRev (dir , rr .Repo , rev )
89
+ }
90
+ return rr .VCS .Create (dir , rr .Repo )
95
91
}
96
92
97
93
func (u * upstream ) tar (gopath , repo string ) error {
@@ -158,7 +154,7 @@ func (u *upstream) findDependencies(gopath, repo string) error {
158
154
return fmt .Errorf ("%v: %v" , cmd .Args , err )
159
155
}
160
156
161
- var godependencies [] string
157
+ godependencies := make ( map [ string ] bool )
162
158
for _ , p := range strings .Split (strings .TrimSpace (string (out )), "\n " ) {
163
159
if p == "" {
164
160
continue // skip separators between import types
@@ -170,7 +166,7 @@ func (u *upstream) findDependencies(gopath, repo string) error {
170
166
if p == "C" {
171
167
// TODO: maybe parse the comments to figure out C deps from pkg-config files?
172
168
} else {
173
- godependencies = append ( godependencies , p )
169
+ godependencies [ p ] = true
174
170
}
175
171
}
176
172
@@ -179,10 +175,7 @@ func (u *upstream) findDependencies(gopath, repo string) error {
179
175
}
180
176
181
177
// Remove all packages which are in the standard lib.
182
- args := []string {"list" , "-f" , "{{.ImportPath}}: {{.Standard}}" }
183
- args = append (args , godependencies ... )
184
-
185
- cmd = exec .Command ("go" , args ... )
178
+ cmd = exec .Command ("go" , "list" , "std" )
186
179
cmd .Dir = filepath .Join (gopath , "src" , repo )
187
180
cmd .Stderr = os .Stderr
188
181
cmd .Env = append ([]string {
@@ -194,24 +187,24 @@ func (u *upstream) findDependencies(gopath, repo string) error {
194
187
return fmt .Errorf ("%v: %v" , cmd .Args , err )
195
188
}
196
189
197
- // dependencies is a map in order to de-duplicate multiple imports
198
- // pointing into the same repository.
199
- dependencies := make (map [string ]bool )
200
190
for _ , line := range strings .Split (strings .TrimSpace (string (out )), "\n " ) {
201
- if ! strings .HasSuffix (line , ": false" ) {
202
- continue
203
- }
204
- importpath := strings .TrimSuffix (line , ": false" )
205
- rr , err := vcs .RepoRootForImportPath (importpath , false )
191
+ delete (godependencies , line )
192
+ }
193
+
194
+ // Resolve all packages to the root of their repository.
195
+ roots := make (map [string ]bool )
196
+ for dep := range godependencies {
197
+ rr , err := vcs .RepoRootForImportPath (dep , false )
206
198
if err != nil {
207
- log .Printf ("Could not determine repo path for import path %q: %v\n " , importpath , err )
199
+ log .Printf ("Could not determine repo path for import path %q: %v\n " , dep , err )
208
200
}
209
- dependencies [rr .Root ] = true
201
+
202
+ roots [rr .Root ] = true
210
203
}
211
204
212
- u .repoDeps = make ([]string , 0 , len (dependencies ))
213
- for dep := range dependencies {
214
- u .repoDeps = append (u .repoDeps , dep )
205
+ u .repoDeps = make ([]string , 0 , len (godependencies ))
206
+ for root := range roots {
207
+ u .repoDeps = append (u .repoDeps , root )
215
208
}
216
209
217
210
return nil
@@ -228,7 +221,7 @@ func makeUpstreamSourceTarball(repo, revision string) (*upstream, error) {
228
221
var u upstream
229
222
230
223
log .Printf ("Downloading %q\n " , repo + "/..." )
231
- if err := u .get (gopath , repo ); err != nil {
224
+ if err := u .get (gopath , repo , revision ); err != nil {
232
225
return nil , err
233
226
}
234
227
@@ -237,18 +230,6 @@ func makeUpstreamSourceTarball(repo, revision string) (*upstream, error) {
237
230
return nil , fmt .Errorf ("Not a git repository, dh-make-golang currently only supports git" )
238
231
}
239
232
240
- if revision != "" {
241
- log .Printf ("Checking out git revision %q\n " , revision )
242
- if err := runGitCommandIn (repoDir , "reset" , "--hard" , revision ); err != nil {
243
- return nil , fmt .Errorf ("could not check out git revision %q: %v\n " , revision , err )
244
- }
245
-
246
- log .Printf ("Refreshing %q\n " , repo + "/..." )
247
- if err := u .get (gopath , repo ); err != nil {
248
- return nil , err
249
- }
250
- }
251
-
252
233
if _ , err := os .Stat (filepath .Join (repoDir , "debian" )); err == nil {
253
234
log .Printf ("WARNING: ignoring debian/ directory that came with the upstream sources\n " )
254
235
}
@@ -258,15 +239,12 @@ func makeUpstreamSourceTarball(repo, revision string) (*upstream, error) {
258
239
return nil , err
259
240
}
260
241
if len (u .vendorDirs ) > 0 {
261
- log .Printf ("Deleting upstream vendor/ directories, installing remaining dependencies " )
242
+ log .Printf ("Deleting upstream vendor/ directories" )
262
243
for _ , dir := range u .vendorDirs {
263
244
if err := os .RemoveAll (filepath .Join (repoDir , dir )); err != nil {
264
245
return nil , err
265
246
}
266
247
}
267
- if err := u .get (gopath , repo ); err != nil {
268
- return nil , err
269
- }
270
248
}
271
249
272
250
log .Printf ("Determining upstream version number\n " )
0 commit comments