-
Notifications
You must be signed in to change notification settings - Fork 31
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
Task / Enable root package target caching #146
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
1e96e3c
Support pin retrieval directly from package
dmhts ba0e317
Avoid environment affecting final hash
dmhts bd84919
Exclude environment from cache digest calculation
dmhts 47a6681
Merge remote-tracking branch 'upstream/main' into task/improved-targe…
dmhts ef12f80
Merge remote-tracking branch 'upstream/main' into task/improved-targe…
dmhts acba575
Fix warnings
dmhts bf891e2
Move ClangCheckerTests to a separate file
dmhts b9ba5d3
Introduce testCacheKeyCalculationForRootPackageTarget test
dmhts 19c2c45
Test cache key calculation
dmhts 0d7d795
Remove duplicated import
dmhts daf435e
Make linter happy
dmhts 3887b39
Add respective compiler checks
dmhts 1ee3410
Make linter happy
dmhts 22f87d8
Improve naming: pin -> makePinFromRevision()
dmhts File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,22 @@ | ||
import Foundation | ||
@testable import ScipioKit | ||
import XCTest | ||
import Basics | ||
|
||
private let fixturePath = URL(fileURLWithPath: #filePath) | ||
.deletingLastPathComponent() | ||
.appendingPathComponent("Resources") | ||
.appendingPathComponent("Fixtures") | ||
|
||
final class CacheSystemTests: XCTestCase { | ||
|
||
final class ClangCheckerTests: XCTestCase { | ||
private let clangVersion = """ | ||
Apple clang version 14.0.0 (clang-1400.0.29.102) | ||
Target: arm64-apple-darwin21.6.0 | ||
Thread model: posix | ||
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin | ||
""" | ||
private let customModuleMap = """ | ||
framework module MyTarget { | ||
umbrella header "umbrella.h" | ||
export * | ||
} | ||
""" | ||
|
||
func testParseClangVersion() async throws { | ||
let hook = { arguments in | ||
XCTAssertEqual(arguments, ["/usr/bin/xcrun", "clang", "--version"]) | ||
return StubbableExecutorResult(arguments: arguments, success: self.clangVersion) | ||
} | ||
let clangParser = ClangChecker(executor: StubbableExecutor(executeHook: hook)) | ||
let version = try await clangParser.fetchClangVersion() | ||
XCTAssertEqual(version, "clang-1400.0.29.102") | ||
} | ||
Comment on lines
-19
to
-27
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I hope it's fine that I extracted the Clang version checking logic into a separate test case. |
||
|
||
func testEncodeCacheKey() throws { | ||
let cacheKey = SwiftPMCacheKey(targetName: "MyTarget", | ||
pin: .revision("111111111"), | ||
|
@@ -45,38 +36,112 @@ InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault | |
encoder.outputFormatting = [.sortedKeys, .prettyPrinted] | ||
let data = try encoder.encode(cacheKey) | ||
let rawString = try XCTUnwrap(String(decoding: data, as: UTF8.self)) | ||
|
||
// swiftlint:disable line_length | ||
let expected = """ | ||
{ | ||
"buildOptions" : { | ||
"buildConfiguration" : "release", | ||
"customFrameworkModuleMapContents" : "ZnJhbWV3b3JrIG1vZHVsZSBNeVRhcmdldCB7CiAgICB1bWJyZWxsYSBoZWFkZXIgInVtYnJlbGxhLmgiCiAgICBleHBvcnQgKgp9", | ||
"enableLibraryEvolution" : true, | ||
"extraBuildParameters" : { | ||
"SWIFT_OPTIMIZATION_LEVEL" : "-Osize" | ||
}, | ||
"extraFlags" : { | ||
"swiftFlags" : [ | ||
"-D", | ||
"SOME_FLAG" | ||
] | ||
}, | ||
"frameworkType" : "dynamic", | ||
"isDebugSymbolsEmbedded" : false, | ||
"sdks" : [ | ||
"iOS" | ||
] | ||
}, | ||
"clangVersion" : "clang-1400.0.29.102", | ||
"pin" : { | ||
"revision" : "111111111" | ||
}, | ||
"targetName" : "MyTarget", | ||
"xcodeVersion" : { | ||
"xcodeBuildVersion" : "15F31d", | ||
"xcodeVersion" : "15.4" | ||
} | ||
} | ||
""" | ||
{ | ||
"buildOptions" : { | ||
"buildConfiguration" : "release", | ||
"customFrameworkModuleMapContents" : "ZnJhbWV3b3JrIG1vZHVsZSBNeVRhcmdldCB7CiAgICB1bWJyZWxsYSBoZWFkZXIgInVtYnJlbGxhLmgiCiAgICBleHBvcnQgKgp9", | ||
"enableLibraryEvolution" : true, | ||
"extraBuildParameters" : { | ||
"SWIFT_OPTIMIZATION_LEVEL" : "-Osize" | ||
}, | ||
"extraFlags" : { | ||
"swiftFlags" : [ | ||
"-D", | ||
"SOME_FLAG" | ||
] | ||
}, | ||
"frameworkType" : "dynamic", | ||
"isDebugSymbolsEmbedded" : false, | ||
"sdks" : [ | ||
"iOS" | ||
] | ||
}, | ||
"clangVersion" : "clang-1400.0.29.102", | ||
"pin" : { | ||
"revision" : "111111111" | ||
}, | ||
"targetName" : "MyTarget", | ||
"xcodeVersion" : { | ||
"xcodeBuildVersion" : "15F31d", | ||
"xcodeVersion" : "15.4" | ||
} | ||
} | ||
""" | ||
// swiftlint:enable line_length | ||
XCTAssertEqual(rawString, expected) | ||
} | ||
|
||
#if compiler(>=6.0) | ||
|
||
func testCacheKeyCalculationForRootPackageTarget() async throws { | ||
let fileSystem = localFileSystem | ||
let testingPackagePath = fixturePath.appendingPathComponent("TestingPackage") | ||
let tempTestingPackagePath = testingPackagePath.absolutePath.parentDirectory.appending(component: "temp_TestingPackage") | ||
|
||
try fileSystem.removeFileTree(tempTestingPackagePath) | ||
try fileSystem.copy(from: testingPackagePath.absolutePath, to: tempTestingPackagePath) | ||
|
||
defer { try? fileSystem.removeFileTree(tempTestingPackagePath) } | ||
|
||
let descriptionPackage = try DescriptionPackage( | ||
packageDirectory: tempTestingPackagePath, | ||
mode: .createPackage, | ||
onlyUseVersionsFromResolvedFile: false | ||
) | ||
let cacheSystem = CacheSystem( | ||
pinsStore: try descriptionPackage.workspace.pinsStore.load(), | ||
outputDirectory: FileManager.default.temporaryDirectory.appendingPathComponent("XCFrameworks"), | ||
storage: nil | ||
) | ||
let testingPackage = descriptionPackage | ||
.graph | ||
.packages | ||
.first { $0.manifest.displayName == descriptionPackage.manifest.displayName }! | ||
|
||
let myTarget = testingPackage.modules.first { $0.name == "MyTarget" }! | ||
let cacheTarget = CacheSystem.CacheTarget( | ||
buildProduct: BuildProduct( | ||
package: testingPackage, | ||
target: myTarget | ||
), | ||
buildOptions: BuildOptions( | ||
buildConfiguration: .release, | ||
isDebugSymbolsEmbedded: false, | ||
frameworkType: .dynamic, | ||
sdks: [.iOS, .iOSSimulator], | ||
extraFlags: nil, | ||
extraBuildParameters: nil, | ||
enableLibraryEvolution: false, | ||
customFrameworkModuleMapContents: nil | ||
) | ||
) | ||
|
||
// Ensure that the cache key cannot be calculated if the package is not in the Git repository. | ||
do { | ||
_ = try await cacheSystem.calculateCacheKey(of: cacheTarget) | ||
XCTFail("A cache key should not be possible to calculate if the package is not in a repository.") | ||
} catch let error as CacheSystem.Error { | ||
XCTAssertEqual(error.errorDescription, "Repository version is not detected for \(descriptionPackage.name).") | ||
} catch { | ||
XCTFail("Wrong error type.") | ||
} | ||
giginet marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// Ensure that the cache key is properly calculated when the package is in a repository with the correct tag." | ||
let processExecutor: Executor = ProcessExecutor() | ||
try await processExecutor.execute(["git", "init", tempTestingPackagePath.pathString]) | ||
try await processExecutor.execute(["git", "-C", tempTestingPackagePath.pathString, "add", tempTestingPackagePath.pathString]) | ||
try await processExecutor.execute(["git", "-C", tempTestingPackagePath.pathString, "commit", "-m", "Initial commit"]) | ||
try await processExecutor.execute(["git", "-C", tempTestingPackagePath.pathString, "tag", "v1.1"]) | ||
|
||
let cacheKey = try await cacheSystem.calculateCacheKey(of: cacheTarget) | ||
|
||
XCTAssertEqual(cacheKey.targetName, myTarget.name) | ||
XCTAssertEqual(cacheKey.pin.description, "1.1.0") | ||
} | ||
|
||
#endif | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
@testable import ScipioKit | ||
import XCTest | ||
|
||
final class ClangCheckerTests: XCTestCase { | ||
private let clangVersion = """ | ||
Apple clang version 14.0.0 (clang-1400.0.29.102) | ||
Target: arm64-apple-darwin21.6.0 | ||
Thread model: posix | ||
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin | ||
""" | ||
|
||
func testParseClangVersion() async throws { | ||
let hook = { arguments in | ||
XCTAssertEqual(arguments, ["/usr/bin/xcrun", "clang", "--version"]) | ||
return StubbableExecutorResult(arguments: arguments, success: self.clangVersion) | ||
} | ||
let clangParser = ClangChecker(executor: StubbableExecutor(executeHook: hook)) | ||
let version = try await clangParser.fetchClangVersion() | ||
XCTAssertEqual(version, "clang-1400.0.29.102") | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Question] I'm not sure why the addition is gated by
#if compiler(>=6.0)
. Is that change not compatible with Swift 5.10 (Xcode 15.3)?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand that
GitRepository.getCurrentTag
is added in Swift 6.0 👍https://github.com/swiftlang/swift-package-manager/blob/release/6.0.2/CHANGELOG.md#swift-60
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the question. I should've mentioned that in the PR description. There are two reasons for this:
GitRepository.getCurrentTag
is only available in SwiftPM'srelease/6.0
branch. Reimplementing the function (with the respective tests) would, of course, be trivial. And here comes the second reason, as I understand it, support forXcode 15
is going to be dropped soon, so I thought it wouldn't be worth the effort. Let me know if it makes sense.Update: I just saw your previous post where you figured it out yourself :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. it is correct it will cause the incompatibility.
But I told to @dmhts that we don't need to maintain the backward compatibility.
#140 (comment)
So, I think it's no problem if the compatibility is broken because Swift 5 support will be dropped soon. We don't need to make an effort to keep backward compatibility.
I'll drop the Swift 5 support.