Skip to content

Commit

Permalink
Rename ios module to apple
Browse files Browse the repository at this point in the history
* Added CI tests for watchOS and tvOS
  • Loading branch information
simlay committed Feb 21, 2024
1 parent 0ff515e commit 37cd7b7
Show file tree
Hide file tree
Showing 8 changed files with 364 additions and 53 deletions.
43 changes: 37 additions & 6 deletions .travis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -x

title() {
set +x
echo -e '\n\033[1;33m '$@' \033[0m\n'
echo -e '\n\033[1;33m '$@' \033[0m\n'
set -x
}

Expand Down Expand Up @@ -40,7 +40,7 @@ tests_sequence() {
&& ! $CARGO_DINGHY -d $1 test fails \
&& ! $CARGO_DINGHY -d $1 test \
)

title "testing from project directory"
( \
cd test-ws/test-app \
Expand All @@ -49,7 +49,7 @@ tests_sequence() {
&& ! $CARGO_DINGHY -d $1 test fails \
&& ! $CARGO_DINGHY -d $1 test \
)

title "test from workspace directory with project filter"
( \
cd test-ws \
Expand All @@ -69,7 +69,7 @@ tests_sequence_aarch64_ios_sim() {
&& ! $CARGO_DINGHY -d $1 -p auto-ios-aarch64-sim test fails \
&& ! $CARGO_DINGHY -d $1 -p auto-ios-aarch64-sim test \
)

title "testing from project directory"
( \
cd test-ws/test-app \
Expand All @@ -78,7 +78,7 @@ tests_sequence_aarch64_ios_sim() {
&& ! $CARGO_DINGHY -d $1 -p auto-ios-aarch64-sim test fails \
&& ! $CARGO_DINGHY -d $1 -p auto-ios-aarch64-sim test \
)

title "test from workspace directory with project filter"
( \
cd test-ws \
Expand All @@ -88,6 +88,17 @@ tests_sequence_aarch64_ios_sim() {
&& ! $CARGO_DINGHY -d $1 -p auto-ios-aarch64-sim test -p test-app \
)
}
tests_sequence_unstable_target() {
# There's something odd with using the .cargo/config runner attribute and
# workspaces when the runner uses `cargo run --manifest-path ../Cargo.toml
# --bin cargo-dinghy ...`
title "testing from project directory for rust target $1"
( \
cd test-ws/test-bin \
&& cargo clean \
&& cargo +nightly run -Zbuild-std --target $1 \
)
}


if [ `uname` = Darwin ]
Expand Down Expand Up @@ -124,6 +135,26 @@ then
rustup target add aarch64-apple-ios
tests_sequence $device
fi

title "••••• Darwin: tvos simulator tests •••••"
title "boot a simulator"
rustup toolchain add nightly --component rust-src;
TVOS_RUNTIME_ID=$(xcrun simctl list runtimes | grep tvOS | cut -d ' ' -f 7 | tail -1)
export TV_SIM_ID=$(xcrun simctl create My-4ktv com.apple.CoreSimulator.SimDeviceType.Apple-TV-4K-3rd-generation-4K $TVOS_RUNTIME_ID)

xcrun simctl boot $TV_SIM_ID
tests_sequence_unstable_target x86_64-apple-tvos
xcrun simctl delete $TV_SIM_ID

title "••••• Darwin: watchvos simulator tests •••••"
title "boot a simulator"
rustup toolchain add nightly --component rust-src;
WATCHOS_RUNTIME_ID=$(xcrun simctl list runtimes | grep watchOS | cut -d ' ' -f 7 | tail -1)
export WATCHOS_SIM_ID=$(xcrun simctl create My-apple-watch com.apple.CoreSimulator.SimDeviceType.Apple-Watch-SE-44mm-2nd-generation $WATCHOS_RUNTIME_ID)

xcrun simctl boot $WATCHOS_SIM_ID
tests_sequence_unstable_target x86_64-apple-watchos-sim
xcrun simctl delete $WATCHOS_SIM_ID
else
if [ -n "$ANDROID_SDK_ROOT" ]
then
Expand All @@ -150,7 +181,7 @@ else
echo no | $ANDROID_SDK_ROOT/cmdline-tools/latest/bin/avdmanager create avd -n testdinghy -k "system-images;android-24;default;armeabi-v7a"
$EMULATOR @testdinghy -no-audio -no-boot-anim -no-window -accel on -gpu off &
timeout 180 $ANDROID_SDK_ROOT/platform-tools/adb wait-for-device

export ANDROID_NDK_HOME=$ANDROID_SDK_ROOT/ndk/22.1.7171670

tests_sequence android
Expand Down
104 changes: 83 additions & 21 deletions dinghy-lib/src/ios/device.rs → dinghy-lib/src/apple/device.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::xcode;
use super::{xcode, AppleSimulatorType};
use crate::device::make_remote_app_with_name;
use crate::errors::*;
use crate::ios::IosPlatform;
use crate::apple::AppleDevicePlatform;
use crate::project::Project;
use crate::utils::LogCommandExt;
use crate::utils::{get_current_verbosity, user_facing_log};
Expand All @@ -27,10 +27,11 @@ pub struct IosDevice {
}

#[derive(Clone, Debug)]
pub struct IosSimDevice {
pub struct AppleSimDevice {
pub id: String,
pub name: String,
pub os: String,
pub sim_type: AppleSimulatorType,
}

unsafe impl Send for IosDevice {}
Expand Down Expand Up @@ -191,7 +192,7 @@ impl Device for IosDevice {
}
}

impl IosSimDevice {
impl AppleSimDevice {
fn install_app(
&self,
project: &Project,
Expand All @@ -203,7 +204,7 @@ impl IosSimDevice {
&format!("{} to {}", build.runnable.id, self.id),
0,
);
let build_bundle = IosSimDevice::make_app(project, build, runnable)?;
let build_bundle = self.make_app(project, build, runnable)?;
let _ = process::Command::new("xcrun")
.args(&["simctl", "uninstall", &self.id, "Dinghy"])
.log_invocation(2)
Expand Down Expand Up @@ -231,12 +232,16 @@ impl IosSimDevice {
}
}

fn make_app(project: &Project, build: &Build, runnable: &Runnable) -> Result<BuildBundle> {
make_ios_app(project, build, runnable, "Dinghy")
fn make_app(&self, project: &Project, build: &Build, runnable: &Runnable) -> Result<BuildBundle> {
match self.sim_type {
AppleSimulatorType::Ios => make_ios_app(project, build, runnable, "Dinghy"),
AppleSimulatorType::Watchos => make_watchos_app(project, build, runnable, "Dinghy"),
AppleSimulatorType::Tvos => make_tvos_app(project, build, runnable, "Dinghy"),
}
}
}

impl Device for IosSimDevice {
impl Device for AppleSimDevice {
fn clean_app(&self, _build_bundle: &BuildBundle) -> Result<()> {
unimplemented!()
}
Expand Down Expand Up @@ -312,11 +317,11 @@ impl Display for IosDevice {
}
}

impl Display for IosSimDevice {
impl Display for AppleSimDevice {
fn fmt(&self, fmt: &mut Formatter) -> fmt::Result {
Ok(fmt.write_str(
format!(
"IosSimDevice {{ \"id\": \"{}\", \"name\": {}, \"os\": {} }}",
"AppleSimDevice {{ \"id\": \"{}\", \"name\": {}, \"os\": {} }}",
self.id, self.name, self.os
)
.as_str(),
Expand All @@ -325,8 +330,8 @@ impl Display for IosSimDevice {
}

impl DeviceCompatibility for IosDevice {
fn is_compatible_with_ios_platform(&self, platform: &IosPlatform) -> bool {
if platform.sim {
fn is_compatible_with_simulator_platform(&self, platform: &AppleDevicePlatform) -> bool {
if platform.sim.is_some() {
return false;
}

Expand All @@ -337,11 +342,13 @@ impl DeviceCompatibility for IosDevice {
}
}

impl DeviceCompatibility for IosSimDevice {
fn is_compatible_with_ios_platform(&self, platform: &IosPlatform) -> bool {
platform.sim
&& (platform.toolchain.rustc_triple == "x86_64-apple-ios"
|| platform.toolchain.rustc_triple == "aarch64-apple-ios-sim")
impl DeviceCompatibility for AppleSimDevice {
fn is_compatible_with_simulator_platform(&self, platform: &AppleDevicePlatform) -> bool {
if let Some(sim) = &platform.sim {
self.sim_type == *sim
} else {
false
}
}
}

Expand All @@ -368,11 +375,65 @@ fn make_ios_app(
.split(" ")
.last()
.ok_or_else(|| anyhow!("empty magic"))?;
xcode::add_plist_to_app(&build_bundle, target, app_id)?;
xcode::add_plist_to_ios_app(&build_bundle, target, app_id)?;
Ok(build_bundle)
}

fn make_watchos_app(
project: &Project,
build: &Build,
runnable: &Runnable,
app_id: &str,
) -> Result<BuildBundle> {
use crate::project;
let build_bundle = make_remote_app_with_name(project, build, Some("Dinghy.app"))?;
project::rec_copy(&runnable.exe, build_bundle.bundle_dir.join("Dinghy"), false)?;
let magic = process::Command::new("file")
.arg(
runnable
.exe
.to_str()
.ok_or_else(|| anyhow!("path conversion to string: {:?}", runnable.exe))?,
)
.log_invocation(3)
.output()?;
let magic = String::from_utf8(magic.stdout)?;
let target = magic
.split(" ")
.last()
.ok_or_else(|| anyhow!("empty magic"))?;
xcode::add_plist_to_watchos_app(&build_bundle, target, app_id)?;
Ok(build_bundle)
}

fn make_tvos_app(
project: &Project,
build: &Build,
runnable: &Runnable,
app_id: &str,
) -> Result<BuildBundle> {
use crate::project;
let build_bundle = make_remote_app_with_name(project, build, Some("Dinghy.app"))?;
project::rec_copy(&runnable.exe, build_bundle.bundle_dir.join("Dinghy"), false)?;
let magic = process::Command::new("file")
.arg(
runnable
.exe
.to_str()
.ok_or_else(|| anyhow!("path conversion to string: {:?}", runnable.exe))?,
)
.log_invocation(3)
.output()?;
let magic = String::from_utf8(magic.stdout)?;
let target = magic
.split(" ")
.last()
.ok_or_else(|| anyhow!("empty magic"))?;
xcode::add_plist_to_tvos_app(&build_bundle, target, app_id)?;
Ok(build_bundle)
}

fn launch_app(dev: &IosSimDevice, app_args: &[&str], _envs: &[&str]) -> Result<()> {
fn launch_app(dev: &AppleSimDevice, app_args: &[&str], _envs: &[&str]) -> Result<()> {
use std::io::Write;
let dir = ::tempdir::TempDir::new("mobiledevice-rs-lldb")?;
let tmppath = dir.path();
Expand All @@ -397,6 +458,7 @@ fn launch_app(dev: &IosSimDevice, app_args: &[&str], _envs: &[&str]) -> Result<(
.log_invocation(1)
.output()?;
let launch_output = String::from_utf8_lossy(&launch_output.stdout);
debug!("xcrun simctl launch output: {:?}", launch_output);

// Output from the launch command should be "Dinghy: $PID" which is after the 8th character.
let dinghy_pid = launch_output.split_at(8).1;
Expand Down Expand Up @@ -458,12 +520,12 @@ fn launch_app(dev: &IosSimDevice, app_args: &[&str], _envs: &[&str]) -> Result<(
);
}
} else {
panic!("Failed to get the exit status line from lldb: {:?}", output);
panic!("Failed to get the exit status line from lldb: {}", output);
}
}

fn launch_lldb_simulator(
dev: &IosSimDevice,
dev: &AppleSimDevice,
installed: &str,
args: &[&str],
envs: &[&str],
Expand Down
File renamed without changes.
Loading

0 comments on commit 37cd7b7

Please sign in to comment.