Skip to content

Commit 5f2a00f

Browse files
fix: Avoid modifying WDA sources (#1101)
1 parent 1fb32e6 commit 5f2a00f

File tree

3 files changed

+7
-81
lines changed

3 files changed

+7
-81
lines changed

lib/utils.ts

Lines changed: 1 addition & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@ import path, { dirname } from 'node:path';
44
import { fileURLToPath } from 'node:url';
55
import { log } from './logger';
66
import _ from 'lodash';
7-
import { WDA_RUNNER_BUNDLE_ID, PLATFORM_NAME_TVOS } from './constants';
7+
import { PLATFORM_NAME_TVOS } from './constants';
88
import B from 'bluebird';
99
import _fs from 'node:fs';
1010
import { waitForCondition } from 'asyncbox';
1111
import { arch } from 'node:os';
1212
import type { DeviceInfo } from './types';
1313

14-
const PROJECT_FILE = 'project.pbxproj';
15-
1614
// Get current filename - works in both CommonJS and ESM
1715
const currentFilename =
1816
typeof __filename !== 'undefined'
@@ -94,47 +92,6 @@ export function isTvOS (platformName: string): boolean {
9492
return _.toLower(platformName) === _.toLower(PLATFORM_NAME_TVOS);
9593
}
9694

97-
/**
98-
* Update WebDriverAgentRunner project bundle ID with newBundleId.
99-
* This method assumes project file is in the correct state.
100-
* @param agentPath - Path to the .xcodeproj directory.
101-
* @param newBundleId the new bundle ID used to update.
102-
*/
103-
export async function updateProjectFile (agentPath: string, newBundleId: string): Promise<void> {
104-
const projectFilePath = path.resolve(agentPath, PROJECT_FILE);
105-
try {
106-
// Assuming projectFilePath is in the correct state, create .old from projectFilePath
107-
await fs.copyFile(projectFilePath, `${projectFilePath}.old`);
108-
await replaceInFile(projectFilePath, new RegExp(_.escapeRegExp(WDA_RUNNER_BUNDLE_ID), 'g'), newBundleId);
109-
log.debug(`Successfully updated '${projectFilePath}' with bundle id '${newBundleId}'`);
110-
} catch (err: any) {
111-
log.debug(`Error updating project file: ${err.message}`);
112-
log.warn(`Unable to update project file '${projectFilePath}' with ` +
113-
`bundle id '${newBundleId}'. WebDriverAgent may not start`);
114-
}
115-
}
116-
117-
/**
118-
* Reset WebDriverAgentRunner project bundle ID to correct state.
119-
* @param agentPath - Path to the .xcodeproj directory.
120-
*/
121-
export async function resetProjectFile (agentPath: string): Promise<void> {
122-
const projectFilePath = path.join(agentPath, PROJECT_FILE);
123-
try {
124-
// restore projectFilePath from .old file
125-
if (!await fs.exists(`${projectFilePath}.old`)) {
126-
return; // no need to reset
127-
}
128-
await fs.mv(`${projectFilePath}.old`, projectFilePath);
129-
log.debug(`Successfully reset '${projectFilePath}' with bundle id '${WDA_RUNNER_BUNDLE_ID}'`);
130-
} catch (err: any) {
131-
log.debug(`Error resetting project file: ${err.message}`);
132-
log.warn(`Unable to reset project file '${projectFilePath}' with ` +
133-
`bundle id '${WDA_RUNNER_BUNDLE_ID}'. WebDriverAgent has been ` +
134-
`modified and not returned to the original state.`);
135-
}
136-
}
137-
13895
export async function setRealDeviceSecurity (keychainPath: string, keychainPassword: string): Promise<void> {
13996
log.debug('Setting security for iOS device');
14097
await exec('security', ['-v', 'list-keychains', '-s', keychainPath]);
@@ -382,12 +339,4 @@ async function getPIDsUsingPattern (pattern: string): Promise<string[]> {
382339
}
383340
}
384341

385-
async function replaceInFile (file: string, find: string | RegExp, replace: string): Promise<void> {
386-
const contents = await fs.readFile(file, 'utf8');
387-
388-
const newContents = contents.replace(find, replace);
389-
if (newContents !== contents) {
390-
await fs.writeFile(file, newContents, 'utf8');
391-
}
392-
}
393342

lib/webdriveragent.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,6 @@ export class WebDriverAgent {
355355
this.log.info('Shutting down sub-processes');
356356
if (this._xcodebuild) {
357357
await this.xcodebuild.quit();
358-
await this.xcodebuild.reset();
359358
}
360359
} else {
361360
this.log.debug('Do not stop xcodebuild nor XCTest session ' +

lib/xcodebuild.ts

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ import { log as defaultLogger } from './logger';
66
import B from 'bluebird';
77
import {
88
setRealDeviceSecurity, setXctestrunFile,
9-
updateProjectFile, resetProjectFile, killProcess,
10-
getWDAUpgradeTimestamp, isTvOS
9+
killProcess, getWDAUpgradeTimestamp, isTvOS
1110
} from './utils';
1211
import _ from 'lodash';
1312
import path from 'path';
@@ -135,7 +134,7 @@ export class XcodeBuild {
135134

136135
/**
137136
* Initializes the XcodeBuild instance with a no-session proxy.
138-
* Sets up xctestrun file if needed, or updates project bundle ID for real devices.
137+
* Sets up xctestrun file if needed.
139138
* @param noSessionProxy - The proxy instance for WDA communication
140139
*/
141140
async init (noSessionProxy: NoSessionProxy): Promise<void> {
@@ -157,19 +156,6 @@ export class XcodeBuild {
157156
});
158157
return;
159158
}
160-
161-
// if necessary, update the bundleId to user's specification
162-
if (this.realDevice) {
163-
// In case the project still has the user specific bundle ID, reset the project file first.
164-
// - We do this reset even if updatedWDABundleId is not specified,
165-
// since the previous updatedWDABundleId test has generated the user specific bundle ID project file.
166-
// - We don't call resetProjectFile for simulator,
167-
// since simulator test run will work with any user specific bundle ID.
168-
await resetProjectFile(this.agentPath);
169-
if (this.updatedWDABundleId) {
170-
await updateProjectFile(this.agentPath, this.updatedWDABundleId);
171-
}
172-
}
173159
}
174160

175161
/**
@@ -211,17 +197,6 @@ export class XcodeBuild {
211197
return await this._derivedDataPathPromise;
212198
}
213199

214-
/**
215-
* Resets the project file to its original state.
216-
* Restores the bundle ID to the original value for real devices if it was modified.
217-
*/
218-
async reset (): Promise<void> {
219-
// if necessary, reset the bundleId to original value
220-
if (this.realDevice && this.updatedWDABundleId) {
221-
await resetProjectFile(this.agentPath);
222-
}
223-
}
224-
225200
/**
226201
* Pre-builds WebDriverAgent before launching tests.
227202
* Performs a build-only operation and sets usePrebuiltWDA flag.
@@ -360,7 +335,7 @@ export class XcodeBuild {
360335
}
361336
args.push('-destination', `id=${this.device.udid}`);
362337

363-
let versionMatch;
338+
let versionMatch: RegExpMatchArray | null = null;
364339
if (this.platformVersion && (versionMatch = new RegExp(/^(\d+)\.(\d+)/).exec(this.platformVersion))) {
365340
args.push(
366341
`${isTvOS(this.platformName || '') ? 'TV' : 'IPHONE'}OS_DEPLOYMENT_TARGET=${versionMatch[1]}.${versionMatch[2]}`
@@ -383,6 +358,9 @@ export class XcodeBuild {
383358
`CODE_SIGN_IDENTITY=${this.xcodeSigningId}`,
384359
);
385360
}
361+
if (this.updatedWDABundleId) {
362+
args.push(`PRODUCT_BUNDLE_IDENTIFIER=${this.updatedWDABundleId}`);
363+
}
386364
}
387365

388366
if (!process.env.APPIUM_XCUITEST_TREAT_WARNINGS_AS_ERRORS) {

0 commit comments

Comments
 (0)