Skip to content

[Frontend] Lock the swiftmodule when rebuilding from the swiftinterface #36185

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/Frontend/ModuleInterfaceBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ bool ModuleInterfaceBuilder::buildSwiftModule(StringRef OutPath,
// processes are doing the same.
// FIXME: We should surface the module building step to the build system so
// we don't need to synchronize here.
llvm::LockFileManager Locked(interfacePath);
llvm::LockFileManager Locked(OutPath);
switch (Locked) {
case llvm::LockFileManager::LFS_Error:{
// ModuleInterfaceBuilder takes care of correctness and locks are only
Expand Down
2 changes: 1 addition & 1 deletion test/APIJSON/access.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// REQUIRES: objc_interop, OS=macosx
// RUN: %empty-directory(%t)
// RUN: cp %s %t/MyModule.swiftinterface
// RUN: %target-swift-api-extract -target x86_64-apple-macos11.0 -o - -pretty-print %t/MyModule.swiftinterface -module-name MyModule | %FileCheck %s
// RUN: %target-swift-api-extract -target x86_64-apple-macos11.0 -o - -pretty-print %t/MyModule.swiftinterface -module-name MyModule -module-cache-path %t | %FileCheck %s

public func publicFunction()
internal func internalFunction()
Expand Down
4 changes: 2 additions & 2 deletions test/APIJSON/apigen.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// REQUIRES: objc_interop, OS=macosx
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend %s -typecheck -emit-module-interface-path %t/MyModule.swiftinterface -enable-library-evolution -module-name MyModule -swift-version 5
// RUN: %target-swift-api-extract -o - -pretty-print %t/MyModule.swiftinterface -module-name MyModule | %FileCheck %s
// RUN: %target-swift-frontend %s -typecheck -emit-module-interface-path %t/MyModule.swiftinterface -enable-library-evolution -module-name MyModule -swift-version 5
// RUN: %target-swift-api-extract -o - -pretty-print %t/MyModule.swiftinterface -module-name MyModule -module-cache-path %t | %FileCheck %s

import Foundation

Expand Down
2 changes: 1 addition & 1 deletion test/APIJSON/non-objc-class.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// REQUIRES: objc_interop, OS=macosx
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend %s -typecheck -emit-module-interface-path %t/MyModule.swiftinterface -enable-library-evolution -module-name MyModule -swift-version 5
// RUN: %target-swift-api-extract -o - -pretty-print %t/MyModule.swiftinterface -module-name MyModule | %FileCheck %s
// RUN: %target-swift-api-extract -o - -pretty-print %t/MyModule.swiftinterface -module-name MyModule -module-cache-path %t | %FileCheck %s

import Foundation

Expand Down
2 changes: 1 addition & 1 deletion test/APIJSON/spi.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// REQUIRES: objc_interop, OS=macosx
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend %s -typecheck -emit-module-interface-path %t/MyModule.swiftinterface -enable-library-evolution -module-name MyModule -swift-version 5
// RUN: %target-swift-api-extract -o - -pretty-print %t/MyModule.swiftinterface -module-name MyModule | %FileCheck %s
// RUN: %target-swift-api-extract -o - -pretty-print %t/MyModule.swiftinterface -module-name MyModule -module-cache-path %t | %FileCheck %s

import Foundation

Expand Down
2 changes: 1 addition & 1 deletion test/APIJSON/struct.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// REQUIRES: objc_interop, OS=macosx
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend %s -typecheck -emit-module-interface-path %t/MyModule.swiftinterface -enable-library-evolution -module-name MyModule -swift-version 5
// RUN: %target-swift-api-extract -o - -pretty-print %t/MyModule.swiftinterface -module-name MyModule | %FileCheck %s
// RUN: %target-swift-api-extract -o - -pretty-print %t/MyModule.swiftinterface -module-name MyModule -module-cache-path %t | %FileCheck %s

// Struct has no objc data.
@available(macOS 10.13, *)
Expand Down
16 changes: 11 additions & 5 deletions test/Driver/lock_interface.swift
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
// REQUIRES: rdar59977439
// RUN: %empty-directory(%t)
// RUN: %empty-directory(%t/sdk)
// RUN: %empty-directory(%t/module-cache-lock)
// RUN: %empty-directory(%t/module-cache-no-lock)
// RUN: echo 'public func foo() {}' > %t/Foo.swift
// RUN: %target-swift-frontend-typecheck -emit-module-interface-path %t/Foo.swiftinterface %t/Foo.swift -enable-library-evolution
// RUN: echo 'public func foo() {}' > %t/sdk/Foo.swift
// RUN: %target-swift-frontend-typecheck -emit-module-interface-path %t/sdk/Foo.swiftinterface %t/sdk/Foo.swift -enable-library-evolution
// RUN: chmod a-w %t/sdk

// RUN: touch %t/main.swift %t/file-01.swift %t/file-02.swift %t/file-03.swift
// RUN: echo 'import Foo' > %t/file-01.swift
// RUN: echo 'import Foo' > %t/file-02.swift
// RUN: echo 'import Foo' > %t/file-03.swift
// 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
// 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
// RUN: %FileCheck %s -check-prefix=CHECK-REBUILD < %t/result.txt

// 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
// 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

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

// Reset the permissions
// RUN: chmod a+w %t/sdk
Comment on lines +5 to +21
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this test is brittle for incremental builds. It really needs a chmod a+x at the start of the test to reset %t/sdk to a known good state before running line 5: echo 'public func foo() {}' > %t/sdk/Foo.swift


// Ensure we only build Foo module once from the interface
// CHECK-REBUILD: rebuilding module 'Foo' from interface
// CHECK-REBUILD-NOT: rebuilding module 'Foo' from interface
// CHECK-REBUILD-NOT: building module interface without lock file

// CHECK-REBUILD-NO-LOCK: rebuilding module 'Foo' from interface
// CHECK-REBUILD-NO-LOCK: rebuilding module 'Foo' from interface
Expand Down