Skip to content

Commit

Permalink
Improve file path handling and update function mapping
Browse files Browse the repository at this point in the history
The changes improve the handling of file paths during parsing, by fully resolving paths before performing checks. Error messages have now been updated to provide the absolute paths that failed the checks. Additionally, function reference mapping has been updated to handle and escape "%" character for better consistency. Unit tests have been updated to accommodate these changes.
  • Loading branch information
Alexandre Mommers committed Feb 14, 2024
1 parent 624414d commit f53bff6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import org.slf4j.LoggerFactory
import java.io.File
import java.net.URL
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.StandardCopyOption
import java.security.MessageDigest

Expand Down Expand Up @@ -137,8 +138,8 @@ class KlangPlugin : Plugin<Project> {
.filterIsInstance<KlangPluginTask.Parse>()
.map { Triple(it.sourceFile, workingDirectory.resolve(it.sourcePath), it.onSuccess) }
.forEach { (fileToParse, sourcePath, onSuccess) ->
val localFileToParse = File(fileToParse)
check(localFileToParse.exists()) { "File to parse does not exist" }
val localFileToParse = Path.of(sourcePath.absolutePath).resolve(fileToParse).toFile()
check(localFileToParse.exists()) { "${localFileToParse.absolutePath} to parse does not exist" }
check(localFileToParse.isFile()) { "${localFileToParse.absolutePath} is not a file" }
check(localFileToParse.canRead()) { "${localFileToParse.absolutePath} is not readable" }
check(localFileToParse.length() > 0) { "${localFileToParse.absolutePath} is empty" }
Expand Down
3 changes: 2 additions & 1 deletion klang/klang/src/main/kotlin/klang/mapper/Function.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ private fun NativeFunction.toSpec(packageName: String) = FunSpec

private fun NativeFunction.Argument.toSpec(packageName: String, index: Int) = ParameterSpec
.builder(name ?: "parameter$index", type.toType(packageName).copy(nullable = type.isNullable ?: true))
.addKdoc("mapped from ${type.referenceAsString}")
//TODO find how to escape %
.addKdoc("mapped from ${type.referenceAsString.replace("%", "")}")
.build()
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ class SDL2ItTest : ParserTestCommon({
it.name.value.isNotBlank() shouldBe true
it.values.isEmpty() shouldNotBe true
}

findFunctionByName("SDL_ReportAssertion")
.let {
it shouldNotBe null
//it?.arguments?.forEachIndexed { index, argument -> argument.name shouldBe "arg$index" }
}
}

}
Expand Down

0 comments on commit f53bff6

Please sign in to comment.