@@ -7,20 +7,44 @@ import sbt._
7
7
/** Helper methods to package up files into compressed archives. */
8
8
object Archives {
9
9
10
- /** Makes a zip file in the given target directory using the given name. */
11
- def makeZip (target : File , name : String , mappings : Seq [(File , String )]): File = {
10
+ /**
11
+ * Makes a zip file in the given target directory using the given name.
12
+ *
13
+ * @param target folder to build package in
14
+ * @param name of output (without extension)
15
+ * @param mappings included in the output
16
+ * @param top level directory
17
+ * @return zip file
18
+ */
19
+ def makeZip (target : File , name : String , mappings : Seq [(File , String )], top : Option [String ]): File = {
12
20
val zip = target / (name + " .zip" )
13
- // TODO - If mappings already start with the given name, don't add it?
14
- val m2 = mappings map { case (f, p) => f -> (name + " /" + p) }
21
+
22
+ // add top level directory if defined
23
+ val m2 = top map { dir =>
24
+ mappings map { case (f, p) => f -> (dir + " /" + p) }
25
+ } getOrElse (mappings)
26
+
15
27
ZipHelper .zip(m2, zip)
16
28
zip
17
29
}
18
30
19
- /** Makes a zip file in the given target directory using the given name. */
20
- def makeNativeZip (target : File , name : String , mappings : Seq [(File , String )]): File = {
31
+ /**
32
+ * Makes a zip file in the given target directory using the given name.
33
+ *
34
+ * @param target folder to build package in
35
+ * @param name of output (without extension)
36
+ * @param mappings included in the output
37
+ * @param top level directory
38
+ * @return zip file
39
+ */
40
+ def makeNativeZip (target : File , name : String , mappings : Seq [(File , String )], top : Option [String ]): File = {
21
41
val zip = target / (name + " .zip" )
22
- // TODO - If mappings already start with the given name, don't add it?
23
- val m2 = mappings map { case (f, p) => f -> (name + " /" + p) }
42
+
43
+ // add top level directory if defined
44
+ val m2 = top map { dir =>
45
+ mappings map { case (f, p) => f -> (dir + " /" + p) }
46
+ } getOrElse (mappings)
47
+
24
48
ZipHelper .zipNative(m2, zip)
25
49
zip
26
50
}
@@ -29,8 +53,14 @@ object Archives {
29
53
* Makes a dmg file in the given target directory using the given name.
30
54
*
31
55
* Note: Only works on OSX
56
+ *
57
+ * @param target folder to build package in
58
+ * @param name of output (without extension)
59
+ * @param mappings included in the output
60
+ * @param top level directory : NOT USED
61
+ * @return dmg file
32
62
*/
33
- def makeDmg (target : File , name : String , mappings : Seq [(File , String )]): File = {
63
+ def makeDmg (target : File , name : String , mappings : Seq [(File , String )], top : Option [ String ] ): File = {
34
64
val t = target / " dmg"
35
65
val dmg = target / (name + " .dmg" )
36
66
if (! t.isDirectory) IO .createDirectory(t)
@@ -113,25 +143,43 @@ object Archives {
113
143
val makeTgz = makeTarball(gzip, " .tgz" ) _
114
144
val makeTar = makeTarball(identity, " .tar" ) _
115
145
116
- /** Helper method used to construct tar-related compression functions. */
117
- def makeTarball (compressor : File => File , ext : String )(target : File , name : String , mappings : Seq [(File , String )]): File = {
146
+ /**
147
+ * Helper method used to construct tar-related compression functions.
148
+ * @param target folder to build package in
149
+ * @param name of output (without extension)
150
+ * @param mappings included in the output
151
+ * @param top level directory
152
+ * @return tar file
153
+ *
154
+ */
155
+ def makeTarball (compressor : File => File , ext : String )(target : File , name : String , mappings : Seq [(File , String )], top : Option [String ]): File = {
118
156
val relname = name
119
157
val tarball = target / (name + ext)
120
158
IO .withTemporaryDirectory { f =>
121
159
val rdir = f / relname
122
- val m2 = mappings map { case (f, p) => f -> (rdir / name / p) }
160
+ val m2 = top map { dir =>
161
+ mappings map { case (f, p) => f -> (rdir / dir / p) }
162
+ } getOrElse {
163
+ mappings map { case (f, p) => f -> (rdir / p) }
164
+ }
165
+
123
166
IO .copy(m2)
124
167
// TODO - Is this enough?
125
168
for (f <- (m2 map { case (_, f) => f }); if f.getAbsolutePath contains " /bin/" ) {
126
169
println(" Making " + f.getAbsolutePath + " executable" )
127
170
f.setExecutable(true , false )
128
171
}
172
+
129
173
IO .createDirectory(tarball.getParentFile)
130
- val distdir = IO .listFiles(rdir).headOption.getOrElse {
131
- sys.error(" Unable to find tarball in directory: " + rdir.getAbsolutePath + " .\n This could be an issue with the temporary filesystem used to create tarballs." )
174
+
175
+ // all directories that should be zipped
176
+ val distdirs = top map (_ :: Nil ) getOrElse {
177
+ IO .listFiles(rdir).map(_.getName).toList // no top level dir, use all available
132
178
}
179
+
133
180
val tmptar = f / (relname + " .tar" )
134
- Process (Seq (" tar" , " -pcvf" , tmptar.getAbsolutePath, distdir.getName), Some (rdir)).! match {
181
+
182
+ Process (Seq (" tar" , " -pcvf" , tmptar.getAbsolutePath) ++ distdirs, Some (rdir)).! match {
135
183
case 0 => ()
136
184
case n => sys.error(" Error tarballing " + tarball + " . Exit code: " + n)
137
185
}
0 commit comments