r177194 - <rdar://problem/13426257> Introduce SDKSettings.plist as an input file dependency for PCH/modules.

Douglas Gregor dgregor at apple.com
Fri Mar 15 16:36:26 PDT 2013


On Mar 15, 2013, at 4:33 PM, Jean-Daniel Dupas <devlists at shadowlab.org> wrote:

> Out of curiosity, what happen while compiling on Darwin without specifying an sdkroot as in such case, it uses headers from /System directly and will not be able to locate a SDKSettings.plist file.

If there is no SDKSettings.plist file, then we won't add a dependency on it. The net effect is that modules will not automatically rebuild if you (say) hack your system headers.

	- Doug

> 
> 
> Le 15 mars 2013 à 23:15, Douglas Gregor <dgregor at apple.com> a écrit :
> 
>> Author: dgregor
>> Date: Fri Mar 15 17:15:07 2013
>> New Revision: 177194
>> 
>> URL: http://llvm.org/viewvc/llvm-project?rev=177194&view=rev
>> Log:
>> <rdar://problem/13426257> Introduce SDKSettings.plist as an input file dependency for PCH/modules.
>> 
>> When we're building a precompiled header or module against an SDK on
>> Darwin, there will be a file SDKSettings.plist in the sysroot. Since
>> stat()'ing every system header on which a module or PCH file depends
>> is performance suicide, we instead stat() just SDKSettings.plist. This
>> hack works well on Darwin; it's unclear how we want to handle this on
>> other platforms. If there is a canonical file, we should use it; if
>> not, we either have to take the performance hit of stat()'ing system
>> headers repeatedly or roll the dice by not checking anything.
>> 
>> Modified:
>>   cfe/trunk/include/clang/Serialization/ASTWriter.h
>>   cfe/trunk/lib/Serialization/ASTWriter.cpp
>> 
>> Modified: cfe/trunk/include/clang/Serialization/ASTWriter.h
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTWriter.h?rev=177194&r1=177193&r2=177194&view=diff
>> ==============================================================================
>> --- cfe/trunk/include/clang/Serialization/ASTWriter.h (original)
>> +++ cfe/trunk/include/clang/Serialization/ASTWriter.h Fri Mar 15 17:15:07 2013
>> @@ -48,6 +48,7 @@ class CXXCtorInitializer;
>> class FileEntry;
>> class FPOptions;
>> class HeaderSearch;
>> +class HeaderSearchOptions;
>> class IdentifierResolver;
>> class MacroDefinition;
>> class OpaqueValueExpr;
>> @@ -416,7 +417,9 @@ private:
>>  void WriteBlockInfoBlock();
>>  void WriteControlBlock(Preprocessor &PP, ASTContext &Context,
>>                         StringRef isysroot, const std::string &OutputFile);
>> -  void WriteInputFiles(SourceManager &SourceMgr, StringRef isysroot);
>> +  void WriteInputFiles(SourceManager &SourceMgr,
>> +                       HeaderSearchOptions &HSOpts,
>> +                       StringRef isysroot);
>>  void WriteSourceManagerBlock(SourceManager &SourceMgr,
>>                               const Preprocessor &PP,
>>                               StringRef isysroot);
>> 
>> Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=177194&r1=177193&r2=177194&view=diff
>> ==============================================================================
>> --- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)
>> +++ cfe/trunk/lib/Serialization/ASTWriter.cpp Fri Mar 15 17:15:07 2013
>> @@ -1213,11 +1213,24 @@ void ASTWriter::WriteControlBlock(Prepro
>>    Stream.EmitRecordWithBlob(AbbrevCode, Record, origDir);
>>  }
>> 
>> -  WriteInputFiles(Context.SourceMgr, isysroot);
>> +  WriteInputFiles(Context.SourceMgr,
>> +                  PP.getHeaderSearchInfo().getHeaderSearchOpts(),
>> +                  isysroot);
>>  Stream.ExitBlock();
>> }
>> 
>> -void ASTWriter::WriteInputFiles(SourceManager &SourceMgr, StringRef isysroot) {
>> +namespace  {
>> +  /// \brief An input file.
>> +  struct InputFileEntry {
>> +    const FileEntry *File;
>> +    bool IsSystemFile;
>> +    bool BufferOverridden;
>> +  };
>> +}
>> +
>> +void ASTWriter::WriteInputFiles(SourceManager &SourceMgr,
>> +                                HeaderSearchOptions &HSOpts,
>> +                                StringRef isysroot) {
>>  using namespace llvm;
>>  Stream.EnterSubblock(INPUT_FILES_BLOCK_ID, 4);
>>  RecordData Record;
>> @@ -1234,7 +1247,7 @@ void ASTWriter::WriteInputFiles(SourceMa
>> 
>>  // Get all ContentCache objects for files, sorted by whether the file is a
>>  // system one or not. System files go at the back, users files at the front.
>> -  std::deque<const SrcMgr::ContentCache *> SortedFiles;
>> +  std::deque<InputFileEntry> SortedFiles;
>>  for (unsigned I = 1, N = SourceMgr.local_sloc_entry_size(); I != N; ++I) {
>>    // Get this source location entry.
>>    const SrcMgr::SLocEntry *SLoc = &SourceMgr.getLocalSLocEntry(I);
>> @@ -1247,20 +1260,38 @@ void ASTWriter::WriteInputFiles(SourceMa
>>    if (!Cache->OrigEntry)
>>      continue;
>> 
>> +    InputFileEntry Entry;
>> +    Entry.File = Cache->OrigEntry;
>> +    Entry.IsSystemFile = Cache->IsSystemFile;
>> +    Entry.BufferOverridden = Cache->BufferOverridden;
>>    if (Cache->IsSystemFile)
>> -      SortedFiles.push_back(Cache);
>> +      SortedFiles.push_back(Entry);
>>    else
>> -      SortedFiles.push_front(Cache);
>> +      SortedFiles.push_front(Entry);
>> +  }
>> +
>> +  // If we have an isysroot for a Darwin SDK, include its SDKSettings.plist in
>> +  // the set of (non-system) input files. This is simple heuristic for
>> +  // detecting whether the system headers may have changed, because it is too
>> +  // expensive to stat() all of the system headers.
>> +  FileManager &FileMgr = SourceMgr.getFileManager();
>> +  if (!HSOpts.Sysroot.empty()) {
>> +    llvm::SmallString<128> SDKSettingsFileName(HSOpts.Sysroot);
>> +    llvm::sys::path::append(SDKSettingsFileName, "SDKSettings.plist");
>> +    if (const FileEntry *SDKSettingsFile = FileMgr.getFile(SDKSettingsFileName)) {
>> +      InputFileEntry Entry = { SDKSettingsFile, false, false };
>> +      SortedFiles.push_front(Entry);
>> +    }
>>  }
>> 
>>  unsigned UserFilesNum = 0;
>>  // Write out all of the input files.
>>  std::vector<uint32_t> InputFileOffsets;
>> -  for (std::deque<const SrcMgr::ContentCache *>::iterator
>> +  for (std::deque<InputFileEntry>::iterator
>>         I = SortedFiles.begin(), E = SortedFiles.end(); I != E; ++I) {
>> -    const SrcMgr::ContentCache *Cache = *I;
>> +    const InputFileEntry &Entry = *I;
>> 
>> -    uint32_t &InputFileID = InputFileIDs[Cache->OrigEntry];
>> +    uint32_t &InputFileID = InputFileIDs[Entry.File];
>>    if (InputFileID != 0)
>>      continue; // already recorded this file.
>> 
>> @@ -1269,7 +1300,7 @@ void ASTWriter::WriteInputFiles(SourceMa
>> 
>>    InputFileID = InputFileOffsets.size();
>> 
>> -    if (!Cache->IsSystemFile)
>> +    if (!Entry.IsSystemFile)
>>      ++UserFilesNum;
>> 
>>    Record.clear();
>> @@ -1277,19 +1308,19 @@ void ASTWriter::WriteInputFiles(SourceMa
>>    Record.push_back(InputFileOffsets.size());
>> 
>>    // Emit size/modification time for this file.
>> -    Record.push_back(Cache->OrigEntry->getSize());
>> -    Record.push_back(Cache->OrigEntry->getModificationTime());
>> +    Record.push_back(Entry.File->getSize());
>> +    Record.push_back(Entry.File->getModificationTime());
>> 
>>    // Whether this file was overridden.
>> -    Record.push_back(Cache->BufferOverridden);
>> +    Record.push_back(Entry.BufferOverridden);
>> 
>>    // Turn the file name into an absolute path, if it isn't already.
>> -    const char *Filename = Cache->OrigEntry->getName();
>> +    const char *Filename = Entry.File->getName();
>>    SmallString<128> FilePath(Filename);
>> 
>>    // Ask the file manager to fixup the relative path for us. This will 
>>    // honor the working directory.
>> -    SourceMgr.getFileManager().FixupRelativePath(FilePath);
>> +    FileMgr.FixupRelativePath(FilePath);
>> 
>>    // FIXME: This call to make_absolute shouldn't be necessary, the
>>    // call to FixupRelativePath should always return an absolute path.
>> @@ -1300,7 +1331,7 @@ void ASTWriter::WriteInputFiles(SourceMa
>> 
>>    Stream.EmitRecordWithBlob(IFAbbrevCode, Record, Filename);
>>  }  
>> -  
>> +
>>  Stream.ExitBlock();
>> 
>>  // Create input file offsets abbreviation.
>> 
>> 
>> _______________________________________________
>> cfe-commits mailing list
>> cfe-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
> 
> -- Jean-Daniel

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130315/6e6157bf/attachment.html>


More information about the cfe-commits mailing list