aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeroen Leenarts <jeroen.leenarts@gmail.com>2018-10-02 21:03:44 +0200
committerJeroen Leenarts <jeroen.leenarts@gmail.com>2018-10-02 21:14:18 +0200
commiteadb09eda8dab95febb955fe2dd9819f1e4c4212 (patch)
tree57ab2abe65f95bc2c6f8b8cc9afceb1eeb3f09f0
parentDeal with type body length warning. (diff)
downloadwireguard-apple-eadb09eda8dab95febb955fe2dd9819f1e4c4212.tar.xz
wireguard-apple-eadb09eda8dab95febb955fe2dd9819f1e4c4212.zip
Extract WireGuardGo version at build time.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
-rw-r--r--Resources/Settings.bundle/Root.plist14
-rwxr-xr-xScripts/extract_wireguard_go_version.sh23
-rwxr-xr-xScripts/set_build_number.sh9
-rw-r--r--WireGuard.xcodeproj/project.pbxproj19
-rw-r--r--WireGuard/Coordinators/AppCoordinator+SettingsTableViewControllerDelegate.swift20
-rw-r--r--WireGuard/Coordinators/AppCoordinator.swift24
-rw-r--r--WireGuard/Info.plist2
-rw-r--r--WireGuard/ViewControllers/SetttingsTableViewController.swift24
8 files changed, 90 insertions, 45 deletions
diff --git a/Resources/Settings.bundle/Root.plist b/Resources/Settings.bundle/Root.plist
index a2355f1..5bac309 100644
--- a/Resources/Settings.bundle/Root.plist
+++ b/Resources/Settings.bundle/Root.plist
@@ -7,6 +7,8 @@
<dict>
<key>Type</key>
<string>PSGroupSpecifier</string>
+ <key>Title</key>
+ <string>Version Info</string>
</dict>
<dict>
<key>DefaultValue</key>
@@ -14,7 +16,17 @@
<key>Key</key>
<string>version_preference</string>
<key>Title</key>
- <string>Version Info</string>
+ <string>WireGuard iOS</string>
+ <key>Type</key>
+ <string>PSTitleValueSpecifier</string>
+ </dict>
+ <dict>
+ <key>DefaultValue</key>
+ <string>Set at build time.</string>
+ <key>Key</key>
+ <string>wireguard_version_preference</string>
+ <key>Title</key>
+ <string>WireGuard Go</string>
<key>Type</key>
<string>PSTitleValueSpecifier</string>
</dict>
diff --git a/Scripts/extract_wireguard_go_version.sh b/Scripts/extract_wireguard_go_version.sh
new file mode 100755
index 0000000..7a5153c
--- /dev/null
+++ b/Scripts/extract_wireguard_go_version.sh
@@ -0,0 +1,23 @@
+#!/bin/bash
+
+sed=$(sh /etc/profile; which sed)
+wireguard_go_version=$("$sed" -n 's/.*WireGuardGoVersion = "\(.*\)\".*/\1/p' wireguard-go/version.go)
+
+target_plist="$TARGET_BUILD_DIR/$INFOPLIST_PATH"
+dsym_plist="$DWARF_DSYM_FOLDER_PATH/$DWARF_DSYM_FILE_NAME/Contents/Info.plist"
+
+for plist in "$target_plist" "$dsym_plist"; do
+ if [ -f "$plist" ]; then
+ echo $wireguard_go_version
+ /usr/libexec/PlistBuddy -c "Set :WireGuardGoVersion $wireguard_go_version" "$plist"
+ fi
+done
+
+settings_root_plist="$TARGET_BUILD_DIR/WireGuard.app/Settings.bundle/Root.plist"
+
+if [ -f "$settings_root_plist" ]; then
+ /usr/libexec/PlistBuddy -c "Set :PreferenceSpecifiers:2:DefaultValue $wireguard_go_version" "$settings_root_plist"
+else
+ echo "Could not find: $settings_root_plist"
+ exit 1
+fi
diff --git a/Scripts/set_build_number.sh b/Scripts/set_build_number.sh
index d857f03..1c49437 100755
--- a/Scripts/set_build_number.sh
+++ b/Scripts/set_build_number.sh
@@ -7,13 +7,17 @@ number_of_commits=$("$git" rev-list HEAD --count)
date_timestamp=$("$date" +%Y%m%d)
target_plist="$TARGET_BUILD_DIR/$INFOPLIST_PATH"
+echo $target_plist
dsym_plist="$DWARF_DSYM_FOLDER_PATH/$DWARF_DSYM_FILE_NAME/Contents/Info.plist"
+echo $dsym_plist
for plist in "$target_plist" "$dsym_plist"; do
if [ -f "$plist" ]; then
echo $date_timestamp
- /usr/libexec/PlistBuddy -c "Set :CFBundleVersion ${number_of_commits}" "$plist"
- /usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString 0.0.${date_timestamp}" "$plist"
+ echo $plist
+ echo $number_of_commits
+ /usr/libexec/PlistBuddy -c "Set :CFBundleVersion $number_of_commits" "$plist"
+ /usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString 0.0.$date_timestamp" "$plist"
fi
done
@@ -28,3 +32,4 @@ else
echo "Could not find: $settings_root_plist"
exit 1
fi
+
diff --git a/WireGuard.xcodeproj/project.pbxproj b/WireGuard.xcodeproj/project.pbxproj
index 7209ab8..8bbdf91 100644
--- a/WireGuard.xcodeproj/project.pbxproj
+++ b/WireGuard.xcodeproj/project.pbxproj
@@ -417,6 +417,7 @@
4A4BACDE20B5F1BF00F12B28 /* Sources */,
4A4BACDF20B5F1BF00F12B28 /* Frameworks */,
4A4BACE020B5F1BF00F12B28 /* Resources */,
+ 4A7CE90F2163EE6000D60BD7 /* Set wireguard go version */,
4A4BAD0920B5F56200F12B28 /* Set build number */,
6F743EFD0F63EA8C605CE349 /* [CP] Embed Pods Frameworks */,
4A61D83220D98CE2006C7A76 /* Embed App Extensions */,
@@ -597,6 +598,24 @@
shellPath = /bin/sh;
shellScript = "$SRCROOT/Scripts/set_build_number.sh\n";
};
+ 4A7CE90F2163EE6000D60BD7 /* Set wireguard go version */ = {
+ isa = PBXShellScriptBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ );
+ inputFileListPaths = (
+ );
+ inputPaths = (
+ );
+ name = "Set wireguard go version";
+ outputFileListPaths = (
+ );
+ outputPaths = (
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ shellPath = /bin/sh;
+ shellScript = "$SRCROOT/Scripts/extract_wireguard_go_version.sh\n";
+ };
6F743EFD0F63EA8C605CE349 /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
diff --git a/WireGuard/Coordinators/AppCoordinator+SettingsTableViewControllerDelegate.swift b/WireGuard/Coordinators/AppCoordinator+SettingsTableViewControllerDelegate.swift
index d19422c..9961043 100644
--- a/WireGuard/Coordinators/AppCoordinator+SettingsTableViewControllerDelegate.swift
+++ b/WireGuard/Coordinators/AppCoordinator+SettingsTableViewControllerDelegate.swift
@@ -12,26 +12,6 @@ enum GoVersionCoordinatorError: Error {
}
extension AppCoordinator: SettingsTableViewControllerDelegate {
- func goVersionInformation() -> Promise<String> {
- return Promise(resolver: { (resolver) in
- guard let session = self.providerManagers?.first(where: { $0.isEnabled })?.connection as? NETunnelProviderSession else {
- resolver.reject(GoVersionCoordinatorError.noEnabledSession)
- return
- }
- do {
- try session.sendProviderMessage(ExtensionMessage.requestVersion.data, responseHandler: { (data) in
- guard let data = data, let responseString = String(data: data, encoding: .utf8) else {
- resolver.reject(GoVersionCoordinatorError.noResponse)
- return
- }
- resolver.fulfill(responseString)
- })
- } catch {
- resolver.reject(error)
- }
- })
- }
-
func exportTunnels(settingsTableViewController: SettingsTableViewController, sourceView: UIView) {
self.exportConfigs(sourceView: sourceView)
}
diff --git a/WireGuard/Coordinators/AppCoordinator.swift b/WireGuard/Coordinators/AppCoordinator.swift
index 07f8aa1..b3a29c3 100644
--- a/WireGuard/Coordinators/AppCoordinator.swift
+++ b/WireGuard/Coordinators/AppCoordinator.swift
@@ -329,7 +329,9 @@ class AppCoordinator: RootViewCoordinator { // swiftlint:disable:this type_body_
func connect(tunnel: Tunnel) {
_ = refreshProviderManagers().then { () -> Promise<Void> in
- let manager = self.providerManager(for: tunnel)!
+ guard let manager = self.providerManager(for: tunnel) else {
+ return Promise.value(())
+ }
let block = {
switch manager.connection.status {
case .invalid, .disconnected:
@@ -411,6 +413,26 @@ class AppCoordinator: RootViewCoordinator { // swiftlint:disable:this type_body_
return tunnelIdentifier == tunnel.tunnelIdentifier
}
}
+
+ func extensionGoVersionInformation() -> Promise<String> {
+ return Promise(resolver: { (resolver) in
+ guard let session = self.providerManagers?.first(where: { $0.isEnabled })?.connection as? NETunnelProviderSession else {
+ resolver.reject(GoVersionCoordinatorError.noEnabledSession)
+ return
+ }
+ do {
+ try session.sendProviderMessage(ExtensionMessage.requestVersion.data, responseHandler: { (data) in
+ guard let data = data, let responseString = String(data: data, encoding: .utf8) else {
+ resolver.reject(GoVersionCoordinatorError.noResponse)
+ return
+ }
+ resolver.fulfill(responseString)
+ })
+ } catch {
+ resolver.reject(error)
+ }
+ })
+ }
}
class AppDocumentPickerDelegate: NSObject, UIDocumentPickerDelegate {
diff --git a/WireGuard/Info.plist b/WireGuard/Info.plist
index 4c2bc46..842a2a2 100644
--- a/WireGuard/Info.plist
+++ b/WireGuard/Info.plist
@@ -67,6 +67,8 @@
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
+ <key>WireGuardGoVersion</key>
+ <string>unknown</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
diff --git a/WireGuard/ViewControllers/SetttingsTableViewController.swift b/WireGuard/ViewControllers/SetttingsTableViewController.swift
index 8f87bb7..50832eb 100644
--- a/WireGuard/ViewControllers/SetttingsTableViewController.swift
+++ b/WireGuard/ViewControllers/SetttingsTableViewController.swift
@@ -11,7 +11,6 @@ enum GoVersionError: Error {
protocol SettingsTableViewControllerDelegate: class {
func exportTunnels(settingsTableViewController: SettingsTableViewController, sourceView: UIView)
- func goVersionInformation() -> Promise<String>
}
class SettingsTableViewController: UITableViewController {
@@ -27,24 +26,7 @@ class SettingsTableViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
versionInfoLabel.text = versionInformation
- _ = firstly { () -> Promise<String> in
- self.goVersionInfoLabel.text = NSLocalizedString("Loading...", comment: "")
- return goVersionInformation()
- }.then { (goVersion: String) -> Guarantee<Void> in
- if let label = self.goVersionInfoLabel {
- label.text = goVersion
- }
- return Guarantee.value(())
- }.recover({ (error) in
- switch error {
- case GoVersionCoordinatorError.noEnabledSession:
- self.goVersionInfoLabel.text = NSLocalizedString("Unavailable", comment: "")
- self.showNotEnabledAlert()
- default:
- self.goVersionInfoLabel.text = NSLocalizedString("Unknown", comment: "")
- }
-
- })
+ goVersionInfoLabel.text = goVersionInformation
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
@@ -72,8 +54,8 @@ class SettingsTableViewController: UITableViewController {
return versionElements.joined(separator: " ")
}
- func goVersionInformation() -> Promise<String> {
- return self.delegate?.goVersionInformation() ?? Promise(error: GoVersionError.noDelegate)
+ var goVersionInformation: String {
+ return Bundle.main.infoDictionary!["WireGuardGoVersion"] as? String ?? "Unknown!!!"
}
private func showNotEnabledAlert() {