|
| 1 | +package scala.scalanative.cli |
| 2 | + |
| 3 | +import caseapp.core.app.CaseApp |
| 4 | +import caseapp.core.RemainingArgs |
| 5 | +import java.nio.file.Paths |
| 6 | +import java.io.File |
| 7 | +import scala.scalanative.util.Scope |
| 8 | +import scala.scalanative.cli.options._ |
| 9 | +import scala.scalanative.nir.Global |
| 10 | +import scala.scalanative.build.Config |
| 11 | +import scala.scalanative.linker.ClassLoader |
| 12 | + |
| 13 | +object ScalaNativeP extends CaseApp[POptions] { |
| 14 | + |
| 15 | + def run(options: POptions, args: RemainingArgs): Unit = { |
| 16 | + if (options.misc.version) { |
| 17 | + println(BuildInfo.nativeVersion) |
| 18 | + exit(0) |
| 19 | + } |
| 20 | + |
| 21 | + if (args.all.isEmpty) { |
| 22 | + System.err.println("Required NIR file not specified.") |
| 23 | + exit(1) |
| 24 | + } |
| 25 | + |
| 26 | + val (classpath, ignoredPaths) = |
| 27 | + options.classpath |
| 28 | + .flatMap(_.split(File.pathSeparator)) |
| 29 | + .map(Paths.get(_)) |
| 30 | + .partition(_.toFile().exists()) |
| 31 | + ignoredPaths.foreach { path => |
| 32 | + System.err.println(s"Ignoring non existing path: $path") |
| 33 | + } |
| 34 | + |
| 35 | + Scope { implicit scope => |
| 36 | + val classLoader = |
| 37 | + ClassLoader.fromDisk { |
| 38 | + Config.empty.withClassPath(classpath) |
| 39 | + } |
| 40 | + |
| 41 | + for { |
| 42 | + fileName <- args.all |
| 43 | + } { |
| 44 | + classLoader.load(Global.Top(fileName)) match { |
| 45 | + case Some(defns) => |
| 46 | + defns |
| 47 | + .sortBy(_.name.mangle) |
| 48 | + .foreach { d => |
| 49 | + println(d.show) |
| 50 | + println() |
| 51 | + } |
| 52 | + case None => fail(s"Not found class/object with name `${fileName}`") |
| 53 | + } |
| 54 | + } |
| 55 | + } |
| 56 | + } |
| 57 | + |
| 58 | + private def fail(msg: String): Nothing = { |
| 59 | + Console.err.println(msg) |
| 60 | + exit(1) |
| 61 | + } |
| 62 | + |
| 63 | +} |
0 commit comments