-
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
Follow-up / Making Scipio environment-configurable #154
Conversation
|
||
/// A non-caching environment-aware implementation of `SwiftSDK.sdkPlatformFrameworkPaths` | ||
/// Returns `macosx` sdk platform framework path. | ||
func nonCachingSDKPlatformFrameworkPaths() async throws -> (fwk: AbsolutePath, lib: AbsolutePath) { |
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.
As I mentioned in the PR description, this is just a copy of the existing function without the path-caching part.
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.
Could you note this context in the comment?
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.
Please avoid abbreviations frameworkPath
, libPath
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 prefer to add a verb to the name. This method executes external commands, so it's not better to name it like a getter.
How about renaming like resolveSDKPlatformFrameworkPaths
?
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.
Please avoid abbreviations frameworkPath, libPath
Sorry, I just copied Apple's implementation one-to-one. Of course, it makes sense. Done.
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.
How about renaming like resolveSDKPlatformFrameworkPaths?
Yes, I also like it. Done.
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.
Could you note this context in the comment?
/// A non-caching environment-aware implementation of
SwiftSDK.sdkPlatformFrameworkPaths
I believe it's already in the comment above, or did you mean something else?
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.
Its concept looks good. However, it's better to tweak the interface of adding the method even if you just moved the existing implementation.
|
||
/// A non-caching environment-aware implementation of `SwiftSDK.sdkPlatformFrameworkPaths` | ||
/// Returns `macosx` sdk platform framework path. | ||
func nonCachingSDKPlatformFrameworkPaths() async throws -> (fwk: AbsolutePath, lib: AbsolutePath) { |
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.
Could you note this context in the comment?
|
||
/// A non-caching environment-aware implementation of `SwiftSDK.sdkPlatformFrameworkPaths` | ||
/// Returns `macosx` sdk platform framework path. | ||
func nonCachingSDKPlatformFrameworkPaths() async throws -> (fwk: AbsolutePath, lib: AbsolutePath) { |
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.
Please avoid abbreviations frameworkPath
, libPath
|
||
/// A non-caching environment-aware implementation of `SwiftSDK.sdkPlatformFrameworkPaths` | ||
/// Returns `macosx` sdk platform framework path. | ||
func nonCachingSDKPlatformFrameworkPaths() async throws -> (fwk: AbsolutePath, lib: AbsolutePath) { |
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 prefer to add a verb to the name. This method executes external commands, so it's not better to name it like a getter.
How about renaming like resolveSDKPlatformFrameworkPaths
?
import struct Basics.AbsolutePath | ||
@_spi(SwiftPMInternal) import struct Basics.Environment | ||
|
||
public typealias ToolchainEnvironment = [String: String] |
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.
@giginet I've extracted all the ToolchainEnvironment
-related logic into a separate file and introduced a type alias for improved semantics. Does that work for you?
self.toolchain = try UserToolchain( | ||
swiftSDK: try .hostSwiftSDK( | ||
toolchainEnvironment?.toolchainBinPath, | ||
environment: toolchainEnvironment.asSwiftPMEnvironment | ||
), | ||
environment: toolchainEnvironment.asSwiftPMEnvironment | ||
) |
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.
Sorry for the belated response. I'm back as of today!
We’re almost finished with our Scipio-powered tool, and during final testing, we discovered another environment-related issue (hopefully the last one!).
There’s a bug in SwiftPM where Environment isn’t passed down to the shell-executing function here. Fortunately, it’s possible to work around this by supplying a custom binDir (pointing to the bin dir of the current toolchain in our case) a few lines above.
I’m planning to file another fix for this in SwiftPM soon (I've already merged these two, and have one currently open). Although it’s not a critical issue, resolving it would allow a cleaner setup by removing the need to specify a custom bin path.
Apologies for including this change in the current PR, but I believe it’s closely related to its focus, and it’s purely additive, leaving existing behavior unaffected.
As mentioned, this appears to be the last environment-related enhancement needed to enable Scipio for multi-toolchain use. 🎉
@giginet is it the CI issue? |
The CI failure is related to actions/runner-images#10703 |
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.
Almost great. I'll modify the small points on this PR and I'll merge this
@@ -0,0 +1,19 @@ | |||
import XCTest |
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.
You can use @Testing
for new tests 😄
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 haven't noticed you already used it in the other tests. No problem, I'll do it next time 👍
} | ||
} | ||
|
||
extension ToolchainEnvironment? { |
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.
It's confusing to extend to Optional
.
.current
is injected on the callee side, but I prefer to inject on the caller side explicitly.
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.
The idea is to shift all the boilerplate from the calling site to the extension. Sure, we can use map
or flatMap
at the calling site, but then it would be like this:
try UserToolchain(
swiftSDK: try .hostSwiftSDK(
toolchainEnvironment?.toolchainBinPath,
environment: toolchainEnvironment.flatMap { Environment($0) } ?? Environment.current
),
environment: toolchainEnvironment.flatMap { Environment($0) } ?? Environment.current
)
versus with the optional extension:
try UserToolchain(
swiftSDK: try .hostSwiftSDK(
toolchainEnvironment?.toolchainBinPath,
environment: toolchainEnvironment.asSwiftPMEnvironment
),
environment: toolchainEnvironment.asSwiftPMEnvironment
)
Additionally, in the first case, we would also need to use this clunky import: @_spi(SwiftPMInternal) import struct Basics.Environment
every time Environment
is referenced.
or did you mean something else?
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.
Thank you for the comment. I haven't considered _spi.
I already tweaked my changes, but I'll revert this commit. 260baa5
Sorry for the modification!
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.
@giginet I see what you mean! Looks good to me 👍
Update: yeah, it doesn't solve the issue with the import.
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.
Oops, I already reverted the commit 😓
If you think it's good, I'll apply the commit again and merge this. Thank you!
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 was mistaken, the import was not needed in your case. Yeah, feel free to apply it again. As a benefit of your approach - it's more obvious that the variable is optional at the calling site.
Sorry, I tweaked your patch. I'll merge this 🚀 |
This reverts commit 260baa5.
This reverts commit 0664260.
Co-authored-by: IKEDA Sho <suicaicoca@gmail.com>
This PR is a follow-up built on #140, where Runner became more environment-aware. This follow-up addresses two additional issues:
Issue 1:
It fixes an issue where the environment dictionary was not properly passed through to
UserToolchain
.Issue 2:
It introduces a non-caching implementation of the SwiftSDK.sdkPlatformFrameworkPaths(environment:) function (which basically copies the original function without the path-caching part). The original function, although environment-aware, caches the resolved platform path unconditionally on the first call in a private static property, with no way to reset the cache later. For
Scipio
to be fully environment-configurable, especially when the environment may change multiple times within a single run (e.g., when Scipio is used with multiple toolchains), each environment (associated with a specific toolchain) requires a unique platform path, e.g.:Therefore, to enable greater flexibility, a non-caching implementation of the original function has been introduced.
@giginet As always, looking forward to your comments and questions.