Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 10 additions & 18 deletions Core/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,11 @@

import PackageDescription

let gitTag: String = "\"" + (Context.gitInformation?.currentTag ?? "unknown") + "\""
let gitCommit: String = "\"" + (Context.gitInformation?.currentCommit ?? "unknown") + "\""

let package = Package(
name: "Core",
platforms: [.macOS(.v13)],
products: [
// Products define the executables and libraries a package produces, making them visible to other packages.
.library(
name: "Metadata",
targets: ["Metadata"]
),
.library(
name: "Core",
targets: ["Core"]
Expand All @@ -24,24 +17,23 @@ let package = Package(
.package(url: "https://github.com/azooKey/AzooKeyKanaKanjiConverter", from: "0.8.0", traits: ["Zenzai"]),
],
targets: [
.target(
name: "Metadata",
cSettings: [
.define(
"GIT_TAG", to: gitTag
),
.define(
"GIT_COMMIT", to: gitCommit
),
]
.executableTarget(
name: "git-info-generator",
),
.plugin(
name: "GitInfoPlugin",
capability: .buildTool(),
dependencies: [.target(name: "git-info-generator")]
),
.target(
name: "Core",
dependencies: [
.target(name: "Metadata"),
.product(name: "SwiftUtils", package: "AzooKeyKanaKanjiConverter"),
.product(name: "KanaKanjiConverterModuleWithDefaultDictionary", package: "AzooKeyKanaKanjiConverter"),
],
plugins: [
.plugin(name: "GitInfoPlugin")
],
),
.testTarget(
name: "CoreTests",
Expand Down
20 changes: 20 additions & 0 deletions Core/Plugins/GitInfoPlugin/plugin.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import PackagePlugin
import Foundation

@main
struct GitInfoPlugin: BuildToolPlugin {
func createBuildCommands(context: PluginContext, target: Target) throws -> [Command] {
let tool = try context.tool(named: "git-info-generator")
let outputFile = context.pluginWorkDirectoryURL.appending(path: "GitInfo.swift")
print(outputFile)

return [
.buildCommand(
displayName: "Generate Git Info",
executable: tool.url,
arguments: [outputFile.path()],
outputFiles: [outputFile]
)
]
}
}
16 changes: 2 additions & 14 deletions Core/Sources/Core/Metadata/Git.swift
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
import Metadata

public struct PackageMetadata {
public static var gitTag: String? {
let gitTag = String(validatingCString: git_tag_string())
return if gitTag == "unknown" {
nil
} else {
gitTag
}
gitTagFromPlugin
}
public static var gitCommit: String? {
let gitCommit = String(validatingCString: git_commit_string())
return if gitCommit == "unknown" {
nil
} else {
gitCommit
}
gitCommitFromPlugin
}
}
15 changes: 0 additions & 15 deletions Core/Sources/Metadata/git.c

This file was deleted.

7 changes: 0 additions & 7 deletions Core/Sources/Metadata/include/git.h

This file was deleted.

35 changes: 35 additions & 0 deletions Core/Sources/git-info-generator/main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import Foundation

var tag = try? shell("git tag --points-at HEAD")
var commit = try? shell("git rev-parse HEAD")
if tag?.isEmpty == true {
tag = nil
}
if commit?.isEmpty == true {
commit = nil
}

let outputPath = CommandLine.arguments[1]
let contents = """
// This file is auto-generated.

let gitTagFromPlugin: String? = \(tag as String?)
let gitCommitFromPlugin: String? = \(commit as String?)
"""

try contents.write(toFile: outputPath, atomically: true, encoding: .utf8)

@discardableResult
func shell(_ command: String) throws -> String {
let process = Process()
let pipe = Pipe()

process.standardOutput = pipe
process.executableURL = URL(fileURLWithPath: "/bin/bash")
process.arguments = ["-c", command]

try process.run()
let data = pipe.fileHandleForReading.readDataToEndOfFile()

return String(data: data, encoding: .utf8)!.trimmingCharacters(in: .whitespacesAndNewlines)
}
17 changes: 17 additions & 0 deletions exportOptions.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>method</key>
<string>developer-id</string>
<key>signingStyle</key>
<string>automatic</string>
<key>destination</key>
<string>export</string>
<key>stripSwiftSymbols</key>
<true/>
<key>compileBitcode</key>
<false/>
</dict>
</plist>
52 changes: 50 additions & 2 deletions pkgbuild.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,60 @@
set -e
set -ex

PROJECT_NAME="azooKeyMac"
SCHEME="azooKeyMac"
CONFIGURATION="Release"
ARCHIVE_PATH="./build/archive.xcarchive"
EXPORT_PATH="./build/export"
EXPORT_OPTIONS_PLIST="./exportOptions.plist"

# 1. Clean Build
rm -rf ./build
mkdir -p ./build
rm -rf ./Core/.build
rm -f ./Core/Package.resolved

# 2. Archive
# Note: use `"$(mktemp -d)` to avoid conflicts with previous builds
xcodebuild \
-project "${PROJECT_NAME}.xcodeproj" \
-scheme "${SCHEME}" \
clean archive \
-configuration "${CONFIGURATION}" \
-archivePath "${ARCHIVE_PATH}" \
-derivedDataPath "$(mktemp -d)" \
-clonedSourcePackagesDirPath $(mktemp -d) \
-allowProvisioningUpdates \
-destination "generic/platform=macOS"

# 3. Export
xcodebuild -exportArchive \
-archivePath "${ARCHIVE_PATH}" \
-exportPath "${EXPORT_PATH}" \
-exportOptionsPlist "${EXPORT_OPTIONS_PLIST}" \
-allowProvisioningUpdates

# 4. Notarize .app
APP_PATH="${EXPORT_PATH}/${PROJECT_NAME}.app"
APP_ZIP="${PROJECT_NAME}.zip"

# Zip the .app for notarization
ditto -c -k --sequesterRsrc --keepParent "${APP_PATH}" "${APP_ZIP}"

# Submit the .app (zip) for notarization
xcrun notarytool submit "${APP_ZIP}" --keychain-profile "Notarytool" --wait

# Staple the notarization ticket to the .app
xcrun stapler staple "${APP_PATH}"

# Remove the temporary zip
rm "${APP_ZIP}"

# Suppose we have build/azooKeyMac.app
# Use this script to create a plist package for distribution
# pkgbuild --analyze --root ./build/ pkg.plist

# Create a temporary package
pkgbuild --root ./build/ \
pkgbuild --root ${EXPORT_PATH} \
--component-plist pkg.plist --identifier dev.ensan.inputmethod.azooKeyMac \
--version 0 \
--install-location /Library/Input\ Methods \
Expand Down