Skip to content

Commit

Permalink
Create prebuilt Detox framework (wix#1954)
Browse files Browse the repository at this point in the history
* Swap to bash for convenience

* Switch to Swift 5 and no longer embed Swift standard libraries

This means we require Xcode 10.2, iOS 12.2 at minimum

* Fix Xcode version regex

* Do not pack iOS artifacts during prepublish or publish

Artifacts will be built during a separate step in CI.

* Add “package:ios” script to be run on CI

* Rather than build during postinstall, extract existing prebuilt framework

Dev mode will continue to build from source

* Make the script exit on build error

* Update ci.publish.js
  • Loading branch information
LeoNatan authored Mar 12, 2020
1 parent 08ee137 commit c94365b
Show file tree
Hide file tree
Showing 14 changed files with 55 additions and 63 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,4 @@ detox/test/artifacts

Detox-android/
Detox-ios-src.tbz
Detox-ios.tbz
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ The most difficult part of automated testing on mobile is the tip of the testing

### Environment

* **OS**: MacOS 10.13 (High Sierra) or higher.
* **Xcode**: 10.1 or higher.
* **OS**: MacOS 10.13 (High Sierra) or higher
* **Xcode**: 10.2 or higher
* **iOS Simulator Runtime**: iOS 12.2 or higher

### React Native

Expand All @@ -63,7 +64,7 @@ The following React Native versions have been tested:

| iOS | Android |
| ------ | ------------------------------------------------------------ |
| <=0.60.4 | <=0.56 - Full support |
| <=0.61.* | <=0.56 - Full support |
| | >=0.57 <=0.61 - Visibility edge-case: see this [RN issue](https://github.com/facebook/react-native/issues/23870)* |

Future versions are most likely supported, but have not been tested yet. Please open issues if you find specific issues with newer React Native versions.
Expand Down
18 changes: 5 additions & 13 deletions detox/ios/Detox.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,6 @@
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OBJC_BRIDGING_HEADER = "DetoxUserNotificationTests/Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.2;
};
name = Debug;
};
Expand All @@ -815,7 +814,6 @@
PRODUCT_BUNDLE_IDENTIFIER = com.wix.DetoxUserNotificationTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "DetoxUserNotificationTests/Bridging-Header.h";
SWIFT_VERSION = 4.2;
};
name = Release;
};
Expand Down Expand Up @@ -872,11 +870,13 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 11.3;
IPHONEOS_DEPLOYMENT_TARGET = 12.2;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_TREAT_WARNINGS_AS_ERRORS = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
Expand Down Expand Up @@ -930,12 +930,13 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 11.3;
IPHONEOS_DEPLOYMENT_TARGET = 12.2;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_OPTIMIZATION_LEVEL = "-O";
SWIFT_TREAT_WARNINGS_AS_ERRORS = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
VERSIONING_SYSTEM = "apple-generic";
Expand All @@ -947,7 +948,6 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 390D1C981E3A2893007F5F46 /* Detox.xcconfig */;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
CLANG_ENABLE_MODULES = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = NO;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = NO;
Expand All @@ -962,7 +962,6 @@
HEADER_SEARCH_PATHS = EarlGrey/fishhook;
INFOPLIST_FILE = Detox/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 11.3;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand All @@ -982,17 +981,13 @@
SKIP_INSTALL = YES;
STRIP_INSTALLED_PRODUCT = NO;
STRIP_SWIFT_SYMBOLS = NO;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_TREAT_WARNINGS_AS_ERRORS = NO;
SWIFT_VERSION = 4.2;
};
name = Debug;
};
394767A11DBF985400D72256 /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 390D1C981E3A2893007F5F46 /* Detox.xcconfig */;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
CLANG_ENABLE_MODULES = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = NO;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = NO;
Expand All @@ -1007,7 +1002,6 @@
HEADER_SEARCH_PATHS = EarlGrey/fishhook;
INFOPLIST_FILE = Detox/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 11.3;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand All @@ -1027,8 +1021,6 @@
SKIP_INSTALL = YES;
STRIP_INSTALLED_PRODUCT = NO;
STRIP_SWIFT_SYMBOLS = NO;
SWIFT_TREAT_WARNINGS_AS_ERRORS = NO;
SWIFT_VERSION = 4.2;
};
name = Release;
};
Expand Down
2 changes: 1 addition & 1 deletion detox/ios/Detox/DetoxUserActivityDispatcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class DetoxUserActivityDispatcher: NSObject {
Swift.fatalError("Unable to read user activity data file.")
}

guard let jsonObject = (try? JSONSerialization.jsonObject(with: data, options: .init(rawValue: 0)) as! [String: Any]) else {
guard let jsonObject = try? (JSONSerialization.jsonObject(with: data, options: .init(rawValue: 0)) as! [String: Any]) else {
Swift.fatalError("Unable to parse user activity data file.")
}

Expand Down
2 changes: 1 addition & 1 deletion detox/ios/Detox/DetoxUserNotificationDispatcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public class DetoxUserNotificationDispatcher: NSObject {
Swift.fatalError("Unable to read user notification data file.")
}

guard var jsonObject = (try? JSONSerialization.jsonObject(with: data, options: .init(rawValue: 0)) as! [String: Any]) else {
guard var jsonObject = try? (JSONSerialization.jsonObject(with: data, options: .init(rawValue: 0)) as! [String: Any]) else {
Swift.fatalError("Unable to parse user notification data file.")
}

Expand Down
3 changes: 3 additions & 0 deletions detox/ios/Detox/GREYMatchers+Detox.m
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ @implementation GREYMatchers (Detox)
//Either take scroll views or web views that match the provided matcher, or take views whose parent is a RCTScrollView subclass and the parent matches the provided matcher.
return grey_anyOf(grey_allOf(
grey_anyOf(grey_kindOfClass([UIScrollView class]),
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
grey_kindOfClass([UIWebView class]),
#pragma clang diagnostic pop
nil),
matcher,
nil),
Expand Down
5 changes: 1 addition & 4 deletions detox/scripts/build.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
const fs = require('fs-extra');
const {sh} = require('./utils');

if (process.platform === 'darwin') {
const {packageIosSources} = require('./pack_ios');
packageIosSources();
}
//No need to pack iOS artifacts here. The build_framework.ios.sh script will be called during the post-install phase.

if (process.argv[2] === "android" || process.argv[3] === "android") {
console.log("\nBuilding Detox aars");
Expand Down
18 changes: 7 additions & 11 deletions detox/scripts/build_framework.ios.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,17 @@ detoxFrameworkPath="${detoxFrameworkDirPath}/Detox.framework"
function prepareAndBuildFramework () {
if [ -d "$detoxRootPath"/ios ]; then
detoxSourcePath="${detoxRootPath}"/ios
echo "Dev mode, will build from ${detoxSourcePath}"
echo "Dev mode, building from ${detoxSourcePath}"
buildFramework "${detoxSourcePath}"
else
detoxSourcePath="${detoxRootPath}"/ios_src
extractSources "${detoxSourcePath}"
buildFramework "${detoxSourcePath}"
rm -fr "${detoxSourcePath}"
extractFramework
fi
}

function extractSources () {
detoxSourcePath="${1}"
echo "Extracting Detox sources..."
mkdir -p "${detoxSourcePath}"
tar -xjf "${detoxRootPath}"/Detox-ios-src.tbz -C "${detoxSourcePath}"
function extractFramework () {
echo "Extracting Detox framework..."
mkdir -p "${detoxFrameworkDirPath}"
tar -xjf "${detoxRootPath}"/Detox-ios.tbz -C "${detoxFrameworkDirPath}"
}

function buildFramework () {
Expand All @@ -55,7 +51,7 @@ function main () {
rm -rf "${detoxFrameworkDirPath}"
prepareAndBuildFramework
else
echo "Detox.framework was previously compiled, skipping..."
echo "Detox.framework exists, skipping..."
fi
else
prepareAndBuildFramework
Expand Down
4 changes: 3 additions & 1 deletion detox/scripts/build_universal_framework.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash -e

PROJECT=$1
OUTPUT_DIR=$2
CONFIGURATION=Release
Expand All @@ -19,7 +21,7 @@ echo TEMP_DIR = "${TEMP_DIR}"

# Step 0. Xcode version

XCODEVERSION=$(xcodebuild -version | grep -oEi "([0-9]*\.[0-9]*)")
XCODEVERSION=$(xcodebuild -version | grep -oEi "([0-9]*(\.[0-9]*)+)")
echo "Xcode ${XCODEVERSION}"
USE_NEW_BUILD_SYSTEM="YES"
if [ "${XCODEVERSION}" != "`echo -e "${XCODEVERSION}\n11.0" | sort --version-sort -r | head -n1`" ]; then
Expand Down
18 changes: 0 additions & 18 deletions detox/scripts/pack_ios.js

This file was deleted.

24 changes: 24 additions & 0 deletions detox/scripts/pack_ios.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash -e

rm -rf Detox-ios-src.tbz
rm -rf Detox-ios.tbz
rm -rf build_temp

ios/EarlGrey/Scripts/setup-earlgrey.sh
find ./ios -name Build -type d -exec rm -rf {} \;

#Package sources
pushd . &> /dev/null
cd ios
tar --exclude-from=.tbzignore -cjf ../Detox-ios-src.tbz .
popd &> /dev/null

#Package prebuilt framework
mkdir build_temp
scripts/build_universal_framework.sh "ios/Detox.xcodeproj" "build_temp" &> build_temp/detox_ios.log
pushd . &> /dev/null
cd build_temp
tar --exclude-from=../ios/.tbzignore -cjf ../Detox-ios.tbz .
popd &> /dev/null

rm -fr build_temp
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"test:e2e:android": "pushd detox/test && npm run e2e:android && popd",
"release": "node scripts/ci.release.js",
"package:android": "node scripts/ci.android-release.js",
"package:ios": "scripts/ci.ios-release.sh",
"postinstall": "scripts/postinstall.sh"
},
"publishConfig": {
Expand Down
4 changes: 4 additions & 0 deletions scripts/ci.ios-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash -e

cd detox
scripts/pack_ios.sh
11 changes: 0 additions & 11 deletions scripts/ci.publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const {log, logSection, getVersionSafe} = require('./ci.common');
function publishNewVersion(packageVersion) {
validatePrerequisites();
projectSetup();
prePublishToNpm();
publishToNpm();

const newVersion = getVersionSafe();
Expand Down Expand Up @@ -37,16 +36,6 @@ function projectSetup() {
exec.execSync(`git checkout master`);
}

function prePublishToNpm() {
logSection('Prepublish');

log('Gathering up iOS artifacts...');
process.chdir('detox');
const {packageIosSources} = require('../detox/scripts/pack_ios');
packageIosSources();
process.chdir('..');
}

function publishToNpm() {
logSection('Lerna publish');

Expand Down

0 comments on commit c94365b

Please sign in to comment.