Skip to content
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

msbuild temp props in build folder #4113

Merged
merged 6 commits into from
Dec 12, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions conans/client/build/msbuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from conans.model.conan_file import ConanFile
from conans.model.version import Version
from conans.util.env_reader import get_env
from conans.util.files import decode_text, tmp_file
from conans.util.files import decode_text, tmp_file, save


class MSBuild(object):
Expand All @@ -29,23 +29,25 @@ def __init__(self, conanfile):

def build(self, project_file, targets=None, upgrade_project=True, build_type=None, arch=None,
parallel=True, force_vcvars=False, toolset=None, platforms=None, use_env=True,
vcvars_ver=None, winsdk_version=None, properties=None, output_binary_log=None):
vcvars_ver=None, winsdk_version=None, properties=None, output_binary_log=None,
property_file_name=None):

property_file_name = property_file_name or "conan_build.props"
self.build_env.parallel = parallel

with tools.environment_append(self.build_env.vars):
# Path for custom properties file
props_file_contents = self._get_props_file_contents()
with tmp_file(props_file_contents) as props_file_path:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tmp_file context manager is now dead code, please remove it.

vcvars = vcvars_command(self._conanfile.settings, force=force_vcvars,
vcvars_ver=vcvars_ver, winsdk_version=winsdk_version)
command = self.get_command(project_file, props_file_path,
targets=targets, upgrade_project=upgrade_project,
build_type=build_type, arch=arch, parallel=parallel,
toolset=toolset, platforms=platforms,
use_env=use_env, properties=properties, output_binary_log=output_binary_log)
command = "%s && %s" % (vcvars, command)
return self._conanfile.run(command)
save(property_file_name, props_file_contents)
vcvars = vcvars_command(self._conanfile.settings, force=force_vcvars,
vcvars_ver=vcvars_ver, winsdk_version=winsdk_version)
command = self.get_command(project_file, property_file_name,
targets=targets, upgrade_project=upgrade_project,
build_type=build_type, arch=arch, parallel=parallel,
toolset=toolset, platforms=platforms,
use_env=use_env, properties=properties, output_binary_log=output_binary_log)
command = "%s && %s" % (vcvars, command)
return self._conanfile.run(command)

def get_command(self, project_file, props_file_path=None, targets=None, upgrade_project=True,
build_type=None, arch=None, parallel=True, toolset=None, platforms=None,
Expand Down
13 changes: 13 additions & 0 deletions conans/test/build_helpers/msbuild_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from conans.client import tools
from conans.client.build.msbuild import MSBuild
from conans.errors import ConanException
from conans.model.ref import PackageReference
from conans.model.version import Version
from conans.paths import CONANFILE
from conans.test.utils.conanfile import MockConanfile, MockSettings
Expand Down Expand Up @@ -115,6 +116,18 @@ def package(self):
self.assertIn("Debug|x86", client.user_io.out)
self.assertIn("Copied 1 '.exe' file: MyProject.exe", client.user_io.out)

# Try with a custom property file name
files[CONANFILE] = conan_build_vs.replace('msbuild.build("MyProject.sln")',
'msbuild.build("MyProject.sln", '
'property_file_name="myprops.props")')
client.save(files, clean_first=True)
client.run("create . Hello/1.2.1@lasote/stable --build -s arch=x86 -s build_type=Debug")
self.assertIn("Debug|x86", client.user_io.out)
self.assertIn("Copied 1 '.exe' file: MyProject.exe", client.user_io.out)
pref = PackageReference.loads("Hello/1.2.1@lasote/stable:b786e9ece960c3a76378ca4d5b0d0e922f4cedc1")
build_folder = client.client_cache.build(pref)
self.assertTrue(os.path.exists(os.path.join(build_folder, "myprops.props")))

def custom_properties_test(self):
settings = MockSettings({"build_type": "Debug",
"compiler": "Visual Studio",
Expand Down