Skip to content

Commit

Permalink
Refactoring: drop PackageBuildInfo sources, add PackageBuildInfo bina…
Browse files Browse the repository at this point in the history
…ryTarget
  • Loading branch information
DimaRU committed Jun 13, 2022
1 parent 9caf63f commit f48e26f
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 246 deletions.
4 changes: 0 additions & 4 deletions .swiftformat

This file was deleted.

Binary file added Binaries/PackageBuildInfo.zip
Binary file not shown.
6 changes: 2 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@ import PackageDescription

let package = Package(
name: "PackageBuildInfo",
platforms: [.macOS(.v11)],
products: [
.plugin(name: "packageBuildInfoPlugin", targets: ["PackageBuildInfoPlugin"]),
.executable(name: "packageBuildInfo", targets: ["PackageBuildInfo"]),
.plugin(name: "PackageBuildInfoPlugin", targets: ["PackageBuildInfoPlugin"]),
],
targets: [
.plugin(
name: "PackageBuildInfoPlugin",
capability: .buildTool(),
dependencies: ["PackageBuildInfo"]
),
.executableTarget(name: "PackageBuildInfo"),
.binaryTarget(name: "PackageBuildInfo", path: "Binaries/PackageBuildInfo.zip"),
]
)
21 changes: 1 addition & 20 deletions Plugins/PackageBuildInfoPlugin/plugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,14 @@ import Foundation
@main
struct PackageBuildInfoPlugin: BuildToolPlugin {
func createBuildCommands(context: PluginContext, target: Target) throws -> [Command] {
func searchTool() -> String? {
let mintPath = FileManager.default.homeDirectoryForCurrentUser.appendingPathComponent(".mint/bin")
let pathList = (ProcessInfo.processInfo.environment["PATH"] ?? "/usr/local/bin") + ":\(mintPath.path)"

for path in pathList.split(separator: ":") {
let url = URL(fileURLWithPath: String(path)).appendingPathComponent("packageBuildInfo")
if let res = try? url.resourceValues(forKeys: [.isExecutableKey]),
res.isExecutable ?? false
{
return url.path
}
}
return nil
}

guard let target = target as? SourceModuleTarget else { return [] }
guard let tool = searchTool() else {
Diagnostics.error("Please install PackageBuildInfo")
return []
}
let outputFile = context.pluginWorkDirectory.appending("packageBuildInfo.swift")

let command: Command = .prebuildCommand(
displayName:
"Generating \(outputFile.lastComponent) for \(target.directory)",
executable:
PackagePlugin.Path(tool),
try context.tool(named: "PackageBuildInfo").path,
arguments: [ "\(target.directory)", "\(outputFile)" ],
outputFilesDirectory: context.pluginWorkDirectory
)
Expand Down
33 changes: 8 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,7 @@ Using a new amazing feature - Swift Package Manager prebuild plugin, you can gen

* SwiftPM 5.6 or later.
* git

## Installation

* Use the [Mint](https://github.com/yonaskolb/Mint) to install PackageBuildInfo:

```bash
mint install DimaRU/PackageBuildInfo
```

* or build manually:

```bash
git clone https://github.com/DimaRU/PackageBuildInfo
cd PackageBuildInfo
swift build -c release
cp .build/release/packageBuildInfo /usr/local/bin
```
* bash

## Usage

Expand Down Expand Up @@ -68,7 +52,7 @@ public struct PackageBuild {
let timeZone: TimeZone // Time Zone
let count: Int // Total commit count
let tag: String? // Tag, if exist
let countSince: Int // Commit count since tag
let countSinceTag: Int // Commit count since tag
let branch: String? // Git branch name
let digest: [UInt8] // Latest commit sha1 digest (20 bytes)

Expand All @@ -77,14 +61,13 @@ public struct PackageBuild {
}
static let info = PackageBuild(
isDirty: false,
timeStamp: Date(timeIntervalSince1970: 1651860865),
timeZone: TimeZone(secondsFromGMT: 10800)!,
count: 4,
tag: "0.0.1",
countSince: 3,
timeStamp: Date(timeIntervalSince1970: 1651955365),
timeZone: TimeZone(secondsFromGMT: 10800) ?? TimeZone.current,
count: 6,
tag: "1.0.0",
countSinceTag: 2,
branch: "master",
digest: [0xee, 0x53, 0x6a, 0x73, 0xff, 0xc6, 0x16, 0x76, 0x50, 0xe9,
0x5e, 0x2c, 0xd2, 0xa8, 0xcb, 0x96, 0x38, 0x49, 0x15, 0xc7])
digest: [0x72, 0x75, 0x92, 0xa4, 0x2d, 0xa7, 0x16, 0xb5, 0x9d, 0x2b, 0x0f, 0x06, 0x1d, 0xbc, 0x61, 0x4d, 0xc9, 0xa7, 0x58, 0x92])
}
```

Expand Down
165 changes: 0 additions & 165 deletions Sources/PackageBuildInfo/GitInfo.swift

This file was deleted.

28 changes: 0 additions & 28 deletions Sources/PackageBuildInfo/main.swift

This file was deleted.

0 comments on commit f48e26f

Please sign in to comment.