This repository has been archived by the owner on Feb 21, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.sbt
134 lines (115 loc) · 3.87 KB
/
build.sbt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
scalaVersion := "2.11.12"
nativeLinkStubs := true
scalaSource in Compile := baseDirectory.value / "source"
scalaSource in Test := baseDirectory.value / "specs"
cleanFiles += baseDirectory.value / "pack"
libraryDependencies ++= Seq(
"org.scalatest" % "scalatest_native0.3_2.11" % "3.2.0-SNAP10"
)
enablePlugins(ScalaNativePlugin)
lazy val programVersion = settingKey[String]("The program version.")
programVersion := "1.4.0"
lazy val supportedShells = settingKey[List[String]]("All supported shells.")
supportedShells := List("bash", "dash", "zsh", "ksh", "fish")
lazy val scrub = taskKey[Unit]("Cleans repo and removes additional junk.")
scrub := {
import scala.sys.process._
clean.value
"rm -rf target/ project/project/ project/target/ dist/" !
}
lazy val prepack = taskKey[Unit]("Executes required tasks before packaging.")
prepack := Def.sequential(
clean,
Compile / nativeLink
).value
lazy val packDeb = taskKey[Unit]("Creates a Debian package.")
packDeb := {
prepack.value
import java.nio.charset.StandardCharsets
import java.nio.file.{
Files,
Paths
}
import scala.sys.process._
val packageName = s"shellcuts_${programVersion.value}-1"
val installRoot = s"pack/${packageName}"
// Create all required directories for the packaging process.
val requiredDirs = List(
"dist",
s"${installRoot}/DEBIAN",
s"${installRoot}/usr/bin",
s"${installRoot}/etc/shellcuts/shells",
s"${installRoot}/usr/share/man/man1",
s"${installRoot}/usr/share/doc/shellcuts"
)
requiredDirs foreach {
(path) => Files.createDirectories(Paths.get(path))
}
// Copy files into the packaging directory tree.
val copies = Map(
"scripts/sc" -> s"${installRoot}/usr/bin/sc",
"target/scala-2.11/shellcuts-out" -> s"${installRoot}/usr/bin/sc-core",
"docs/sc.1" -> s"${installRoot}/usr/share/man/man1/sc.1",
"docs/CHANGES.txt" -> s"${installRoot}/usr/share/doc/shellcuts/CHANGES.txt",
"docs/README.md" -> s"${installRoot}/usr/share/doc/shellcuts/README.md",
"docs/LICENSE.txt" -> s"${installRoot}/usr/share/doc/shellcuts/LICENSE.txt",
"shells/shellcuts.fish" -> s"${installRoot}/etc/shellcuts/shells/shellcuts.fish",
"shells/shellcuts.sh" -> s"${installRoot}/etc/shellcuts/shells/shellcuts.sh"
)
copies foreach {
case (source, destination) => {
Files.copy(Paths.get(source), Paths.get(destination))
}
}
// Create the required Debian control file for metadata.
val controlContents = s"""
|Package: shellcuts
|Version: ${programVersion.value}-1
|Section: base
|Priority: optional
|Architecture: amd64
|Depends: libre2-dev
|Maintainer: Tiger Sachse <tgsachse@gmail.com>
|Description: Directory shortcuts for your shell
|""".stripMargin.replaceFirst("\n", "")
Files.write(
Paths.get(s"${installRoot}/DEBIAN/control"),
controlContents.getBytes(StandardCharsets.UTF_8)
)
// Build the deb package.
s"dpkg-deb --build ${installRoot} dist/${packageName}.deb" !
}
lazy val pack = taskKey[Unit]("Packages this software.")
pack := Def.sequential(
packDeb
).value
lazy val integrate = taskKey[Unit]("Executes the integration tests.")
integrate := {
import scala.sys.process._
val testSuites = List(
"integ/new-flag-tests.sh",
"integ/crumb-flag-tests.sh",
"integ/delete-flag-tests.sh",
"integ/follow-flag-tests.sh",
"integ/unfollow-flag-tests.sh",
"integ/move-flag-tests.sh"
)
val failed = supportedShells.value map {
(shell) => {
val functionSource = shell match {
case "bash" | "dash" | "zsh" | "ksh" => {
"/etc/shellcuts/shells/shellcuts.sh"
}
case "fish" => {
"/etc/shellcuts/shells/shellcuts.fish"
}
}
testSuites map {
(suite) => s"${suite} ${shell} ${functionSource}" !
} sum
}
} sum
if (failed != 0) {
throw new MessageOnlyException(s"$failed tests failed!")
}
}