Skip to content
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 14 commits into from
Oct 9, 2024

Conversation

dmhts
Copy link
Contributor

@dmhts dmhts commented Oct 1, 2024

Motivation:

Currently, Scipio does not support caching root package (local, if you will) targets. Apparently, this is because the version requirement is typically known for the root package dependencies, but not for the root package's direct targets themselves (as they're not pinned in the underlying PinStore, for obvious reasons). However, such a version requirement can be easily derived from the git repository that "wraps" the root package, and this is what this PR is about. Moreover, SwiftPM requires each package to be within a repository with the respective version requirement set.

Context:

We're using Scipio only with the .createPackage mode where the runner goes over a list of 3rd party packages. The issue is reproducible specifically in that mode, and you also can see it happening in the integration tests if run in the .createPackage mode with the caching flag enabled; the reason is that fixture packages are not wrapped in git repositories (which normally shouldn't happen in real life), otherwise, this PR fixes a potential issue there too.

Additional considerations:

The change is purely additive and doesn't alter any existing functionality.

Expected result:

Before:
🚀 Cache MyTarget.xcframework to cache storage
⚠️ Can't create caches for .../TestingPackage/MyTarget.xcframework

After:
🚀 Cache MyTarget.xcframework to cache storage
[No warning as cache created successfuly]

@giginet as always, I'd love to hear your thoughts on this.

Comment on lines -19 to -27
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")
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Owner

@giginet giginet left a comment

Choose a reason for hiding this comment

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

Thank you for the contribution!

Your concept looks good. I commented to minor points.

Comment on lines 318 to 320
fileprivate extension ResolvedPackage {

var pin: PinsStore.Pin? {
Copy link
Owner

Choose a reason for hiding this comment

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

It should be private extension or fileprivate func.

I prefer to add the accessor on the function sides.

Suggested change
fileprivate extension ResolvedPackage {
var pin: PinsStore.Pin? {
extension ResolvedPackage {
fileprivate var pin: PinsStore.Pin? {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.


fileprivate extension ResolvedPackage {

var pin: PinsStore.Pin? {
Copy link
Owner

Choose a reason for hiding this comment

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

I feel pin is too generic a property name, even if it's a fileprivate extension.

This property generates a pin it is using GitRepository

How about it be makePinByRevision() or something?

Copy link
Contributor Author

@dmhts dmhts Oct 7, 2024

Choose a reason for hiding this comment

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

Agree, I like using the optional factory-like makePinFromRevision() method for that. I just slightly changed the preposition.

Tests/ScipioKitTests/CacheSystemTests.swift Show resolved Hide resolved
Comment on lines +275 to +276
#if compiler(>=6.0)
guard let pin = pinsStore.pins[package.identity] ?? package.makePinFromRevision() else {
Copy link
Collaborator

@ikesyo ikesyo Oct 7, 2024

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)?

Copy link
Collaborator

@ikesyo ikesyo Oct 7, 2024

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

Copy link
Contributor Author

@dmhts dmhts Oct 7, 2024

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's release/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 for Xcode 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 :)

Copy link
Owner

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.

@giginet giginet merged commit 8eb442f into giginet:main Oct 9, 2024
4 checks passed
@ikesyo ikesyo mentioned this pull request Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants