-
Notifications
You must be signed in to change notification settings - Fork 362
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for linker and optimizer reporters (#405)
Reporters supersede harcoded `nativeEmitDependencyGraph` and `nativeVerbose` options that were used to debug the scala native toolchain before.
- Loading branch information
Showing
18 changed files
with
333 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import scalanative.tools.LinkerReporter | ||
import scalanative.sbtplugin.ScalaNativePluginInternal.nativeLinkerReporter | ||
|
||
ScalaNativePlugin.projectSettings | ||
|
||
scalaVersion := "2.11.8" | ||
|
||
nativeLinkerReporter := LinkerReporter.toFile(target.value / "out.dot") | ||
|
||
lazy val check = taskKey[Unit]("Check that dot file was created.") | ||
|
||
check := { | ||
assert((target.value / "out.dot").exists) | ||
} |
10 changes: 10 additions & 0 deletions
10
scripted-tests/run/linker-reporter/project/scala-native.sbt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
val pluginVersion = System.getProperty("plugin.version") | ||
if (pluginVersion == null) | ||
throw new RuntimeException( | ||
"""|The system property 'plugin.version' is not defined. | ||
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin) | ||
else addSbtPlugin("org.scala-native" % "sbt-scala-native" % pluginVersion) | ||
} | ||
|
||
resolvers += Resolver.sonatypeRepo("snapshots") |
3 changes: 3 additions & 0 deletions
3
scripted-tests/run/linker-reporter/src/main/scala/Hello.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
object Main { | ||
def main(args: Array[String]): Unit = () | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
> nativeLink | ||
> check |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import scalanative.tools.OptimizerReporter | ||
import scalanative.sbtplugin.ScalaNativePluginInternal.nativeOptimizerReporter | ||
|
||
ScalaNativePlugin.projectSettings | ||
|
||
scalaVersion := "2.11.8" | ||
|
||
nativeOptimizerReporter := OptimizerReporter.toDirectory(crossTarget.value) | ||
|
||
lazy val check = taskKey[Unit]("Check that dot file was created.") | ||
|
||
check := { | ||
assert((crossTarget.value / "out.00.hnir").exists) | ||
} |
10 changes: 10 additions & 0 deletions
10
scripted-tests/run/optimizer-reporter/project/scala-native.sbt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
val pluginVersion = System.getProperty("plugin.version") | ||
if (pluginVersion == null) | ||
throw new RuntimeException( | ||
"""|The system property 'plugin.version' is not defined. | ||
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin) | ||
else addSbtPlugin("org.scala-native" % "sbt-scala-native" % pluginVersion) | ||
} | ||
|
||
resolvers += Resolver.sonatypeRepo("snapshots") |
3 changes: 3 additions & 0 deletions
3
scripted-tests/run/optimizer-reporter/src/main/scala/Hello.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
object Main { | ||
def main(args: Array[String]): Unit = () | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
> nativeLink | ||
> check |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
tools/src/main/scala/scala/scalanative/linker/Reporter.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package scala.scalanative | ||
package linker | ||
|
||
import java.io.{File, PrintWriter} | ||
import nir.Global | ||
import nir.Shows._ | ||
import util.sh | ||
|
||
/** Linking reporters can override one of the corresponding methods to | ||
* get notified whenever one of the linking events happens. | ||
*/ | ||
trait Reporter { | ||
|
||
/** Gets called whenever linking starts. */ | ||
def onStart(): Unit = () | ||
|
||
/** Gets called whenever a new entry point is discovered. */ | ||
def onEntry(global: Global): Unit = () | ||
|
||
/** Gets called whenever a new definition is loaded from nir path. */ | ||
def onResolved(global: Global): Unit = () | ||
|
||
/** Gets called whenever linker fails to resolve a global. */ | ||
def onUnresolved(globa: Global): Unit = () | ||
|
||
/** Gets called whenever a new direct dependency is discovered. */ | ||
def onDirectDependency(from: Global, to: Global): Unit = () | ||
|
||
/** Gets called whenever a new conditional dependency is discovered. */ | ||
def onConditionalDependency(from: Global, to: Global, cond: Global): Unit = | ||
() | ||
|
||
/** Gets called whenever linking is complete. */ | ||
def onComplete(): Unit = () | ||
} | ||
|
||
object Reporter { | ||
|
||
/** Default no-op reporter. */ | ||
val empty = new Reporter {} | ||
|
||
/** Generate dot file for observed dependency graph. */ | ||
def toFile(file: File): Reporter = new Reporter { | ||
private var writer: PrintWriter = _ | ||
|
||
private def writeStart(): Unit = { | ||
writer = new PrintWriter(file) | ||
writer.println("digraph G {") | ||
} | ||
|
||
private def writeEdge(from: Global, to: Global): Unit = { | ||
def quoted(s: String) = "\"" + s + "\"" | ||
writer.print(quoted(sh"$from".toString)) | ||
writer.print("->") | ||
writer.print(quoted(sh"$to".toString)) | ||
writer.println(";") | ||
} | ||
|
||
private def writeEnd(): Unit = { | ||
writer.println("}") | ||
writer.close() | ||
} | ||
|
||
override def onStart(): Unit = | ||
writeStart() | ||
|
||
override def onDirectDependency(from: Global, to: Global): Unit = | ||
writeEdge(from, to) | ||
|
||
override def onConditionalDependency(from: Global, | ||
to: Global, | ||
cond: Global): Unit = | ||
writeEdge(from, to) | ||
|
||
override def onComplete(): Unit = | ||
writeEnd() | ||
} | ||
} |
Oops, something went wrong.