@@ -1493,42 +1493,45 @@ void ASTWriter::WriteControlBlock(Preprocessor &PP, StringRef isysroot) {
1493
1493
unsigned AbbrevCode = Stream.EmitAbbrev (std::move (Abbrev));
1494
1494
RecordData::value_type Record[] = {MODULE_NAME};
1495
1495
Stream.EmitRecordWithBlob (AbbrevCode, Record, WritingModule->Name );
1496
- }
1497
1496
1498
- if (WritingModule && WritingModule->Directory ) {
1499
- SmallString<128 > BaseDir;
1500
- if (PP.getHeaderSearchInfo ().getHeaderSearchOpts ().ModuleFileHomeIsCwd ) {
1501
- // Use the current working directory as the base path for all inputs.
1502
- auto CWD = FileMgr.getOptionalDirectoryRef (" ." );
1503
- BaseDir.assign (CWD->getName ());
1504
- } else {
1505
- BaseDir.assign (WritingModule->Directory ->getName ());
1506
- }
1507
- cleanPathForOutput (FileMgr, BaseDir);
1508
-
1509
- // If the home of the module is the current working directory, then we
1510
- // want to pick up the cwd of the build process loading the module, not
1511
- // our cwd, when we load this module.
1512
- if (!PP.getHeaderSearchInfo ().getHeaderSearchOpts ().ModuleFileHomeIsCwd &&
1513
- (!PP.getHeaderSearchInfo ()
1514
- .getHeaderSearchOpts ()
1515
- .ModuleMapFileHomeIsCwd ||
1516
- WritingModule->Directory ->getName () != " ." )) {
1517
- // Module directory.
1518
- auto Abbrev = std::make_shared<BitCodeAbbrev>();
1519
- Abbrev->Add (BitCodeAbbrevOp (MODULE_DIRECTORY));
1520
- Abbrev->Add (BitCodeAbbrevOp (BitCodeAbbrevOp::Blob)); // Directory
1521
- unsigned AbbrevCode = Stream.EmitAbbrev (std::move (Abbrev));
1497
+ auto BaseDir = [&]() -> std::optional<SmallString<128 >> {
1498
+ if (PP.getHeaderSearchInfo ().getHeaderSearchOpts ().ModuleFileHomeIsCwd ) {
1499
+ // Use the current working directory as the base path for all inputs.
1500
+ auto CWD = FileMgr.getOptionalDirectoryRef (" ." );
1501
+ return CWD->getName ();
1502
+ }
1503
+ if (WritingModule->Directory ) {
1504
+ return WritingModule->Directory ->getName ();
1505
+ }
1506
+ return std::nullopt;
1507
+ }();
1508
+ if (BaseDir) {
1509
+ cleanPathForOutput (FileMgr, *BaseDir);
1510
+
1511
+ // If the home of the module is the current working directory, then we
1512
+ // want to pick up the cwd of the build process loading the module, not
1513
+ // our cwd, when we load this module.
1514
+ if (!PP.getHeaderSearchInfo ().getHeaderSearchOpts ().ModuleFileHomeIsCwd &&
1515
+ (!PP.getHeaderSearchInfo ()
1516
+ .getHeaderSearchOpts ()
1517
+ .ModuleMapFileHomeIsCwd ||
1518
+ WritingModule->Directory ->getName () != " ." )) {
1519
+ // Module directory.
1520
+ auto Abbrev = std::make_shared<BitCodeAbbrev>();
1521
+ Abbrev->Add (BitCodeAbbrevOp (MODULE_DIRECTORY));
1522
+ Abbrev->Add (BitCodeAbbrevOp (BitCodeAbbrevOp::Blob)); // Directory
1523
+ unsigned AbbrevCode = Stream.EmitAbbrev (std::move (Abbrev));
1524
+
1525
+ RecordData::value_type Record[] = {MODULE_DIRECTORY};
1526
+ Stream.EmitRecordWithBlob (AbbrevCode, Record, *BaseDir);
1527
+ }
1522
1528
1523
- RecordData::value_type Record[] = {MODULE_DIRECTORY};
1524
- Stream.EmitRecordWithBlob (AbbrevCode, Record, BaseDir);
1529
+ // Write out all other paths relative to the base directory if possible.
1530
+ BaseDirectory.assign (BaseDir->begin (), BaseDir->end ());
1531
+ } else if (!isysroot.empty ()) {
1532
+ // Write out paths relative to the sysroot if possible.
1533
+ BaseDirectory = std::string (isysroot);
1525
1534
}
1526
-
1527
- // Write out all other paths relative to the base directory if possible.
1528
- BaseDirectory.assign (BaseDir.begin (), BaseDir.end ());
1529
- } else if (!isysroot.empty ()) {
1530
- // Write out paths relative to the sysroot if possible.
1531
- BaseDirectory = std::string (isysroot);
1532
1535
}
1533
1536
1534
1537
// Module map file
0 commit comments