Skip to content

Commit 2a1e5ed

Browse files
committed
[Frontend] Lock the swiftmodule when rebuilding from the swiftinterface
When rebuilding a module interface from the textual interface, lock the destination path of the created swiftmodule instead of the source swiftinterface. The swiftinterface files are likely to be in the SDK and may be on a read-only filesystem. rdar://60247977
1 parent 86dadac commit 2a1e5ed

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

lib/Frontend/ModuleInterfaceBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ bool ModuleInterfaceBuilder::buildSwiftModule(StringRef OutPath,
290290
// processes are doing the same.
291291
// FIXME: We should surface the module building step to the build system so
292292
// we don't need to synchronize here.
293-
llvm::LockFileManager Locked(interfacePath);
293+
llvm::LockFileManager Locked(OutPath);
294294
switch (Locked) {
295295
case llvm::LockFileManager::LFS_Error:{
296296
// ModuleInterfaceBuilder takes care of correctness and locks are only

test/Driver/lock_interface.swift

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
1-
// REQUIRES: rdar59977439
21
// RUN: %empty-directory(%t)
2+
// RUN: %empty-directory(%t/sdk)
33
// RUN: %empty-directory(%t/module-cache-lock)
44
// RUN: %empty-directory(%t/module-cache-no-lock)
5-
// RUN: echo 'public func foo() {}' > %t/Foo.swift
6-
// RUN: %target-swift-frontend-typecheck -emit-module-interface-path %t/Foo.swiftinterface %t/Foo.swift -enable-library-evolution
5+
// RUN: echo 'public func foo() {}' > %t/sdk/Foo.swift
6+
// RUN: %target-swift-frontend-typecheck -emit-module-interface-path %t/sdk/Foo.swiftinterface %t/sdk/Foo.swift -enable-library-evolution
7+
// RUN: chmod a-w %t/sdk
8+
79
// RUN: touch %t/main.swift %t/file-01.swift %t/file-02.swift %t/file-03.swift
810
// RUN: echo 'import Foo' > %t/file-01.swift
911
// RUN: echo 'import Foo' > %t/file-02.swift
1012
// RUN: echo 'import Foo' > %t/file-03.swift
11-
// RUN: %target-swiftc_driver -j20 %t/main.swift %t/file-01.swift %t/file-02.swift %t/file-03.swift -I %t -Xfrontend -Rmodule-interface-rebuild -module-cache-path %t/module-cache &> %t/result.txt
13+
// RUN: %target-swiftc_driver -j20 %t/main.swift %t/file-01.swift %t/file-02.swift %t/file-03.swift -I %t/sdk -Xfrontend -Rmodule-interface-rebuild -module-cache-path %t/module-cache &> %t/result.txt
1214
// RUN: %FileCheck %s -check-prefix=CHECK-REBUILD < %t/result.txt
1315

14-
// RUN: %target-swiftc_driver -j20 %t/main.swift %t/file-01.swift %t/file-02.swift %t/file-03.swift -I %t -Xfrontend -Rmodule-interface-rebuild -Xfrontend -disable-interface-lock -module-cache-path %t/module-cache-no-lock &> %t/result.txt
16+
// RUN: %target-swiftc_driver -j20 %t/main.swift %t/file-01.swift %t/file-02.swift %t/file-03.swift -I %t/sdk -Xfrontend -Rmodule-interface-rebuild -Xfrontend -disable-interface-lock -module-cache-path %t/module-cache-no-lock &> %t/result.txt
1517

1618
// RUN: %FileCheck %s -check-prefix=CHECK-REBUILD-NO-LOCK < %t/result.txt
1719

20+
// Reset the permissions
21+
// RUN: chmod a+w %t/sdk
22+
1823
// Ensure we only build Foo module once from the interface
1924
// CHECK-REBUILD: rebuilding module 'Foo' from interface
2025
// CHECK-REBUILD-NOT: rebuilding module 'Foo' from interface
26+
// CHECK-REBUILD-NOT: building module interface without lock file
2127

2228
// CHECK-REBUILD-NO-LOCK: rebuilding module 'Foo' from interface
2329
// CHECK-REBUILD-NO-LOCK: rebuilding module 'Foo' from interface

0 commit comments

Comments
 (0)