Skip to content

Commit

Permalink
Merge pull request twitter#482 from wiwa/f/checkbc-classfiles
Browse files Browse the repository at this point in the history
checkbytecode should be able to run on pre-compiled jars
  • Loading branch information
Shane Delmore committed Sep 13, 2019
2 parents 0a8c665 + eace06d commit be11120
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 23 deletions.
10 changes: 10 additions & 0 deletions check/src/main/scala/rsc/checkbase/SettingsBase.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
// Licensed under the Apache License, Version 2.0 (see LICENSE.md).
package rsc.checkbase

import java.io.File.pathSeparator
import java.nio.file.{Path, Paths}

trait SettingsBase {
def quiet: Boolean
}
object SettingsBase {

final case class ClassfilesPath(rsc: Option[List[Path]], nsc: Option[List[Path]])

def pathsFor(pathStr: String): List[Path] =
pathStr.split(pathSeparator).map(s => Paths.get(s)).toList
}
7 changes: 5 additions & 2 deletions check/src/main/scala/rsc/checkbytecode/Checker.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ import java.nio.file._
import rsc.checkbase._
import scala.tools.jardiff._

class Checker(nscResult: Path, rscResult: Path) extends CheckerBase {
class Checker(
nscResults: List[Path],
rscResults: List[Path]
) extends CheckerBase {
def check(): Unit = {
val baos = new ByteArrayOutputStream()
val paths = List(List(nscResult), List(rscResult))
val paths = List(nscResults, rscResults)
val config = JarDiff.Config(
gitRepo = None,
code = true,
Expand Down
20 changes: 14 additions & 6 deletions check/src/main/scala/rsc/checkbytecode/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,30 @@ package rsc.checkbytecode
import java.nio.file._
import rsc.checkbase._

object Main extends SimpleBase[Settings, Path, Path] {
def settings(args: List[String]) = {
object Main extends SimpleBase[Settings, List[Path], List[Path]] {
def settings(args: List[String]): Either[List[String], Settings] = {
Settings.parse(args)
}

def nscResult(settings: Settings) = {
private def compileNscResult(settings: Settings): ToolResult[Path] = {
val nscJars = nscs(settings.cp, settings.deps :+ settings.ins)
nscJars.right.flatMap(nscJars => Right(nscJars.last))
}

def rscResult(settings: Settings) = {
private def compileRscResult(settings: Settings): ToolResult[Path] = {
val rscJars = rscs(settings.cp, settings.deps)
rscJars.right.flatMap(rscJars => nsc(settings.cp ++ rscJars, settings.ins))
}

def checker(settings: Settings, nscResult: Path, rscResult: Path) = {
new Checker(nscResult, rscResult)
def nscResult(settings: Settings): ToolResult[List[Path]] = {
settings.precomputedJars.nsc.map(Right(_)).getOrElse(compileNscResult(settings).map(List(_)))
}

def rscResult(settings: Settings): ToolResult[List[Path]] = {
settings.precomputedJars.rsc.map(Right(_)).getOrElse(compileRscResult(settings).map(List(_)))
}

def checker(settings: Settings, nscResults: List[Path], rscResults: List[Path]): Checker = {
new Checker(nscResults, rscResults)
}
}
16 changes: 12 additions & 4 deletions check/src/main/scala/rsc/checkbytecode/Settings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@
// Licensed under the Apache License, Version 2.0 (see LICENSE.md).
package rsc.checkbytecode

import java.io.File.pathSeparator
import java.nio.file._
import rsc.checkbase.SettingsBase.ClassfilesPath
import rsc.checkbase._

final case class Settings(
cp: List[Path] = Nil,
deps: List[List[Path]] = Nil,
ins: List[Path] = Nil,
quiet: Boolean = false)
extends SettingsBase
quiet: Boolean = false,
precomputedJars: ClassfilesPath = ClassfilesPath(None, None)
) extends SettingsBase

// FIXME: https://github.com/twitter/rsc/issues/166
object Settings {
Expand All @@ -24,7 +25,7 @@ object Settings {
case "--" +: rest =>
loop(settings, false, rest)
case "--classpath" +: s_cp +: rest if allowOptions =>
val cp = s_cp.split(pathSeparator).map(s => Paths.get(s)).toList
val cp = SettingsBase.pathsFor(s_cp)
loop(settings.copy(cp = settings.cp ++ cp), true, rest)
case "--deps" +: args if allowOptions =>
def collectDeps(deps: List[Path], args: List[String]): (List[Path], List[String]) = {
Expand All @@ -36,6 +37,13 @@ object Settings {
}
val (deps, rest) = collectDeps(Nil, args)
loop(settings.copy(deps = settings.deps :+ deps), true, rest)
case "--jars" +: rsc_path +: nsc_path +: Nil =>
val rsc_files = SettingsBase.pathsFor(rsc_path)
val nsc_files = SettingsBase.pathsFor(nsc_path)
loop(
settings.copy(precomputedJars = ClassfilesPath(Some(rsc_files), Some(nsc_files))),
true,
Nil)
case "--quiet" +: rest if allowOptions =>
loop(settings.copy(quiet = true), true, rest)
case flag +: rest if allowOptions && flag.startsWith("-") =>
Expand Down
15 changes: 4 additions & 11 deletions check/src/main/scala/rsc/checkscalasig/Settings.scala
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package rsc.checkscalasig

import java.io.File.pathSeparator
import java.nio.file.{Path, Paths}
import rsc.checkbase.SettingsBase
import rsc.checkscalasig.Settings.ClassfilesPath
import rsc.checkbase.SettingsBase.ClassfilesPath

final case class Settings(
cp: List[Path] = Nil,
Expand All @@ -14,12 +13,6 @@ final case class Settings(
) extends SettingsBase

object Settings {

final case class ClassfilesPath(rsc: Option[List[Path]], nsc: Option[List[Path]])

private def pathsFor(pathStr: String): List[Path] =
pathStr.split(pathSeparator).map(s => Paths.get(s)).toList

def parse(args: List[String]): Either[List[String], Settings] = {
def loop(
settings: Settings,
Expand All @@ -29,14 +22,14 @@ object Settings {
case "--" +: rest =>
loop(settings, false, rest)
case "--classfiles" +: rsc_path +: nsc_path +: Nil =>
val rsc_files = pathsFor(rsc_path)
val nsc_files = pathsFor(nsc_path)
val rsc_files = SettingsBase.pathsFor(rsc_path)
val nsc_files = SettingsBase.pathsFor(nsc_path)
loop(
settings.copy(classfiles = ClassfilesPath(Some(rsc_files), Some(nsc_files))),
true,
Nil)
case "--classpath" +: s_cp +: rest if allowOptions =>
val cp = pathsFor(s_cp)
val cp = SettingsBase.pathsFor(s_cp)
loop(settings.copy(cp = settings.cp ++ cp), true, rest)
case "--save-output" +: rest if allowOptions =>
loop(settings.copy(saveOutput = true), true, rest)
Expand Down

0 comments on commit be11120

Please sign in to comment.