Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

chore: Simplify xcodebuild lines monitoring #916

Merged
merged 3 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
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
31 changes: 18 additions & 13 deletions lib/xcodebuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
} from './utils';
import _ from 'lodash';
import path from 'path';
import { EOL } from 'os';
import { WDA_RUNNER_BUNDLE_ID } from './constants';


Expand All @@ -26,6 +25,13 @@ const IGNORED_ERRORS = [
ERROR_COPYING_ATTACHMENT,
'Failed to remove screenshot at path',
];
const IGNORED_ERRORS_PATTERN = new RegExp(
'(' +
IGNORED_ERRORS
.map((errStr) => _.escapeRegExp(errStr))
.join('|') +
')'
);

const RUNNER_SCHEME_TV = 'WebDriverAgentRunner_tvOS';
const LIB_SCHEME_TV = 'WebDriverAgentLib_tvOS';
Expand Down Expand Up @@ -324,27 +330,26 @@ export class XcodeBuild {
? `Output from xcodebuild ${this.showXcodeLog ? 'will' : 'will not'} be logged`
: 'Output from xcodebuild will only be logged if any errors are present there';
this.log.debug(`${logMsg}. To change this, use 'showXcodeLog' desired capability`);
xcodebuild.on('output', (stdout, stderr) => {
let out = stdout || stderr;

const onStreamLine = (/** @type {string} */ line) => {
if (this.showXcodeLog === false || IGNORED_ERRORS_PATTERN.test(line)) {
return;
}
// if we have an error we want to output the logs
// otherwise the failure is inscrutible
// but do not log permission errors from trying to write to attachments folder
const ignoreError = IGNORED_ERRORS.some((x) => out.includes(x));
if (this.showXcodeLog !== false && out.includes('Error Domain=') && !ignoreError) {
if (line.includes('Error Domain=')) {
logXcodeOutput = true;

// handle case where xcode returns 0 but is failing
this._didBuildFail = true;
}

// do not log permission errors from trying to write to attachments folder
if (logXcodeOutput && !ignoreError) {
for (const line of out.split(EOL)) {
xcodeLog.error(line);
}
if (logXcodeOutput) {
xcodeLog.info(line);
}
});
};
for (const streamName of ['stderr', 'stdout']) {
xcodebuild.on(`line-${streamName}`, onStreamLine);
}

return xcodebuild;
}
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
},
"homepage": "https://github.com/appium/WebDriverAgent#readme",
"devDependencies": {
"@appium/eslint-config-appium": "^8.0.4",
"@appium/eslint-config-appium-ts": "^0.x",
"@appium/test-support": "^3.0.0",
"@appium/tsconfig": "^0.x",
Expand Down Expand Up @@ -86,7 +85,7 @@
"bluebird": "^3.5.5",
"lodash": "^4.17.11",
"source-map-support": "^0.x",
"teen_process": "^2.0.0"
"teen_process": "^2.2.0"
},
"files": [
"index.ts",
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"extends": "@appium/tsconfig/tsconfig.json",
"compilerOptions": {
"strict": false, // TODO: make this flag true
"esModuleInterop": true,
"outDir": "build",
"types": ["node"],
"checkJs": true
Expand Down
Loading