Skip to content

Commit

Permalink
Generate index when invoking buildStdLib tasks (#6000)
Browse files Browse the repository at this point in the history
The change adds support for generating suggestions and bindings when using the convenient task for building individual stdlib components. By default commands do not generate index since it adds build time. But `buildStdLibAllWithIndex` will.

Closes #5999.
  • Loading branch information
hubertp authored Mar 28, 2023
1 parent d1c52fe commit 49e2c5a
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 35 deletions.
32 changes: 24 additions & 8 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2137,8 +2137,9 @@ runEngineDistribution := {
)
}

val allStdBitsSuffix = List("All", "AllWithIndex")
val stdBitsProjects =
List("Base", "Database", "Google_Api", "Image", "Table", "All")
List("Base", "Database", "Google_Api", "Image", "Table") ++ allStdBitsSuffix
val allStdBits: Parser[String] =
stdBitsProjects.map(v => v: Parser[String]).reduce(_ | _)

Expand Down Expand Up @@ -2168,10 +2169,12 @@ buildStdLib := Def.inputTaskDyn {

lazy val pkgStdLibInternal = inputKey[Unit]("Use `buildStdLib`")
pkgStdLibInternal := Def.inputTask {
val cmd = allStdBits.parsed
val root = engineDistributionRoot.value
val log: sbt.Logger = streams.value.log
val cacheFactory = streams.value.cacheStoreFactory
val cmd = allStdBits.parsed
val root = engineDistributionRoot.value
val log: sbt.Logger = streams.value.log
val cacheFactory = streams.value.cacheStoreFactory
val standardNamespace = "Standard"
val buildAllCmd = allStdBitsSuffix.contains(cmd)
cmd match {
case "Base" =>
(`std-base` / Compile / packageBin).value
Expand All @@ -2185,7 +2188,7 @@ pkgStdLibInternal := Def.inputTask {
(`std-table` / Compile / packageBin).value
case "TestHelpers" =>
(`enso-test-java-helpers` / Compile / packageBin).value
case "All" =>
case _ if buildAllCmd =>
(`std-base` / Compile / packageBin).value
(`enso-test-java-helpers` / Compile / packageBin).value
(`std-table` / Compile / packageBin).value
Expand All @@ -2195,13 +2198,14 @@ pkgStdLibInternal := Def.inputTask {
case _ =>
}
val libs =
if (cmd != "All") Seq(cmd)
if (!buildAllCmd) Seq(cmd)
else {
val prefix = "Standard."
val prefix = s"$standardNamespace."
Editions.standardLibraries
.filter(_.startsWith(prefix))
.map(_.stripPrefix(prefix))
}
val generateIndex = cmd.endsWith("WithIndex")
libs.foreach { lib =>
StdBits.buildStdLibPackage(
lib,
Expand All @@ -2210,6 +2214,18 @@ pkgStdLibInternal := Def.inputTask {
log,
defaultDevEnsoVersion
)
if (generateIndex) {
val stdlibStandardRoot = root / "lib" / standardNamespace
DistributionPackage.indexStdLib(
libMajor = stdlibStandardRoot,
libName = stdlibStandardRoot / lib,
stdLibVersion = defaultDevEnsoVersion,
ensoVersion = defaultDevEnsoVersion,
ensoExecutable = root / "bin" / "enso",
cacheFactory = cacheFactory.sub("stdlib"),
log = log
)
}
}
}.evaluated

Expand Down
77 changes: 50 additions & 27 deletions project/DistributionPackage.scala
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ object DistributionPackage {
javaVersion = javaVersion
)

indexStdLib(
indexStdLibs(
stdLibVersion = targetStdlibVersion,
ensoVersion = ensoVersion,
stdLibRoot = distributionRoot / "lib",
Expand All @@ -181,7 +181,7 @@ object DistributionPackage {
)
}

def indexStdLib(
def indexStdLibs(
stdLibVersion: String,
ensoVersion: String,
stdLibRoot: File,
Expand All @@ -193,32 +193,55 @@ object DistributionPackage {
libMajor <- stdLibRoot.listFiles()
libName <- (stdLibRoot / libMajor.getName).listFiles()
} yield {
val cache = cacheFactory.make(s"$libName.$ensoVersion")
val path = libName / ensoVersion
Tracked.diffInputs(cache, FileInfo.lastModified)(
path.globRecursive("*.enso").get().toSet
) { diff =>
if (diff.modified.nonEmpty) {
log.info(s"Generating index for $libName")
val command = Seq(
Platform.executableFileName(ensoExecutable.toString),
"--no-compile-dependencies",
"--no-global-cache",
"--compile",
path.toString
)
log.debug(command.mkString(" "))
val exitCode = Process(
command,
None,
"JAVA_OPTS" -> "-Dorg.jline.terminal.dumb=true"
).!
if (exitCode != 0) {
throw new RuntimeException(s"Cannot compile $libMajor.$libName.")
}
} else {
println(s"No modified files. Not generating index for ${libName} ")
indexStdLib(
libMajor,
libName,
stdLibVersion,
ensoVersion,
ensoExecutable,
cacheFactory,
log
)
}
}

def indexStdLib(
libMajor: File,
libName: File,
stdLibVersion: String,
ensoVersion: String,
ensoExecutable: File,
cacheFactory: CacheStoreFactory,
log: Logger
): Unit = {
object FileOnlyFilter extends sbt.io.FileFilter {
def accept(arg: File): Boolean = arg.isFile
}
val cache = cacheFactory.make(s"$libName.$ensoVersion")
val path = libName / ensoVersion
Tracked.diffInputs(cache, FileInfo.lastModified)(
path.globRecursive("*.enso" && FileOnlyFilter).get().toSet
) { diff =>
if (diff.modified.nonEmpty) {
log.info(s"Generating index for ${libName} ")
val command = Seq(
Platform.executableFileName(ensoExecutable.toString),
"--no-compile-dependencies",
"--no-global-cache",
"--compile",
path.toString
)
log.debug(command.mkString(" "))
val exitCode = Process(
command,
None,
"JAVA_OPTS" -> "-Dorg.jline.terminal.dumb=true"
).!
if (exitCode != 0) {
throw new RuntimeException(s"Cannot compile $libMajor.$libName.")
}
} else {
log.info(s"No modified files. Not generating index for ${libName} ")
}
}
}
Expand Down

0 comments on commit 49e2c5a

Please sign in to comment.