Skip to content

Commit

Permalink
Delegate compilation and packaging to bleep
Browse files Browse the repository at this point in the history
Bleep started its life by extracting the build components of ST, so it only makes sense that it now replaces it.

This has a lot of really nice properties.
- way better compile performance
- we lose very very heavy dependencies
- CLI tool is now close to build as graalvm native image
- when it is, the sbt plugin can then download and call that native image
- that should in turn provide even much much better performance for the conversion itself, at least compared to cold JVM

details:
- cleanup, `SbtProject` and `PublishedSbtProject` => `ScalaProject`
- specify a JVM 17 so bloop will start, plus consistent builds
- ignore error when cleaning up
  • Loading branch information
oyvindberg committed Nov 13, 2022
1 parent 42eccb8 commit a6e3c3f
Show file tree
Hide file tree
Showing 164 changed files with 3,216 additions and 975 deletions.
3 changes: 2 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ lazy val `importer-portable` = project
.dependsOn(ts, scalajs, phases)
.enablePlugins(BuildInfoPlugin)
.settings(
libraryDependencies ++= List(Deps.bleepModel),
buildInfoPackage := "org.scalablytyped.converter.internal",
buildInfoKeys := Seq[BuildInfoKey](
"gitSha" -> "git rev-parse -1 HEAD".!!.split("\n").last.trim,
Expand All @@ -56,7 +57,7 @@ lazy val importer = project
.configure(baseSettings, optimize)
.settings(
libraryDependencies ++= Seq(
Deps.bloop,
Deps.gigahorse,
Deps.coursier,
Deps.scalatest % Test,
),
Expand Down
25 changes: 11 additions & 14 deletions cli/src/main/scala/org/scalablytyped/converter/cli/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package org.scalablytyped.converter.cli
import com.olvind.logging.{stdout, storing, LogLevel, Logger}
import fansi.{Attr, Color, Str}
import org.scalablytyped.converter.internal.importer._
import org.scalablytyped.converter.internal.importer.build.{BloopCompiler, PublishedSbtProject, SbtProject}
import org.scalablytyped.converter.internal.importer.build.{BleepCompiler, ScalaProject}
import org.scalablytyped.converter.internal.importer.documentation.Npmjs
import org.scalablytyped.converter.internal.phases.PhaseListener.NoListener
import org.scalablytyped.converter.internal.phases.{PhaseRes, PhaseRunner, RecPhase}
Expand Down Expand Up @@ -248,12 +248,9 @@ object Main {
),
)

val compiler = Await.result(
BloopCompiler(logger.filter(LogLevel.debug).void, conversion.versions, failureCacheFolderOpt = None),
Duration.Inf,
)
val bleepCompiler = Await.result(BleepCompiler(logger.filter(LogLevel.debug).void), Duration.Inf)

val Pipeline: RecPhase[LibTsSource, PublishedSbtProject] =
val Pipeline: RecPhase[LibTsSource, ScalaProject] =
RecPhase[LibTsSource]
.next(
new Phase1ReadTypescript(
Expand Down Expand Up @@ -285,10 +282,10 @@ object Main {
.next(
new Phase3Compile(
versions = conversion.versions,
compiler = compiler,
bleepCompiler = bleepCompiler,
targetFolder = c.paths.out,
organization = conversion.organization,
publishLocalFolder = constants.defaultLocalPublishFolder,
publishLocalTarget = PublishLocalTarget.DefaultIvy2,
metadataFetcher = Npmjs.No,
softWrites = true,
flavour = conversion.flavourImpl,
Expand All @@ -298,7 +295,7 @@ object Main {
"build",
)

val results: Map[LibTsSource, PhaseRes[LibTsSource, PublishedSbtProject]] =
val results: Map[LibTsSource, PhaseRes[LibTsSource, ScalaProject]] =
sources
.map(source => source -> PhaseRunner(Pipeline, (_: LibTsSource) => logger.void, NoListener)(source))
.toMap
Expand All @@ -324,16 +321,16 @@ object Main {

System.exit(1)
} else {
val allSuccesses: Map[LibTsSource, PublishedSbtProject] = {
def go(source: LibTsSource, p: PublishedSbtProject): Map[LibTsSource, PublishedSbtProject] =
Map(source -> p) ++ p.project.deps.flatMap { case (k, v) => go(k, v) }
val allSuccesses: Map[LibTsSource, ScalaProject] = {
def go(source: LibTsSource, p: ScalaProject): Map[LibTsSource, ScalaProject] =
Map(source -> p) ++ p.deps.flatMap { case (k, v) => go(k, v) }

results.collect { case (s, PhaseRes.Ok(res)) => go(s, res) }.reduceOption(_ ++ _).getOrElse(Map.empty)
}

val short: Seq[SbtProject] =
val short: Seq[ScalaProject] =
results
.collect { case (_, PhaseRes.Ok(res)) => res.project }
.collect { case (_, PhaseRes.Ok(res)) => res }
.toSeq
.filter(_.name != Name.std.unescaped)
.sortBy(_.name)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
package org.scalablytyped.converter.internal
package scalajs

import java.util.regex.Pattern

import ammonite.ops._
import bloop.io.AbsolutePath
import com.olvind.logging
import org.scalablytyped.converter.internal.importer.build.BloopCompiler
import coursier.Fetch
import coursier.cache.{ArtifactError, FileCache}
import coursier.core.{Dependency, Module}
import coursier.error.{FetchError, ResolutionError}
import coursier.util.Task
import org.scalablytyped.converter.internal.maps._
import org.scalablytyped.converter.internal.scalajs.transforms.Sorter

import scala.concurrent.Await
import java.util.regex.Pattern
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration.Duration
import scala.concurrent.{Await, Future}
import scala.reflect.NameTransformer
import scala.tools.scalap.scalax.rules.scalasig._

Expand All @@ -29,9 +31,37 @@ import scala.tools.scalap.scalax.rules.scalasig._
object ImportScalaDefinitions extends App {
private val defaultVersions: Versions = Versions(Versions.Scala213, Versions.ScalaJs1)

val All: Array[AbsolutePath] = Await
val fileCache = FileCache[Task]().withChecksums(List(None))

def toCoursier(dep: Dep.Concrete): Dependency =
Dependency(
Module(coursier.Organization(dep.org), coursier.ModuleName(dep.mangledArtifact), Map.empty),
dep.version,
)

def resolve(deps: Dep.Concrete*): Future[Array[Path]] = {
def go(remainingAttempts: Int): Future[Array[Path]] =
Fetch[Task](fileCache)
.withDependencies(deps.map(toCoursier))
.io
.future()
.map(files => files.map(f => Path(f)).toArray)
.recoverWith {
case x: ResolutionError.CantDownloadModule
if remainingAttempts > 0 && x.perRepositoryErrors.exists(_.contains("concurrent download")) =>
go(remainingAttempts - 1)
case x: FetchError.DownloadingArtifacts if remainingAttempts > 0 && x.errors.exists {
case (_, artifactError) => artifactError.isInstanceOf[ArtifactError.Recoverable]
} =>
go(remainingAttempts - 1)
}

go(remainingAttempts = 3)
}

val All: Array[Path] = Await
.result(
BloopCompiler.resolve(
resolve(
defaultVersions.scalajsReact.concrete(defaultVersions),
defaultVersions.scalaJsDom.concrete(defaultVersions),
defaultVersions.slinkyWeb.concrete(defaultVersions),
Expand Down
Loading

0 comments on commit a6e3c3f

Please sign in to comment.