[K/N] cinterop: Do not expand non-constant macros

Expanding macros such as __FILE__ or __TIME__ exposes
arbitrary generated filenames and timestamps from the compiler
pipeline which are not useful for interop and makes the klib
generation non-deterministic. This patch instead redefines
the macros to just map to their name in the properties
available from Kotlin.

Co-authored-by: Johan Bay <jobay@google.com>
This commit is contained in:
Johan Bay
2022-10-12 16:54:00 +00:00
committed by Space
parent 49e343e08e
commit bc13173ea9
4 changed files with 37 additions and 1 deletions
@@ -60,6 +60,13 @@ private fun expandMacros(
// or function-like construction (e.g. #define FOO throw()) but such a function is undeclared.
compilerArgs += "-Werror=implicit-function-declaration"
// Some predefined macros expand to contextual values that won't make sense to expose in Kotlin properties.
// We instead redefined them to string values of the macro name.
compilerArgs += "-Wno-builtin-macro-redefined"
val predefinedMacros = listOf("__DATE__", "__TIME__", "__TIMESTAMP__", "__FILE__", "__FILE_NAME__", "__BASE_FILE__", "__LINE__")
predefinedMacros.forEach {
compilerArgs += "-D${it}=\"${it}\""
}
// Ensure libclang reports all errors:
compilerArgs += "-ferror-limit=0"
@@ -319,4 +326,4 @@ private fun canMacroBeConstant(cursor: CValue<CXCursor>): Boolean {
// Requires updating to 3.9.1 due to https://bugs.llvm.org//show_bug.cgi?id=9069
return true
}
}