Extract WireGuardGo version at build time.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Jeroen Leenarts 2018-10-02 21:03:44 +02:00
parent 589bba60b1
commit eadb09eda8
8 changed files with 90 additions and 45 deletions

View File

@ -7,6 +7,8 @@
<dict> <dict>
<key>Type</key> <key>Type</key>
<string>PSGroupSpecifier</string> <string>PSGroupSpecifier</string>
<key>Title</key>
<string>Version Info</string>
</dict> </dict>
<dict> <dict>
<key>DefaultValue</key> <key>DefaultValue</key>
@ -14,7 +16,17 @@
<key>Key</key> <key>Key</key>
<string>version_preference</string> <string>version_preference</string>
<key>Title</key> <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> <key>Type</key>
<string>PSTitleValueSpecifier</string> <string>PSTitleValueSpecifier</string>
</dict> </dict>

View File

@ -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

View File

@ -7,13 +7,17 @@ number_of_commits=$("$git" rev-list HEAD --count)
date_timestamp=$("$date" +%Y%m%d) date_timestamp=$("$date" +%Y%m%d)
target_plist="$TARGET_BUILD_DIR/$INFOPLIST_PATH" target_plist="$TARGET_BUILD_DIR/$INFOPLIST_PATH"
echo $target_plist
dsym_plist="$DWARF_DSYM_FOLDER_PATH/$DWARF_DSYM_FILE_NAME/Contents/Info.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 for plist in "$target_plist" "$dsym_plist"; do
if [ -f "$plist" ]; then if [ -f "$plist" ]; then
echo $date_timestamp echo $date_timestamp
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion ${number_of_commits}" "$plist" echo $plist
/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString 0.0.${date_timestamp}" "$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 fi
done done
@ -28,3 +32,4 @@ else
echo "Could not find: $settings_root_plist" echo "Could not find: $settings_root_plist"
exit 1 exit 1
fi fi

View File

@ -417,6 +417,7 @@
4A4BACDE20B5F1BF00F12B28 /* Sources */, 4A4BACDE20B5F1BF00F12B28 /* Sources */,
4A4BACDF20B5F1BF00F12B28 /* Frameworks */, 4A4BACDF20B5F1BF00F12B28 /* Frameworks */,
4A4BACE020B5F1BF00F12B28 /* Resources */, 4A4BACE020B5F1BF00F12B28 /* Resources */,
4A7CE90F2163EE6000D60BD7 /* Set wireguard go version */,
4A4BAD0920B5F56200F12B28 /* Set build number */, 4A4BAD0920B5F56200F12B28 /* Set build number */,
6F743EFD0F63EA8C605CE349 /* [CP] Embed Pods Frameworks */, 6F743EFD0F63EA8C605CE349 /* [CP] Embed Pods Frameworks */,
4A61D83220D98CE2006C7A76 /* Embed App Extensions */, 4A61D83220D98CE2006C7A76 /* Embed App Extensions */,
@ -597,6 +598,24 @@
shellPath = /bin/sh; shellPath = /bin/sh;
shellScript = "$SRCROOT/Scripts/set_build_number.sh\n"; 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 */ = { 6F743EFD0F63EA8C605CE349 /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase; isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;

View File

@ -12,26 +12,6 @@ enum GoVersionCoordinatorError: Error {
} }
extension AppCoordinator: SettingsTableViewControllerDelegate { 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) { func exportTunnels(settingsTableViewController: SettingsTableViewController, sourceView: UIView) {
self.exportConfigs(sourceView: sourceView) self.exportConfigs(sourceView: sourceView)
} }

View File

@ -329,7 +329,9 @@ class AppCoordinator: RootViewCoordinator { // swiftlint:disable:this type_body_
func connect(tunnel: Tunnel) { func connect(tunnel: Tunnel) {
_ = refreshProviderManagers().then { () -> Promise<Void> in _ = refreshProviderManagers().then { () -> Promise<Void> in
let manager = self.providerManager(for: tunnel)! guard let manager = self.providerManager(for: tunnel) else {
return Promise.value(())
}
let block = { let block = {
switch manager.connection.status { switch manager.connection.status {
case .invalid, .disconnected: case .invalid, .disconnected:
@ -411,6 +413,26 @@ class AppCoordinator: RootViewCoordinator { // swiftlint:disable:this type_body_
return tunnelIdentifier == tunnel.tunnelIdentifier 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 { class AppDocumentPickerDelegate: NSObject, UIDocumentPickerDelegate {

View File

@ -67,6 +67,8 @@
<string>6.0</string> <string>6.0</string>
<key>CFBundleName</key> <key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string> <string>$(PRODUCT_NAME)</string>
<key>WireGuardGoVersion</key>
<string>unknown</string>
<key>CFBundlePackageType</key> <key>CFBundlePackageType</key>
<string>APPL</string> <string>APPL</string>
<key>CFBundleShortVersionString</key> <key>CFBundleShortVersionString</key>

View File

@ -11,7 +11,6 @@ enum GoVersionError: Error {
protocol SettingsTableViewControllerDelegate: class { protocol SettingsTableViewControllerDelegate: class {
func exportTunnels(settingsTableViewController: SettingsTableViewController, sourceView: UIView) func exportTunnels(settingsTableViewController: SettingsTableViewController, sourceView: UIView)
func goVersionInformation() -> Promise<String>
} }
class SettingsTableViewController: UITableViewController { class SettingsTableViewController: UITableViewController {
@ -27,24 +26,7 @@ class SettingsTableViewController: UITableViewController {
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
versionInfoLabel.text = versionInformation versionInfoLabel.text = versionInformation
_ = firstly { () -> Promise<String> in goVersionInfoLabel.text = goVersionInformation
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: "")
}
})
} }
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
@ -72,8 +54,8 @@ class SettingsTableViewController: UITableViewController {
return versionElements.joined(separator: " ") return versionElements.joined(separator: " ")
} }
func goVersionInformation() -> Promise<String> { var goVersionInformation: String {
return self.delegate?.goVersionInformation() ?? Promise(error: GoVersionError.noDelegate) return Bundle.main.infoDictionary!["WireGuardGoVersion"] as? String ?? "Unknown!!!"
} }
private func showNotEnabledAlert() { private func showNotEnabledAlert() {