diff options
author | Miguel Costa <miguel.costa@qt.io> | 2023-11-23 12:52:58 +0100 |
---|---|---|
committer | Miguel Costa <miguel.costa@qt.io> | 2023-11-28 09:49:38 +0000 |
commit | 39410db954214362df676ef6ec1e27c706fc58e6 (patch) | |
tree | 113f6499cbf0727727291f450c29ee4ad1e040e4 | |
parent | 4f4ac12608fa95e3f241cad0d2fc9e06d82acc62 (diff) |
Allow late-binding of Qt/MSBuild properties
The QtDeployDir property is now defined as late-bound to $(OutDir).
Change-Id: I5a596722aced3490760443b5b2f944e2dfc83ddd
Reviewed-by: Karsten Heimrich <karsten.heimrich@qt.io>
-rw-r--r-- | QtMSBuild/QtMsBuild/deploy/qtdeploy.props | 4 | ||||
-rw-r--r-- | QtMSBuild/QtMsBuild/qt_defaults.props | 34 | ||||
-rw-r--r-- | QtMSBuild/QtMsBuild/qt_settings.xml | 8 | ||||
-rw-r--r-- | QtMSBuild/QtMsBuild/qt_vars.targets | 11 | ||||
-rw-r--r-- | Tests/Test_QtMsBuild.Build/Test_LateBinding.cs | 69 | ||||
-rw-r--r-- | Tests/Test_QtMsBuild.Build/Test_QtMsBuild.Build.csproj | 1 |
6 files changed, 125 insertions, 2 deletions
diff --git a/QtMSBuild/QtMsBuild/deploy/qtdeploy.props b/QtMSBuild/QtMsBuild/deploy/qtdeploy.props index e08c1b00..02d60151 100644 --- a/QtMSBuild/QtMsBuild/deploy/qtdeploy.props +++ b/QtMSBuild/QtMsBuild/deploy/qtdeploy.props @@ -24,7 +24,9 @@ <QtDeployDir Condition="'$(QtDeployDir)' == '' AND '$(QtDeployToProjectDir)' == 'true'" >$(ProjectDir)</QtDeployDir> <QtDeployDir Condition="'$(QtDeployDir)' == '' AND '$(QtDeployToProjectDir)' != 'true'" - >$(OutDir)</QtDeployDir> + >@(Qt->'%(OutDir)')</QtDeployDir> + <QtDeployQmlDir Condition="'$(QtDeployQmlDir)' == ''" + >$(ProjectDir)</QtDeployQmlDir> <QtDeployDebugRelease Condition="'$(QtDeployDebugRelease)' == ''" >false</QtDeployDebugRelease> <QtDeployPdb Condition="'$(QtDeployPdb)' == ''" diff --git a/QtMSBuild/QtMsBuild/qt_defaults.props b/QtMSBuild/QtMsBuild/qt_defaults.props index 383db511..091b4f99 100644 --- a/QtMSBuild/QtMsBuild/qt_defaults.props +++ b/QtMSBuild/QtMsBuild/qt_defaults.props @@ -96,6 +96,40 @@ <QtModules Condition="'$(QtModules)' == ''">core</QtModules> </PropertyGroup> + <!--// Default late bindings --> + <ItemGroup> + <Qt Include="Qt"> + <IntDir>$(IntDir)</IntDir> + <OutDir>$(OutDir)</OutDir> + </Qt> + <QtLateBindings Include="IntDir" /> + <QtLateBindings Include="OutDir" /> + <QtLateBindings Include="QtInstall" /> + <QtLateBindings Include="QtModules" /> + <QtLateBindings Include="QtPlugin" /> + <QtLateBindings Include="QtBuildConfig" /> + <QtLateBindings Include="QtToolsDesignTime" /> + <QtLateBindings Include="QtPathBinaries" /> + <QtLateBindings Include="QtPathLibraryExecutables" /> + <QtLateBindings Include="QtHeaderSearchPath" /> + <QtLateBindings Include="QtLibrarySearchPath" /> + <QtLateBindings Include="QtQMakeTemplate" /> + <QtLateBindings Include="QtVars" /> + <QtLateBindings Include="QMakeExtraArgs" /> + <QtLateBindings Include="QMakeCodeLines" /> + <QtLateBindings Include="QtQMLDebugEnable" /> + <QtLateBindings Include="Qt_CL_OPTIONS_" /> + <QtLateBindings Include="QtExcludedOptions" /> + <QtLateBindings Include="QtOptionsBuildLog" /> + <QtLateBindings Include="QtLinkNatvisFile" /> + <QtLateBindings Include="QtInstallDir" /> + <QtLateBindings Include="QtToolsPath" /> + <QtLateBindings Include="QtDllPath" /> + </ItemGroup> + <PropertyGroup> + <QtLateBindings Condition="'$(QtLateBindings)' == ''">@(QtLateBindings)</QtLateBindings> + </PropertyGroup> + <!-- ///////////////////////////////////////////////////////////////////////////////////////////////// // Read subfolder dependencies (qt_import.props) diff --git a/QtMSBuild/QtMsBuild/qt_settings.xml b/QtMSBuild/QtMsBuild/qt_settings.xml index 012e8425..7a115f41 100644 --- a/QtMSBuild/QtMsBuild/qt_settings.xml +++ b/QtMSBuild/QtMsBuild/qt_settings.xml @@ -22,6 +22,7 @@ <Category Name="QtSettings_04_QML" DisplayName="QML"/> <Category Name="QtSettings_05_AdditionalOptions" DisplayName="Qt Additional Compiler Options"/> <Category Name="QtSettings_06_AdditionalLinkOptions" DisplayName="Qt Additional Linker Options"/> + <Category Name="QtSettings_07_LateBindings" DisplayName="Qt Settings Late Bindings"/> </Rule.Categories> <EnumProperty Name="Keyword" @@ -167,4 +168,9 @@ files located in %USERPROFILE%\\Documents\\Visual Studio 2022\\Visualizers)."> <EnumValue Name="false" DisplayName="No" /> <EnumValue Name="true" DisplayName="Yes" /> </EnumProperty> - </Rule> + <StringListProperty + Name="QtLateBindings" + Category="QtSettings_07_LateBindings" + DisplayName="Property Names" + Description="Names of properties available for late bindings."/> +</Rule> diff --git a/QtMSBuild/QtMsBuild/qt_vars.targets b/QtMSBuild/QtMsBuild/qt_vars.targets index efb44b72..4ddf1786 100644 --- a/QtMSBuild/QtMsBuild/qt_vars.targets +++ b/QtMSBuild/QtMsBuild/qt_vars.targets @@ -501,6 +501,11 @@ DummyQmlObject { } <QtBuildConfig Include="$(QtCleaned_QtBuildConfig)"/> </ItemGroup> + <!--// Late bindings --> + <ItemGroup> + <QtLateBind Include="$(QtLateBindings)"/> + </ItemGroup> + <!--// Write end of .props (XML) file // * Add Qt tools output directories to include path // * Save settings backup @@ -538,6 +543,12 @@ DummyQmlObject { } <QtVersionMinor>$(QtVersionMinor)</QtVersionMinor> <QtVersionPatch>$(QtVersionPatch)</QtVersionPatch> </PropertyGroup> + <ItemGroup> + <Qt Remove="@(Qt)"/> + <Qt Include="Qt"> +@(QtLateBind->' %3C%(Identity)%3E%24%28%(Identity)%29%3C/%(Identity)%3E','%0D%0A') + </Qt> + </ItemGroup> </Project> ]]> </QtVarsDataFileText> diff --git a/Tests/Test_QtMsBuild.Build/Test_LateBinding.cs b/Tests/Test_QtMsBuild.Build/Test_LateBinding.cs new file mode 100644 index 00000000..b1a3db36 --- /dev/null +++ b/Tests/Test_QtMsBuild.Build/Test_LateBinding.cs @@ -0,0 +1,69 @@ +/*************************************************************************************************** + Copyright (C) 2023 The Qt Company Ltd. + SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only +***************************************************************************************************/ + +using System; +using System.IO; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.Build.Construction; + +namespace QtVsTools.Test.QtMsBuild.Build +{ + [TestClass] + public class Test_LateBinding + { + [TestMethod] + public void Concept() + { + using var temp = new TempProject(); + temp.Create(@" +<?xml version=""1.0"" encoding=""utf-8""?> +<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""> + <ItemGroup> + <Eval Include=""LateBinding""> + <X>$(X)</X> + </Eval> + </ItemGroup> + <PropertyGroup> + <X>The quick brown fox</X> + <Y>$(X) jumped over the lazy dog.</Y> + <Z>@(Eval->'%(X)') jumped over the lazy dog.</Z> + <X>The sleek gray wolf</X> + </PropertyGroup> +</Project>".Trim()); + + var project = MsBuild.Evaluate(temp.ProjectPath); + Assert.AreEqual( + project.ExpandString("$(X)"), "The sleek gray wolf"); + Assert.AreEqual( + project.ExpandString("$(Y)"), "The quick brown fox jumped over the lazy dog."); + Assert.AreEqual( + project.ExpandString("$(Z)"), "The sleek gray wolf jumped over the lazy dog."); + } + + [TestMethod] + public void QtDeployDir() + { + using TempProject temp = new(); + temp.Clone($@"{Properties.SolutionDir}Tests\ProjectFormats\304\QtProjectV304.vcxproj"); + + var project = MsBuild.Evaluate(temp.ProjectPath, ("Platform", "x64"), + ("QtMsBuild", Path.Combine(Environment.CurrentDirectory, "QtMsBuild"))); + Assert.AreEqual( + project.ExpandString("$(QtDeployDir)"), project.ExpandString("$(OutDir)"), + ignoreCase: true); + + var xml = ProjectRootElement.Open(temp.ProjectPath); + var props = xml.AddPropertyGroup(); + props.AddProperty("OutDir", @$"{temp.ProjectDir}\out\"); + xml.Save(); + + project = MsBuild.Evaluate(temp.ProjectPath, ("Platform", "x64"), + ("QtMsBuild", Path.Combine(Environment.CurrentDirectory, "QtMsBuild"))); + Assert.AreEqual( + project.ExpandString("$(QtDeployDir)"), project.ExpandString("$(OutDir)"), + ignoreCase: true); + } + } +} diff --git a/Tests/Test_QtMsBuild.Build/Test_QtMsBuild.Build.csproj b/Tests/Test_QtMsBuild.Build/Test_QtMsBuild.Build.csproj index f09df206..c81bb0f7 100644 --- a/Tests/Test_QtMsBuild.Build/Test_QtMsBuild.Build.csproj +++ b/Tests/Test_QtMsBuild.Build/Test_QtMsBuild.Build.csproj @@ -110,6 +110,7 @@ <Compile Include="Props.cs" /> <Compile Include="Logger.cs" /> <Compile Include="MsBuild.cs" /> + <Compile Include="Test_LateBinding.cs" /> <Compile Include="Test_Eval.cs" /> <Compile Include="Test_Build.cs" /> </ItemGroup> |