-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add -Ythrough-tasty to debug from TASTY compilation direct from sources #3786
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
Changes from 1 commit
19c13f3
cf0212f
d525de3
d992f6c
4b1385e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package dotty.tools | ||
package dotc | ||
package fromtasty | ||
|
||
import scala.util.control.NonFatal | ||
|
||
import dotty.tools.io.Path | ||
|
||
import java.nio.file.{Files, Paths} | ||
|
||
object Debug { | ||
def main(args: Array[String]): Unit = { | ||
// Preload scala.util.control.NonFatal. Otherwise, when trying to catch a StackOverflowError, | ||
// we may try to load it but fail with another StackOverflowError and lose the original exception, | ||
// see <https://groups.google.com/forum/#!topic/scala-user/kte6nak-zPM>. | ||
val _ = NonFatal | ||
|
||
|
||
println("From tasty debug driver") | ||
assert(!args.contains("-d")) | ||
|
||
val fromSourcesOut = Files.createTempDirectory(Paths.get("out").toAbsolutePath, "from-sources-tmp") | ||
|
||
println(s"Compiling scala to sources to $fromSourcesOut") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No sure it useful to print the output directory since the file will be deleted when the program exit There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We do not delete them in case of failure. I will print the directories only in case of failure. |
||
val compilation1 = dotc.Main.process("-d" +: fromSourcesOut.toString +: args) | ||
|
||
if (compilation1.hasErrors) { | ||
println("Failed compilation from sources") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would remove this. If the compilation failed, the compiler already tells you "error found" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would not tell me which of the two compilation failed. |
||
sys.exit(1) | ||
} | ||
|
||
val fromTastyOut = Files.createTempDirectory(Paths.get("out").toAbsolutePath, "from-tasty-tmp") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why a temporary directory? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To ensure it is a clean directory and the only contents are the ones coming from this compilation. |
||
|
||
val ext = "hasTasty" | ||
val classes = Path(fromSourcesOut).walk.filter(x => x.isFile && x.extension == ext).map { x => | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
val source = x.toString | ||
source.substring(fromSourcesOut.toString.length + 1, source.length - ext.length - 1).replace('/', '.') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe add a comment to explain what this does There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok |
||
}.toList | ||
|
||
val fromTastyArgs = | ||
"-from-tasty" :: insertClasspathInArgs(args.filterNot(_.endsWith(".scala")).toList, fromSourcesOut.toString) ::: classes | ||
|
||
println(s"Compiling TASTY to sources from $fromSourcesOut to $fromTastyOut") | ||
val compilation2 = dotc.Main.process(fromTastyArgs.toArray) | ||
|
||
if (compilation2.hasErrors) { | ||
println("Failed compilation from sources") | ||
sys.exit(1) | ||
} | ||
|
||
Path(fromSourcesOut).deleteRecursively() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this needed if the directory is temporary? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Those temporary directories do not delete themselves. The |
||
Path(fromTastyOut).deleteRecursively() | ||
} | ||
|
||
private def insertClasspathInArgs(args: List[String], cp: String): List[String] = { | ||
val (beforeCp, fromCp) = args.span(_ != "-classpath") | ||
val classpath = fromCp.drop(1).headOption.fold(cp)(_ + ":" + cp) | ||
"-classpath" :: classpath :: beforeCp ::: fromCp.drop(2) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sure
out
exist?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It works only on
sbt dotc
,out
should exist.