diff --git a/tools/versioner/src/Preprocessor.cpp b/tools/versioner/src/Preprocessor.cpp index 619173c85..33531bd8b 100644 --- a/tools/versioner/src/Preprocessor.cpp +++ b/tools/versioner/src/Preprocessor.cpp @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -31,6 +32,8 @@ #include #include +#include +#include #include "Arch.h" #include "DeclarationDatabase.h" @@ -456,6 +459,36 @@ bool preprocessHeaders(const std::string& dst_dir, const std::string& src_dir, } } + // Copy over any unchanged files directly. + char* fts_paths[2] = { const_cast(src_dir.c_str()), nullptr }; + FTS* fts = fts_open(fts_paths, FTS_LOGICAL, nullptr); + while (FTSENT* ent = fts_read(fts)) { + llvm::StringRef path = ent->fts_path; + if (!path.startswith(src_dir)) { + err(1, "path '%s' doesn't start with source dir '%s'", ent->fts_path, src_dir.c_str()); + } + + if (ent->fts_info != FTS_F) { + continue; + } + + std::string rel_path = path.substr(src_dir.length() + 1); + if (guards.count(rel_path) == 0) { + std::string dst_path = dst_dir + "/" + rel_path; + llvm::StringRef parent_path = llvm::sys::path::parent_path(dst_path); + if (llvm::sys::fs::create_directories(parent_path)) { + errx(1, "failed to ensure existence of directory '%s'", parent_path.str().c_str()); + } + if (llvm::sys::fs::copy_file(path, dst_path)) { + errx(1, "failed to copy '%s/%s' to '%s'", src_dir.c_str(), path.str().c_str(), + dst_path.c_str()); + } + + printf("Copied unmodified header %s\n", dst_path.c_str()); + } + } + fts_close(fts); + for (const auto& file_it : guards) { file_lines[file_it.first] = readFileLines(file_it.first); }