Author: rsmith Date: Thu Aug 13 18:47:44 2015 New Revision: 244988 URL: http://llvm.org/viewvc/llvm-project?rev=244988&view=rev Log: [modules] When writing a module file built with -fmodule-map-file-home-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.
Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp cfe/trunk/test/Modules/relative-dep-gen.cpp Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=244988&r1=244987&r2=244988&view=diff ============================================================================== --- cfe/trunk/lib/Serialization/ASTWriter.cpp (original) +++ cfe/trunk/lib/Serialization/ASTWriter.cpp Thu Aug 13 18:47:44 2015 @@ -1185,17 +1185,26 @@ void ASTWriter::WriteControlBlock(Prepro } 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()); Modified: cfe/trunk/test/Modules/relative-dep-gen.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/relative-dep-gen.cpp?rev=244988&r1=244987&r2=244988&view=diff ============================================================================== --- cfe/trunk/test/Modules/relative-dep-gen.cpp (original) +++ cfe/trunk/test/Modules/relative-dep-gen.cpp Thu Aug 13 18:47:44 2015 @@ -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 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits