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

Update the tasty inspector returned value #13316

Merged
merged 1 commit into from
Aug 24, 2021
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
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