r179346 - <rdar://problem/13615607> Include SDK version information in the module hash.
Douglas Gregor
dgregor at apple.com
Thu Apr 11 17:18:54 PDT 2013
Author: dgregor
Date: Thu Apr 11 19:18:53 2013
New Revision: 179346
URL: http://llvm.org/viewvc/llvm-project?rev=179346&view=rev
Log:
<rdar://problem/13615607> Include SDK version information in the module hash.
This is a Darwin-SDK-specific hash criteria used to identify a
particular SDK without having to hash the contents of all of its
headers. If other platforms have such versioned files, we should add
those checks here.
Added:
cfe/trunk/test/Modules/system_version.m
Modified:
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=179346&r1=179345&r2=179346&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Thu Apr 11 19:18:53 2013
@@ -29,6 +29,7 @@
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/Host.h"
#include "llvm/Support/Path.h"
+#include "llvm/Support/system_error.h"
using namespace clang;
//===----------------------------------------------------------------------===//
@@ -1696,5 +1697,21 @@ std::string CompilerInvocation::getModul
hsOpts.UseStandardCXXIncludes,
hsOpts.UseLibcxx);
+ // Darwin-specific hack: if we have a sysroot, use the contents of
+ // $sysroot/System/Library/CoreServices/SystemVersion.plist
+ // as part of the module hash.
+ if (!hsOpts.Sysroot.empty()) {
+ llvm::OwningPtr<llvm::MemoryBuffer> buffer;
+ SmallString<128> systemVersionFile;
+ systemVersionFile += hsOpts.Sysroot;
+ llvm::sys::path::append(systemVersionFile, "System");
+ llvm::sys::path::append(systemVersionFile, "Library");
+ llvm::sys::path::append(systemVersionFile, "CoreServices");
+ llvm::sys::path::append(systemVersionFile, "SystemVersion.plist");
+ if (!llvm::MemoryBuffer::getFile(systemVersionFile, buffer)) {
+ code = hash_combine(code, buffer.get()->getBuffer());
+ }
+ }
+
return llvm::APInt(64, code).toString(36, /*Signed=*/false);
}
Added: cfe/trunk/test/Modules/system_version.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/system_version.m?rev=179346&view=auto
==============================================================================
--- cfe/trunk/test/Modules/system_version.m (added)
+++ cfe/trunk/test/Modules/system_version.m Thu Apr 11 19:18:53 2013
@@ -0,0 +1,32 @@
+// Test checking that we're hashing a system version file in the
+// module hash.
+// REQUIRES: shell
+
+// First, build a system root.
+// RUN: rm -rf %t
+// RUN: mkdir -p %t/usr/include
+// RUN: cp %S/Inputs/Modified/A.h %t/usr/include
+// RUN: cp %S/Inputs/Modified/B.h %t/usr/include
+// RUN: cp %S/Inputs/Modified/module.map %t/usr/include
+
+// Run once with no system version file. We should end up with one module.
+// RUN: %clang_cc1 -fmodules-cache-path=%t/cache -fmodules -isysroot %t %s -verify
+// RUN: ls -R %t | grep -c ModA.pcm| grep 1
+
+// Add a system version file and run again. We should now have two
+// module variants.
+// RUN: mkdir -p %t/System/Library/CoreServices
+// RUN: echo "hello" > %t/System/Library/CoreServices/SystemVersion.plist
+// RUN: %clang_cc1 -fmodules-cache-path=%t/cache -fmodules -isysroot %t %s -verify
+// RUN: ls -R %t | grep -c ModA.pcm| grep 2
+
+// Change the system version file and run again. We should now have three
+// module variants.
+// RUN: mkdir -p %t/System/Library/CoreServices
+// RUN: echo "modules" > %t/System/Library/CoreServices/SystemVersion.plist
+// RUN: %clang_cc1 -fmodules-cache-path=%t/cache -fmodules -isysroot %t %s -verify
+// RUN: ls -R %t | grep -c ModA.pcm| grep 3
+
+// expected-no-diagnostics
+ at import ModA;
+
More information about the cfe-commits
mailing list