Extract WireGuardGo version at build time.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
parent
589bba60b1
commit
eadb09eda8
|
@ -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>
|
||||
|
|
|
@ -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
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue