diff --git a/.changeset/long-dolls-juggle.md b/.changeset/long-dolls-juggle.md new file mode 100644 index 000000000..ada836653 --- /dev/null +++ b/.changeset/long-dolls-juggle.md @@ -0,0 +1,6 @@ +--- +'rock': patch +'create-rock': patch +--- + +feat: add ccache support in clean command diff --git a/packages/cli/src/lib/plugins/clean.ts b/packages/cli/src/lib/plugins/clean.ts index 2d28228cc..bbfcc62b6 100644 --- a/packages/cli/src/lib/plugins/clean.ts +++ b/packages/cli/src/lib/plugins/clean.ts @@ -31,6 +31,7 @@ const CLEANUP_TASK_NAMES = [ 'android', 'gradle', 'cocoapods', + 'ccache', 'metro', 'watchman', 'node_modules', @@ -97,6 +98,20 @@ function hasMetroProject(projectRoot: string): boolean { return false; } +/** + * Checks if ccache is installed on the system. + * @returns Promise that resolves to true if ccache is available, false otherwise + */ +async function isCCacheInstalled(): Promise { + try { + await spawn('which', ['ccache']); + return true; + } catch (error) { + logger.debug(`Failed to find ccache binary: ${error}`); + return false; + } +} + /** * Cleans temporary directories that match a given pattern. * @param pattern - The pattern to match temporary directory names @@ -135,10 +150,10 @@ function cleanDirectories(directories: string[], baseDir: string): void { * @param options - Clean options that affect task creation * @returns Array of cleanup tasks with their configurations */ -function createCleanupTasks( +async function createCleanupTasks( projectRoot: string, options: CleanOptions, -): CleanupTask[] { +): Promise { const tasks: CleanupTask[] = []; // Android cleanup @@ -207,6 +222,17 @@ function createCleanupTasks( }, }); + const hasCCache = await isCCacheInstalled(); + // CCache cleanup (only if ccache is installed) + tasks.push({ + name: 'ccache', + description: '[C/C++] CCache compiler cache', + enabled: hasCCache, + action: async () => { + await spawn('ccache', ['--clear']); + }, + }); + // Watchman cleanup (only for Metro projects) const hasMetro = hasMetroProject(projectRoot); tasks.push({ @@ -302,7 +328,7 @@ function createCleanupTasks( * @param options - Clean options that determine which tasks to run */ async function cleanProject(projectRoot: string, options: CleanOptions) { - const tasks = createCleanupTasks(projectRoot, options); + const tasks = await createCleanupTasks(projectRoot, options); let selectedTasks: CleanupTask[]; const availableTasks = tasks.filter((task) => task.enabled);