Header dependencies (#4530)

This commit is contained in:
Alexander Shabalin
2020-11-19 10:48:20 +03:00
committed by Stanislav Erokhin
parent 20931eebe1
commit a19bf5c48e
@@ -95,7 +95,29 @@ open class CompileToBitcode @Inject constructor(
@get:InputFiles
protected val headers: Iterable<File>
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<File>()
// 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")