Skip to content

Commit 2976776

Browse files
committed
adapt template & tests
1 parent 5326ef5 commit 2976776

File tree

5 files changed

+12
-62
lines changed

5 files changed

+12
-62
lines changed

conans/assets/templates/new_v2_msbuild.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,6 @@
6161
<RootNamespace>{{name}}</RootNamespace>
6262
</PropertyGroup>
6363
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
64-
<ImportGroup Label="PropertySheets">
65-
<Import Project="conan\\conantoolchain.props" />
66-
{{dependencies}}
67-
</ImportGroup>
6864
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
6965
<ConfigurationType>{{type}}</ConfigurationType>
7066
<UseDebugLibraries>true</UseDebugLibraries>
@@ -399,14 +395,12 @@ def test(self):
399395

400396

401397
def get_msbuild_lib_files(name, version, package_name="Pkg"):
402-
d = {"name": name, "version": version, "pkg_name": package_name, "type": "StaticLibrary",
403-
"dependencies": ""}
398+
d = {"name": name, "version": version, "pkg_name": package_name, "type": "StaticLibrary"}
404399
sln = Template(sln_file, keep_trailing_newline=True).render(d)
405400
vcp = Template(vcxproj, keep_trailing_newline=True).render(d)
406401
conanfile = Template(conanfile_sources_v2, keep_trailing_newline=True).render(d)
407402
test_d = {"name": "test_" + name, "version": version, "pkg_name": package_name,
408-
"type": "Application",
409-
"dependencies": '<Import Project="conan\\conandeps.props" />'}
403+
"type": "Application"}
410404
test_sln = Template(sln_file, keep_trailing_newline=True).render(test_d)
411405
test_vcp = Template(vcxproj, keep_trailing_newline=True).render(test_d)
412406
test_conanfile = Template(test_conanfile_v2, keep_trailing_newline=True).render(test_d)
@@ -496,8 +490,7 @@ def test(self):
496490

497491

498492
def get_msbuild_exe_files(name, version, package_name="Pkg"):
499-
d = {"name": name, "version": version, "pkg_name": package_name, "type": "Application",
500-
"dependencies": ""}
493+
d = {"name": name, "version": version, "pkg_name": package_name, "type": "Application"}
501494
sln = Template(sln_file, keep_trailing_newline=True).render(d)
502495
vcp = Template(vcxproj, keep_trailing_newline=True).render(d)
503496
conanfile = Template(conanfile_exe, keep_trailing_newline=True).render(d)

conans/test/functional/toolchains/microsoft/test_msbuild.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,6 @@
132132
<WholeProgramOptimization>true</WholeProgramOptimization>
133133
<CharacterSet>Unicode</CharacterSet>
134134
</PropertyGroup>
135-
<!-- Very IMPORTANT this should go BEFORE the Microsoft.Cpp.props.
136-
If it goes after, the Toolset definition is ignored -->
137-
<ImportGroup Label="PropertySheets">
138-
<Import Project="..\conan\conan_hello.props" />
139-
<Import Project="..\conan\conantoolchain.props" />
140-
</ImportGroup>
141135
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
142136
<ImportGroup Label="ExtensionSettings">
143137
</ImportGroup>
@@ -581,9 +575,13 @@ def test_toolchain_win_multi(self):
581575
configuration = build_type
582576

583577
# The "conan build" command is not good enough, cannot do the switch between configs
578+
props_paths = ";".join([
579+
os.path.join(client.current_folder, "conan", "conantoolchain.props"),
580+
os.path.join(client.current_folder, "conan", "conandeps.props"),
581+
])
584582
cmd = ('set "VSCMD_START_DIR=%%CD%%" && '
585-
'"%s" x64 && msbuild "MyProject.sln" /p:Configuration=%s '
586-
'/p:Platform=%s ' % (vcvars_path, configuration, platform_arch))
583+
f'"{vcvars_path}" x64 && msbuild "MyProject.sln" /p:Configuration={configuration} '
584+
f'/p:Platform={platform_arch} /p:ForceImportBeforeCppTargets="{props_paths}"')
587585
client.run_command(cmd)
588586
self.assertIn("Visual Studio {ide_year}".format(ide_year=self.ide_year), client.out)
589587
self.assertIn("[vcvarsall.bat] Environment initialized for: 'x64'", client.out)

conans/test/functional/toolchains/microsoft/test_msbuilddeps.py

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,6 @@
115115
</ImportGroup>
116116
<ImportGroup Label="Shared">
117117
</ImportGroup>
118-
<ImportGroup Label="PropertySheets">
119-
<Import Project="..\conan_Hello3.props" />
120-
</ImportGroup>
121118
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
122119
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props"
123120
Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')"
@@ -286,9 +283,6 @@
286283
</ImportGroup>
287284
<ImportGroup Label="Shared">
288285
</ImportGroup>
289-
<ImportGroup Label="PropertySheets">
290-
<Import Project="..\conan_Hello1.props" />
291-
</ImportGroup>
292286
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
293287
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props"
294288
Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')"
@@ -583,11 +577,9 @@ def build(self):
583577
myapp_cpp = gen_function_cpp(name="main", msg="MyApp")
584578
myproject_cpp = gen_function_cpp(name="main", msg="MyProject")
585579
files = {"MyProject.sln": sln_file,
586-
"MyProject/MyProject.vcxproj": myproject_vcxproj.replace("conan_Hello3.props",
587-
"conandeps.props"),
580+
"MyProject/MyProject.vcxproj": myproject_vcxproj,
588581
"MyProject/MyProject.cpp": myproject_cpp,
589-
"MyApp/MyApp.vcxproj": myapp_vcxproj.replace("conan_Hello1.props",
590-
"conandeps.props"),
582+
"MyApp/MyApp.vcxproj": myapp_vcxproj,
591583
"MyApp/MyApp.cpp": myapp_cpp,
592584
"conanfile.py": conanfile}
593585

@@ -772,10 +764,6 @@ def build(self):
772764
main_cpp = gen_function_cpp(name="main", includes=["hello"], calls=["hello"])
773765
files["MyProject/main.cpp"] = main_cpp
774766
files["conanfile.py"] = consumer
775-
props = os.path.join(client.current_folder, "conandeps.props")
776-
old = r'<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />'
777-
new = old + '<Import Project="{props}" />'.format(props=props)
778-
files["MyProject/MyProject.vcxproj"] = files["MyProject/MyProject.vcxproj"].replace(old, new)
779767
client.save(files, clean_first=True)
780768
client.run('install . -s compiler="Visual Studio"'
781769
' -s compiler.version={vs_version}'.format(vs_version=vs_version))
@@ -828,10 +816,6 @@ def build(self):
828816
main_cpp = gen_function_cpp(name="main", includes=["mydep_pkg_team"], calls=["mydep_pkg_team"])
829817
files["MyProject/main.cpp"] = main_cpp
830818
files["conanfile.py"] = consumer
831-
props = os.path.join(client.current_folder, "conandeps.props")
832-
old = r'<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />'
833-
new = old + '<Import Project="{props}" />'.format(props=props)
834-
files["MyProject/MyProject.vcxproj"] = files["MyProject/MyProject.vcxproj"].replace(old, new)
835819
client.save(files, clean_first=True)
836820
client.run('install . -s compiler.version={vs_version}'.format(vs_version=vs_version))
837821
client.run("build .")
@@ -915,10 +899,6 @@ def build(self):
915899
916900
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
917901
918-
<ImportGroup Label="PropertySheets">
919-
<Import Project="..\conandeps.props" />
920-
</ImportGroup>
921-
922902
<PropertyGroup Label="UserMacros" />
923903
924904
<ItemGroup>

conans/test/functional/toolchains/microsoft/test_msbuilddeps_components.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -153,16 +153,9 @@ def package_info(self):
153153
'requires="chat/1.0"\n'
154154
' generators = "MSBuildDeps"\n'
155155
' settings = ')
156-
vcproj = client.load("greet.vcxproj")
157-
vcproj2 = vcproj.replace(r'<Import Project="conan\\conantoolchain.props" />',
158-
r"""<Import Project="conan\\conantoolchain.props" />
159-
<Import Project="conan\\conandeps.props" />
160-
""")
161-
assert vcproj2 != vcproj
162156
client.save({"conanfile.py": conanfile,
163157
"src/greet.cpp": gen_function_cpp(name="main", includes=["chat"],
164-
calls=["chat"]),
165-
"greet.vcxproj": vcproj2})
158+
calls=["chat"])})
166159
client.run("create .")
167160
assert "main: Release!" in client.out
168161
assert "core/1.0: Hello World Release!" in client.out

conans/test/functional/toolchains/microsoft/test_msbuildtoolchain.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,11 @@
11
import platform
22
import sys
33
import textwrap
4-
import os
54

65
import pytest
7-
try:
8-
from unittest.mock import MagicMock
9-
except:
10-
from mock import MagicMock
116

12-
from conan.tools.files import replace_in_file
137
from conans.test.utils.tools import TestClient
148

15-
toolchain_props = """
16-
<ImportGroup Label="PropertySheets">
17-
<Import Project="conan\\conantoolchain_release_x64.props" />
18-
"""
19-
209

2110
@pytest.mark.skipif(sys.version_info.major == 2, reason="Meson not supported in Py2")
2211
@pytest.mark.skipif(platform.system() not in ["Windows"], reason="Requires Windows")
@@ -42,9 +31,6 @@ def test_msbuildtoolchain_props_with_extra_flags():
4231
client.save({
4332
"myprofile": profile
4433
})
45-
# Let's import manually the created conantoolchain_release_x64.props
46-
replace_in_file(MagicMock(), os.path.join(client.current_folder, "hello.vcxproj"),
47-
r' <ImportGroup Label="PropertySheets">', toolchain_props)
4834
client.run("create . -pr myprofile -tf None")
4935
assert "/analyze:quiet /doc src/hello.cpp" in client.out
5036
assert r"/VERBOSE:UNUSEDLIBS /PDB:mypdbfile x64\Release\hello.obj" in client.out

0 commit comments

Comments
 (0)