Support `xtool --version` (#53)
- Commit
fbbd8366ca138a0a44ca28242973b109fe3eced6- Author
- Kabir Oberai <[email protected]>
- When
- 2025-05-21 12:46 UTC (1 year ago)
- Parents
73f42d9
Diff
.github/workflows/release.yml
diff --git a/.github/workflows/release.yml b/.github/workflows/release.ymlindex 36fd0a4..747a5fe 100644--- a/.github/workflows/release.yml+++ b/.github/workflows/release.yml@@ -1,5 +1,7 @@ on:- workflow_dispatch:+ push:+ tags:+ - "*" jobs: build-linux:@@ -19,7 +21,9 @@ jobs: uses: actions/checkout@v4 - name: Build run: |- docker compose run --build --rm xtool Linux/build.sh+ docker compose run --build \+ -e XTOOL_VERSION=${{ github.ref_name }} \+ --rm xtool Linux/build.sh - name: Upload artifact uses: actions/upload-artifact@v4 with:@@ -46,6 +50,7 @@ jobs: APP_STORE_CONNECT_API_KEY_KEY: ${{ secrets.APP_STORE_CONNECT_API_KEY_KEY }} IDENTITY_P12: ${{ secrets.IDENTITY_P12 }} DEVELOPMENT_TEAM: ${{ secrets.DEVELOPMENT_TEAM }}+ XTOOL_VERSION: ${{ github.ref_name }} run: | cd macOS bundle exec fastlane package@@ -72,6 +77,6 @@ jobs: path: output - name: Create and publish release run: |- TAG="${GITHUB_REF##*/}-${GITHUB_SHA:0:7}"- gh release create "$TAG" --draft --title "Draft Release"+ TAG="${{ github.ref_name }}"+ gh release create "$TAG" --draft --title "v$TAG" gh release upload "$TAG" output/**/*.{AppImage,AppImage.zsync,app.zip,app.dSYM.zip}
Linux/build.sh
diff --git a/Linux/build.sh b/Linux/build.shindex 8a269f7..87dff15 100755--- a/Linux/build.sh+++ b/Linux/build.sh@@ -5,9 +5,6 @@ shopt -s nullglob cd "$(dirname "$0")" -# release version-export LINUXDEPLOY_OUTPUT_VERSION="latest"- if ! command -v fusermount &>/dev/null; then # Docker doesn't support FUSE export APPIMAGE_EXTRACT_AND_RUN=1@@ -43,10 +40,10 @@ fi mkdir -p staging/tmp/AppDir/usr/bin find "${bin}"/ -name '*.resources' -print0 | xargs -0 -I {} cp -a {} "${PWD}/staging/tmp/AppDir/usr/bin/" -env \-LDAI_OUTPUT="staging/tmp/xtool-${curr_arch}.AppImage" \-LDAI_UPDATE_INFORMATION="gh-releases-zsync|xtool-org|xtool|latest|xtool-${curr_arch}.AppImage.zsync" \- ./staging/linuxdeploy/linuxdeploy.AppImage \+export LINUXDEPLOY_OUTPUT_VERSION="${XTOOL_VERSION:-unversioned}"+export LDAI_OUTPUT="staging/tmp/xtool-${curr_arch}.AppImage"+export LDAI_UPDATE_INFORMATION="gh-releases-zsync|xtool-org|xtool|latest|xtool-${curr_arch}.AppImage.zsync"+./staging/linuxdeploy/linuxdeploy.AppImage \ --appdir staging/tmp/AppDir \ --output appimage \ -e "${bin}/xtool" \
Package.swift
diff --git a/Package.swift b/Package.swiftindex 8237c1a..3d85b24 100644--- a/Package.swift+++ b/Package.swift@@ -2,6 +2,19 @@ import PackageDescription +let xtoolVersion: String? = {+ if let explicitVersion = Context.environment["XTOOL_VERSION"] {+ return explicitVersion+ } else if let info = Context.gitInformation {+ let gitCommit = info.currentCommit+ let gitTag = info.currentTag+ let gitRef = gitTag ?? "commit \(gitCommit)"+ return "\(gitRef)\(info.hasUncommittedChanges ? " (dirty)" : "")"+ } else {+ return nil+ }+}()+ let cSettings: [CSetting] = [ .define("_GNU_SOURCE", .when(platforms: [.linux])), ]@@ -64,7 +77,11 @@ let package = Package( dependencies: [ .product(name: "OpenSSL", package: "xtool-core") ],- cSettings: cSettings+ cSettings: cSettings + (+ xtoolVersion+ .map { [.define("XTOOL_VERSION", to: "\"\($0)\"")] }+ ?? []+ ) ), .target( name: "DeveloperAPI",
Sources/CXKit/include/version.h
diff --git a/Sources/CXKit/include/version.h b/Sources/CXKit/include/version.hnew file mode 100644index 0000000..f58c6cc--- /dev/null+++ b/Sources/CXKit/include/version.h@@ -0,0 +1 @@+const char * _Nonnull xtl_version(void);
Sources/CXKit/version.c
diff --git a/Sources/CXKit/version.c b/Sources/CXKit/version.cnew file mode 100644index 0000000..26637a4--- /dev/null+++ b/Sources/CXKit/version.c@@ -0,0 +1,9 @@+#include "version.h"++const char *xtl_version(void) {+#ifdef XTOOL_VERSION+ return XTOOL_VERSION;+#else+ return "unversioned";+#endif+}
Sources/XToolSupport/XTool+Version.swift
diff --git a/Sources/XToolSupport/XTool+Version.swift b/Sources/XToolSupport/XTool+Version.swiftnew file mode 100644index 0000000..9ad80e2--- /dev/null+++ b/Sources/XToolSupport/XTool+Version.swift@@ -0,0 +1,5 @@+import CXKit++extension XTool {+ public static let version = String(cString: xtl_version())+}
Sources/XToolSupport/XTool.swift
diff --git a/Sources/XToolSupport/XToolCommand.swift b/Sources/XToolSupport/XTool.swiftsimilarity index 95%rename from Sources/XToolSupport/XToolCommand.swiftrename to Sources/XToolSupport/XTool.swiftindex ca5600f..cb05e6f 100644--- a/Sources/XToolSupport/XToolCommand.swift+++ b/Sources/XToolSupport/XTool.swift@@ -8,10 +8,11 @@ public enum XTool { } } -struct XToolCommand: AsyncParsableCommand {+private struct XToolCommand: AsyncParsableCommand { static let configuration = CommandConfiguration( commandName: "xtool", abstract: "Cross-platform Xcode replacement",+ version: "xtool \(XTool.version)", groupedSubcommands: [ CommandGroup( name: "Configuration",