@@ -39,17 +39,43 @@ func passthroughEnv() []string {
39
39
return result
40
40
}
41
41
42
+ func findVendorDirs (dir string ) ([]string , error ) {
43
+ var vendorDirs []string
44
+ err := filepath .Walk (dir , func (path string , info os.FileInfo , err error ) error {
45
+ if err != nil {
46
+ return err
47
+ }
48
+ if info != nil && ! info .IsDir () {
49
+ return nil // nothing to do for anything but directories
50
+ }
51
+ if info .Name () == ".git" ||
52
+ info .Name () == ".hg" ||
53
+ info .Name () == ".bzr" {
54
+ return filepath .SkipDir
55
+ }
56
+ if info .Name () == "vendor" {
57
+ rel , err := filepath .Rel (dir , path )
58
+ if err != nil {
59
+ return err
60
+ }
61
+ vendorDirs = append (vendorDirs , rel )
62
+ }
63
+ return nil
64
+ })
65
+ return vendorDirs , err
66
+ }
67
+
42
68
// TODO: refactor this function into multiple smaller ones. Currently all the
43
69
// code is in this function only due to the os.RemoveAll(tempdir).
44
- func makeUpstreamSourceTarball (gopkg string , gitRevision string , pkgType string ) (string , string , map [string ]bool , string , error ) {
70
+ func makeUpstreamSourceTarball (gopkg string , gitRevision string , pkgType string ) (string , string , map [string ]bool , string , [] string , error ) {
45
71
// dependencies is a map in order to de-duplicate multiple imports
46
72
// pointing into the same repository.
47
73
dependencies := make (map [string ]bool )
48
74
autoPkgType := "library"
49
75
50
76
tempdir , err := ioutil .TempDir ("" , "dh-make-golang" )
51
77
if err != nil {
52
- return "" , "" , dependencies , autoPkgType , err
78
+ return "" , "" , dependencies , autoPkgType , nil , err
53
79
}
54
80
defer os .RemoveAll (tempdir )
55
81
@@ -72,7 +98,7 @@ func makeUpstreamSourceTarball(gopkg string, gitRevision string, pkgType string)
72
98
73
99
if err := cmd .Run (); err != nil {
74
100
done <- true
75
- return "" , "" , dependencies , autoPkgType , err
101
+ return "" , "" , dependencies , autoPkgType , nil , err
76
102
}
77
103
done <- true
78
104
fmt .Printf ("\r " )
@@ -96,7 +122,7 @@ func makeUpstreamSourceTarball(gopkg string, gitRevision string, pkgType string)
96
122
97
123
if err := cmd .Run (); err != nil {
98
124
done <- true
99
- return "" , "" , dependencies , autoPkgType , err
125
+ return "" , "" , dependencies , autoPkgType , nil , err
100
126
}
101
127
done <- true
102
128
fmt .Printf ("\r " )
@@ -106,11 +132,16 @@ func makeUpstreamSourceTarball(gopkg string, gitRevision string, pkgType string)
106
132
log .Printf ("WARNING: ignoring debian/ directory that came with the upstream sources\n " )
107
133
}
108
134
109
- vendorpath := filepath .Join (tempdir , "src" , gopkg , "vendor" )
110
- if fi , err := os .Stat (vendorpath ); err == nil && fi .IsDir () {
111
- log .Printf ("Deleting upstream vendor/ directory, installing remaining dependencies" )
112
- if err := os .RemoveAll (vendorpath ); err != nil {
113
- return "" , "" , dependencies , autoPkgType , err
135
+ vendorDirs , err := findVendorDirs (filepath .Join (tempdir , "src" , gopkg ))
136
+ if err != nil {
137
+ return "" , "" , dependencies , autoPkgType , nil , err
138
+ }
139
+ if len (vendorDirs ) > 0 {
140
+ log .Printf ("Deleting upstream vendor/ directories, installing remaining dependencies" )
141
+ for _ , dir := range vendorDirs {
142
+ if err := os .RemoveAll (filepath .Join (tempdir , "src" , gopkg , dir )); err != nil {
143
+ return "" , "" , dependencies , autoPkgType , nil , err
144
+ }
114
145
}
115
146
done := make (chan bool )
116
147
go progressSize ("go get" , filepath .Join (tempdir , "src" ), done )
@@ -122,7 +153,7 @@ func makeUpstreamSourceTarball(gopkg string, gitRevision string, pkgType string)
122
153
cmd .Dir = filepath .Join (tempdir , "src" , gopkg )
123
154
if err := cmd .Run (); err != nil {
124
155
done <- true
125
- return "" , "" , dependencies , autoPkgType , err
156
+ return "" , "" , dependencies , autoPkgType , nil , err
126
157
}
127
158
done <- true
128
159
fmt .Printf ("\r " )
@@ -144,18 +175,18 @@ func makeUpstreamSourceTarball(gopkg string, gitRevision string, pkgType string)
144
175
cmd .Dir = filepath .Join (tempdir , "src" , dir )
145
176
cmd .Stderr = os .Stderr
146
177
if err := cmd .Run (); err != nil {
147
- return "" , "" , dependencies , autoPkgType , err
178
+ return "" , "" , dependencies , autoPkgType , nil , err
148
179
}
149
180
150
181
if _ , err := os .Stat (filepath .Join (tempdir , "src" , gopkg , ".git" )); os .IsNotExist (err ) {
151
- return "" , "" , dependencies , autoPkgType , fmt .Errorf ("Not a git repository, dh-make-golang currently only supports git" )
182
+ return "" , "" , dependencies , autoPkgType , nil , fmt .Errorf ("Not a git repository, dh-make-golang currently only supports git" )
152
183
}
153
184
154
185
log .Printf ("Determining upstream version number\n " )
155
186
156
187
version , err := pkgVersionFromGit (filepath .Join (tempdir , "src" , gopkg ))
157
188
if err != nil {
158
- return "" , "" , dependencies , autoPkgType , err
189
+ return "" , "" , dependencies , autoPkgType , nil , err
159
190
}
160
191
161
192
log .Printf ("Package version is %q\n " , version )
@@ -171,7 +202,7 @@ func makeUpstreamSourceTarball(gopkg string, gitRevision string, pkgType string)
171
202
172
203
out , err := cmd .Output ()
173
204
if err != nil {
174
- return "" , "" , dependencies , autoPkgType , err
205
+ return "" , "" , dependencies , autoPkgType , nil , err
175
206
}
176
207
for _ , line := range strings .Split (string (out ), "\n " ) {
177
208
if strings .TrimSpace (line ) == "" {
@@ -203,7 +234,7 @@ func makeUpstreamSourceTarball(gopkg string, gitRevision string, pkgType string)
203
234
204
235
out , err = cmd .Output ()
205
236
if err != nil {
206
- return "" , "" , dependencies , autoPkgType , err
237
+ return "" , "" , dependencies , autoPkgType , nil , err
207
238
}
208
239
209
240
var godependencies []string
@@ -223,7 +254,7 @@ func makeUpstreamSourceTarball(gopkg string, gitRevision string, pkgType string)
223
254
}
224
255
225
256
if len (godependencies ) == 0 {
226
- return tempfile , version , dependencies , autoPkgType , nil
257
+ return tempfile , version , dependencies , autoPkgType , vendorDirs , nil
227
258
}
228
259
229
260
// Remove all packages which are in the standard lib.
@@ -239,7 +270,7 @@ func makeUpstreamSourceTarball(gopkg string, gitRevision string, pkgType string)
239
270
240
271
out , err = cmd .Output ()
241
272
if err != nil {
242
- return "" , "" , dependencies , autoPkgType , err
273
+ return "" , "" , dependencies , autoPkgType , nil , err
243
274
}
244
275
245
276
for _ , p := range strings .Split (string (out ), "\n " ) {
@@ -252,7 +283,7 @@ func makeUpstreamSourceTarball(gopkg string, gitRevision string, pkgType string)
252
283
dependencies [rr .Root ] = true
253
284
}
254
285
}
255
- return tempfile , version , dependencies , autoPkgType , nil
286
+ return tempfile , version , dependencies , autoPkgType , vendorDirs , nil
256
287
}
257
288
258
289
func runGitCommandIn (dir string , arg ... string ) error {
@@ -433,7 +464,7 @@ func getDebianEmail() string {
433
464
return "TODO"
434
465
}
435
466
436
- func writeTemplates (dir , gopkg , debsrc , debbin , debversion , pkgType string , dependencies []string ) error {
467
+ func writeTemplates (dir , gopkg , debsrc , debbin , debversion , pkgType string , dependencies []string , vendorDirs [] string ) error {
437
468
if err := os .Mkdir (filepath .Join (dir , "debian" ), 0755 ); err != nil {
438
469
return err
439
470
}
@@ -526,7 +557,11 @@ func writeTemplates(dir, gopkg, debsrc, debbin, debversion, pkgType string, depe
526
557
fmt .Fprintf (f , "Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/\n " )
527
558
fmt .Fprintf (f , "Upstream-Name: %s\n " , filepath .Base (gopkg ))
528
559
fmt .Fprintf (f , "Source: %s\n " , getHomepageForGopkg (gopkg ))
529
- fmt .Fprintf (f , "Files-Excluded: vendor Godeps/_workspace\n " )
560
+ fmt .Fprintf (f , "Files-Excluded:\n " )
561
+ for _ , dir := range vendorDirs {
562
+ fmt .Fprintf (f , " %s\n " , dir )
563
+ }
564
+ fmt .Fprintf (f , " Godeps/_workspace\n " )
530
565
fmt .Fprintf (f , "\n " )
531
566
fmt .Fprintf (f , "Files: *\n " )
532
567
fmt .Fprintf (f , "Copyright: %s\n " , copyright )
@@ -733,7 +768,7 @@ func execMake(args []string) {
733
768
golangBinaries , err = getGolangBinaries ()
734
769
return err
735
770
})
736
- tempfile , version , godependencies , autoPkgType , err := makeUpstreamSourceTarball (gopkg , gitRevision , pkgType )
771
+ tempfile , version , godependencies , autoPkgType , vendorDirs , err := makeUpstreamSourceTarball (gopkg , gitRevision , pkgType )
737
772
if err != nil {
738
773
log .Fatalf ("Could not create a tarball of the upstream source: %v\n " , err )
739
774
}
@@ -801,7 +836,7 @@ func execMake(args []string) {
801
836
debdependencies = append (debdependencies , bin )
802
837
}
803
838
804
- if err := writeTemplates (dir , gopkg , debsrc , debbin , debversion , pkgType , debdependencies ); err != nil {
839
+ if err := writeTemplates (dir , gopkg , debsrc , debbin , debversion , pkgType , debdependencies , vendorDirs ); err != nil {
805
840
log .Fatalf ("Could not create debian/ from templates: %v\n " , err )
806
841
}
807
842
0 commit comments