From a5affd3d793ed1deff2c1719bd0ca92f90f45316 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Zyba=C5=82a?= Date: Thu, 12 Aug 2021 15:07:38 +0200 Subject: [PATCH] Fetch Inkuire at scaladoc build instead of documentation generation --- project/Build.scala | 20 +++++++++++++++++++ .../tools/scaladoc/renderers/Resources.scala | 6 ++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/project/Build.scala b/project/Build.scala index 2e5b15abf555..29f6564d3dff 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -1317,6 +1317,26 @@ object Build { sbt.IO.copyFile(cssSourceFile, cssDesitnationFile) Seq(cssDesitnationFile) }.taskValue, + Compile / resourceGenerators += Def.task { + import _root_.scala.sys.process._ + import _root_.scala.concurrent._ + import ExecutionContext.Implicits.global + val inkuireVersion = "1.0.0-M2" + val inkuireLink = s"https://github.com/VirtusLab/Inkuire/releases/download/$inkuireVersion/inkuire.js" + val inkuireDestinationFile = (Compile / resourceManaged).value / "dotty_res" / "scripts" / "inkuire.js" + sbt.IO.touch(inkuireDestinationFile) + val downloadProcess = (new java.net.URL(inkuireLink) #> inkuireDestinationFile).run() + val result: Future[Int] = Future(blocking(downloadProcess.exitValue())) + val res = try { + Await.result(result, duration.Duration(20, "sec")) + } catch { + case _: TimeoutException => + downloadProcess.destroy() + throw new MessageOnlyException(s"Failed to fetch inkuire.js from $inkuireLink: Download timeout") + } + if(res != 0) throw new MessageOnlyException(s"Failed to fetch inkuire.js from $inkuireLink: Error code $res") + Seq(inkuireDestinationFile) + }.taskValue, libraryDependencies ++= Dependencies.flexmarkDeps ++ Seq( "nl.big-o" % "liqp" % "0.6.7", "org.jsoup" % "jsoup" % "1.13.1", // Needed to process .html files for static site diff --git a/scaladoc/src/dotty/tools/scaladoc/renderers/Resources.scala b/scaladoc/src/dotty/tools/scaladoc/renderers/Resources.scala index 6425dac347b5..8a4696ec38c0 100644 --- a/scaladoc/src/dotty/tools/scaladoc/renderers/Resources.scala +++ b/scaladoc/src/dotty/tools/scaladoc/renderers/Resources.scala @@ -54,10 +54,8 @@ trait Resources(using ctx: DocContext) extends Locations, Writer: val onlyRenderedResources: Seq[Resource] = List( - ("https://github.com/VirtusLab/Inkuire/releases/download/1.0.0-M2/inkuire.js", "scripts/inkuire.js"), - ).map { case (url, path) => - Resource.URLToCopy(url, path) - } ++ + "scripts/inkuire.js" + ).map(dottyRes) ++ List( "scripts/inkuire-worker.js" ).map(dottyRes)