Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delegate compilation and packaging to bleep #495

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,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 @@ -59,7 +60,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