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
This commit is contained in:
parent
3e4f16a2a6
commit
5276db492a
|
@ -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,9 +81,28 @@ 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`;
|
||||
let appPath = `build/Build/Products/Debug-iphonesimulator/${inferredSchemeName}.app`;
|
||||
const xcodeBuildProcess = child_process.spawn('xcodebuild', xcodebuildArgs, {
|
||||
stdio: [process.stdin, 'pipe', process.stderr]
|
||||
});
|
||||
|
||||
xcodeBuildProcess.stdout.on('data', (data) => {
|
||||
process.stdout.write(data);
|
||||
|
||||
// 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'});
|
||||
|
||||
|
@ -96,6 +114,9 @@ function _runIOS(argv, config, resolve, reject) {
|
|||
|
||||
console.log(`Launching ${bundleID}`);
|
||||
child_process.spawnSync('xcrun', ['simctl', 'launch', 'booted', bundleID], {stdio: 'inherit'});
|
||||
|
||||
resolve();
|
||||
});
|
||||
}
|
||||
|
||||
function matchingSimulator(simulators, simulatorName) {
|
||||
|
|
Loading…
Reference in New Issue