Skip to content
Merged
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
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.0.4
sbt.version=1.2.8
18 changes: 8 additions & 10 deletions src/main/scala/org/scalajs/cli/Scalajsld.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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._
Expand All @@ -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

Expand Down Expand Up @@ -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 =
Expand All @@ -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)
}
}
}
58 changes: 45 additions & 13 deletions src/main/scala/org/scalajs/cli/Scalajsp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -63,7 +69,7 @@ object Scalajsp {
readFromFile(fileName)
}

displayFileContent(vfile, options)
displayFileContent(Await.result(vfile, Duration.Inf), options)
}
}

Expand All @@ -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()
}
Expand All @@ -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
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ouch... This is clearly a shortcoming of the API as it stands now. scala-js#3675 should fix this though.

}
}

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
}
}

Expand Down