1
1
import scala .sys .process ._
2
+ import org .scalanative .bindgen .sbt .ScalaNativeBindgenPlugin
2
3
3
- addCommandAlias(" verify" , " ; ^test:compile ; ^test ; ^scripted ; docs/makeSite" )
4
+ addCommandAlias(" verify" ,
5
+ " ; tests/test ; docs/test ; ^scripted ; docs/makeSite" )
4
6
5
7
val Versions = new {
6
8
val scala210 = " 2.10.6"
@@ -88,6 +90,7 @@ lazy val tests = project("tests")
88
90
),
89
91
libraryDependencies += " org.scalatest" %% " scalatest" % " 3.0.5" % Test
90
92
)
93
+ .aggregate(samples)
91
94
92
95
lazy val samples = project(" samples" )
93
96
.in(file(" tests/samples" ))
@@ -98,47 +101,7 @@ lazy val samples = project("samples")
98
101
libraryDependencies += " com.lihaoyi" %%% " utest" % " 0.6.3" % " test" ,
99
102
testFrameworks += new TestFramework (" utest.runner.Framework" ),
100
103
nativeLinkStubs := true ,
101
- Test / nativeLinkingOptions += {
102
- Seq (" -L" , (Test / target).value.getAbsoluteFile / " bindgen" ).mkString
103
- },
104
- Test / compile := {
105
- val log = streams.value.log
106
- val cwd = (Test / target).value / " bindgen"
107
- val compileOptions = (Test / nativeCompileOptions).value
108
- val cpaths = (baseDirectory.value.getAbsoluteFile * " *.c" ).get
109
- val clangPath = nativeClang.value.toPath.toAbsolutePath.toString
110
-
111
- cwd.mkdirs()
112
-
113
- def abs (path : File ): String =
114
- path.getAbsolutePath
115
-
116
- def run (command : Seq [String ]): Int = {
117
- log.info(" Running " + command.mkString(" " ))
118
- Process (command, cwd) ! log
119
- }
120
-
121
- val opaths = cpaths.map { cpath =>
122
- val opath = abs(cwd / s " ${cpath.getName}.o " )
123
- val command = Seq (clangPath) ++ compileOptions ++ Seq (" -c" ,
124
- abs(cpath),
125
- " -o" ,
126
- opath)
127
-
128
- if (run(command) != 0 ) {
129
- sys.error(s " Failed to compile $cpath" )
130
- }
131
- opath
132
- }
133
-
134
- val archivePath = cwd / " libbindgentests.a"
135
- val archive = Seq (" ar" , " cr" , abs(archivePath)) ++ opaths
136
- if (run(archive) != 0 ) {
137
- sys.error(s " Failed to create archive $archivePath" )
138
- }
139
-
140
- (Test / compile).value
141
- }
104
+ compileTask(" bindgentests" , baseDirectory)
142
105
)
143
106
144
107
lazy val tools = project(" tools" )
@@ -166,16 +129,33 @@ lazy val sbtPlugin = project("sbt-scala-native-bindgen", ScriptedPlugin)
166
129
167
130
lazy val docs = project(" docs" )
168
131
.enablePlugins(GhpagesPlugin , ParadoxSitePlugin , ParadoxMaterialThemePlugin )
132
+ .enablePlugins(ScalaNativePlugin , ScalaNativeBindgenPlugin )
169
133
.settings(
170
134
publish / skip := true ,
135
+ scalaVersion := Versions .scala211,
136
+ // FIXME: Remove when a version has been released with Test scope settings.
137
+ ScalaNativeBindgenPlugin .nativeBindgenScopedSettings(Test ),
138
+ Test / nativeBindings += {
139
+ NativeBinding ((Test / resourceDirectory).value / " vector.h" )
140
+ .name(" vector" )
141
+ .link(" vector" )
142
+ .packageName(" org.example" )
143
+ },
144
+ Test / nativeBindgen / target := (Test / scalaSource).value / " org/example" ,
145
+ nativeLinkStubs := true ,
146
+ compileTask(" vector" , Test / resourceDirectory),
147
+ libraryDependencies += " org.scalatest" %%% " scalatest" % " 3.2.0-SNAP10" % Test ,
171
148
Paradox / paradoxProperties ++= Map (
172
149
" github.base_url" -> scmInfo.value.get.browseUrl.toString
173
150
),
174
151
ParadoxMaterialThemePlugin .paradoxMaterialThemeSettings(Paradox ),
175
152
Paradox / paradoxMaterialTheme := {
153
+ val licenseUrl = scmInfo.value.get.browseUrl.toString + " blob/master/LICENSE.txt"
176
154
(Paradox / paradoxMaterialTheme).value
177
155
.withRepository(scmInfo.value.get.browseUrl.toURI)
178
156
.withColor(" indigo" , " indigo" )
157
+ .withCopyright(
158
+ s " Copyright © Liudmila Kornilova, distributed under the <a href=' $licenseUrl'>Scala license</a>. " )
179
159
}
180
160
)
181
161
@@ -209,3 +189,53 @@ def project(name: String, plugged: AutoPlugin*) = {
209
189
210
190
lazy val setReleaseVersions : String => State => State =
211
191
v => _.put(ReleaseKeys .versions, (v, v))
192
+
193
+ def compileTask (libname : String , srcDirTask : SettingKey [File ]) = Def .settings(
194
+ Test / nativeLinkingOptions += {
195
+ Seq (" -L" , (Test / target).value.getAbsoluteFile / " bindgen" ).mkString
196
+ },
197
+ Test / compile := {
198
+ val log = streams.value.log
199
+ val cwd = (Test / target).value / " bindgen"
200
+ val compileOptions = (Test / nativeCompileOptions).value
201
+ val cpaths = (srcDirTask.value.getAbsoluteFile * " *.c" ).get
202
+ val clangPath = nativeClang.value.toPath.toAbsolutePath.toString
203
+
204
+ cwd.mkdirs()
205
+
206
+ def abs (path : File ): String =
207
+ path.getAbsolutePath
208
+
209
+ def run (command : Seq [String ]): Int = {
210
+ log.info(" Running " + command.mkString(" " ))
211
+ Process (command, cwd) ! log
212
+ }
213
+
214
+ val opaths = cpaths.map {
215
+ cpath =>
216
+ val opath = cwd / s " ${cpath.getName}.o "
217
+ val command = Seq (clangPath) ++ compileOptions ++ Seq (" -c" ,
218
+ abs(cpath),
219
+ " -o" ,
220
+ abs(opath))
221
+ val doCompile =
222
+ ! opath.exists() || cpath.lastModified() >= opath.lastModified()
223
+
224
+ if (doCompile && run(command) != 0 ) {
225
+ sys.error(s " Failed to compile $cpath" )
226
+ }
227
+ opath
228
+ }
229
+
230
+ val archivePath = cwd / s " lib $libname.a "
231
+ val archive = Seq (" ar" , " cr" , abs(archivePath)) ++ opaths.map(abs)
232
+ val doArchive =
233
+ opaths.map(_.lastModified).max >= archivePath.lastModified()
234
+
235
+ if (doArchive && run(archive) != 0 ) {
236
+ sys.error(s " Failed to create archive $archivePath" )
237
+ }
238
+
239
+ (Test / compile).value
240
+ }
241
+ )
0 commit comments