Skip to content

Commit

Permalink
Update the tasty inspector returned value
Browse files Browse the repository at this point in the history
  • Loading branch information
BarkingBad committed Aug 21, 2021
1 parent 86c9a7e commit 48121d8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ object BootstrappedStdLibTASYyTest:
()
}
val tastyFiles = scalaLibTastyPaths.filterNot(blacklisted)
val hasErrors = TastyInspector.inspectTastyFiles(tastyFiles.map(x => scalaLibClassesPath.resolve(x).toString))(inspector)
assert(!hasErrors, "Errors reported while loading from TASTy")
val isSuccess = TastyInspector.inspectTastyFiles(tastyFiles.map(x => scalaLibClassesPath.resolve(x).toString))(inspector)
assert(isSuccess, "Errors reported while loading from TASTy")

def compileFromTastyInJar(blacklisted: Set[String]): Unit = {
val driver = new dotty.tools.dotc.Driver
Expand Down
18 changes: 12 additions & 6 deletions tasty-inspector/src/scala/tasty/inspector/TastyInspector.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@ object TastyInspector:
/** Load and process TASTy files using TASTy reflect
*
* @param tastyFiles List of paths of `.tasty` files
*
* @return boolean value indicating whether the process succeeded
*/
def inspectTastyFiles(tastyFiles: List[String])(inspector: Inspector): Boolean =
inspectAllTastyFiles(tastyFiles, Nil, Nil)(inspector)

/** Load and process TASTy files in a `jar` file using TASTy reflect
*
* @param jars Path of `.jar` file
*
* @return boolean value indicating whether the process succeeded
*/
def inspectTastyFilesInJar(jar: String)(inspector: Inspector): Boolean =
inspectAllTastyFiles(Nil, List(jar), Nil)(inspector)
Expand All @@ -38,6 +42,8 @@ object TastyInspector:
* @param tastyFiles List of paths of `.tasty` files
* @param jars List of path of `.jar` files
* @param dependenciesClasspath Classpath with extra dependencies needed to load class in the `.tasty` files
*
* @return boolean value indicating whether the process succeeded
*/
def inspectAllTastyFiles(tastyFiles: List[String], jars: List[String], dependenciesClasspath: List[String])(inspector: Inspector): Boolean =
def checkFile(fileName: String, ext: String): Unit =
Expand All @@ -49,7 +55,7 @@ object TastyInspector:
tastyFiles.foreach(checkFile(_, "tasty"))
jars.foreach(checkFile(_, "jar"))
val files = tastyFiles ::: jars
files.nonEmpty && inspectFiles(dependenciesClasspath, files)(inspector)
inspectFiles(dependenciesClasspath, files)(inspector)

private def inspectorDriver(inspector: Inspector) =
class InspectorDriver extends Driver:
Expand Down Expand Up @@ -100,11 +106,11 @@ object TastyInspector:


private def inspectFiles(classpath: List[String], classes: List[String])(inspector: Inspector): Boolean =
if (classes.isEmpty)
throw new IllegalArgumentException("Parameter classes should no be empty")

val reporter = inspectorDriver(inspector).process(inspectorArgs(classpath, classes))
reporter.hasErrors
classes match
case Nil => true
case _ =>
val reporter = inspectorDriver(inspector).process(inspectorArgs(classpath, classes))
!reporter.hasErrors

end inspectFiles

Expand Down

0 comments on commit 48121d8

Please sign in to comment.