Cleanup iOS/Android samples to use xharness (#55926)
authorAlexander Köplinger <alex.koeplinger@outlook.com>
Tue, 20 Jul 2021 10:14:22 +0000 (12:14 +0200)
committerGitHub <noreply@github.com>
Tue, 20 Jul 2021 10:14:22 +0000 (12:14 +0200)
Instead of manually calling adb or simctl.

src/mono/sample/Android/AndroidSampleApp.csproj
src/mono/sample/iOS/Makefile
src/mono/sample/iOS/Program.csproj
src/tasks/AotCompilerTask/MonoAOTCompiler.cs

index e85e49d..1abf765 100644 (file)
@@ -21,7 +21,6 @@
     <PropertyGroup>
       <StripDebugSymbols>False</StripDebugSymbols>
       <StripDebugSymbols Condition="'$(Configuration)' == 'Release'">True</StripDebugSymbols>
-      <AdbTool>$(ANDROID_SDK_ROOT)\platform-tools\adb</AdbTool>
       <ApkDir>$(PublishDir)apk\</ApkDir>
     </PropertyGroup>
 
     <Message Importance="High" Text="Apk:       $(ApkBundlePath)"/>
     <Message Importance="High" Text="PackageId: $(ApkPackageId)"/>
 
-    <Exec Condition="'$(DeployAndRun)' == 'true' and '$(ArchiveTests)' != 'true'" Command="$(AdbTool) kill-server"/>
-    <Exec Condition="'$(DeployAndRun)' == 'true' and '$(ArchiveTests)' != 'true'" Command="$(AdbTool) start-server"/>
-    <Exec Condition="'$(DeployAndRun)' == 'true' and '$(ArchiveTests)' != 'true'" Command="$(AdbTool) logcat -c" ContinueOnError="WarnAndContinue" />
-    <Message Condition="'$(DeployAndRun)' == 'true' and '$(ArchiveTests)' != 'true'" Importance="High" Text="Uninstalling apk (ignore errors if any):"/>
-    <Exec Condition="'$(DeployAndRun)' == 'true' and '$(ArchiveTests)' != 'true'" Command="$(AdbTool) uninstall net.dot.HelloAndroid" ContinueOnError="WarnAndContinue" />
-    <Exec Condition="'$(DeployAndRun)' == 'true' and '$(ArchiveTests)' != 'true'" Command="$(AdbTool) install $(ApkDir)/bin/HelloAndroid.apk" />
-    <Exec Condition="'$(DeployAndRun)' == 'true' and '$(RunActivity)' != 'true' and '$(ArchiveTests)' != 'true'"
-          Command="$(AdbTool) shell am instrument -e env:MONO_LOG_LEVEL warning -e env:MONO_LOG_MASK all -w net.dot.HelloAndroid/net.dot.MonoRunner"/>
-    <Exec Condition="'$(DeployAndRun)' == 'true' and '$(RunActivity)' == 'true' and '$(ArchiveTests)' != 'true'" Command="$(AdbTool) shell am start -n net.dot.HelloAndroid/net.dot.MainActivity" />
-    <Exec Condition="'$(DeployAndRun)' == 'true' and '$(ArchiveTests)' != 'true'" Command="$(AdbTool) logcat -d" />
+    <Exec Condition="'$(DeployAndRun)' == 'true' and '$(ArchiveTests)' != 'true'" Command="dotnet xharness android test --package-name=net.dot.HelloAndroid --instrumentation=net.dot.MonoRunner --app=$(ApkDir)/bin/HelloAndroid.apk --expected-exit-code=42 --output-directory=$(ApkDir)/log" />
   </Target>
 
   <ItemGroup>
index e3b7578..34279c4 100644 (file)
@@ -26,6 +26,7 @@ runtimepack:
 run: clean appbuilder
        $(DOTNET) publish \
        -c $(MONO_CONFIG) \
+       /p:TargetOS=iOS \
        /p:TargetArchitecture=$(MONO_ARCH) \
        /p:UseLLVM=$(USE_LLVM) \
        /p:ForceAOT=$(AOT) \
index 04b2bde..471abcb 100644 (file)
           Condition="'$(ArchiveTests)' != 'true'">
     <!-- FIXME: only run if the TargetArchitecture matches the current architecture -->
 
-    <!-- install and run on ios simulator -->
-    <Exec Condition="'$(IosSimulator)' != '' and '$(ArchiveTests)' != 'true'" Command="xcrun simctl shutdown &quot;$(IosSimulator)&quot;" ContinueOnError="WarnAndContinue" />
-    <Exec Condition="'$(IosSimulator)' != '' and '$(ArchiveTests)' != 'true'" Command="xcrun simctl boot &quot;$(IosSimulator)&quot;" />
-    <Exec Condition="'$(IosSimulator)' != '' and '$(ArchiveTests)' != 'true'" Command="open -a Simulator" />
-    <Exec Condition="'$(IosSimulator)' != '' and '$(ArchiveTests)' != 'true'" Command="xcrun simctl install &quot;$(IosSimulator)&quot; $(AppBundlePath)" />
-    <Exec Condition="'$(IosSimulator)' != '' and '$(ArchiveTests)' != 'true'" Command="xcrun simctl launch --console booted net.dot.HelloiOS" />
+    <!-- install and run on ios simulator or device -->
+    <Exec Condition="'$(TargetOS)' == 'iOSSimulator'" Command="dotnet xharness apple run --app=$(AppBundlePath) --targets=ios-simulator-64 --output-directory=/tmp/out" />
+    <Exec Condition="'$(TargetOS)' == 'iOS'" Command="dotnet xharness apple run --app=$(AppBundlePath) --targets=ios-device --output-directory=/tmp/out" />
 
     <!-- run on MacCatalyst -->
     <Exec Condition="'$(TargetOS)' == 'MacCatalyst'" Command="open -W $(AppBundlePath)" />
index 465c884..0d48bf4 100644 (file)
@@ -176,6 +176,7 @@ public class MonoAOTCompiler : Microsoft.Build.Utilities.Task
     /// </summary>
     public string? DedupAssembly { get; set; }
 
+    /// <summary>
     /// Debug option in llvm aot mode
     /// defaults to "nodebug" since some targes can't generate debug info
     /// </summary>