Repository navigation
utils: small tweaks #387
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
base: swb/io
Are you sure you want to change the base?
utils: small tweaks #387
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,3 +13,4 @@ DerivedData/ | |
|
|
||
| /openapi | ||
| /.tmp | ||
| /xtool | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,4 @@ | ||
| #include <stdbool.h> | ||
|
|
||
| const char * _Nonnull xtl_version(void); | ||
| bool xtl_has_uncommitted_changes(void); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| public struct CommandVersion: Sendable, Hashable { | ||
| public var version: String | ||
| public var hasUncommittedChanges: Bool | ||
|
|
||
| public init(version: String, hasUncommittedChanges: Bool) { | ||
| self.version = version | ||
| self.hasUncommittedChanges = hasUncommittedChanges | ||
| } | ||
|
|
||
| public static var unversioned: Self { | ||
| .init(version: "unversioned", hasUncommittedChanges: true) | ||
| } | ||
| } | ||
|
|
||
| extension CommandVersion: CustomStringConvertible { | ||
| public var description: String { | ||
| version + (hasUncommittedChanges ? "-dirty" : "") | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,9 @@ | ||
| import CXKit | ||
| import XCLIUtils | ||
|
|
||
| extension XTool { | ||
| public static let version = String(cString: xtl_version()) | ||
| public static let version = CommandVersion( | ||
| version: String(cString: xtl_version()), | ||
| hasUncommittedChanges: xtl_has_uncommitted_changes(), | ||
| ) | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,22 @@ | ||||||||||
| import Foundation | ||||||||||
|
|
||||||||||
| package enum XToolCache { | ||||||||||
| package static var directory: URL { | ||||||||||
| let env = ProcessInfo.processInfo.environment | ||||||||||
| if let tmpdir = env["XTL_TMPDIR"] { | ||||||||||
| return URL(fileURLWithPath: tmpdir).appendingPathComponent("sh.xtool") | ||||||||||
|
Comment on lines
+6
to
+7
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. 🔎 Supported by static analysis
Treat an empty An empty value reaches Suggested fix
Committable suggestion
|
||||||||||
| } | ||||||||||
| #if os(Linux) | ||||||||||
| let xdgCache: URL | ||||||||||
| if let xdgCachePath = env["XDG_CACHE_HOME"], | ||||||||||
| (xdgCachePath as NSString).isAbsolutePath { | ||||||||||
| xdgCache = URL(filePath: xdgCachePath) | ||||||||||
| } else { | ||||||||||
| xdgCache = FileManager.default.homeDirectoryForCurrentUser.appendingPathComponent(".cache") | ||||||||||
| } | ||||||||||
| return xdgCache.appending(component: "xtool") | ||||||||||
| #else | ||||||||||
| return URL.cachesDirectory.appending(component: "sh.xtool") | ||||||||||
| #endif | ||||||||||
| } | ||||||||||
| } | ||||||||||
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.
Preserve the string-valued public API.
If a client passes
XTool.versionto aStringparameter, this change prevents that client from compiling.CustomStringConvertiblepreserves interpolation, but it does not makeCommandVersionaString.XToolSupportis exposed as a library product. Keep the string property and give the structured value a new name, or make this change as part of an explicit breaking release. (raw.githubusercontent.com)