mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-03-29 22:41:56 +08:00
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:
committed by
Facebook Github Bot 4
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,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) {
|
||||
|
||||
Reference in New Issue
Block a user