From a19bf5c48e8d2d5a756120baf34e53706f5d89bd Mon Sep 17 00:00:00 2001 From: Alexander Shabalin Date: Thu, 19 Nov 2020 10:48:20 +0300 Subject: [PATCH] Header dependencies (#4530) --- .../kotlin/bitcode/CompileToBitcode.kt | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/bitcode/CompileToBitcode.kt b/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/bitcode/CompileToBitcode.kt index 4cd0298ef37..f753c99b409 100644 --- a/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/bitcode/CompileToBitcode.kt +++ b/kotlin-native/build-tools/src/main/kotlin/org/jetbrains/kotlin/bitcode/CompileToBitcode.kt @@ -95,7 +95,29 @@ open class CompileToBitcode @Inject constructor( @get:InputFiles protected val headers: Iterable get() { - return headersDirs.files.flatMap { dir -> + // Not using clang's -M* flags because there's a problem with our current include system: + // We allow includes relative to the current directory and also pass -I for each imported module + // Given file tree: + // a: + // header.hpp + // b: + // impl.cpp + // Assume module b adds a to its include path. + // If b/impl.cpp has #include "header.hpp", it'll be included from a/header.hpp. If we add another file + // header.hpp into b/, the next compilation of b/impl.cpp will include b/header.hpp. -M flags, however, + // won't generate a dependency on b/header.hpp, so incremental compilation will be broken. + // TODO: Apart from dependency generation this also makes it awkward to have two files with + // the same name (e.g. Utils.h) in directories a/ and b/: For the b/impl.cpp to include a/header.hpp + // it needs to have #include "../a/header.hpp" + + val dirs = mutableSetOf() + // First add dirs with sources, as clang by default adds directory with the source to the include path. + inputFiles.forEach { + dirs.add(it.parentFile) + } + // Now add manually given header dirs. + dirs.addAll(headersDirs.files) + return dirs.flatMap { dir -> project.fileTree(dir) { val includePatterns = when (language) { Language.C -> arrayOf("**/.h")