Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/ten-bugs-warn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@rock-js/platform-apple-helpers': patch
'@rock-js/plugin-brownfield-ios': patch
'@rock-js/platform-android': patch
---

feat: filter xcodebuild errors for readability
2 changes: 1 addition & 1 deletion .github/workflows/pr-labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ jobs:
configuration-path: .github/pr-labeler.yml
enable-versioned-regex: 0
include-title: 1
sync-labels: 1
sync-labels: 1
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const args: Flags = {
};

const androidProject: AndroidProjectConfig = {
sourceDir: '/Users/thymikee/Developer/tmp/App73/android',
sourceDir: '/Users/developer/tmp/App73/android',
appName: 'app',
packageName: 'com.myapp',
applicationId: 'com.myapp.custom',
Expand Down
103 changes: 10 additions & 93 deletions packages/platform-apple-helpers/src/lib/commands/build/buildProject.ts
Original file line number Diff line number Diff line change
@@ -1,69 +1,12 @@
import path from 'node:path';
import type { SubprocessError } from '@rock-js/tools';
import { color, logger, RockError, spawn, spinner } from '@rock-js/tools';
import { color, logger, RockError } from '@rock-js/tools';
import type { ApplePlatform, XcodeProjectInfo } from '../../types/index.js';
import { getBuildPaths } from '../../utils/getBuildPaths.js';
import { runXcodebuild } from '../../utils/runXcodebuild.js';
import { supportedPlatforms } from '../../utils/supportedPlatforms.js';
import type { RunFlags } from '../run/runOptions.js';
import type { BuildFlags } from './buildOptions.js';

let lastProgress = 0;
/**
* Creates an ASCII progress bar
* @param percent - Percentage of completion (0-100)
* @param length - Length of the progress bar in characters
* @returns ASCII progress bar string
*/
function createProgressBar(percent: number, length = 20): string {
const latestPercent = percent > lastProgress ? percent : lastProgress;
lastProgress = latestPercent;
const filledLength = Math.round(length * (latestPercent / 100));
const emptyLength = length - filledLength;

const filled = '█'.repeat(filledLength);
const empty = '░'.repeat(emptyLength);

return `[${filled}${empty}]`;
}

function reportProgress(
chunk: string,
loader: ReturnType<typeof spinner>,
message: string,
) {
if (chunk.includes('PhaseScriptExecution')) {
if (chunk.includes('[CP-User]\\ [Hermes]\\ Replace\\ Hermes\\')) {
const progressBar = createProgressBar(10);
loader.message(`${message} ${progressBar}`);
}
if (
chunk.includes('[CP-User]\\ [RN]Check\\ rncore') &&
chunk.includes('React-Fabric')
) {
const progressBar = createProgressBar(35);
loader.message(`${message} ${progressBar}`);
}
if (chunk.includes('[CP-User]\\ [RN]Check\\ FBReactNativeSpec')) {
const progressBar = createProgressBar(53);
loader.message(`${message} ${progressBar}`);
}
if (
chunk.includes('[CP-User]\\ [RN]Check\\ rncore') &&
chunk.includes('React-FabricComponents')
) {
const progressBar = createProgressBar(66);
loader.message(`${message} ${progressBar}`);
}
if (chunk.includes('[CP]\\ Check\\ Pods\\ Manifest.lock')) {
const progressBar = createProgressBar(90);
loader.message(`${message} ${progressBar}`);
}
} else if (chunk.includes('BUILD SUCCEEDED')) {
const progressBar = createProgressBar(100);
loader.message(`${message} ${progressBar}`);
}
}

export const buildProject = async ({
xcodeProject,
sourceDir,
Expand All @@ -80,7 +23,7 @@ export const buildProject = async ({
configuration: string;
destinations: string[];
args: RunFlags | BuildFlags;
}) => {
}): Promise<void> => {
if (!supportedPlatforms[platformName]) {
throw new RockError(
`Unknown platform: ${platformName}. Please, use one of: ${Object.values(
Expand Down Expand Up @@ -122,45 +65,19 @@ export const buildProject = async ({
Scheme ${color.bold(scheme)}
Configuration ${color.bold(configuration)}`);

const loader = spinner({ indicator: 'timer' });
const { errorSummary } = await runXcodebuild(xcodebuildArgs, {
cwd: sourceDir,
});

const message = `${args.archive ? 'Archiving' : 'Building'} the app`;

let commandOutput = '';

loader.start(message);
try {
const process = spawn('xcodebuild', xcodebuildArgs, {
cwd: sourceDir,
});

if (!logger.isVerbose()) {
// Process the output from the AsyncIterable
for await (const chunk of process) {
commandOutput += chunk + '\n';
reportProgress(chunk, loader, message);
}
}

await process;
loader.stop(`${args.archive ? 'Archived' : 'Built'} the app.`);
} catch (error) {
loader.stop(`Failed: ${message}.`, 1);
if (errorSummary) {
if (!xcodeProject.isWorkspace) {
logger.error(
`If your project uses CocoaPods, make sure to install pods with "pod install" in ${sourceDir} directory.`,
);
}
if (commandOutput) {
// Use lightweight console.error instead of logger.error to avoid stack overflow issues when Xcode logs go crazy
console.error(color.red(`xcodebuild output: ${commandOutput}`));
throw new RockError(
'Running xcodebuild failed. See error details above.',
);
}
throw new RockError('Running xcodebuild failed', {
cause:
(error as SubprocessError).stderr || (error as SubprocessError).command,

throw new RockError('Failed to build the project', {
cause: errorSummary,
});
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,9 @@ import {
logger,
promptSelect,
relativeToCwd,
RockError,
saveLocalBuildCache,
} from '@rock-js/tools';
import type {
BuilderCommand,
ProjectConfig,
XcodeProjectInfo,
} from '../../types/index.js';
import type { BuilderCommand, ProjectConfig } from '../../types/index.js';
import { buildApp } from '../../utils/buildApp.js';
import { getBuildPaths } from '../../utils/getBuildPaths.js';
import type { BuildFlags } from './buildOptions.js';
Expand All @@ -43,9 +38,6 @@ export const createBuild = async ({
}) => {
await validateArgs(args);

let xcodeProject: XcodeProjectInfo;
let sourceDir: string;
let scheme = args.scheme;
const deviceOrSimulator = args.destination
? // there can be multiple destinations, so we'll pick the first one
args.destination[0].match(/simulator/i)
Expand Down Expand Up @@ -81,30 +73,21 @@ export const createBuild = async ({
}
}

return { scheme };
return { scheme: args.scheme };
}

try {
const { appPath, ...buildAppResult } = await buildApp({
projectRoot,
projectConfig,
platformName,
args,
reactNativePath,
artifactName,
deviceOrSimulator,
fingerprintOptions,
usePrebuiltRNCore,
});
logger.log(`Build available at: ${colorLink(relativeToCwd(appPath))}`);

xcodeProject = buildAppResult.xcodeProject;
sourceDir = buildAppResult.sourceDir;
scheme = buildAppResult.scheme;
} catch (error) {
const message = `Failed to create ${args.archive ? 'archive' : 'build'}`;
throw new RockError(message, { cause: error });
}
const { appPath, xcodeProject, sourceDir, scheme } = await buildApp({
projectRoot,
projectConfig,
platformName,
args,
reactNativePath,
artifactName,
deviceOrSimulator,
fingerprintOptions,
usePrebuiltRNCore,
});
logger.log(`Build available at: ${colorLink(relativeToCwd(appPath))}`);

if (args.archive) {
const { archiveDir } = getBuildPaths(platformName);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
import type { SubprocessError } from '@rock-js/tools';
import {
colorLink,
relativeToCwd,
RockError,
spawn,
spinner,
} from '@rock-js/tools';
import { colorLink, logger, relativeToCwd, RockError } from '@rock-js/tools';
import { existsSync, readdirSync } from 'fs';
import path from 'path';
import { getBuildPaths } from '../../utils/getBuildPaths.js';
import { runXcodebuild } from '../../utils/runXcodebuild.js';

export const exportArchive = async ({
sourceDir,
Expand All @@ -23,16 +17,12 @@ export const exportArchive = async ({
exportExtraParams: string[];
exportOptionsPlist?: string;
}): Promise<{ ipaPath: string }> => {
const loader = spinner();

loader.start('Exporting the archive...');
const exportOptionsPlistPath = path.join(
sourceDir,
exportOptionsPlist ?? 'ExportOptions.plist',
);

if (!existsSync(exportOptionsPlistPath)) {
loader.stop('Failed to export the archive.', 1);
throw new RockError(
`ExportOptions.plist not found, please create ${colorLink(
relativeToCwd(exportOptionsPlistPath),
Expand All @@ -52,29 +42,28 @@ export const exportArchive = async ({
...exportExtraParams,
];

let ipaFiles: string[] = [];

const { errorSummary } = await runXcodebuild(xcodebuildArgs, {
cwd: sourceDir,
});
try {
let ipaFiles: string[] = [];
ipaFiles = readdirSync(exportDir).filter((file) => file.endsWith('.ipa'));
} catch {
ipaFiles = [];
}

await spawn('xcodebuild', xcodebuildArgs, {
cwd: sourceDir,
stdio: 'pipe',
if (errorSummary) {
throw new Error('Running xcodebuild failed', {
cause: errorSummary,
});
try {
ipaFiles = readdirSync(exportDir).filter((file) => file.endsWith('.ipa'));
} catch {
ipaFiles = [];
}

loader.stop(
} else {
logger.success(
`Archive available at: ${colorLink(
path.join(exportDir, ipaFiles[0]) ?? exportDir,
)}`,
);
return { ipaPath: path.join(exportDir, ipaFiles[0]) };
} catch (error) {
loader.stop('Running xcodebuild failed.', 1);
throw new Error('Running xcodebuild failed', {
cause: (error as SubprocessError).stderr,
});
}

return { ipaPath: path.join(exportDir, ipaFiles[0]) };
};
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,6 @@ ${devices
await Promise.all([
launchSimulator(bootedDevice),
buildApp({
brownfield: false,
args,
projectConfig,
platformName,
Expand Down
Loading
Loading