-
Notifications
You must be signed in to change notification settings - Fork 948
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/msbuild toolchain generator #7754
Changes from 14 commits
9002d45
e033754
32bfb9c
d77f4d1
d73f574
806f7ce
56a740f
d48a530
b81831b
b6ed353
5561282
2844575
a1b8093
d86459c
b673c53
eccf622
310fc41
ab6f3b0
413e2db
841fd77
0a3bbe5
3fa5b7a
b8263f2
8228222
46bad5c
1a932e2
47fd550
f90ef50
de7e50c
f5488ac
2724244
7be4ea6
06e3785
172ae6f
db535dd
cee39aa
7ca8469
9cfc235
76f0dab
8791b8e
6f94959
a1747f5
1f1d742
d0f1a2d
625f8e2
c85dc25
882e0e8
bfcd4dd
e66563c
98db92c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
import os | ||
import platform | ||
import shutil | ||
import textwrap | ||
import unittest | ||
|
||
|
||
from conans.client.tools import chdir | ||
from conans.util.files import mkdir | ||
from conans.client.tools import vs_installation_path | ||
from conans.test.utils.tools import TestClient | ||
|
||
|
@@ -21,16 +24,10 @@ | |
Debug|x86 = Debug|x86 | ||
Release|x64 = Release|x64 | ||
Release|x86 = Release|x86 | ||
ReleaseShared|x64 = ReleaseShared|x64 | ||
ReleaseShared|x86 = ReleaseShared|x86 | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{6F392A05-B151-490C-9505-B2A49720C4D9}.Debug|x64.ActiveCfg = Debug|x64 | ||
{6F392A05-B151-490C-9505-B2A49720C4D9}.Debug|x64.Build.0 = Debug|x64 | ||
{6F392A05-B151-490C-9505-B2A49720C4D9}.Debug|x86.ActiveCfg = Debug|Win32 | ||
{6F392A05-B151-490C-9505-B2A49720C4D9}.Debug|x86.Build.0 = Debug|Win32 | ||
{6F392A05-B151-490C-9505-B2A49720C4D9}.Release|x64.ActiveCfg = Release|x64 | ||
{6F392A05-B151-490C-9505-B2A49720C4D9}.Release|x64.Build.0 = Release|x64 | ||
{6F392A05-B151-490C-9505-B2A49720C4D9}.Release|x86.ActiveCfg = Release|Win32 | ||
{6F392A05-B151-490C-9505-B2A49720C4D9}.Release|x86.Build.0 = Release|Win32 | ||
{B58316C0-C78A-4E9B-AE8F-5D6368CE3840}.Debug|x64.ActiveCfg = Debug|x64 | ||
{B58316C0-C78A-4E9B-AE8F-5D6368CE3840}.Debug|x64.Build.0 = Debug|x64 | ||
{B58316C0-C78A-4E9B-AE8F-5D6368CE3840}.Debug|x86.ActiveCfg = Debug|Win32 | ||
|
@@ -39,6 +36,11 @@ | |
{B58316C0-C78A-4E9B-AE8F-5D6368CE3840}.Release|x64.Build.0 = Release|x64 | ||
{B58316C0-C78A-4E9B-AE8F-5D6368CE3840}.Release|x86.ActiveCfg = Release|Win32 | ||
{B58316C0-C78A-4E9B-AE8F-5D6368CE3840}.Release|x86.Build.0 = Release|Win32 | ||
{B58316C0-C78A-4E9B-AE8F-5D6368CE3840}.ReleaseShared|x64.ActiveCfg = ReleaseShared|x64 | ||
{B58316C0-C78A-4E9B-AE8F-5D6368CE3840}.ReleaseShared|x64.Build.0 = ReleaseShared|x64 | ||
{B58316C0-C78A-4E9B-AE8F-5D6368CE3840}.ReleaseShared|x86.ActiveCfg = ReleaseShared|Win32 | ||
{B58316C0-C78A-4E9B-AE8F-5D6368CE3840}.ReleaseShared|x86.Build.0 = ReleaseShared|Win32 | ||
|
||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
|
@@ -58,6 +60,14 @@ | |
<Configuration>Debug</Configuration> | ||
<Platform>Win32</Platform> | ||
</ProjectConfiguration> | ||
<ProjectConfiguration Include="ReleaseShared|Win32"> | ||
<Configuration>ReleaseShared</Configuration> | ||
<Platform>Win32</Platform> | ||
</ProjectConfiguration> | ||
<ProjectConfiguration Include="ReleaseShared|x64"> | ||
<Configuration>ReleaseShared</Configuration> | ||
<Platform>x64</Platform> | ||
</ProjectConfiguration> | ||
<ProjectConfiguration Include="Release|Win32"> | ||
<Configuration>Release</Configuration> | ||
<Platform>Win32</Platform> | ||
|
@@ -78,6 +88,20 @@ | |
<RootNamespace>MyApp</RootNamespace> | ||
</PropertyGroup> | ||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseShared|Win32'" Label="Configuration"> | ||
<ConfigurationType>Application</ConfigurationType> | ||
<UseDebugLibraries>false</UseDebugLibraries> | ||
<PlatformToolset>v141</PlatformToolset> | ||
<WholeProgramOptimization>true</WholeProgramOptimization> | ||
<CharacterSet>Unicode</CharacterSet> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseShared|x64'" Label="Configuration"> | ||
<ConfigurationType>Application</ConfigurationType> | ||
<UseDebugLibraries>false</UseDebugLibraries> | ||
<PlatformToolset>v141</PlatformToolset> | ||
<WholeProgramOptimization>true</WholeProgramOptimization> | ||
<CharacterSet>Unicode</CharacterSet> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> | ||
<ConfigurationType>Application</ConfigurationType> | ||
<UseDebugLibraries>true</UseDebugLibraries> | ||
|
@@ -122,6 +146,16 @@ | |
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" | ||
Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" | ||
Label="LocalAppDataPlatform" /> | ||
</ImportGroup> | ||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='ReleaseShared|Win32'"> | ||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" | ||
Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" | ||
Label="LocalAppDataPlatform" /> | ||
</ImportGroup> | ||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='ReleaseShared|Win32'"> | ||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" | ||
Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" | ||
Label="LocalAppDataPlatform" /> | ||
</ImportGroup> | ||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | ||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" | ||
|
@@ -146,6 +180,12 @@ | |
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | ||
<LinkIncremental>false</LinkIncremental> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseShared|Win32'"> | ||
<LinkIncremental>false</LinkIncremental> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseShared|x64'"> | ||
<LinkIncremental>false</LinkIncremental> | ||
</PropertyGroup> | ||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> | ||
<ClCompile> | ||
<PrecompiledHeader>NotUsing</PrecompiledHeader> | ||
|
@@ -161,6 +201,43 @@ | |
<GenerateDebugInformation>true</GenerateDebugInformation> | ||
</Link> | ||
</ItemDefinitionGroup> | ||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseShared|Win32'"> | ||
<ClCompile> | ||
<PrecompiledHeader>NotUsing</PrecompiledHeader> | ||
<WarningLevel>Level3</WarningLevel> | ||
<Optimization>MaxSpeed</Optimization> | ||
<FunctionLevelLinking>true</FunctionLevelLinking> | ||
<IntrinsicFunctions>true</IntrinsicFunctions> | ||
<SDLCheck>true</SDLCheck> | ||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) | ||
</PreprocessorDefinitions> | ||
<ConformanceMode>true</ConformanceMode> | ||
</ClCompile> | ||
<Link> | ||
<SubSystem>Console</SubSystem> | ||
<EnableCOMDATFolding>true</EnableCOMDATFolding> | ||
<OptimizeReferences>true</OptimizeReferences> | ||
<GenerateDebugInformation>true</GenerateDebugInformation> | ||
</Link> | ||
</ItemDefinitionGroup> | ||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseShared|x64'"> | ||
<ClCompile> | ||
<PrecompiledHeader>NotUsing</PrecompiledHeader> | ||
<WarningLevel>Level3</WarningLevel> | ||
<Optimization>MaxSpeed</Optimization> | ||
<FunctionLevelLinking>true</FunctionLevelLinking> | ||
<IntrinsicFunctions>true</IntrinsicFunctions> | ||
<SDLCheck>true</SDLCheck> | ||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||
<ConformanceMode>true</ConformanceMode> | ||
</ClCompile> | ||
<Link> | ||
<SubSystem>Console</SubSystem> | ||
<EnableCOMDATFolding>true</EnableCOMDATFolding> | ||
<OptimizeReferences>true</OptimizeReferences> | ||
<GenerateDebugInformation>true</GenerateDebugInformation> | ||
</Link> | ||
</ItemDefinitionGroup> | ||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | ||
<ClCompile> | ||
<PrecompiledHeader>NotUsing</PrecompiledHeader> | ||
|
@@ -230,17 +307,25 @@ class WinTest(unittest.TestCase): | |
class App(ConanFile): | ||
settings = "os", "arch", "compiler", "build_type" | ||
requires = "hello/0.1" | ||
generators = "msbuild" | ||
options = {"shared": [True, False]} | ||
default_options = {"shared": False} | ||
def toolchain(self): | ||
tc = MSBuildToolchain(self) | ||
if self.options["hello"].shared and self.settings.build_type == "Release": | ||
tc.configuration = "ReleaseShared" | ||
tc.generator.configuration = "ReleaseShared" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A Question: the generator configuration should follow always the configuration of the project or not necessarily? Should be the same by default or not really? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, after conversation with users, it is very typical that the configuration of the project refers to the way it is linking dependencies. It could be both, of course, but users can do:
While other users or other projects could define:
So it seems that the system should be flexible to let the users define the logic they want differently to generators and toolchains. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mhhh, so answering my questions...
Did you mean the matrix is the following?:
While other users or other projects could define:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think in the second case, it would be both In the first case, it seems that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm so sorry but I don't get it hahahah. Could you do a Matrix of possible values of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The name of the config is irrelevant, it is just something a user will define. So lets define it from the other side:
Please let me know if this makes sense. |
||
|
||
tc.preprocessor_definitions["DEFINITIONS_BOTH"] = "True" | ||
if self.settings.build_type == "Debug": | ||
tc.preprocessor_definitions["DEFINITIONS_CONFIG"] = "Debug" | ||
else: | ||
tc.preprocessor_definitions["DEFINITIONS_CONFIG"] = "Release" | ||
tc.write_toolchain_files() | ||
|
||
def imports(self): | ||
self.copy("*.dll", src="bin", | ||
dst="%s/%s" % (self.settings.arch, self.settings.build_type), | ||
keep_path=False) | ||
""") | ||
|
||
app = textwrap.dedent(""" | ||
|
@@ -285,12 +370,20 @@ def toolchain(self): | |
} | ||
""") | ||
|
||
def _run_app(self, client, arch, build_type, msg="App"): | ||
def _run_app(self, client, arch, build_type, shared=None, msg="App"): | ||
if build_type == "Release" and shared == "shared": | ||
configuration = "ReleaseShared" | ||
else: | ||
configuration = build_type | ||
if arch == "x86": | ||
command_str = "%s\\MyApp.exe" % build_type | ||
command_str = "%s\\MyApp.exe" % configuration | ||
else: | ||
command_str = "x64\\%s\\MyApp.exe" % build_type | ||
client.run_command(command_str) | ||
command_str = "x64\\%s\\MyApp.exe" % configuration | ||
new_cmd = "conan\\%s\\%s\\MyApp.exe" % (arch, build_type) | ||
with chdir(client.current_folder): | ||
mkdir(os.path.dirname(new_cmd)) | ||
shutil.copy(command_str, new_cmd) | ||
client.run_command(new_cmd) | ||
if arch == "x86": | ||
self.assertIn("AppArch x86!!!", client.out) | ||
else: | ||
|
@@ -398,12 +491,14 @@ def test_toolchain_win_multi(self): | |
"compiler.cppstd": "17"} | ||
settings = " ".join('-s %s="%s"' % (k, v) for k, v in settings.items() if v) | ||
client.run("new hello/0.1 -s") | ||
configs = [("Release", "x86"), ("Release", "x86_64"), ("Debug", "x86"), ("Debug", "x86_64")] | ||
for build_type, arch in configs: | ||
configs = [("Release", "x86", "shared"), ("Release", "x86_64", "shared"), | ||
("Debug", "x86", "static"), ("Debug", "x86_64", "static")] | ||
for build_type, arch, shared in configs: | ||
# Build the profile according to the settings provided | ||
runtime = "MT" if build_type == "Release" else "MTd" | ||
client.run("create . hello/0.1@ %s -s build_type=%s -s arch=%s -s compiler.runtime=%s" | ||
% (settings, build_type, arch, runtime)) | ||
shared = "True" if shared == "shared" else "False" | ||
client.run("create . hello/0.1@ %s -s build_type=%s -s arch=%s -s compiler.runtime=%s " | ||
" -o hello:shared=%s" % (settings, build_type, arch, runtime, shared)) | ||
|
||
# Prepare the actual consumer package | ||
client.save({"conanfile.py": self.conanfile, | ||
|
@@ -413,22 +508,28 @@ def test_toolchain_win_multi(self): | |
clean_first=True) | ||
|
||
# Run the configure corresponding to this test case | ||
for build_type, arch in configs: | ||
for build_type, arch, shared in configs: | ||
runtime = "MT" if build_type == "Release" else "MTd" | ||
shared = "True" if shared == "shared" else "False" | ||
client.run("install . %s -s build_type=%s -s arch=%s -s compiler.runtime=%s -if=conan" | ||
% (settings, build_type, arch, runtime)) | ||
" -o hello:shared=%s" % (settings, build_type, arch, runtime, shared)) | ||
|
||
vs_path = vs_installation_path("15") | ||
vcvars_path = os.path.join(vs_path, "VC/Auxiliary/Build/vcvarsall.bat") | ||
|
||
for build_type, arch in configs: | ||
for build_type, arch, shared in configs: | ||
platform_arch = "x86" if arch == "x86" else "x64" | ||
if build_type == "Release" and shared == "shared": | ||
configuration = "ReleaseShared" | ||
else: | ||
configuration = build_type | ||
cmd = ('set "VSCMD_START_DIR=%%CD%%" && ' | ||
'"%s" x64 && msbuild "MyProject.sln" /p:Configuration=%s ' | ||
'/p:Platform=%s ' % (vcvars_path, build_type, platform_arch)) | ||
'/p:Platform=%s ' % (vcvars_path, configuration, platform_arch)) | ||
client.run_command(cmd) | ||
self.assertIn("Visual Studio 2017", client.out) | ||
self.assertIn("[vcvarsall.bat] Environment initialized for: 'x64'", client.out) | ||
self._run_app(client, arch, build_type) | ||
|
||
self._run_app(client, arch, build_type, shared) | ||
self.assertIn("AppMSCVER 17!!", client.out) | ||
self.assertIn("AppCppStd 17!!!", client.out) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why these removed lines?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They were unused. Seems a legacy from a refactor or something. Dead code.