Skip to content
This repository was archived by the owner on Feb 24, 2026. It is now read-only.
Merged
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
55 changes: 51 additions & 4 deletions packages/build-tools/src/steps/functions/startCuttlefishDevice.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand Down Expand Up @@ -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 });
Expand Down