Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(ios): parse xcodebuild errors #2362

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,21 @@ import {simulatorDestinationMap} from './simulatorDestinationMap';
import {supportedPlatforms} from '../../config/supportedPlatforms';
import {ApplePlatform} from '../../types';

function prettifyXcodebuildMessages(output: string): Set<string> {
const errorRegex = /error\b[^\S\r\n]*[:\-\s]*([^\r\n]*)/gim;
const errors = new Set<string>();

let match;
while ((match = errorRegex.exec(output)) !== null) {
if (match[1]) {
// match[1] contains the captured group that excludes any leading colons or spaces
errors.add(match[1].trim());
}
}

return errors;
}

export function buildProject(
xcodeProject: IOSProjectInfo,
platform: ApplePlatform,
Expand Down Expand Up @@ -84,7 +99,6 @@ export function buildProject(
getProcessOptions(args),
);
let buildOutput = '';
let errorOutput = '';
buildProcess.stdout.on('data', (data: Buffer) => {
const stringData = data.toString();
buildOutput += stringData;
Expand All @@ -100,10 +114,6 @@ export function buildProject(
}
}
});

buildProcess.stderr.on('data', (data: Buffer) => {
errorOutput += data;
});
buildProcess.on('close', (code: number) => {
if (xcodebuildOutputFormatter) {
xcodebuildOutputFormatter.stdin.end();
Expand All @@ -112,22 +122,23 @@ export function buildProject(
}
if (code !== 0) {
printRunDoctorTip();
if (!xcodebuildOutputFormatter) {
Array.from(prettifyXcodebuildMessages(buildOutput)).forEach((error) =>
logger.error(error),
);
}

reject(
new CLIError(
`
Failed to build ${platform} project.

"xcodebuild" exited with error code '${code}'. To debug build
logs further, consider building your app with Xcode.app, by opening
'${xcodeProject.name}'.
`,
xcodebuildOutputFormatter
? undefined
: buildOutput + '\n' + errorOutput,
),
new CLIError(`
Failed to build ${platform} project.

"xcodebuild" exited with error code '${code}'. To debug build
logs further, consider building your app with Xcode.app, by opening
'${xcodeProject.name}'.`),
);
return;
}

logger.success('Successfully built the app');
resolve(buildOutput);
});
Expand Down