mirror of
https://github.com/irmen/prog8.git
synced 2024-09-10 09:54:32 +00:00
library modules imported from embedded resource now contain proper file path (useful for error messages)
This commit is contained in:
parent
680b2df08a
commit
b5fa6c2d0a
@ -131,13 +131,14 @@ internal class ModuleImporter {
|
|||||||
if(existing!=null)
|
if(existing!=null)
|
||||||
return null
|
return null
|
||||||
|
|
||||||
val resource = tryGetEmbeddedResource("$moduleName.p8")
|
val rsc = tryGetEmbeddedResource("$moduleName.p8")
|
||||||
val importedModule =
|
val importedModule =
|
||||||
if(resource!=null) {
|
if(rsc!=null) {
|
||||||
// load the module from the embedded resource
|
// load the module from the embedded resource
|
||||||
|
val (resource, resourcePath) = rsc
|
||||||
resource.use {
|
resource.use {
|
||||||
println("importing '$moduleName' (library)")
|
println("importing '$moduleName' (library)")
|
||||||
importModule(program, CharStreams.fromStream(it), Paths.get("@embedded@/$moduleName"), true)
|
importModule(program, CharStreams.fromStream(it), Paths.get("@embedded@/$resourcePath"), true)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
val modulePath = discoverImportedModuleFile(moduleName, source, import.position)
|
val modulePath = discoverImportedModuleFile(moduleName, source, import.position)
|
||||||
@ -148,11 +149,18 @@ internal class ModuleImporter {
|
|||||||
return importedModule
|
return importedModule
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun tryGetEmbeddedResource(name: String): InputStream? {
|
private fun tryGetEmbeddedResource(name: String): Pair<InputStream, String>? {
|
||||||
val target = CompilationTarget.instance.name
|
val target = CompilationTarget.instance.name
|
||||||
val targetSpecific = object{}.javaClass.getResourceAsStream("/prog8lib/$target/$name")
|
val targetSpecificPath = "/prog8lib/$target/$name"
|
||||||
if(targetSpecific!=null)
|
val targetSpecificResource = object{}.javaClass.getResourceAsStream(targetSpecificPath)
|
||||||
return targetSpecific
|
if(targetSpecificResource!=null)
|
||||||
return object{}.javaClass.getResourceAsStream("/prog8lib/$name")
|
return Pair(targetSpecificResource, targetSpecificPath)
|
||||||
|
|
||||||
|
val generalPath = "/prog8lib/$name"
|
||||||
|
val generalResource = object{}.javaClass.getResourceAsStream(generalPath)
|
||||||
|
if(generalResource!=null)
|
||||||
|
return Pair(generalResource, generalPath)
|
||||||
|
|
||||||
|
return null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user