From 4effad22ece80e69c559caa52ffbd41cc6756ca0 Mon Sep 17 00:00:00 2001 From: Scott Dixon Date: Mon, 14 Dec 2015 10:39:33 -0800 Subject: [PATCH] Porting binaries: xcode-iwd & ios-webkit-debug-proxy-launcher --- bin/ios-webkit-debug-proxy-launcher.js | 69 ++++++++++++++++++++++++++ bin/xcode-iwd.sh | 5 ++ 2 files changed, 74 insertions(+) create mode 100644 bin/ios-webkit-debug-proxy-launcher.js create mode 100644 bin/xcode-iwd.sh diff --git a/bin/ios-webkit-debug-proxy-launcher.js b/bin/ios-webkit-debug-proxy-launcher.js new file mode 100644 index 000000000..83f79b473 --- /dev/null +++ b/bin/ios-webkit-debug-proxy-launcher.js @@ -0,0 +1,69 @@ +#!/usr/bin/env node + +/* + * Small tool, launching and monitoring ios-web-kit-proxy, and relauching + * on predefined errors. + * + * Usage: + * ./bin/ios-webkit-debug-proxy-launcher.js [args] + * args: ios-webkit-debug-proxy args (they will be passed over) + * + * Example: + * ./bin/ios-webkit-debug-proxy-launcher.js -c :27753 -d + * + * Note: + * For iOS8.1 try this first: + * brew install --HEAD ideviceinstaller + */ + +"use strict"; + +var spawn = require('child_process').spawn, + _ = require('underscore'); + +var args = process.argv.slice(2); + +var RESTART_ON_MESSAGES = [ + 'Invalid message _rpc_applicationUpdated', + 'Invalid message _rpc_applicationSentListing']; + +var PROXY_CMD = 'ios_webkit_debug_proxy'; +var proxy; + +var handleKillProcess = function (exitCode) { + console.log('\nKilling proxy process!'); + proxy.kill('SIGTERM'); + process.exit((exitCode || 0)); +}; + +var startProxy = function () { + console.log('RUNNING:', PROXY_CMD, args.join(' ')); + + proxy = spawn(PROXY_CMD, args); + + proxy.stdout.on('data', function (data) { + console.log('stdout: ' + data); + }); + + proxy.stderr.on('data', function (data) { + console.log('stderr: ' + data); + var restartMessage = _(RESTART_ON_MESSAGES).find(function (message) { + return ('' + data).indexOf(message) >= 0; + }); + if (restartMessage) { + console.log('Detected error message:', restartMessage); + console.log('Killing proxy!'); + proxy.kill('SIGTERM'); + process.nextTick(startProxy); + } + }); + + proxy.on('close', function (code) { + console.log('child process exited with code ' + code); + }); +}; + +process.on('SIGINT', handleKillProcess); +process.on('SIGTERM', handleKillProcess); + +startProxy(); diff --git a/bin/xcode-iwd.sh b/bin/xcode-iwd.sh new file mode 100644 index 000000000..066fd6496 --- /dev/null +++ b/bin/xcode-iwd.sh @@ -0,0 +1,5 @@ +plist_path=$1/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/Developer/Library/LaunchDaemons/com.apple.instruments.deviceservice.plist +iwd_path=$2/node_modules/appium-instruments/thirdparty/iwd7 +/usr/libexec/PlistBuddy -c "Add :EnvironmentVariables dict" $plist_path +/usr/libexec/PlistBuddy -c "Add :EnvironmentVariables:DYLD_INSERT_LIBRARIES string $iwd_path/DTMobileISShim.dylib" $plist_path +/usr/libexec/PlistBuddy -c "Add :EnvironmentVariables:LIB_PATH string $iwd_path/" $plist_path