diff --git a/packages/build-tools/src/steps/functions/startAgentDeviceRemoteSession.ts b/packages/build-tools/src/steps/functions/startAgentDeviceRemoteSession.ts index 2a7ce0fca1..2ac35c6c00 100644 --- a/packages/build-tools/src/steps/functions/startAgentDeviceRemoteSession.ts +++ b/packages/build-tools/src/steps/functions/startAgentDeviceRemoteSession.ts @@ -19,6 +19,7 @@ import { getDeviceRunSessionIdOrThrow, getNgrokAuthtokenOrThrow, getNgrokTunnelDomainOrThrow, + selectXcodeDeveloperDirectoryAsync, spawnDetached, startNgrokTunnelAsync, startServeSimWithTunnelAsync, @@ -30,7 +31,6 @@ const AGENT_DEVICE_PACKAGE_NAME = 'agent-device'; const AGENT_DEVICE_REPO_URL = 'https://github.com/callstackincubator/agent-device.git'; const SRC_DIR = '/tmp/agent-device-src'; const DAEMON_JSON_PATH = path.join(os.homedir(), '.agent-device', 'daemon.json'); -const XCODE_DEVELOPER_DIR = '/Applications/Xcode.app/Contents/Developer'; const STARTUP_TIMEOUT_MS = 60_000; export function createStartAgentDeviceRemoteSessionBuildFunction( @@ -64,8 +64,7 @@ export function createStartAgentDeviceRemoteSessionBuildFunction( ); if (runtimePlatform === BuildRuntimePlatform.DARWIN) { - logger.info(`Selecting Xcode developer directory: ${XCODE_DEVELOPER_DIR}.`); - await spawn('sudo', ['xcode-select', '-s', XCODE_DEVELOPER_DIR], { env, logger }); + await selectXcodeDeveloperDirectoryAsync({ env, logger }); } logger.info('Launching agent-device daemon.'); diff --git a/packages/build-tools/src/steps/functions/startArgentRemoteSession.ts b/packages/build-tools/src/steps/functions/startArgentRemoteSession.ts index aaac3a6dca..b27c41766d 100644 --- a/packages/build-tools/src/steps/functions/startArgentRemoteSession.ts +++ b/packages/build-tools/src/steps/functions/startArgentRemoteSession.ts @@ -19,6 +19,7 @@ import { getDeviceRunSessionIdOrThrow, getNgrokAuthtokenOrThrow, getNgrokTunnelDomainOrThrow, + selectXcodeDeveloperDirectoryAsync, spawnDetached, startNgrokTunnelAsync, startServeSimWithTunnelAsync, @@ -30,7 +31,6 @@ const ARGENT_PACKAGE_NAME = '@swmansion/argent'; export const MIN_ARGENT_REMOTE_SESSION_VERSION = '0.12.0'; const ARGENT_ARTIFACTS_LIST_ENDPOINT_FLAG = 'artifacts-list-endpoint'; const ARGENT_STATE_FILE = path.join(os.homedir(), '.argent', 'tool-server.json'); -const XCODE_DEVELOPER_DIR = '/Applications/Xcode.app/Contents/Developer'; const STARTUP_TIMEOUT_MS = 60_000; const ArgentToolServerStateSchema = z.object({ @@ -71,8 +71,7 @@ export function createStartArgentRemoteSessionBuildFunction( ); if (runtimePlatform === BuildRuntimePlatform.DARWIN) { - logger.info(`Selecting Xcode developer directory: ${XCODE_DEVELOPER_DIR}.`); - await spawn('sudo', ['xcode-select', '-s', XCODE_DEVELOPER_DIR], { env, logger }); + await selectXcodeDeveloperDirectoryAsync({ env, logger }); } // Stale state from a previous run would mask the new server's port. diff --git a/packages/build-tools/src/steps/functions/startServeSimRemoteSession.ts b/packages/build-tools/src/steps/functions/startServeSimRemoteSession.ts index dc619514f5..8daccbced5 100644 --- a/packages/build-tools/src/steps/functions/startServeSimRemoteSession.ts +++ b/packages/build-tools/src/steps/functions/startServeSimRemoteSession.ts @@ -1,15 +1,14 @@ import { BuildFunction, BuildRuntimePlatform } from '@expo/steps'; -import spawn from '@expo/turtle-spawn'; import { CustomBuildContext } from '../../customBuildContext'; import { getDeviceRunSessionIdOrThrow, getNgrokTunnelDomainOrThrow, + selectXcodeDeveloperDirectoryAsync, startServeSimWithTunnelAsync, uploadRemoteSessionConfigAsync, } from '../utils/remoteDeviceRunSession'; -const XCODE_DEVELOPER_DIR = '/Applications/Xcode.app/Contents/Developer'; const STARTUP_TIMEOUT_MS = 60_000; export function createStartServeSimRemoteSessionBuildFunction( @@ -27,8 +26,7 @@ export function createStartServeSimRemoteSessionBuildFunction( logger.info('Starting serve-sim remote session.'); - logger.info(`Selecting Xcode developer directory: ${XCODE_DEVELOPER_DIR}.`); - await spawn('sudo', ['xcode-select', '-s', XCODE_DEVELOPER_DIR], { env, logger }); + await selectXcodeDeveloperDirectoryAsync({ env, logger }); const { previewUrl, streamUrl } = await startServeSimWithTunnelAsync(ctx, { baseDomain: ngrokTunnelDomain, diff --git a/packages/build-tools/src/steps/utils/remoteDeviceRunSession.ts b/packages/build-tools/src/steps/utils/remoteDeviceRunSession.ts index 672f065e7c..5e084a1aa6 100644 --- a/packages/build-tools/src/steps/utils/remoteDeviceRunSession.ts +++ b/packages/build-tools/src/steps/utils/remoteDeviceRunSession.ts @@ -1,6 +1,6 @@ import { SystemError } from '@expo/eas-build-job'; import { bunyan } from '@expo/logger'; -import { BuildStepEnv } from '@expo/steps'; +import { BuildStepEnv, spawnAsync } from '@expo/steps'; import spawn from '@expo/turtle-spawn'; import * as ngrok from '@ngrok/ngrok'; import { graphql } from 'gql.tada'; @@ -14,6 +14,8 @@ import { Sentry } from '../../sentry'; import { sleepAsync } from '../../utils/retry'; import { turtleFetch } from '../../utils/turtleFetch'; +const XCODE_DEVELOPER_DIR = '/Applications/Xcode.app/Contents/Developer'; + const START_DEVICE_RUN_SESSION_MUTATION = graphql(` mutation StartDeviceRunSession($deviceRunSessionId: ID!, $remoteConfig: JSONObject!) { deviceRunSession { @@ -74,6 +76,26 @@ const TurnIceServersSchema = z.array( export type TurnIceServers = z.infer; +export async function selectXcodeDeveloperDirectoryAsync({ + env, + logger, +}: { + env: BuildStepEnv; + logger: bunyan; +}): Promise { + if (process.env.ENVIRONMENT === 'development') { + logger.info('Job running outside of EAS, not selecting Xcode developer directory.'); + return; + } + + logger.info(`Selecting Xcode developer directory: ${XCODE_DEVELOPER_DIR}.`); + await spawnAsync('sudo', ['xcode-select', '-s', XCODE_DEVELOPER_DIR], { + env, + logger, + stdio: ['ignore', 'pipe', 'pipe'], + }); +} + const TurnIceServersResponseSchema = z.object({ data: z.object({ iceServers: TurnIceServersSchema,