Skip to content

Commit

Permalink
Create a parent CMake project for building app bundles on CI (dotnet#…
Browse files Browse the repository at this point in the history
  • Loading branch information
akoeplinger authored Sep 13, 2021
1 parent 206dba7 commit 0becd27
Show file tree
Hide file tree
Showing 6 changed files with 294 additions and 75 deletions.
3 changes: 3 additions & 0 deletions eng/testing/AppleRunnerTemplate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ if [[ "$TARGET" == "ios-device" ]]; then SCHEME_SDK=Release-iphoneos; fi
if [[ "$TARGET" == "tvos-device" ]]; then SCHEME_SDK=Release-appletvos; fi
if [[ "$TARGET" == "maccatalyst" ]]; then SCHEME_SDK=Release-maccatalyst; fi

if [[ "$TARGET" == "ios-device" || "$TARGET" == "tvos-device" ]]; then SIGNAL_APP_END="--signal-app-end"; fi

cd $EXECUTION_DIR

# it doesn't support parallel execution yet, so, here is a hand-made semaphore:
Expand Down Expand Up @@ -62,6 +64,7 @@ $HARNESS_RUNNER apple $XHARNESS_CMD \
--targets="$TARGET" \
--xcode="$XCODE_PATH" \
--output-directory="$XHARNESS_OUT" \
$SIGNAL_APP_END \
$ADDITIONAL_ARGS

_exitCode=$?
Expand Down
20 changes: 14 additions & 6 deletions eng/testing/tests.mobile.targets
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
<PropertyGroup>
<!-- OutDir is not set early enough to set this property in .props file. -->
<BundleDir>$([MSBuild]::NormalizeDirectory('$(OutDir)', 'AppBundle'))</BundleDir>
<PublishDir Condition="'$(UseAppBundleRootForBuildingTests)' == 'true' and '$(IgnoreForCI)' != 'true' and '$(IsFunctionalTest)' != 'true'">$(AppBundleRoot)tests\$(AssemblyName)</PublishDir>
<PublishDir Condition="'$(UseAppBundleRootForBuildingTests)' == 'true' and '$(IgnoreForCI)' != 'true' and '$(IsFunctionalTest)' == 'true'">$(AppBundleRoot)runonly\$(AssemblyName)</PublishDir>
<BundleDir Condition="'$(UseAppBundleRootForBuildingTests)' == 'true' and '$(IgnoreForCI)' != 'true'">$([MSBuild]::NormalizeDirectory('$(PublishDir)', 'AppBundle'))</BundleDir>
<RunScriptOutputPath>$([MSBuild]::NormalizePath('$(BundleDir)', '$(RunScriptOutputName)'))</RunScriptOutputPath>
<RunAOTCompilation Condition="'$(TargetOS)' == 'iOS' or '$(TargetOS)' == 'tvOS'">true</RunAOTCompilation>

Expand Down Expand Up @@ -159,6 +162,10 @@
<Optimized>true</Optimized>
<MainLibraryFileName Condition="'$(MainLibraryFileName)' == ''">AppleTestRunner.dll</MainLibraryFileName>
<_MobileIntermediateOutputPath Condition="'$(RunAOTCompilation)' == 'true'">$(IntermediateOutputPath)mobile</_MobileIntermediateOutputPath>
<GenerateXcodeProject>true</GenerateXcodeProject>
<GenerateCMakeProject>false</GenerateCMakeProject>
<GenerateXcodeProject Condition="'$(UseAppBundleRootForBuildingTests)' == 'true'">false</GenerateXcodeProject>
<GenerateCMakeProject Condition="'$(UseAppBundleRootForBuildingTests)' == 'true' and '$(IgnoreForCI)' != 'true'">true</GenerateCMakeProject>
</PropertyGroup>
<PropertyGroup>
<AOTMode Condition="'$(TargetOS)' != 'MacCatalyst'">Full</AOTMode>
Expand Down Expand Up @@ -217,26 +224,27 @@
ForceInterpreter="$(MonoForceInterpreter)"
InvariantGlobalization="$(InvariantGlobalization)"
UseConsoleUITemplate="True"
GenerateXcodeProject="True"
BuildAppBundle="True"
GenerateXcodeProject="$(GenerateXcodeProject)"
GenerateCMakeProject="$(GenerateCMakeProject)"
BuildAppBundle="$(GenerateXcodeProject)"
Optimized="$(Optimized)"
DevTeamProvisioning="$(DevTeamProvisioning)"
OutputDirectory="$(BundleDir)"
AppDir="$(PublishDir)">
<Output TaskParameter="AppBundlePath" PropertyName="AppBundlePath" />
<Output TaskParameter="XcodeProjectPath" PropertyName="XcodeProjectPath" />
</AppleAppBuilderTask>
<Message Importance="High" Text="Xcode: $(XcodeProjectPath)"/>
<Message Importance="High" Text="App: $(AppBundlePath)"/>
<Message Importance="High" Text="Xcode: $(XcodeProjectPath)" Condition="'$(GenerateXcodeProject)' == 'true'" />
<Message Importance="High" Text="App: $(AppBundlePath)" Condition="'$(GenerateXcodeProject)' == 'true'"/>

<ItemGroup>
<ItemGroup Condition="'$(GenerateXcodeProject)' == 'true'">
<_appFiles Include="$(AppBundlePath)/../**/*" />
</ItemGroup>

<Copy SourceFiles="@(_appFiles)"
DestinationFolder="$(TestArchiveTestsDir)/%(RecursiveDir)"
SkipUnchangedFiles="true"
Condition="'$(ArchiveTests)' == 'true' and '$(IgnoreForCI)' != 'true'" />
Condition="'$(ArchiveTests)' == 'true' and '$(IgnoreForCI)' != 'true' and '$(GenerateXcodeProject)' == 'true'" />

<RemoveDir Condition="'$(ArchiveTests)' == 'true' and '$(IgnoreForCI)' != 'true'"
Directories="$(OutDir)" />
Expand Down
3 changes: 3 additions & 0 deletions src/libraries/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@
<TestArchiveTestsDir>$(TestArchiveTestsRoot)$(OSPlatformConfig)/</TestArchiveTestsDir>
<TestArchiveRuntimeRoot>$(TestArchiveRoot)runtime/</TestArchiveRuntimeRoot>

<UseAppBundleRootForBuildingTests Condition="'$(ArchiveTests)' == 'true' and ('$(TargetOS)' == 'MacCatalyst' or '$(TargetOS)' == 'iOS' or '$(TargetOS)' == 'iOSSimulator' or '$(TargetOS)' == 'tvOS' or '$(TargetOS)' == 'tvOSSimulator')">true</UseAppBundleRootForBuildingTests>
<AppBundleRoot Condition="'$(UseAppBundleRootForBuildingTests)' == 'true'">$(ArtifactsDir)bundles\</AppBundleRoot>

<NetCoreAppCurrentRefPath>$([MSBuild]::NormalizeDirectory('$(ArtifactsBinDir)', 'ref', '$(NetCoreAppCurrent)'))</NetCoreAppCurrentRefPath>
<NetCoreAppCurrentRuntimePath>$([MSBuild]::NormalizeDirectory('$(ArtifactsBinDir)', 'runtime', '$(NetCoreAppCurrent)-$(TargetOS)-$(Configuration)-$(TargetArchitecture)'))</NetCoreAppCurrentRuntimePath>

Expand Down
79 changes: 79 additions & 0 deletions src/libraries/tests.proj
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,85 @@
Condition="'$(TestAssemblies)' == 'true' and
'$(Coverage)' == 'true'" />

<!-- Build Apple app bundles using AppBundleRoot -->
<UsingTask Condition="'$(UseAppBundleRootForBuildingTests)' == 'true'"
TaskName="XcodeCreateProject"
AssemblyFile="$(AppleAppBuilderTasksAssemblyPath)" />

<UsingTask Condition="'$(UseAppBundleRootForBuildingTests)' == 'true'"
TaskName="XcodeBuildApp"
AssemblyFile="$(AppleAppBuilderTasksAssemblyPath)" />

<Target Condition="'$(UseAppBundleRootForBuildingTests)' == 'true'"
Name="BuildAppleAppBundles"
AfterTargets="Build">

<PropertyGroup>
<!-- TODO: Unify this with TestArchiveTestsRoot in src/libraries/Directory.Build.props somehow,
we can't use IsFunctionalTest==true here because it is only set in the context of the .csproj -->
<TestArchiveNormalTestsRoot>$(TestArchiveRoot)tests/</TestArchiveNormalTestsRoot>
<TestArchiveFunctionalTestsRoot>$(TestArchiveRoot)runonly/</TestArchiveFunctionalTestsRoot>

<TestArchiveNormalTestsDir>$(TestArchiveNormalTestsRoot)$(OSPlatformConfig)/</TestArchiveNormalTestsDir>
<TestArchiveFunctionalTestsDir>$(TestArchiveFunctionalTestsRoot)$(OSPlatformConfig)/</TestArchiveFunctionalTestsDir>

<NormalTestsAppBundleRoot>$(AppBundleRoot)/tests/</NormalTestsAppBundleRoot>
<FunctionalTestsAppBundleRoot>$(AppBundleRoot)/runonly/</FunctionalTestsAppBundleRoot>

<NormalTestsAllAppBundlesRoot>$(AppBundleRoot)/tests.all/</NormalTestsAllAppBundlesRoot>
<FunctionalTestsAllAppBundlesRoot>$(AppBundleRoot)/runonly.all/</FunctionalTestsAllAppBundlesRoot>
</PropertyGroup>

<ItemGroup>
<NormalTestAppBundles Include="$(NormalTestsAppBundleRoot)*/AppBundle/CMakeLists.txt" />
<NormalTestCMakeEntries Include="cmake_minimum_required(VERSION 3.16)" />
<NormalTestCMakeEntries Include="project(NormalTestAppBundles)" />
<NormalTestCMakeEntries Include="add_subdirectory(%(NormalTestAppBundles.RootDir)%(NormalTestAppBundles.Directory) %(NormalTestAppBundles.RecursiveDir) EXCLUDE_FROM_ALL)" />

<FunctionalTestAppBundles Include="$(FunctionalTestsAppBundleRoot)*/AppBundle/CMakeLists.txt" />
<FunctionalTestCMakeEntries Include="cmake_minimum_required(VERSION 3.16)" />
<FunctionalTestCMakeEntries Include="project(FunctionalTestAppBundles)" />
<FunctionalTestCMakeEntries Include="add_subdirectory(%(FunctionalTestAppBundles.RootDir)%(FunctionalTestAppBundles.Directory) %(FunctionalTestAppBundles.RecursiveDir) EXCLUDE_FROM_ALL)" />
</ItemGroup>

<WriteLinesToFile File="$(NormalTestsAllAppBundlesRoot)CMakeLists.txt" Lines="@(NormalTestCMakeEntries)" Overwrite="true" WriteOnlyWhenDifferent="true" />
<WriteLinesToFile File="$(FunctionalTestsAllAppBundlesRoot)CMakeLists.txt" Lines="@(FunctionalTestCMakeEntries)" Overwrite="true" WriteOnlyWhenDifferent="true" />

<XcodeCreateProject
TargetOS="$(TargetOS)"
Arch="$(TargetArchitecture)"
ProjectName="NormalTestAppBundles"
CMakeListsDirectory="$(NormalTestsAllAppBundlesRoot)"
Condition="'@(NormalTestAppBundles)' != ''" />

<XcodeCreateProject
TargetOS="$(TargetOS)"
Arch="$(TargetArchitecture)"
ProjectName="FunctionalTestAppBundles"
CMakeListsDirectory="$(FunctionalTestsAllAppBundlesRoot)"
Condition="'@(FunctionalTestAppBundles)' != ''" />

<MakeDir Directories="$(TestArchiveNormalTestsDir)" />
<MakeDir Directories="$(TestArchiveFunctionalTestsDir)" />

<ItemGroup>
<!-- xcodeproj are directories, not files -->
<XcodeProjects Condition="'@(NormalTestAppBundles)' != ''" Include="$([System.IO.Directory]::GetDirectories('$(NormalTestsAllAppBundlesRoot)NormalTestAppBundles/%(NormalTestAppBundles.RecursiveDir)', '*.xcodeproj'))" DestinationFolder="$(TestArchiveNormalTestsDir)" />
<XcodeProjects Condition="'@(FunctionalTestAppBundles)' != ''" Include="$([System.IO.Directory]::GetDirectories('$(FunctionalTestsAllAppBundlesRoot)FunctionalTestAppBundles/%(FunctionalTestAppBundles.RecursiveDir)', '*.xcodeproj'))" DestinationFolder="$(TestArchiveFunctionalTestsDir)" />
</ItemGroup>

<XcodeBuildApp
TargetOS="$(TargetOS)"
Arch="$(TargetArchitecture)"
XcodeProjectPath="%(XcodeProjects.Identity)"
DevTeamProvisioning="$(DevTeamProvisioning)"
Optimized="True"
DestinationFolder="%(XcodeProjects.DestinationFolder)" />

<RemoveDir Condition="'$(ArchiveTests)' == 'true'"
Directories="$(AppBundleRoot)" />
</Target>

<!-- Restoring all trimming test projects upfront in one single call to RestoreTrimmingProjects
so as to avoid possible race conditions that could happen if we restore each individually. -->
<Target Name="RestoreTrimmingProjects"
Expand Down
24 changes: 16 additions & 8 deletions src/tasks/AppleAppBuilder/AppleAppBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class AppleAppBuilderTask : Task
private string targetOS = TargetNames.iOS;

/// <summary>
/// The Apple OS we are targeting (iOS or tvOS)
/// The Apple OS we are targeting (ios, tvos, iossimulator, tvossimulator)
/// </summary>
[Required]
public string TargetOS
Expand Down Expand Up @@ -64,7 +64,7 @@ public string TargetOS
public ITaskItem[] Assemblies { get; set; } = Array.Empty<ITaskItem>();

/// <summary>
/// Target arch, can be "arm64" (device) or "x64" (simulator) at the moment
/// Target arch, can be "arm64", "arm" or "x64" at the moment
/// </summary>
[Required]
public string Arch { get; set; } = ""!;
Expand Down Expand Up @@ -106,6 +106,11 @@ public string TargetOS
/// </summary>
public bool GenerateXcodeProject { get; set; }

/// <summary>
/// Generate CMake project
/// </summary>
public bool GenerateCMakeProject { get; set; }

/// <summary>
/// Files to be ignored in AppDir
/// </summary>
Expand Down Expand Up @@ -224,14 +229,12 @@ public override bool Execute()
throw new ArgumentException("Using DiagnosticPorts require diagnostics_tracing runtime component.");
}

var generator = new Xcode(Log, TargetOS, Arch);

if (GenerateXcodeProject)
{
Xcode generator = new Xcode(Log, TargetOS, Arch);
generator.EnableRuntimeLogging = EnableRuntimeLogging;
generator.DiagnosticPorts = DiagnosticPorts;

XcodeProjectPath = generator.GenerateXCode(ProjectName, MainLibraryFileName, assemblerFiles, assemblerFilesToLink,
AppDir, binDir, MonoRuntimeHeaders, !isDevice, UseConsoleUITemplate, ForceAOT, ForceInterpreter, InvariantGlobalization, Optimized, RuntimeComponents, NativeMainSource);
AppDir, binDir, MonoRuntimeHeaders, !isDevice, UseConsoleUITemplate, ForceAOT, ForceInterpreter, InvariantGlobalization, Optimized, EnableRuntimeLogging, DiagnosticPorts, RuntimeComponents, NativeMainSource);

if (BuildAppBundle)
{
Expand All @@ -242,10 +245,15 @@ public override bool Execute()
}
else
{
AppBundlePath = generator.BuildAppBundle(XcodeProjectPath, Arch, Optimized, DevTeamProvisioning);
AppBundlePath = generator.BuildAppBundle(XcodeProjectPath, Optimized, DevTeamProvisioning);
}
}
}
else if (GenerateCMakeProject)
{
generator.GenerateCMake(ProjectName, MainLibraryFileName, assemblerFiles, assemblerFilesToLink,
AppDir, binDir, MonoRuntimeHeaders, !isDevice, UseConsoleUITemplate, ForceAOT, ForceInterpreter, InvariantGlobalization, Optimized, EnableRuntimeLogging, DiagnosticPorts, RuntimeComponents, NativeMainSource);
}

return true;
}
Expand Down
Loading

0 comments on commit 0becd27

Please sign in to comment.