From 5276db492a90db30d436bf9fca233ac7336f6da0 Mon Sep 17 00:00:00 2001 From: Mark Oswald Date: Wed, 22 Jun 2016 03:30:30 -0700 Subject: [PATCH] fix runIOS: appPath is hardcoded, read from log Summary: The runIOS command currently assumes the path to the `xcodebuild` product - it's hardcoded ``` const appPath = `build/Build/Products/Debug-iphonesimulator/${inferredSchemeName}.app`; ``` https://github.com/facebook/react-native/blob/master/local-cli/runIOS/runIOS.js#L87 This can be a problem, when you e.g. install a release version of the app to the simulator using the cli. We use a separate schema for that, which can be selected with `--scheme`. This fix reads the output of the `xcodebuild` call and searches for the path and the name of the *.app file. If it's found, then it will be used to spawn in the simulator. If not, the default (as before) is used. Closes https://github.com/facebook/react-native/pull/8250 Differential Revision: D3469074 Pulled By: javache fbshipit-source-id: b10c7e6f48268b0c71dfcbfa661f8e5960c3aaa6 --- local-cli/runIOS/runIOS.js | 49 +++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/local-cli/runIOS/runIOS.js b/local-cli/runIOS/runIOS.js index 8a92743b6..adfbf03bc 100644 --- a/local-cli/runIOS/runIOS.js +++ b/local-cli/runIOS/runIOS.js @@ -22,7 +22,6 @@ const Promise = require('promise'); function runIOS(argv, config) { return new Promise((resolve, reject) => { _runIOS(argv, config, resolve, reject); - resolve(); }); } @@ -51,7 +50,7 @@ function _runIOS(argv, config, resolve, reject) { process.chdir(args['project-path']); const xcodeProject = findXcodeProject(fs.readdirSync('.')); if (!xcodeProject) { - throw new Error(`Could not find Xcode project files in ios folder`); + reject(new Error(`Could not find Xcode project files in ios folder`)); } const inferredSchemeName = path.basename(xcodeProject.name, path.extname(xcodeProject.name)); @@ -63,7 +62,7 @@ function _runIOS(argv, config, resolve, reject) { ); const selectedSimulator = matchingSimulator(simulators, args.simulator); if (!selectedSimulator) { - throw new Error(`Cound't find ${args.simulator} simulator`); + reject(new Error(`Cound't find ${args.simulator} simulator`)); } const simulatorFullName = `${selectedSimulator.name} (${selectedSimulator.version})`; @@ -82,20 +81,42 @@ function _runIOS(argv, config, resolve, reject) { '-derivedDataPath', 'build', ]; console.log(`Building using "xcodebuild ${xcodebuildArgs.join(' ')}"`); - child_process.spawnSync('xcodebuild', xcodebuildArgs, {stdio: 'inherit'}); - const appPath = `build/Build/Products/Debug-iphonesimulator/${inferredSchemeName}.app`; - console.log(`Installing ${appPath}`); - child_process.spawnSync('xcrun', ['simctl', 'install', 'booted', appPath], {stdio: 'inherit'}); + let appPath = `build/Build/Products/Debug-iphonesimulator/${inferredSchemeName}.app`; + const xcodeBuildProcess = child_process.spawn('xcodebuild', xcodebuildArgs, { + stdio: [process.stdin, 'pipe', process.stderr] + }); - const bundleID = child_process.execFileSync( - '/usr/libexec/PlistBuddy', - ['-c', 'Print:CFBundleIdentifier', path.join(appPath, 'Info.plist')], - {encoding: 'utf8'} - ).trim(); + xcodeBuildProcess.stdout.on('data', (data) => { + process.stdout.write(data); - console.log(`Launching ${bundleID}`); - child_process.spawnSync('xcrun', ['simctl', 'launch', 'booted', bundleID], {stdio: 'inherit'}); + // search this part of the process output for a path to the generated app and replace default + const appPathFromLog = data.toString().match(/Touch (build\/Build\/Products\/.*\/.*\.app)/); + if (appPathFromLog) { + appPath = appPathFromLog[1]; + } + }); + + xcodeBuildProcess.on('close', (code) => { + if (code !== 0) { + reject(new Error(`xcodebuild process exited with code ${code}`)); + return; + } + + console.log(`Installing ${appPath}`); + child_process.spawnSync('xcrun', ['simctl', 'install', 'booted', appPath], {stdio: 'inherit'}); + + const bundleID = child_process.execFileSync( + '/usr/libexec/PlistBuddy', + ['-c', 'Print:CFBundleIdentifier', path.join(appPath, 'Info.plist')], + {encoding: 'utf8'} + ).trim(); + + console.log(`Launching ${bundleID}`); + child_process.spawnSync('xcrun', ['simctl', 'launch', 'booted', bundleID], {stdio: 'inherit'}); + + resolve(); + }); } function matchingSimulator(simulators, simulatorName) {