Skip to content

Commit

Permalink
[release/6.0] Create a parent CMake project for building app bundles …
Browse files Browse the repository at this point in the history
…on CI (#59154)

Backport of #58965 to release/6.0

This allows us to not run the CMake configure step separately for each libraries test suite which speeds up the build.

Helps with #58549
  • Loading branch information
github-actions[bot] committed Oct 21, 2021
1 parent 8da5835 commit de75159
Show file tree
Hide file tree
Showing 7 changed files with 340 additions and 84 deletions.
46 changes: 44 additions & 2 deletions eng/pipelines/runtime-staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,10 @@ jobs:
buildConfig: Release
runtimeFlavor: mono
platforms:
- MacCatalyst_x64
- iOSSimulator_x64
- tvOSSimulator_x64
# don't run tests on arm64 PRs until we can get significantly more devices
- ${{ if eq(variables['isFullMatrix'], true) }}:
- MacCatalyst_arm64
- iOSSimulator_arm64
variables:
# map dependencies variables to local variables
Expand Down Expand Up @@ -101,6 +99,50 @@ jobs:
eq(variables['monoContainsChange'], true),
eq(variables['isFullMatrix'], true))
#
# MacCatalyst interp - requires AOT Compilation and Interp flags
# Build the whole product using Mono and run libraries tests
#
- template: /eng/pipelines/common/platform-matrix.yml
parameters:
jobTemplate: /eng/pipelines/common/global-build-job.yml
helixQueuesTemplate: /eng/pipelines/libraries/helix-queues-setup.yml
buildConfig: Release
runtimeFlavor: mono
platforms:
- MacCatalyst_x64
# don't run tests on arm64 PRs until we can get significantly more devices
- ${{ if eq(variables['isFullMatrix'], true) }}:
- MacCatalyst_arm64
variables:
# map dependencies variables to local variables
- name: librariesContainsChange
value: $[ dependencies.evaluate_paths.outputs['SetPathVars_libraries.containsChange'] ]
- name: monoContainsChange
value: $[ dependencies.evaluate_paths.outputs['SetPathVars_mono.containsChange'] ]
jobParameters:
testGroup: innerloop
nameSuffix: AllSubsets_Mono
buildArgs: -s mono+libs+host+packs+libs.tests -c $(_BuildConfig) /p:ArchiveTests=true /p:DevTeamProvisioning=adhoc /p:RunAOTCompilation=true /p:MonoForceInterpreter=true /p:BuildDarwinFrameworks=true
timeoutInMinutes: 180
condition: >-
or(
eq(dependencies.evaluate_paths.outputs['SetPathVars_libraries.containsChange'], true),
eq(dependencies.evaluate_paths.outputs['SetPathVars_mono.containsChange'], true),
eq(dependencies.evaluate_paths.outputs['SetPathVars_installer.containsChange'], true),
eq(variables['isFullMatrix'], true))
# extra steps, run tests
extraStepsTemplate: /eng/pipelines/libraries/helix.yml
extraStepsParameters:
creator: dotnet-bot
interpreter: true
testRunNamePrefixSuffix: Mono_$(_BuildConfig)
condition: >-
or(
eq(variables['librariesContainsChange'], true),
eq(variables['monoContainsChange'], true),
eq(variables['isFullMatrix'], true))
#
# Build the whole product using Mono and run libraries tests
#
Expand Down
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
29 changes: 16 additions & 13 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 @@ -157,6 +160,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 @@ -214,34 +221,30 @@
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'" />

<RemoveDir Condition="'$(ArchiveTests)' == 'true' and '$(IgnoreForCI)' != 'true'" Directories="$(AppBundlePath)" />
<ItemGroup>
<_removeFiles Include="$(OutDir)*.*" />
</ItemGroup>
Condition="'$(ArchiveTests)' == 'true' and '$(IgnoreForCI)' != 'true' and '$(GenerateXcodeProject)' == 'true'" />

<Delete Condition="'$(ArchiveTests)' == 'true' and '$(IgnoreForCI)' != 'true' and '$(OutDir)' != ''" Files="@(_removeFiles)" />
<RemoveDir Condition="'$(ArchiveTests)' == 'true' and '$(IgnoreForCI)' != 'true'" Directories="$(PublishDir)" />
<RemoveDir Condition="'$(ArchiveTests)' == 'true' and '$(IgnoreForCI)' != 'true'"
Directories="$(OutDir)" />
</Target>

<!-- This .targets file is also imported by the runtime Trimming tests, and we want to be able to manually configure trimming in them so this
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 @@ -326,6 +326,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 de75159

Please sign in to comment.