def _run(self, command): compiler = self._settings.get_safe("compiler") conan_v2_error("compiler setting should be defined.", not compiler) the_os = self._settings.get_safe("os") is_clangcl = the_os == "Windows" and compiler == "clang" is_msvc = compiler == "Visual Studio" is_intel = compiler == "intel" context = tools.no_op() if (is_msvc or is_clangcl) and platform.system() == "Windows": if self.generator in [ "Ninja", "NMake Makefiles", "NMake Makefiles JOM" ]: vcvars_dict = tools.vcvars_dict(self._settings, force=True, filter_known_paths=False, output=self._conanfile.output) context = _environment_add(vcvars_dict, post=self._append_vcvars) elif is_intel: if self.generator in [ "Ninja", "NMake Makefiles", "NMake Makefiles JOM", "Unix Makefiles" ]: intel_compilervars_dict = tools.intel_compilervars_dict( self._conanfile, force=True) context = _environment_add(intel_compilervars_dict, post=self._append_vcvars) with context: self._conanfile.run(command)
def vcvars_filter_known_paths_test(self): settings = Settings.loads(default_settings_yml) settings.os = "Windows" settings.compiler = "Visual Studio" settings.compiler.version = "15" settings.arch = "x86" settings.arch_build = "x86_64" with tools.environment_append({"PATH": ["custom_path", "WindowsFake"]}): tmp = tools.vcvars_dict(settings, only_diff=False, filter_known_paths=True, output=self.output) with tools.environment_append(tmp): self.assertNotIn("custom_path", os.environ["PATH"]) self.assertIn("WindowsFake", os.environ["PATH"]) tmp = tools.vcvars_dict(settings, only_diff=False, filter_known_paths=False, output=self.output) with tools.environment_append(tmp): self.assertIn("custom_path", os.environ["PATH"]) self.assertIn("WindowsFake", os.environ["PATH"])
def _run(self, command): def _build(): env_build = AutoToolsBuildEnvironment(self._conanfile) with environment_append(env_build.vars): self._conanfile.run(command) if self._vcvars_needed: vcvars_dict = tools.vcvars_dict(self._settings, output=self._conanfile.output) with _environment_add(vcvars_dict, post=self._append_vcvars): _build() else: _build()
def _run(self, command): compiler = self._settings.get_safe("compiler") the_os = self._settings.get_safe("os") is_clangcl = the_os == "Windows" and compiler == "clang" is_msvc = compiler == "Visual Studio" if ((is_msvc or is_clangcl) and platform.system() == "Windows" and self.generator in ["Ninja", "NMake Makefiles", "NMake Makefiles JOM"]): vcvars_dict = tools.vcvars_dict(self._settings, force=True, filter_known_paths=False, output=self._conanfile.output) with _environment_add(vcvars_dict, post=self._append_vcvars): self._conanfile.run(command) else: self._conanfile.run(command)
def vcvars_dict_test(self): # https://github.com/conan-io/conan/issues/2904 output_with_newline_and_spaces = """ PROCESSOR_ARCHITECTURE=AMD64 PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 158 Stepping 9, GenuineIntel PROCESSOR_LEVEL=6 PROCESSOR_REVISION=9e09 set nl=^ env_var= without_equals_sign ProgramFiles(x86)=C:\Program Files (x86) """ def vcvars_command_mock(settings, arch, compiler_version, force, vcvars_ver, winsdk_version, output): # @UnusedVariable return "unused command" def subprocess_check_output_mock(cmd): self.assertIn("unused command", cmd) return output_with_newline_and_spaces with mock.patch('conans.client.tools.win.vcvars_command', new=vcvars_command_mock): with patch('conans.client.tools.win.check_output_runner', new=subprocess_check_output_mock): vcvars = tools.vcvars_dict(None, only_diff=False, output=self.output) self.assertEqual(vcvars["PROCESSOR_ARCHITECTURE"], "AMD64") self.assertEqual( vcvars["PROCESSOR_IDENTIFIER"], "Intel64 Family 6 Model 158 Stepping 9, GenuineIntel") self.assertEqual(vcvars["PROCESSOR_LEVEL"], "6") self.assertEqual(vcvars["PROCESSOR_REVISION"], "9e09") self.assertEqual(vcvars["ProgramFiles(x86)"], "C:\\Program Files (x86)")
def vcvars_env_not_duplicated_path_test(self): """vcvars is not looking at the current values of the env vars, with PATH it is a problem because you can already have set some of the vars and accumulate unnecessary entries.""" settings = Settings.loads(default_settings_yml) settings.os = "Windows" settings.compiler = "Visual Studio" settings.compiler.version = "15" settings.arch = "x86" settings.arch_build = "x86_64" # Set the env with a PATH containing the vcvars paths tmp = tools.vcvars_dict(settings, only_diff=False, output=self.output) tmp = {key.lower(): value for key, value in tmp.items()} with tools.environment_append({"path": tmp["path"]}): previous_path = os.environ["PATH"].split(";") # Duplicate the path, inside the tools.vcvars shouldn't have repeated entries in PATH with tools.vcvars(settings, output=self.output): path = os.environ["PATH"].split(";") values_count = {value: path.count(value) for value in path} for value, counter in values_count.items(): if value and counter > 1 and previous_path.count(value) != counter: # If the entry was already repeated before calling "tools.vcvars" we keep it self.fail("The key '%s' has been repeated" % value)