Skip to content

Commit

Permalink
Added manually defined required compilations constants (CommunityTool…
Browse files Browse the repository at this point in the history
…kit#208)

* Moved project identifiers into a new props file

* Moved project identifiers into a new props file

* Merge branch 'fix/compilation-conditionals' of https://github.com/CommunityToolkit/Labs-Windows into fix/compilation-conditionals

* Added WINUI2 and WINUI3 compilation conditionals

* Added platform-specific compilation conditionals

* Added comment for props modified by script

* Added __SKIA__ compilation conditional

* Added Labs.ProjectIdentifiers.props import

* Fixed ProjectIdentifiers on project heads

* Fixed incorrect IsUno value

* Fixed BindableMetadataProvider error on WPF
  • Loading branch information
Arlodotexe authored Jul 20, 2022
1 parent 899dfef commit ad101af
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 39 deletions.
10 changes: 5 additions & 5 deletions Labs.Head.Wasm.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
Because of this, this file must be import immediately after defining all other constant values.
-->
<PropertyGroup>
<IsGtkHead>False</IsGtkHead>
<IsWpfHead>False</IsWpfHead>
<IsWpfLib>False</IsWpfLib>
<IsWasmHead>True</IsWasmHead>
<IsWasmLib>False</IsWasmLib>
<IsGtkHead>false</IsGtkHead>
<IsWpfHead>false</IsWpfHead>
<IsWpfLib>false</IsWpfLib>
<IsWasmHead>true</IsWasmHead>
<IsWasmLib>false</IsWasmLib>
</PropertyGroup>

<!-- Labs Platform Config -->
Expand Down
2 changes: 1 addition & 1 deletion Labs.Head.WinAppSdk.props
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<PublishProfile>win10-$(Platform).pubxml</PublishProfile>
<UseWinUI>true</UseWinUI>
<EnablePreviewMsixTooling>true</EnablePreviewMsixTooling>
<DefineConstants>WINAPPSDK;WINDOWS_WINAPPSDK</DefineConstants>
<DefineConstants>$(DefineConstants);WINAPPSDK;WINDOWS_WINAPPSDK;</DefineConstants>
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>

Expand Down
40 changes: 40 additions & 0 deletions Labs.ProjectIdentifiers.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<Project>
<PropertyGroup>
<IsWasmHead Condition="'$(IsWasmHead)' == '' AND '$(TargetFramework)' == '$(WasmHeadTargetFramework)'">true</IsWasmHead>
<IsWpfHead Condition="'$(IsWpfHead)' == '' AND '$(TargetFramework)' == '$(WpfHeadTargetFramework)'">true</IsWpfHead>
<IsGtkHead Condition="'$(IsGtkHead)' == '' AND '$(TargetFramework)' == '$(LinuxHeadTargetFramework)'">true</IsGtkHead>

<IsWasmLib Condition="'$(IsWasmLib)' == '' AND '$(TargetFramework)' == '$(WasmLibTargetFramework)'">true</IsWasmLib>
<IsWpfLib Condition="'$(IsWpfLib)' == '' AND '$(TargetFramework)' == '$(WpfLibTargetFramework)'">true</IsWpfLib>
<IsGtkLib Condition="'$(IsGtkLib)' == '' AND '$(TargetFramework)' == '$(LinuxLibTargetFramework)'">true</IsGtkLib>

<IsWasm Condition="'$(IsWasm)' == '' AND ('$(IsWasmHead)' == 'true' or '$(IsWasmLib)' == 'true')">true</IsWasm>
<IsWpf Condition="'$(IsWpf)' == '' AND ('$(IsWpfHead)' == 'true' or '$(IsWpfLib)' == 'true')">true</IsWpf>
<IsGtk Condition="'$(IsGtk)' == '' AND ('$(IsGtkHead)' == 'true' or '$(IsGtkLib)' == 'true')">true</IsGtk>

<IsDroid Condition="'$(IsDroid)' == '' AND '$(TargetFramework)' == '$(AndroidLibTargetFramework)'">true</IsDroid>
<IsMacOS Condition="'$(IsMacOS)' == '' AND '$(TargetFramework)' == '$(MacOSLibTargetFramework)'">true</IsMacOS>
<IsiOS Condition="'$(IsiOS)' == '' AND '$(TargetFramework)' == '$(iOSLibTargetFramework)'">true</IsiOS>

<IsUwp Condition="'$(IsUwp)' == '' AND '$(TargetFramework)' == '$(UwpTargetFramework)'">true</IsUwp>
<IsWinAppSdk Condition="'$(IsWinAppSdk)' == '' AND '$(TargetFramework)' == '$(WinAppSdkTargetFramework)'">true</IsWinAppSdk>

<IsUno Condition="'$(IsWasm)' == 'true' OR '$(IsWpf)' == 'true' OR '$(IsGtk)' == 'true' OR '$(IsDroid)' == 'true' OR '$(IsMacOS)' == 'true' OR '$(IsiOS)' == 'true'">true</IsUno>

<!-- THIS AREA MODIFIED BY SCRIPTS -->
<PackageIdVariant>Uwp</PackageIdVariant>
<WinUIMajorVersion>2</WinUIMajorVersion>
<DefineConstants Condition="'$(IsUno)' == 'true'">$(DefineConstants);WINUI2;</DefineConstants>
<!-- END SCRIPT AREA -->

<DefineConstants Condition="'$(IsUno)' == 'true'">$(DefineConstants);HAS_UNO;</DefineConstants>
<DefineConstants Condition="'$(IsUwp)' == 'true'">$(DefineConstants);WINDOWS_UWP;NETFX_CORE;</DefineConstants>
<DefineConstants Condition="'$(IsWinAppSdk)' == 'true'">$(DefineConstants);WINDOWS_WINAPPSDK;</DefineConstants>
<DefineConstants Condition="'$(IsWasm)' == 'true'">$(DefineConstants);__WASM__;HAS_UNO_WASM;</DefineConstants>
<DefineConstants Condition="'$(IsDroid)' == 'true'">$(DefineConstants);__ANDROID__;</DefineConstants>
<DefineConstants Condition="'$(IsiOS)' == 'true'">$(DefineConstants);__IOS__;</DefineConstants>
<DefineConstants Condition="'$(IsMacOS)' == 'true'">$(DefineConstants);__MACOS__;</DefineConstants>
<DefineConstants Condition="'$(IsWpf)' == 'true'">$(DefineConstants);HAS_UNO_SKIA;__SKIA__;WINDOWS_WPF;</DefineConstants>
<DefineConstants Condition="'$(IsGtk)' == 'true'">$(DefineConstants);HAS_UNO_SKIA;__SKIA__;__GTK__;</DefineConstants>
</PropertyGroup>
</Project>
28 changes: 0 additions & 28 deletions Labs.Uno.props
Original file line number Diff line number Diff line change
@@ -1,34 +1,6 @@
<Project>
<!-- This file is modified by common/Scripts/UseUnoWinUI.ps1 to switch between WinUI 2 and 3 under Uno Platform -->
<!-- All Uno-based heads and multitargeted library projects reference this file, while native (UWP/WinAppSdk) heads don't and shouldn't need to. -->
<PropertyGroup>
<IsWasmHead Condition="'$(IsWasmHead)' == '' AND '$(TargetFramework)' == '$(WasmHeadTargetFramework)'">true</IsWasmHead>
<IsWpfHead Condition="'$(IsWpfHead)' == '' AND '$(TargetFramework)' == '$(WpfHeadTargetFramework)'">true</IsWpfHead>
<IsGtkHead Condition="'$(IsGtkHead)' == '' AND '$(TargetFramework)' == '$(LinuxHeadTargetFramework)'">true</IsGtkHead>

<IsWasmLib Condition="'$(IsWasmLib)' == '' AND '$(TargetFramework)' == '$(WasmLibTargetFramework)'">true</IsWasmLib>
<IsWpfLib Condition="'$(IsWpfLib)' == '' AND '$(TargetFramework)' == '$(WpfLibTargetFramework)'">true</IsWpfLib>
<IsGtkLib Condition="'$(IsGtkLib)' == '' AND '$(TargetFramework)' == '$(LinuxLibTargetFramework)'">true</IsGtkLib>

<IsWasm Condition="'$(IsWasm)' == '' AND ('$(IsWasmHead)' == 'true' or '$(IsWasmLib)' == 'true')">true</IsWasm>
<IsWpf Condition="'$(IsWpf)' == '' AND ('$(IsWpfHead)' == 'true' or '$(IsWpfLib)' == 'true')">true</IsWpf>
<IsGtk Condition="'$(IsGtk)' == '' AND ('$(IsGtkHead)' == 'true' or '$(IsGtkLib)' == 'true')">true</IsGtk>

<IsDroid Condition="'$(IsDroid)' == '' AND '$(TargetFramework)' == '$(AndroidLibTargetFramework)'">true</IsDroid>
<IsMacOS Condition="'$(IsMacOS)' == '' AND '$(TargetFramework)' == '$(MacOSLibTargetFramework)'">true</IsMacOS>
<IsiOS Condition="'$(IsiOS)' == '' AND '$(TargetFramework)' == '$(iOSLibTargetFramework)'">true</IsiOS>

<IsUwp Condition="'$(IsUwp)' == '' AND '$(TargetFramework)' == '$(UwpTargetFramework)'">true</IsUwp>
<IsWinAppSdk Condition="'$(IsWinAppSdk)' == '' AND '$(TargetFramework)' == '$(WinAppSdkTargetFramework)'">true</IsWinAppSdk>

<IsUno Condition="'$(IsWasm)' == 'true' OR '$(IsWpf)' == 'true' OR '$(IsGtk)' == 'true' OR '$(IsDroid)' == 'true' OR '$(IsMacOS)' == 'true' OR '$(IsiOS)' == 'true'">true</IsUno>

<DefineConstants Condition="'$(IsUno)' == 'true'">$(DefineConstants);</DefineConstants>

<PackageIdVariant>Uwp</PackageIdVariant>
<WinUIMajorVersion>2</WinUIMajorVersion>
</PropertyGroup>

<ItemGroup Condition="'$(IsUno)' == 'true'">
<PackageReference Include="Uno.UI" Version="4.2.6" />
</ItemGroup>
Expand Down
15 changes: 10 additions & 5 deletions Scripts/UseUnoWinUI.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Param (
[ValidateSet('2', '3')]
[string]$winUIMajorVersion,

[Parameter(HelpMessage = "Disables suppressing changes to the Labs.Uno.props and Labs.Head.Uno.props files in git, allowing changes to be committed.")]
[Parameter(HelpMessage = "Disables suppressing changes to the affected files in git, allowing changes to be committed.")]
[switch]$allowGitChanges = $false
)

Expand All @@ -29,22 +29,27 @@ function ApplyWinUISwap([string] $filePath) {
$fileContents = $fileContents -replace '<WinUIMajorVersion>2</WinUIMajorVersion>', '<WinUIMajorVersion>3</WinUIMajorVersion>';
$fileContents = $fileContents -replace '<PackageIdVariant>Uwp</PackageIdVariant>', '<PackageIdVariant>WinUI</PackageIdVariant>';
$fileContents = $fileContents -replace 'Uno.UI', 'Uno.WinUI';
$fileContents = $fileContents -replace '\$\(DefineConstants\);', '$(DefineConstants);WINAPPSDK;';

$fileContents = $fileContents -replace '\$\(DefineConstants\);WINUI2;', '$(DefineConstants);WINUI3;WINAPPSDK;';
}

if ($winUIMajorVersion -eq "2") {
$fileContents = $fileContents -replace '<WinUIMajorVersion>3</WinUIMajorVersion>', '<WinUIMajorVersion>2</WinUIMajorVersion>';
$fileContents = $fileContents -replace '<PackageIdVariant>WinUI</PackageIdVariant>', '<PackageIdVariant>Uwp</PackageIdVariant>';
$fileContents = $fileContents -replace 'Uno.WinUI', 'Uno.UI';
$fileContents = $fileContents -replace 'WINAPPSDK;', '';

$fileContents = $fileContents -replace '\$\(DefineConstants\);WINUI3;WINAPPSDK;', '$(DefineConstants);WINUI2;';
}

Set-Content -Force -Path $filePath -Value $fileContents;
Write-Output "Updated $(Resolve-Path -Relative $filePath)"
}

Write-Output "Switching to WinUI $winUIMajorVersion";

ApplyWinUISwap $PSScriptRoot/../Labs.Head.Uno.props
ApplyWinUISwap $PSScriptRoot/../Labs.Uno.props
ApplyWinUISwap $PSScriptRoot\..\Labs.Head.Uno.props
ApplyWinUISwap $PSScriptRoot\..\Labs.Uno.props
ApplyWinUISwap $PSScriptRoot\..\Labs.ProjectIdentifiers.props

if ($allowGitChanges.IsPresent) {
Write-Warning "Changes to the default Uno package settings in Labs can now be committed.`r`nRun this command again without -allowGitChanges to disable committing further changes.";
Expand Down

0 comments on commit ad101af

Please sign in to comment.