-
-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Makefile + optional static version (#339)
* Add Makefile + optional static version * add commit hash to version * use swift instead of bash
- Loading branch information
1 parent
150526c
commit 6f29a1b
Showing
4 changed files
with
106 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
VERSION := $(shell ./scripts/current-version.sh) | ||
|
||
build: | ||
# Set version | ||
sed -i '' 's/nil/"${VERSION}"/g' Sources/VaporToolbox/Version.swift | ||
# Build | ||
swift build \ | ||
--disable-sandbox \ | ||
--configuration release \ | ||
-Xswiftc -cross-module-optimization \ | ||
--enable-test-discovery | ||
# Reset version | ||
sed -i '' 's/"${VERSION}"/nil/g' Sources/VaporToolbox/Version.swift | ||
install: build | ||
mv .build/release/vapor /usr/local/bin/vapor-make | ||
uninstall: | ||
rm /usr/local/bin/vapor-make | ||
clean: | ||
rm -rf .build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// This file is edited by Makefile | ||
// Do not change manually. | ||
let staticVersion: String? = nil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/usr/bin/env swift | ||
import Foundation | ||
|
||
try print(currentVersion()) | ||
|
||
func currentVersion() throws -> String { | ||
do { | ||
let tag = try shell("git", "describe", "--tags", "--exact-match") | ||
return tag | ||
} catch { | ||
let branch = try shell("git", "symbolic-ref", "-q", "--short", "HEAD") | ||
let commit = try shell("git", "rev-parse", "--short", "HEAD") | ||
return "\(branch) (\(commit))" | ||
} | ||
} | ||
|
||
func shell(_ args: String...) throws -> String { | ||
let task = Process() | ||
task.launchPath = "/usr/bin/env" | ||
task.arguments = args | ||
// grab stdout | ||
let output = Pipe() | ||
task.standardOutput = output | ||
// ignore stderr | ||
let error = Pipe() | ||
task.standardError = error | ||
task.launch() | ||
task.waitUntilExit() | ||
|
||
guard task.terminationStatus == 0 else { | ||
throw ShellError(terminationStatus: task.terminationStatus) | ||
} | ||
|
||
return String(decoding: output.fileHandleForReading.readDataToEndOfFile(), as: UTF8.self) | ||
.trimmingCharacters(in: .whitespacesAndNewlines) | ||
} | ||
|
||
struct ShellError: Error { | ||
var terminationStatus: Int32 | ||
} |