Skip to content

Commit 64cc7c9

Browse files
Add verbose option (#17)
* Add verbose option * Remove unbouded setting from verbose setting
1 parent 4637f81 commit 64cc7c9

File tree

3 files changed

+27
-12
lines changed

3 files changed

+27
-12
lines changed

cli/src/main/scala/scala/scalanative/cli/ScalaNativeP.scala

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@ import java.nio.file.Paths
44
import java.io.File
55
import scala.scalanative.util.Scope
66
import scala.scalanative.cli.options._
7-
import scala.scalanative.nir.Global
7+
import scala.scalanative.nir._
88
import scala.scalanative.build.Config
99
import scala.scalanative.linker.ClassLoader
1010
import java.nio.file.Path
1111
import scala.scalanative.io.VirtualDirectory
1212
import scala.scalanative.nir.serialization.deserializeBinary
13-
import scala.scalanative.nir.Defn
1413
import scala.annotation.tailrec
1514
import java.nio.ByteBuffer
1615

@@ -66,13 +65,13 @@ object ScalaNativeP {
6665
System.err.println(s"Ignoring non existing path: $path")
6766
}
6867

69-
if (options.fromPath) printFromFiles(classpath, options.classNames)
70-
else printFromNames(classpath, options.classNames)
68+
if (options.fromPath) printFromFiles(classpath, options)
69+
else printFromNames(classpath, options)
7170
}
7271

7372
private def printFromNames(
7473
classpath: List[Path],
75-
args: Seq[String]
74+
options: PrinterOptions
7675
): Unit = {
7776
Scope { implicit scope =>
7877
val classLoader =
@@ -81,10 +80,10 @@ object ScalaNativeP {
8180
}
8281

8382
for {
84-
className <- args
83+
className <- options.classNames
8584
} {
8685
classLoader.load(Global.Top(className)) match {
87-
case Some(defns) => printNIR(defns)
86+
case Some(defns) => printNIR(defns, options.verbose)
8887
case None => fail(s"Not found class/object with name `${className}`")
8988
}
9089
}
@@ -93,7 +92,7 @@ object ScalaNativeP {
9392

9493
private def printFromFiles(
9594
classpath: List[Path],
96-
args: Seq[String]
95+
options: PrinterOptions
9796
): Unit = {
9897

9998
Scope { implicit scope =>
@@ -122,19 +121,24 @@ object ScalaNativeP {
122121
}
123122
}
124123
for {
125-
fileName <- args
124+
fileName <- options.classNames
126125
path = Paths.get(fileName).normalize()
127126
content <- findAndRead(cp, path)
128127
.orElse(fail(s"Not found file with name `${fileName}`"))
129128
} {
130129
val defns = deserializeBinary(content, fileName)
131-
printNIR(defns)
130+
printNIR(defns, options.verbose)
132131
}
133132
}
134133
}
135134

136-
private def printNIR(defns: Seq[Defn]) =
135+
private def printNIR(defns: Seq[Defn], verbose: Boolean) =
137136
defns
137+
.map {
138+
case defn @ Defn.Define(attrs, name, ty, _) if !verbose =>
139+
Defn.Declare(attrs, name, ty)(defn.pos)
140+
case defn => defn
141+
}
138142
.sortBy(_.name.mangle)
139143
.foreach { d =>
140144
println(d.show)

cli/src/main/scala/scala/scalanative/cli/options/PrinterOptions.scala

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ case class PrinterOptions(
66
classNames: List[String] = Nil,
77
classpath: List[String] = "." :: Nil,
88
usingDefaultClassPath: Boolean = true,
9-
fromPath: Boolean = false
9+
fromPath: Boolean = false,
10+
verbose: Boolean = false
1011
)
1112

1213
object PrinterOptions {
@@ -29,5 +30,12 @@ object PrinterOptions {
2930
.optional()
3031
.action((x, c) => c.copy(fromPath = true))
3132
.text("Instead of passing class/object names, pass NIR file paths.")
33+
parser
34+
.opt[Unit]("verbose")
35+
.abbr("-v")
36+
.optional()
37+
.action((_, c) => c.copy(verbose = true))
38+
.text("Print all informations about NIR, including method definitions.")
39+
3240
}
3341
}

cli/src/sbt-test/integration/standalone/test

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ $ exists Foo$.nir
1010
-> runScript scala-native-p not.existing.Class
1111

1212
> runScript scala-native-p --from-path Foo.nir
13+
> runScript scala-native-p --from-path -v Foo.nir
14+
> runScript scala-native-p --from-path --verbose Foo.nir
15+
1316
-> runScript scala-native-p --from-path notExisting.nir
1417

1518
> runExec jar cf inside.jar Foo.class Foo.nir Foo$.class Foo$.nir

0 commit comments

Comments
 (0)