Skip to content

Commit fc37ad4

Browse files
committed
Make samples compilation lazy by checking timestamps
1 parent f2efa9e commit fc37ad4

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

build.sbt

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -211,22 +211,28 @@ def compileTask(libname: String, srcDirTask: SettingKey[File]) = Def.settings(
211211
Process(command, cwd) ! log
212212
}
213213

214-
val opaths = cpaths.map { cpath =>
215-
val opath = abs(cwd / s"${cpath.getName}.o")
216-
val command = Seq(clangPath) ++ compileOptions ++ Seq("-c",
217-
abs(cpath),
218-
"-o",
219-
opath)
220-
221-
if (run(command) != 0) {
222-
sys.error(s"Failed to compile $cpath")
223-
}
224-
opath
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
225228
}
226229

227230
val archivePath = cwd / s"lib$libname.a"
228-
val archive = Seq("ar", "cr", abs(archivePath)) ++ opaths
229-
if (run(archive) != 0) {
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) {
230236
sys.error(s"Failed to create archive $archivePath")
231237
}
232238

0 commit comments

Comments
 (0)