diff --git a/.travis.yml b/.travis.yml index a2afc38..972df16 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,9 +4,9 @@ scala: - 2.11.12 - 2.12.8 jdk: - - oraclejdk8 + - openjdk8 env: - - SCALAJS_VERSION=1.0.0-M7 + - SCALAJS_VERSION=1.0.0-M8 script: - ./scripts/assemble-cli.sh $SCALAJS_VERSION $TRAVIS_SCALA_VERSION cache: diff --git a/appveyor.yml b/appveyor.yml index 7f22792..9c54ab3 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -2,7 +2,7 @@ version: '{build}' os: Windows Server 2012 environment: global: - SCALAJS_VERSION: 1.0.0-M7 + SCALAJS_VERSION: 1.0.0-M8 matrix: - SCALA_VERSION: 2.11.12 - SCALA_VERSION: 2.12.8 diff --git a/build.sbt b/build.sbt index b1db035..9f8238c 100644 --- a/build.sbt +++ b/build.sbt @@ -33,7 +33,7 @@ inThisBuild(Def.settings( scalaVersion := crossScalaVersions.value.head, scalacOptions ++= Seq("-deprecation", "-feature", "-Xfatal-warnings"), - scalaJSVersion := "1.0.0-M7", + scalaJSVersion := "1.0.0-M8", scalaJSBinaryVersion := binaryScalaJSVersion(scalaJSVersion.value), scalaJSScalaVersions := Seq( diff --git a/project/build.properties b/project/build.properties index 394cb75..c0bab04 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=1.0.4 +sbt.version=1.2.8 diff --git a/src/main/scala/org/scalajs/cli/Scalajsld.scala b/src/main/scala/org/scalajs/cli/Scalajsld.scala index 6809f46..945dc55 100644 --- a/src/main/scala/org/scalajs/cli/Scalajsld.scala +++ b/src/main/scala/org/scalajs/cli/Scalajsld.scala @@ -11,8 +11,6 @@ package org.scalajs.cli import org.scalajs.ir.ScalaJSVersions -import org.scalajs.io._ - import org.scalajs.logging._ import org.scalajs.linker._ @@ -22,7 +20,7 @@ import CheckedBehavior.Compliant import scala.collection.immutable.Seq -import scala.concurrent.Await +import scala.concurrent.{Await, Future} import scala.concurrent.duration.Duration import scala.concurrent.ExecutionContext.Implicits.global @@ -149,8 +147,7 @@ object Scalajsld { } for (options <- parser.parse(args, Options())) { - val classpath = options.stdLib.toList ++ options.cp - val irContainers = FileScalaJSIRContainer.fromClasspath(classpath) + val classpath = (options.stdLib.toList ++ options.cp).map(_.toPath()) val moduleInitializers = options.moduleInitializers val semantics = @@ -172,13 +169,14 @@ object Scalajsld { val linker = StandardLinker(config) val logger = new ScalaConsoleLogger(options.logLevel) - val outFile = new WritableFileVirtualBinaryFile(options.output) + val outFile = new WritableFileVirtualBinaryFile(options.output.toPath()) val output = LinkerOutput(outFile) - val cache = (new IRFileCache).newCache - val future = linker.link(cache.cached(irContainers), moduleInitializers, - output, logger) - Await.result(future, Duration.Inf) + val result = FileScalaJSIRContainer + .fromClasspath(classpath) + .flatMap(containers => Future.traverse(containers)(_.sjsirFiles).map(_.flatten)) + .flatMap(linker.link(_, moduleInitializers, output, logger)) + Await.result(result, Duration.Inf) } } } diff --git a/src/main/scala/org/scalajs/cli/Scalajsp.scala b/src/main/scala/org/scalajs/cli/Scalajsp.scala index f2d2d7f..36d2766 100644 --- a/src/main/scala/org/scalajs/cli/Scalajsp.scala +++ b/src/main/scala/org/scalajs/cli/Scalajsp.scala @@ -9,18 +9,24 @@ package org.scalajs.cli +import org.scalajs.ir.Definitions import org.scalajs.ir.ScalaJSVersions import org.scalajs.ir.Trees.{Tree, ClassDef} import org.scalajs.ir.Printers.IRTreePrinter -import org.scalajs.io._ - import org.scalajs.linker.irio._ import scala.collection.immutable.Seq +import scala.concurrent._ +import scala.concurrent.duration.Duration +import scala.concurrent.ExecutionContext.Implicits.global + +import scala.util.{Failure, Success} + import java.io.{Console => _, _} import java.util.zip.{ZipFile, ZipEntry} +import java.nio.file.Path object Scalajsp { @@ -63,7 +69,7 @@ object Scalajsp { readFromFile(fileName) } - displayFileContent(vfile, options) + displayFileContent(Await.result(vfile, Duration.Inf), options) } } @@ -76,7 +82,8 @@ object Scalajsp { private def displayFileContent(vfile: VirtualScalaJSIRFile, opts: Options): Unit = { - new IRTreePrinter(stdout).print(vfile.tree) + val tree = Await.result(vfile.tree, Duration.Inf) + new IRTreePrinter(stdout).print(tree) stdout.write('\n') stdout.flush() } @@ -91,24 +98,49 @@ object Scalajsp { throw new AssertionError("unreachable") } - private def readFromFile(fileName: String): VirtualScalaJSIRFile = { + private def readFromFile(fileName: String): Future[VirtualScalaJSIRFile] = { val file = new File(fileName) - if (!file.exists) + if (!file.exists) { fail(s"No such file: $fileName") - else if (!file.canRead) + } else if (!file.canRead) { fail(s"Unable to read file: $fileName") - else - new FileVirtualScalaJSIRFile(file, file.getName) + } else { + for { + container <- FileScalaJSIRContainer.fromSingleFile(file.toPath()) + sjsirFiles <- container.sjsirFiles + } yield { + sjsirFiles.head + } + } } - private def readFromJar(jar: File, name: String): VirtualScalaJSIRFile = { + private def readFromJar(jar: File, name: String): Future[VirtualScalaJSIRFile] = { /* This could be more efficient if we only read the relevant entry. But it * probably does not matter, and this implementation is very simple. */ - val jarFile = new FileVirtualJarScalaJSIRContainer(jar) - jarFile.sjsirFiles.find(_.relativePath == name).getOrElse { - fail(s"No such file in jar: $name") + + def findRequestedClass(sjsirFiles: List[VirtualScalaJSIRFile]): Future[VirtualScalaJSIRFile] = { + Future.traverse(sjsirFiles) { ir => + ir.entryPointsInfo.map { i => + if (i.encodedName == name || Definitions.decodeClassName(i.encodedName) == name) Success(Some(ir)) + else Success(None) + }.recover { case t => Failure(t) } + }.map { irs => + irs.collectFirst { + case Success(Some(f)) => f + }.getOrElse { + fail(s"No such class in jar: $name") + } + } + } + + for { + jarFile <- FileScalaJSIRContainer.fromJar(jar.toPath()) + sjsirFiles <- jarFile.sjsirFiles + requestedFile <- findRequestedClass(sjsirFiles) + } yield { + requestedFile } }