@@ -106,7 +106,7 @@ object ScalaNativeP {
106106 relativeInJar == regularPath.toString()
107107 }
108108 @ tailrec
109- def findAndRead (
109+ def findInClasspathAndRead (
110110 classpath : Stream [VirtualDirectory ],
111111 path : Path
112112 ): Option [ByteBuffer ] = {
@@ -116,15 +116,31 @@ object ScalaNativeP {
116116 val found = dir.files
117117 .find(virtualDirPathMatches(_, path))
118118 .map(dir.read(_))
119- if (found.isEmpty) findAndRead (tail, path)
119+ if (found.isEmpty) findInClasspathAndRead (tail, path)
120120 else found
121121 }
122122 }
123+
124+ def tryReadFromPath (path : Path ): Option [ByteBuffer ] = {
125+ val file = path.toFile()
126+ val absPath = path.toAbsolutePath()
127+ // When classpath is explicitly provided don't try to read directly
128+ if (! options.usingDefaultClassPath || ! file.exists()) None
129+ else
130+ util.Try {
131+ VirtualDirectory
132+ .real(absPath.getParent())
133+ .read(absPath.getFileName())
134+ }.toOption
135+ }
136+
123137 for {
124138 fileName <- options.classNames
125139 path = Paths .get(fileName).normalize()
126- content <- findAndRead(cp, path)
127- .orElse(fail(s " Not found file with name ` ${fileName}` " ))
140+ content <-
141+ tryReadFromPath(path)
142+ .orElse(findInClasspathAndRead(cp, path))
143+ .orElse(fail(s " Not found file with name ` ${fileName}` " ))
128144 } {
129145 val defns = deserializeBinary(content, fileName)
130146 printNIR(defns, options.verbose)
0 commit comments