From 9ab37d15fdb2b3a8efbf29da42de8872c2feb0ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stanis=C5=82aw=20Chmiela?= Date: Wed, 28 Jan 2026 21:59:54 +0100 Subject: [PATCH] Add support for cuttlefish config --- .../steps/functions/startCuttlefishDevice.ts | 55 +++++++++++++++++-- 1 file changed, 51 insertions(+), 4 deletions(-) diff --git a/packages/build-tools/src/steps/functions/startCuttlefishDevice.ts b/packages/build-tools/src/steps/functions/startCuttlefishDevice.ts index 95d62c08..db454c13 100644 --- a/packages/build-tools/src/steps/functions/startCuttlefishDevice.ts +++ b/packages/build-tools/src/steps/functions/startCuttlefishDevice.ts @@ -1,9 +1,42 @@ +import fs from 'node:fs'; +import os from 'node:os'; +import path from 'node:path'; + import { BuildFunction, BuildStepInput, BuildStepInputValueTypeName } from '@expo/steps'; import spawn from '@expo/turtle-spawn'; import { asyncResult } from '@expo/results'; import { sleepAsync } from '../../utils/retry'; +// Needs to conform to https://github.com/google/android-cuttlefish/blob/928026d2833b3e326d9d3b4a9a477e522b37b825/base/cvd/cuttlefish/host/commands/cvd/cli/parser/load_config.proto#L29-L36. +// See example: https://github.com/google/android-cuttlefish/blob/928026d2833b3e326d9d3b4a9a477e522b37b825/base/cvd/cuttlefish/host/cvd_test_configs/main_phone.json +const CVD_CONFIG_JSON = { + common: { + host_package: '@ab/aosp-android-latest-release/aosp_cf_x86_64_only_phone-userdebug', + }, + instances: [ + { + '@import': 'phone', + graphics: { + displays: [ + // Pixel 5 + { + dpi: 432, + height: 2340, + width: 1080, + }, + ], + }, + vm: { + memory_mb: 4096, + }, + disk: { + default_build: '@ab/aosp-main/aosp_cf_x86_64_phone-trunk_staging-userdebug', + }, + }, + ], +}; + export function createStartCuttlefishDeviceBuildFunction(): BuildFunction { return new BuildFunction({ namespace: 'eas', @@ -79,10 +112,24 @@ export function createStartCuttlefishDeviceBuildFunction(): BuildFunction { } logger.info('Creating CVD'); - await spawn('cvdr', ['create', ...(count > 1 ? ['--num_instances', String(count)] : [])], { - env, - logger, - }); + + const args = []; + + const cvdConfigJson = env.CVD_CONFIG_JSON ?? JSON.stringify(CVD_CONFIG_JSON); + if (cvdConfigJson) { + const configJsonDirectory = await fs.promises.mkdtemp( + path.join(os.tmpdir(), 'start_cuttlefish-') + ); + const configJsonPath = path.join(configJsonDirectory, 'config.json'); + await fs.promises.writeFile(configJsonPath, cvdConfigJson); + args.push(configJsonPath); + } + + if (count > 1) { + args.push('--num_instances', String(count)); + } + + await spawn('cvdr', ['create', ...args], { env, logger }); logger.info('Listing adb devices...'); await spawn('adb', ['devices'], { env, logger });