]> git.ipfire.org Git - thirdparty/wireguard-apple.git/commitdiff
Extract WireGuardGo version at build time.
authorJeroen Leenarts <jeroen.leenarts@gmail.com>
Tue, 2 Oct 2018 19:03:44 +0000 (21:03 +0200)
committerJeroen Leenarts <jeroen.leenarts@gmail.com>
Tue, 2 Oct 2018 19:14:18 +0000 (21:14 +0200)
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Resources/Settings.bundle/Root.plist
Scripts/extract_wireguard_go_version.sh [new file with mode: 0755]
Scripts/set_build_number.sh
WireGuard.xcodeproj/project.pbxproj
WireGuard/Coordinators/AppCoordinator+SettingsTableViewControllerDelegate.swift
WireGuard/Coordinators/AppCoordinator.swift
WireGuard/Info.plist
WireGuard/ViewControllers/SetttingsTableViewController.swift

index a2355f1d263a430d98c8cfb2a895150b4d62c7fb..5bac309c63dffc1e97063416a77c419d77871a4f 100644 (file)
@@ -7,6 +7,8 @@
                <dict>
                        <key>Type</key>
                        <string>PSGroupSpecifier</string>
+                       <key>Title</key>
+                       <string>Version Info</string>
                </dict>
                <dict>
                        <key>DefaultValue</key>
                        <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 (executable)
index 0000000..7a5153c
--- /dev/null
@@ -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
index d857f033c23f1b89763c6932bffb4d967b424c31..1c49437a12e003f56918b73964a9b30852334507 100755 (executable)
@@ -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
+
index 7209ab8a7e69873dfd809fc83c16349335ac8d71..8bbdf91a153d7f5c98fde3b9770a68007695038c 100644 (file)
                                4A4BACDE20B5F1BF00F12B28 /* Sources */,
                                4A4BACDF20B5F1BF00F12B28 /* Frameworks */,
                                4A4BACE020B5F1BF00F12B28 /* Resources */,
+                               4A7CE90F2163EE6000D60BD7 /* Set wireguard go version */,
                                4A4BAD0920B5F56200F12B28 /* Set build number */,
                                6F743EFD0F63EA8C605CE349 /* [CP] Embed Pods Frameworks */,
                                4A61D83220D98CE2006C7A76 /* Embed App Extensions */,
                        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;
index d19422c5ebe5920adf86024cb496e5f7d19ee861..996104379d434e335507db7f93e940a4044632de 100644 (file)
@@ -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)
     }
index 07f8aa11574d985d8810046817e9778539ef49a7..b3a29c3df6ea56611e2cdf59a04302be28f67fa4 100644 (file)
@@ -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 {
index 4c2bc469f40d49f281c726d2242e60775ae489c9..842a2a24a1d18790f59873e2ee049c43d16535dd 100644 (file)
@@ -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>
index 8f87bb70228455f0f20802eaaa84249d5f2ac734..50832eb39eba0ab1f0e8a7895c18610b431b328f 100644 (file)
@@ -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() {