diff options
author | odersky <odersky@gmail.com> | 2017-01-12 16:18:20 +0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-12 16:18:20 +0700 |
commit | 36237cbc7449079574b4171a85bc7dccf19e371d (patch) | |
tree | 45bf3fd30f0ad343268f2dadba365cbb67f3c227 /compiler/test/dotty | |
parent | ba7e12999dc645dbcba04cf365dfd4d621ee4662 (diff) | |
parent | 783a80d0d8f726f7169022457152d4301779244f (diff) | |
download | dotty-36237cbc7449079574b4171a85bc7dccf19e371d.tar.gz dotty-36237cbc7449079574b4171a85bc7dccf19e371d.tar.bz2 dotty-36237cbc7449079574b4171a85bc7dccf19e371d.zip |
Merge pull request #1880 from dotty-staging/improve-whitelist-infrastructure
Improve whitelist infrastructure.
Diffstat (limited to 'compiler/test/dotty')
-rw-r--r-- | compiler/test/dotty/tools/StdLibSources.scala | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/compiler/test/dotty/tools/StdLibSources.scala b/compiler/test/dotty/tools/StdLibSources.scala new file mode 100644 index 000000000..78a132426 --- /dev/null +++ b/compiler/test/dotty/tools/StdLibSources.scala @@ -0,0 +1,59 @@ +package dotty.tools + +import java.io.File + +import scala.io.Source + +object StdLibSources { + + /* For debug only */ + private val useExplicitWhiteList = false + + private final val stdLibPath = "../scala-scala/src/library/" + + def blacklistFile: String = "./test/dotc/scala-collections.blacklist" + private def whitelistFile: String = "./test/dotc/scala-collections.whitelist" + + def whitelisted: List[String] = { + lazy val whitelistBasedOnBlacklist = all.diff(blacklisted) + if (!useExplicitWhiteList) { + whitelistBasedOnBlacklist + } else if (!new File(whitelistFile).exists()) { + genWhitelist(whitelistBasedOnBlacklist.map(_.replace(stdLibPath, ""))) + whitelistBasedOnBlacklist + } else { + loadList(whitelistFile) + } + } + + def blacklisted: List[String] = loadList(blacklistFile) + + def all: List[String] = { + def collectAllFilesInDir(dir: File, acc: List[String]): List[String] = { + val files = dir.listFiles() + val acc2 = files.foldLeft(acc)((acc1, file) => if (file.isFile && file.getPath.endsWith(".scala")) file.getPath :: acc1 else acc1) + files.foldLeft(acc2)((acc3, file) => if (file.isDirectory) collectAllFilesInDir(file, acc3) else acc3) + } + collectAllFilesInDir(new File(stdLibPath), Nil) + } + + private def genWhitelist(list: List[String]): Unit = { + println(s"Generating $whitelistFile based on $blacklistFile") + val whitelist = new File(whitelistFile) + val p = new java.io.PrintWriter(whitelist) + try { + list.foreach(p.println) + } finally { + p.close() + } + } + + private def loadList(path: String): List[String] = Source.fromFile(path, "UTF8").getLines() + .map(_.trim) // allow identation + .filter(!_.startsWith("#")) // allow comment lines prefixed by # + .map(_.takeWhile(_ != '#').trim) // allow comments in the end of line + .filter(_.nonEmpty) + .map(stdLibPath + _) + .toList + +} |