def test_no_msvc(self): settings = Settings.loads(default_settings_yml) settings.compiler = 'clang' settings.arch = 'x86_64' settings.os = 'Windows' with mock.patch('conans.client.tools.win.latest_vs_version_installed', mock.MagicMock(return_value=None)): with self.assertRaises(ConanException): vcvars_command(settings)
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): 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: 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) command = "%s && %s" % (vcvars, command) return self._conanfile.run(command)
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, property_file_name=None, verbosity=None, definitions=None): """ :param project_file: Path to the .sln file. :param targets: List of targets to build. :param upgrade_project: Will call devenv to upgrade the solution to your current Visual Studio. :param build_type: Use a custom build type name instead of the default settings.build_type one. :param arch: Use a custom architecture name instead of the settings.arch one. It will be used to build the /p:Configuration= parameter of MSBuild. It can be used as the key of the platforms parameter. E.g. arch="x86", platforms={"x86": "i386"} :param parallel: Will use the configured number of cores in the conan.conf file or tools.cpu_count(): In the solution: Building the solution with the projects in parallel. (/m: parameter). CL compiler: Building the sources in parallel. (/MP: compiler flag) :param force_vcvars: Will ignore if the environment is already set for a different Visual Studio version. :param toolset: Specify a toolset. Will append a /p:PlatformToolset option. :param platforms: Dictionary with the mapping of archs/platforms from Conan naming to another one. It is useful for Visual Studio solutions that have a different naming in architectures. Example: platforms={"x86":"Win32"} (Visual solution uses "Win32" instead of "x86"). This dictionary will update the default one: msvc_arch = {'x86': 'x86', 'x86_64': 'x64', 'armv7': 'ARM', 'armv8': 'ARM64'} :param use_env: Applies the argument /p:UseEnv=true to the MSBuild call. :param vcvars_ver: Specifies the Visual Studio compiler toolset to use. :param winsdk_version: Specifies the version of the Windows SDK to use. :param properties: Dictionary with new properties, for each element in the dictionary {name: value} it will append a /p:name="value" option. :param output_binary_log: If set to True then MSBuild will output a binary log file called msbuild.binlog in the working directory. It can also be used to set the name of log file like this output_binary_log="my_log.binlog". This parameter is only supported starting from MSBuild version 15.3 and onwards. :param property_file_name: When None it will generate a file named conan_build.props. You can specify a different name for the generated properties file. :param verbosity: Specifies verbosity level (/verbosity: parameter) :param definitions: Dictionary with additional compiler definitions to be applied during the build. Use value of None to set compiler definition with no value. :return: status code of the MSBuild command invocation """ 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(definitions) property_file_name = os.path.abspath(property_file_name) save(property_file_name, props_file_contents) vcvars = vcvars_command(self._conanfile.settings, force=force_vcvars, vcvars_ver=vcvars_ver, winsdk_version=winsdk_version, output=self._output) 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, verbosity=verbosity) command = "%s && %s" % (vcvars, command) return self._conanfile.run(command)
def test_no_version(self): settings = Settings.loads(default_settings_yml) settings.compiler = 'clang' settings.arch = 'x86_64' settings.os = 'Windows' command = vcvars_command(settings) self.assertIn('vcvarsall.bat', command) self.assertIn('amd64', command)
def test_simple(self): settings = Settings.loads(default_settings_yml) settings.compiler = 'clang' settings.compiler.version = '5.0' settings.arch = 'x86' settings.os = 'Windows' command = vcvars_command(settings) self.assertIn('vcvarsall.bat', command) self.assertIn('x86', command)
def get_version(settings): msbuild_cmd = "msbuild -version" vcvars = vcvars_command(settings) command = "%s && %s" % (vcvars, msbuild_cmd) try: out, _ = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True).communicate() version_line = decode_text(out).split("\n")[-1] prog = re.compile("(\d+\.){2,3}\d+") result = prog.match(version_line).group() return Version(result) except Exception as e: raise ConanException("Error retrieving MSBuild version: '{}'".format(e))
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): 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: vcvars = vcvars_command(self._conanfile.settings, force=force_vcvars) 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) command = "%s && %s" % (vcvars, command) return self._conanfile.run(command)
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, 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() 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 vcvars_command(*args, **kwargs): return tools_win.vcvars_command(output=_global_output, *args, **kwargs)