@@ -33,42 +33,64 @@ static std::optional<Path> getActualModuleMapPath(
33
33
StringRef platform = swift::getPlatformNameForTriple (triple);
34
34
StringRef arch = swift::getMajorArchitectureName (triple);
35
35
36
- Path result;
37
-
38
- StringRef SDKPath = Opts.getSDKPath ();
39
- if (!SDKPath.empty ()) {
40
- result.append (SDKPath.begin (), SDKPath.end ());
41
- llvm::sys::path::append (result, " usr" , " lib" , " swift" );
42
- llvm::sys::path::append (result, platform);
43
- if (isArchSpecific) {
44
- llvm::sys::path::append (result, arch);
36
+ auto checkRuntimeResourcesPath = [&]() -> std::optional<Path> {
37
+ Path result;
38
+ if (!Opts.RuntimeResourcePath .empty ()) {
39
+ result.append (Opts.RuntimeResourcePath .begin (),
40
+ Opts.RuntimeResourcePath .end ());
41
+ llvm::sys::path::append (result, platform);
42
+ if (isArchSpecific) {
43
+ llvm::sys::path::append (result, arch);
44
+ }
45
+ llvm::sys::path::append (result, name);
46
+
47
+ // Only specify the module map if that file actually exists. It may not;
48
+ // for example in the case that `swiftc -target x86_64-unknown-linux-gnu
49
+ // -emit-ir` is invoked using a Swift compiler not built for Linux
50
+ // targets.
51
+ if (vfs->exists (result))
52
+ return result;
45
53
}
46
- llvm::sys::path::append (result, name);
47
-
48
- // Only specify the module map if that file actually exists. It may not;
49
- // for example in the case that `swiftc -target x86_64-unknown-linux-gnu
50
- // -emit-ir` is invoked using a Swift compiler not built for Linux targets.
51
- if (vfs->exists (result))
52
- return result;
53
- }
54
+ return std::nullopt;
55
+ };
54
56
55
- if (!Opts.RuntimeResourcePath .empty ()) {
56
- result.clear ();
57
- result.append (Opts.RuntimeResourcePath .begin (),
58
- Opts.RuntimeResourcePath .end ());
59
- llvm::sys::path::append (result, platform);
60
- if (isArchSpecific) {
61
- llvm::sys::path::append (result, arch);
57
+ auto checkSDKPath = [&]() -> std::optional<Path> {
58
+ Path result;
59
+ StringRef SDKPath = Opts.getSDKPath ();
60
+ if (!SDKPath.empty ()) {
61
+ result.append (SDKPath.begin (), SDKPath.end ());
62
+ llvm::sys::path::append (result, " usr" , " lib" , " swift" );
63
+ llvm::sys::path::append (result, platform);
64
+ if (isArchSpecific) {
65
+ llvm::sys::path::append (result, arch);
66
+ }
67
+ llvm::sys::path::append (result, name);
68
+
69
+ // Only specify the module map if that file actually exists. It may not;
70
+ // for example in the case that `swiftc -target x86_64-unknown-linux-gnu
71
+ // -emit-ir` is invoked using a Swift compiler not built for Linux
72
+ // targets.
73
+ if (vfs->exists (result))
74
+ return result;
62
75
}
63
- llvm::sys::path::append (result, name);
76
+ return std::nullopt;
77
+ };
64
78
65
- // Only specify the module map if that file actually exists. It may not;
66
- // for example in the case that `swiftc -target x86_64-unknown-linux-gnu
67
- // -emit-ir` is invoked using a Swift compiler not built for Linux targets.
68
- if (vfs->exists (result))
69
- return result;
79
+ // FIXME: This is a workaround to keep the Android SDK build working.
80
+ // See https://github.com/swiftlang/swift/pull/74814.
81
+ if (triple.isAndroid ()) {
82
+ if (auto path = checkSDKPath ())
83
+ return path;
84
+ if (auto path = checkRuntimeResourcesPath ())
85
+ return path;
86
+ return std::nullopt;
70
87
}
71
88
89
+ if (auto path = checkRuntimeResourcesPath ())
90
+ return path;
91
+ if (auto path = checkSDKPath ())
92
+ return path;
93
+
72
94
return std::nullopt;
73
95
}
74
96
0 commit comments