初始化提交

This commit is contained in:
2026-02-03 16:52:44 +08:00
commit d2f9806384
512 changed files with 65167 additions and 0 deletions

View File

@@ -0,0 +1,79 @@
const path = require('path');
const { asyncify } = require('asyncbox');
const { logger, fs } = require('@appium/support');
const { exec } = require('teen_process');
const xcode = require('appium-xcode');
const LOG = new logger.getLogger('WDABuild');
const ROOT_DIR = path.resolve(__dirname, '..');
const DERIVED_DATA_PATH = `${ROOT_DIR}/wdaBuild`;
const WDA_BUNDLE = 'WebDriverAgentRunner-Runner.app';
const WDA_BUNDLE_PATH = path.join(DERIVED_DATA_PATH, 'Build', 'Products', 'Debug-iphonesimulator');
const WDA_BUNDLE_TV = 'WebDriverAgentRunner_tvOS-Runner.app';
const WDA_BUNDLE_TV_PATH = path.join(DERIVED_DATA_PATH, 'Build', 'Products', 'Debug-appletvsimulator');
const TARGETS = ['runner', 'tv_runner'];
const SDKS = ['sim', 'tv_sim'];
async function buildWebDriverAgent (xcodeVersion) {
const target = process.env.TARGET;
const sdk = process.env.SDK;
if (!TARGETS.includes(target)) {
throw Error(`Please set TARGETS environment variable from the supported targets ${JSON.stringify(TARGETS)}`);
}
if (!SDKS.includes(sdk)) {
throw Error(`Please set SDK environment variable from the supported SDKs ${JSON.stringify(SDKS)}`);
}
LOG.info(`Cleaning ${DERIVED_DATA_PATH} if exists`);
try {
await exec('xcodebuild', ['clean', '-derivedDataPath', DERIVED_DATA_PATH, '-scheme', 'WebDriverAgentRunner'], {
cwd: ROOT_DIR
});
} catch {}
// Get Xcode version
xcodeVersion = xcodeVersion || await xcode.getVersion();
LOG.info(`Building WebDriverAgent for iOS using Xcode version '${xcodeVersion}'`);
// Clean and build
try {
await exec('/bin/bash', ['./Scripts/build.sh'], {
env: {TARGET: target, SDK: sdk, DERIVED_DATA_PATH},
cwd: ROOT_DIR
});
} catch (e) {
LOG.error(`===FAILED TO BUILD FOR ${xcodeVersion}`);
LOG.error(e.stderr);
throw e;
}
const isTv = target === 'tv_runner';
const bundle = isTv ? WDA_BUNDLE_TV : WDA_BUNDLE;
const bundle_path = isTv ? WDA_BUNDLE_TV_PATH : WDA_BUNDLE_PATH;
const zipName = `WebDriverAgentRunner-Runner-${sdk}-${xcodeVersion}.zip`;
LOG.info(`Creating ${zipName} which includes ${bundle}`);
const appBundleZipPath = path.join(ROOT_DIR, zipName);
await fs.rimraf(appBundleZipPath);
LOG.info(`Created './${zipName}'`);
try {
await exec('xattr', ['-cr', bundle], {cwd: bundle_path});
await exec('zip', ['-qr', appBundleZipPath, bundle], {cwd: bundle_path});
} catch (e) {
LOG.error(`===FAILED TO ZIP ARCHIVE`);
LOG.error(e.stderr);
throw e;
}
LOG.info(`Zip bundled at "${appBundleZipPath}"`);
}
if (require.main === module) {
asyncify(buildWebDriverAgent);
}
module.exports = buildWebDriverAgent;

104
Scripts/build.sh Executable file
View File

@@ -0,0 +1,104 @@
#!/bin/bash
#
# Copyright (c) 2015-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.
#
set -ex
function define_xc_macros() {
XC_MACROS="CODE_SIGN_IDENTITY=\"\" CODE_SIGNING_REQUIRED=NO"
case "$TARGET" in
"lib" ) XC_TARGET="WebDriverAgentLib";;
"runner" ) XC_TARGET="WebDriverAgentRunner";;
"tv_lib" ) XC_TARGET="WebDriverAgentLib_tvOS";;
"tv_runner" ) XC_TARGET="WebDriverAgentRunner_tvOS";;
*) echo "Unknown TARGET"; exit 1 ;;
esac
case "${DEST:-}" in
"iphone" ) XC_DESTINATION="name=`echo $IPHONE_MODEL | tr -d "'"`,OS=$IOS_VERSION";;
"ipad" ) XC_DESTINATION="name=`echo $IPAD_MODEL | tr -d "'"`,OS=$IOS_VERSION";;
"tv" ) XC_DESTINATION="name=`echo $TV_MODEL | tr -d "'"`,OS=$TV_VERSION";;
"generic" ) XC_DESTINATION="generic/platform=iOS";;
"tv_generic" ) XC_DESTINATION="generic/platform=tvOS" XC_MACROS="${XC_MACROS} ARCHS=arm64";; # tvOS only supports arm64
esac
case "$ACTION" in
"build" ) XC_ACTION="build";;
"analyze" )
XC_ACTION="analyze"
XC_MACROS="${XC_MACROS} CLANG_ANALYZER_OUTPUT=plist-html CLANG_ANALYZER_OUTPUT_DIR=\"$(pwd)/clang\""
;;
"unit_test" ) XC_ACTION="test -only-testing:UnitTests";;
"tv_unit_test" ) XC_ACTION="test -only-testing:UnitTests_tvOS";;
esac
case "$SDK" in
"sim" ) XC_SDK="iphonesimulator";;
"device" ) XC_SDK="iphoneos";;
"tv_sim" ) XC_SDK="appletvsimulator";;
"tv_device" ) XC_SDK="appletvos";;
*) echo "Unknown SDK"; exit 1 ;;
esac
case "${CODE_SIGN:-}" in
"no" ) XC_MACROS="${XC_MACROS} CODE_SIGNING_ALLOWED=NO";;
esac
}
function analyze() {
xcbuild
if [[ -z $(find clang -name "*.html") ]]; then
echo "Static Analyzer found no issues"
else
echo "Static Analyzer found some issues"
exit 1
fi
}
function xcbuild() {
destination=""
output_command=cat
if [ $(which xcpretty) ] ; then
output_command=xcpretty
fi
XC_BUILD_ARGS=(-project "WebDriverAgent.xcodeproj")
XC_BUILD_ARGS+=(-scheme "$XC_TARGET")
XC_BUILD_ARGS+=(-sdk "$XC_SDK")
XC_BUILD_ARGS+=($XC_ACTION)
if [[ -n "$XC_DESTINATION" ]]; then
XC_BUILD_ARGS+=(-destination "${XC_DESTINATION}")
fi
if [[ -n "$DERIVED_DATA_PATH" ]]; then
XC_BUILD_ARGS+=(-derivedDataPath ${DERIVED_DATA_PATH})
fi
XC_BUILD_ARGS+=($XC_MACROS $EXTRA_XC_ARGS)
xcodebuild "${XC_BUILD_ARGS[@]}" | $output_command && exit ${PIPESTATUS[0]}
}
function fastlane_test() {
bundle install
if [[ -n "$XC_DESTINATION" ]]; then
SDK="$XC_SDK" DEST="$XC_DESTINATION" SCHEME="$1" bundle exec fastlane test
else
SDK="$XC_SDK" SCHEME="$1" bundle exec fastlane test
fi
}
define_xc_macros
case "$ACTION" in
"analyze" ) analyze ;;
"int_test_1" ) fastlane_test IntegrationTests_1 ;;
"int_test_2" ) fastlane_test IntegrationTests_2 ;;
"int_test_3" ) fastlane_test IntegrationTests_3 ;;
*) xcbuild ;;
esac

24
Scripts/ci/build-real.sh Executable file
View File

@@ -0,0 +1,24 @@
#!/bin/bash
xcodebuild clean build-for-testing \
-project WebDriverAgent.xcodeproj \
-derivedDataPath $DERIVED_DATA_PATH \
-scheme $SCHEME \
-destination "$DESTINATION" \
CODE_SIGNING_ALLOWED=NO ARCHS=arm64
pushd $WD
# The reason why here excludes several frameworks are:
# - to remove test packages to refer to the device local instead of embedded ones
# XCTAutomationSupport.framework, XCTest.framewor, XCTestCore.framework,
# XCUIAutomation.framework, XCUnit.framework.
# This can be excluded only for real devices.
# - Xcode 16 started generating 5.9MB of 'Testing.framework', but it might not be necessary for WDA.
# - libXCTestSwiftSupport is used for Swift testing. WDA doesn't include Swift stuff, thus this is not needed.
zip -r $ZIP_PKG_NAME $SCHEME-Runner.app \
-x "$SCHEME-Runner.app/Frameworks/XC*.framework*" \
"$SCHEME-Runner.app/Frameworks/Testing.framework*" \
"$SCHEME-Runner.app/Frameworks/libXCTestSwiftSupport.dylib"
popd
mv $WD/$ZIP_PKG_NAME ./

15
Scripts/ci/build-sim.sh Executable file
View File

@@ -0,0 +1,15 @@
#!/bin/bash
xcodebuild clean build-for-testing \
-project WebDriverAgent.xcodeproj \
-derivedDataPath $DERIVED_DATA_PATH \
-scheme $SCHEME \
-destination "$DESTINATION" \
CODE_SIGNING_ALLOWED=NO ARCHS=$ARCHS
pushd $WD
# Simulators might have an issue to lauch if we drop frameworks even we don't use them.
zip -r $ZIP_PKG_NAME $SCHEME-Runner.app
popd
mv $WD/$ZIP_PKG_NAME ./

View File

@@ -0,0 +1,61 @@
const path = require('path');
const axios = require('axios');
const { asyncify } = require('asyncbox');
const { logger, fs, mkdirp, net } = require('@appium/support');
const _ = require('lodash');
const B = require('bluebird');
const log = logger.getLogger('WDA');
async function fetchPrebuiltWebDriverAgentAssets () {
const tag = require('../package.json').version;
log.info(`Getting links to webdriveragent release ${tag}`);
const downloadUrl = `https://api.github.com/repos/appium/webdriveragent/releases/tags/v${tag}`;
log.info(`Getting WDA release ${downloadUrl}`);
let releases;
try {
releases = (await axios({
url: downloadUrl,
headers: {
'user-agent': 'appium',
'accept': 'application/json, */*',
},
})).data;
} catch (e) {
throw new Error(`Could not fetch endpoint ${downloadUrl}. Reason: ${e.message}`);
}
const webdriveragentsDir = path.resolve(__dirname, '..', 'prebuilt-agents');
log.info(`Creating webdriveragents directory at: ${webdriveragentsDir}`);
await fs.rimraf(webdriveragentsDir);
await mkdirp(webdriveragentsDir);
// Define a method that does a streaming download of an asset
async function downloadAgent (url, targetPath) {
try {
await net.downloadFile(url, targetPath);
} catch (err) {
throw new Error(`Problem downloading webdriveragent from url ${url}: ${err.message}`);
}
}
log.info(`Downloading assets to: ${webdriveragentsDir}`);
const agentsDownloading = [];
for (const asset of releases.assets) {
const url = asset.browser_download_url;
log.info(`Downloading: ${url}`);
try {
const nameOfAgent = _.last(url.split('/'));
agentsDownloading.push(downloadAgent(url, path.join(webdriveragentsDir, nameOfAgent)));
} catch { }
}
// Wait for them all to finish
return await B.all(agentsDownloading);
}
if (require.main === module) {
asyncify(fetchPrebuiltWebDriverAgentAssets);
}
module.exports = fetchPrebuiltWebDriverAgentAssets;

View File

@@ -0,0 +1,41 @@
const {plist, logger} = require('@appium/support');
const path = require('node:path');
const semver = require('semver');
const log = logger.getLogger('Versioner');
/**
* @param {string} argName
* @returns {string|null}
*/
function parseArgValue (argName) {
const argNamePattern = new RegExp(`^--${argName}\\b`);
for (let i = 1; i < process.argv.length; ++i) {
const arg = process.argv[i];
if (argNamePattern.test(arg)) {
return arg.includes('=') ? arg.split('=')[1] : process.argv[i + 1];
}
}
return null;
}
async function updateWdaVersion() {
const newVersion = parseArgValue('package-version');
if (!newVersion) {
throw new Error('No package version argument (use `--package-version=xxx`)');
}
if (!semver.valid(newVersion)) {
throw new Error(
`Invalid version specified '${newVersion}'. Version should be in the form '1.2.3'`
);
}
const libManifest = path.resolve('WebDriverAgentLib', 'Info.plist');
log.info(`Updating the WebDriverAgent manifest at '${libManifest}' to version '${newVersion}'`);
await plist.updatePlistFile(libManifest, {
CFBundleShortVersionString: newVersion,
CFBundleVersion: newVersion,
}, false);
}
(async () => await updateWdaVersion())();