-
-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6f29a1b
commit 7edba49
Showing
3 changed files
with
88 additions
and
53 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 |
---|---|---|
@@ -1,19 +1,12 @@ | ||
VERSION := $(shell ./scripts/current-version.sh) | ||
DEST := /usr/local/bin/vapor | ||
|
||
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 | ||
swiftc ./scripts/build.swift | ||
./build | ||
rm ./build | ||
install: build | ||
mv .build/release/vapor /usr/local/bin/vapor-make | ||
mv .build/release/vapor ${DEST} | ||
uninstall: | ||
rm /usr/local/bin/vapor-make | ||
rm ${DEST} | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#!/usr/bin/env swift | ||
import Foundation | ||
|
||
try build() | ||
|
||
func build() throws { | ||
try withVersion(in: "Sources/VaporToolbox/Version.swift", as: currentVersion()) { | ||
try foregroundShell( | ||
"swift", "build", | ||
"--disable-sandbox", | ||
"--configuration", "release", | ||
"-Xswiftc", "-cross-module-optimization", | ||
"--enable-test-discovery" | ||
) | ||
} | ||
} | ||
|
||
func withVersion(in file: String, as version: String, _ closure: () throws -> ()) throws { | ||
let fileURL = URL(fileURLWithPath: file) | ||
let originalFileContents = try String(contentsOf: fileURL, encoding: .utf8) | ||
// set version | ||
try originalFileContents | ||
.replacingOccurrences(of: "nil", with: "\"\(version)\"") | ||
.write(to: fileURL, atomically: true, encoding: .utf8) | ||
defer { | ||
// undo set version | ||
try! originalFileContents | ||
.write(to: fileURL, atomically: true, encoding: .utf8) | ||
} | ||
// run closure | ||
try closure() | ||
} | ||
|
||
func currentVersion() throws -> String { | ||
do { | ||
let tag = try backgroundShell("git", "describe", "--tags", "--exact-match") | ||
return tag | ||
} catch { | ||
let branch = try backgroundShell("git", "symbolic-ref", "-q", "--short", "HEAD") | ||
let commit = try backgroundShell("git", "rev-parse", "--short", "HEAD") | ||
return "\(branch) (\(commit))" | ||
} | ||
} | ||
|
||
func foregroundShell(_ args: String...) throws { | ||
print("$", args.joined(separator: " ")) | ||
let task = Process() | ||
task.launchPath = "/usr/bin/env" | ||
task.arguments = args | ||
task.launch() | ||
task.waitUntilExit() | ||
|
||
guard task.terminationStatus == 0 else { | ||
throw ShellError(terminationStatus: task.terminationStatus) | ||
} | ||
} | ||
|
||
@discardableResult | ||
func backgroundShell(_ 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: Swift.Error { | ||
var terminationStatus: Int32 | ||
} |
This file was deleted.
Oops, something went wrong.