@@ -413,27 +413,38 @@ void ClangImporter::clearTypeResolver() {
413
413
// / compiling for, and is not included in the resource directory with the other
414
414
// / implicit module maps. It's at {freebsd|linux}/{arch}/glibc.modulemap.
415
415
static Optional<StringRef>
416
- getGlibcModuleMapPath (StringRef resourceDir , llvm::Triple triple,
417
- SmallVectorImpl<char > &scratch ) {
418
- if (resourceDir. empty ())
419
- return None ;
416
+ getGlibcModuleMapPath (SearchPathOptions& Opts , llvm::Triple triple,
417
+ SmallVectorImpl<char > &buffer ) {
418
+ StringRef platform = swift::getPlatformNameForTriple (triple);
419
+ StringRef arch = swift::getMajorArchitectureName (triple) ;
420
420
421
- scratch.append (resourceDir.begin (), resourceDir.end ());
422
- llvm::sys::path::append (
423
- scratch,
424
- swift::getPlatformNameForTriple (triple),
425
- swift::getMajorArchitectureName (triple),
426
- " glibc.modulemap" );
427
-
428
- // Only specify the module map if that file actually exists.
429
- // It may not--for example in the case that
430
- // `swiftc -target x86_64-unknown-linux-gnu -emit-ir` is invoked using
431
- // a Swift compiler not built for Linux targets.
432
- if (llvm::sys::fs::exists (scratch)) {
433
- return StringRef (scratch.data (), scratch.size ());
434
- } else {
435
- return None;
421
+ if (!Opts.SDKPath .empty ()) {
422
+ buffer.clear ();
423
+ buffer.append (Opts.SDKPath .begin (), Opts.SDKPath .end ());
424
+ llvm::sys::path::append (buffer, " usr" , " lib" , " swift" );
425
+ llvm::sys::path::append (buffer, platform, arch, " glibc.modulemap" );
426
+
427
+ // Only specify the module map if that file actually exists. It may not;
428
+ // for example in the case that `swiftc -target x86_64-unknown-linux-gnu
429
+ // -emit-ir` is invoked using a Swift compiler not built for Linux targets.
430
+ if (llvm::sys::fs::exists (buffer))
431
+ return StringRef (buffer.data (), buffer.size ());
436
432
}
433
+
434
+ if (!Opts.RuntimeResourcePath .empty ()) {
435
+ buffer.clear ();
436
+ buffer.append (Opts.RuntimeResourcePath .begin (),
437
+ Opts.RuntimeResourcePath .end ());
438
+ llvm::sys::path::append (buffer, platform, arch, " glibc.modulemap" );
439
+
440
+ // Only specify the module map if that file actually exists. It may not;
441
+ // for example in the case that `swiftc -target x86_64-unknown-linux-gnu
442
+ // -emit-ir` is invoked using a Swift compiler not built for Linux targets.
443
+ if (llvm::sys::fs::exists (buffer))
444
+ return StringRef (buffer.data (), buffer.size ());
445
+ }
446
+
447
+ return None;
437
448
}
438
449
439
450
static void
@@ -606,9 +617,8 @@ getNormalInvocationArguments(std::vector<std::string> &invocationArgStrs,
606
617
}
607
618
}
608
619
609
- SmallString<128 > GlibcModuleMapPath;
610
- if (auto path = getGlibcModuleMapPath (searchPathOpts.RuntimeResourcePath ,
611
- triple, GlibcModuleMapPath)) {
620
+ SmallString<128 > buffer;
621
+ if (auto path = getGlibcModuleMapPath (searchPathOpts, triple, buffer)) {
612
622
invocationArgStrs.push_back ((Twine (" -fmodule-map-file=" ) + *path).str ());
613
623
} else {
614
624
// FIXME: Emit a warning of some kind.
0 commit comments