Skip to content

Commit a448cdd

Browse files
authored
Merge pull request swiftlang#40941 from nkcsgexi/87840268
ModuleInterface: pass-down paths obfuscators to module interface building commands
2 parents a8030b7 + 53d4684 commit a448cdd

File tree

4 files changed

+53
-1
lines changed

4 files changed

+53
-1
lines changed

include/swift/Basic/PathRemapper.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ namespace swift {
3535

3636
class PathRemapper {
3737
SmallVector<std::pair<std::string, std::string>, 2> PathMappings;
38-
38+
friend class PathObfuscator;
3939
public:
4040
/// Adds a mapping such that any paths starting with `FromPrefix` have that
4141
/// portion replaced with `ToPrefix`.
@@ -72,6 +72,11 @@ class PathObfuscator {
7272
std::string recover(StringRef Path) const {
7373
return recoverer.remapPath(Path);
7474
}
75+
void forEachPair(llvm::function_ref<void(StringRef, StringRef)> op) const {
76+
for (auto pair: obfuscator.PathMappings) {
77+
op(pair.first, pair.second);
78+
}
79+
}
7580
};
7681

7782
} // end namespace swift

include/swift/Frontend/Frontend.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,11 @@ class CompilerInvocation {
174174
SearchPathOpts.setImportSearchPaths(Paths);
175175
}
176176

177+
void setSerializedPathObfuscator(const PathObfuscator &obfuscator) {
178+
FrontendOpts.serializedPathObfuscator = obfuscator;
179+
SearchPathOpts.DeserializedPathRecoverer = obfuscator;
180+
}
181+
177182
ArrayRef<std::string> getImportSearchPaths() const {
178183
return SearchPathOpts.getImportSearchPaths();
179184
}

lib/Frontend/ModuleInterfaceLoader.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,6 +1341,15 @@ void InterfaceSubContextDelegateImpl::inheritOptionsForBuildingInterface(
13411341
genericSubInvocation.getLangOptions().DisableAvailabilityChecking = true;
13421342
GenericArgs.push_back("-disable-availability-checking");
13431343
}
1344+
1345+
// Pass-down the obfuscators so we can get the serialized search paths properly.
1346+
genericSubInvocation.setSerializedPathObfuscator(
1347+
SearchPathOpts.DeserializedPathRecoverer);
1348+
SearchPathOpts.DeserializedPathRecoverer
1349+
.forEachPair([&](StringRef lhs, StringRef rhs) {
1350+
GenericArgs.push_back(ArgSaver.save(llvm::Twine("-serialized-path-obfuscate ")
1351+
+ lhs + "=" + rhs).str());
1352+
});
13441353
}
13451354

13461355
bool InterfaceSubContextDelegateImpl::extractSwiftInterfaceVersionAndArgs(

test/ModuleInterface/obfuscator.swift

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// REQUIRES: VENDOR=apple
2+
// RUN: %empty-directory(%t)
3+
// RUN: %empty-directory(%t/module-cache)
4+
5+
// RUN: %target-swift-frontend -emit-module -emit-module-path %t/Foo.swiftmodule -module-name Foo -enable-library-evolution %s -DFoo -I %S/Inputs/imports-clang-modules/ -serialized-path-obfuscate %S=%S_obfuscated
6+
7+
// RUN: %target-swift-frontend -typecheck -emit-module-interface-path %t/Bar.swiftinterface -module-name Bar -enable-library-evolution %s -DBar -I %t -serialized-path-obfuscate %S=%S_obfuscated
8+
9+
// RUN: %target-swift-frontend -typecheck %s -I %t -serialized-path-obfuscate %S=%S_obfuscated -DFooBar
10+
11+
#if Foo
12+
13+
import A
14+
public func fooFunc() {}
15+
16+
#endif
17+
18+
#if Bar
19+
20+
import Foo
21+
22+
func barFunc() {
23+
fooFunc()
24+
}
25+
26+
#endif
27+
28+
#if FooBar
29+
30+
import Bar
31+
import A
32+
33+
#endif

0 commit comments

Comments
 (0)