Skip to content

Commit 58d23cd

Browse files
refactor(ios): parse xcodebuild errors (#2362)
* prettify xcodebuild messages * prettify output * display parsed errors separately
1 parent a60ee28 commit 58d23cd

File tree

1 file changed

+28
-17
lines changed

1 file changed

+28
-17
lines changed

packages/cli-platform-apple/src/commands/buildCommand/buildProject.ts

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,21 @@ import {simulatorDestinationMap} from './simulatorDestinationMap';
1515
import {supportedPlatforms} from '../../config/supportedPlatforms';
1616
import {ApplePlatform} from '../../types';
1717

18+
function prettifyXcodebuildMessages(output: string): Set<string> {
19+
const errorRegex = /error\b[^\S\r\n]*[:\-\s]*([^\r\n]*)/gim;
20+
const errors = new Set<string>();
21+
22+
let match;
23+
while ((match = errorRegex.exec(output)) !== null) {
24+
if (match[1]) {
25+
// match[1] contains the captured group that excludes any leading colons or spaces
26+
errors.add(match[1].trim());
27+
}
28+
}
29+
30+
return errors;
31+
}
32+
1833
export function buildProject(
1934
xcodeProject: IOSProjectInfo,
2035
platform: ApplePlatform,
@@ -84,7 +99,6 @@ export function buildProject(
8499
getProcessOptions(args),
85100
);
86101
let buildOutput = '';
87-
let errorOutput = '';
88102
buildProcess.stdout.on('data', (data: Buffer) => {
89103
const stringData = data.toString();
90104
buildOutput += stringData;
@@ -100,10 +114,6 @@ export function buildProject(
100114
}
101115
}
102116
});
103-
104-
buildProcess.stderr.on('data', (data: Buffer) => {
105-
errorOutput += data;
106-
});
107117
buildProcess.on('close', (code: number) => {
108118
if (xcodebuildOutputFormatter) {
109119
xcodebuildOutputFormatter.stdin.end();
@@ -112,22 +122,23 @@ export function buildProject(
112122
}
113123
if (code !== 0) {
114124
printRunDoctorTip();
125+
if (!xcodebuildOutputFormatter) {
126+
Array.from(prettifyXcodebuildMessages(buildOutput)).forEach((error) =>
127+
logger.error(error),
128+
);
129+
}
130+
115131
reject(
116-
new CLIError(
117-
`
118-
Failed to build ${platform} project.
119-
120-
"xcodebuild" exited with error code '${code}'. To debug build
121-
logs further, consider building your app with Xcode.app, by opening
122-
'${xcodeProject.name}'.
123-
`,
124-
xcodebuildOutputFormatter
125-
? undefined
126-
: buildOutput + '\n' + errorOutput,
127-
),
132+
new CLIError(`
133+
Failed to build ${platform} project.
134+
135+
"xcodebuild" exited with error code '${code}'. To debug build
136+
logs further, consider building your app with Xcode.app, by opening
137+
'${xcodeProject.name}'.`),
128138
);
129139
return;
130140
}
141+
131142
logger.success('Successfully built the app');
132143
resolve(buildOutput);
133144
});

0 commit comments

Comments
 (0)