Skip to content

Commit

Permalink
[modules] When writing a module file built with -fmodule-map-file-hom…
Browse files Browse the repository at this point in the history
…e-is-cwd,

via a module map found by -fmodule-map-file=, the home directory of the module
is the current working directory, even if that's a different directory on
reload.

llvm-svn: 244988
  • Loading branch information
zygoloid committed Aug 13, 2015
1 parent d7be603 commit f7b4137
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 15 deletions.
27 changes: 18 additions & 9 deletions clang/lib/Serialization/ASTWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1185,17 +1185,26 @@ void ASTWriter::WriteControlBlock(Preprocessor &PP, ASTContext &Context,
}

if (WritingModule && WritingModule->Directory) {
// Module directory.
BitCodeAbbrev *Abbrev = new BitCodeAbbrev();
Abbrev->Add(BitCodeAbbrevOp(MODULE_DIRECTORY));
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Directory
unsigned AbbrevCode = Stream.EmitAbbrev(Abbrev);
RecordData Record;
Record.push_back(MODULE_DIRECTORY);

SmallString<128> BaseDir(WritingModule->Directory->getName());
cleanPathForOutput(Context.getSourceManager().getFileManager(), BaseDir);
Stream.EmitRecordWithBlob(AbbrevCode, Record, BaseDir);

// If the home of the module is the current working directory, then we
// want to pick up the cwd of the build process loading the module, not
// our cwd, when we load this module.
if (!PP.getHeaderSearchInfo()
.getHeaderSearchOpts()
.ModuleMapFileHomeIsCwd ||
WritingModule->Directory->getName() != StringRef(".")) {
// Module directory.
BitCodeAbbrev *Abbrev = new BitCodeAbbrev();
Abbrev->Add(BitCodeAbbrevOp(MODULE_DIRECTORY));
Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); // Directory
unsigned AbbrevCode = Stream.EmitAbbrev(Abbrev);

RecordData Record;
Record.push_back(MODULE_DIRECTORY);
Stream.EmitRecordWithBlob(AbbrevCode, Record, BaseDir);
}

// Write out all other paths relative to the base directory if possible.
BaseDirectory.assign(BaseDir.begin(), BaseDir.end());
Expand Down
20 changes: 14 additions & 6 deletions clang/test/Modules/relative-dep-gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,22 @@
// RUN: FileCheck --check-prefix=CHECK-BUILD %s < %t/build-cwd.d
// RUN: FileCheck --check-prefix=CHECK-USE %s < %t/use-explicit-cwd.d
// RUN: FileCheck --check-prefix=CHECK-USE %s < %t/use-implicit-cwd.d
//
// Check that the .d file is still correct after relocating the module.
// RUN: mkdir %t/Inputs
// RUN: cp %S/Inputs/relative-dep-gen-1.h %t/Inputs
// RUN: cp %s %t
// RUN: cd %t
// RUN: %clang_cc1 -cc1 -fno-implicit-modules -fmodule-file=%t/mod-cwd.pcm -dependency-file %t/use-explicit-no-map-cwd.d -MT use.o relative-dep-gen.cpp -fsyntax-only -fmodule-map-file-home-is-cwd
// RUN: cat %t/use-explicit-no-map-cwd.d
// RUN: FileCheck --check-prefix=CHECK-USE %s < %t/use-explicit-no-map-cwd.d

#include "Inputs/relative-dep-gen-1.h"

// CHECK-BUILD: mod.pcm:
// CHECK-BUILD: Inputs/relative-dep-gen{{(-cwd)?}}.modulemap
// CHECK-BUILD: Inputs/relative-dep-gen-1.h
// CHECK-BUILD: Inputs/relative-dep-gen-2.h
// CHECK-BUILD: {{[ \t]}}Inputs/relative-dep-gen{{(-cwd)?}}.modulemap
// CHECK-BUILD: {{[ \t]}}Inputs/relative-dep-gen-1.h
// CHECK-BUILD: {{[ \t]}}Inputs/relative-dep-gen-2.h
// CHECK-USE: use.o:
// CHECK-USE-DAG: Inputs/relative-dep-gen{{(-cwd)?}}.modulemap
// CHECK-USE-DAG: relative-dep-gen.cpp
// CHECK-USE-DAG: Inputs{{[/\\]}}relative-dep-gen-1.h
// CHECK-USE-DAG: {{[ \t]}}relative-dep-gen.cpp
// CHECK-USE-DAG: {{[ \t]}}Inputs{{[/\\]}}relative-dep-gen-1.h

0 comments on commit f7b4137

Please sign in to comment.