def run(self, command, output=True, cwd=None, win_bash=False, subsystem=None, msys_mingw=True, ignore_errors=False, run_environment=False, with_login=True, env=None): # NOTE: "self.win_bash" is the new parameter "win_bash" for Conan 2.0 def _run(cmd, _env): # FIXME: run in windows bash is not using output if platform.system() == "Windows": if win_bash: return tools.run_in_windows_bash(self, bashcmd=cmd, cwd=cwd, subsystem=subsystem, msys_mingw=msys_mingw, with_login=with_login) elif self.win_bash: # New, Conan 2.0 from conan.tools.microsoft.subsystems import run_in_windows_bash return run_in_windows_bash(self, command=cmd, cwd=cwd, env=_env) if _env is None: _env = "conanbuild" from conan.tools.env.environment import environment_wrap_command wrapped_cmd = environment_wrap_command(_env, cmd, cwd=self.generators_folder) return self._conan_runner(wrapped_cmd, output, os.path.abspath(RUN_LOG_NAME), cwd) if run_environment: # When using_build_profile the required environment is already applied through # 'conanfile.env' in the contextmanager 'get_env_context_manager' with tools.run_environment(self) if not self._conan_using_build_profile else no_op(): if OSInfo().is_macos and isinstance(command, string_types): # Security policy on macOS clears this variable when executing /bin/sh. To # keep its value, set it again inside the shell when running the command. command = 'DYLD_LIBRARY_PATH="%s" DYLD_FRAMEWORK_PATH="%s" %s' % \ (os.environ.get('DYLD_LIBRARY_PATH', ''), os.environ.get("DYLD_FRAMEWORK_PATH", ''), command) retcode = _run(command, env) else: retcode = _run(command, env) if not ignore_errors and retcode != 0: raise ConanException("Error %d while executing %s" % (retcode, command)) return retcode
def get_env_context_manager(conanfile, without_python=False): if not conanfile.apply_env: return no_op() if without_python: return environment_append(conanfile.env) return _env_and_python(conanfile)
def _run_muted(cmd, folder=None): with chdir(folder) if folder else no_op(): process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) process.communicate() return process.returncode
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, user_property_file_name=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 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. :param user_property_file_name: Specify a user provided .props file with custom definitions :return: status code of the MSBuild command invocation """ property_file_name = property_file_name or "conan_build.props" self.build_env.parallel = parallel with 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, arch=arch, 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, user_property_file_name=user_property_file_name) command = "%s && %s" % (vcvars, command) context = no_op() if self._conanfile.settings.get_safe("compiler") == "Intel" and \ self._conanfile.settings.get_safe("compiler.base") == "Visual Studio": context = intel_compilervars(self._conanfile.settings, arch) with context: return self._conanfile.run(command)
def run(self, command, output=True, cwd=None, win_bash=False, subsystem=None, msys_mingw=True, ignore_errors=False, run_environment=False, with_login=True): def _run(): if not win_bash: return self._conan_runner(command, output, os.path.abspath(RUN_LOG_NAME), cwd) # FIXME: run in windows bash is not using output return tools.run_in_windows_bash(self, bashcmd=command, cwd=cwd, subsystem=subsystem, msys_mingw=msys_mingw, with_login=with_login) if run_environment: # When using_build_profile the required environment is already applied through # 'conanfile.env' in the contextmanager 'get_env_context_manager' with tools.run_environment(self) if not self._conan_using_build_profile else no_op(): if OSInfo().is_macos and isinstance(command, string_types): # Security policy on macOS clears this variable when executing /bin/sh. To # keep its value, set it again inside the shell when running the command. command = 'DYLD_LIBRARY_PATH="%s" DYLD_FRAMEWORK_PATH="%s" %s' % \ (os.environ.get('DYLD_LIBRARY_PATH', ''), os.environ.get("DYLD_FRAMEWORK_PATH", ''), command) retcode = _run() else: retcode = _run() if not ignore_errors and retcode != 0: raise ConanException("Error %d while executing %s" % (retcode, command)) return retcode
def write_file(self, path, contents, lock_file): with fasteners.InterProcessLock(lock_file) if lock_file else no_op(): with open(path, "w") as f: f.write(contents)
def read_file(self, path, lock_file): with fasteners.InterProcessLock(lock_file) if lock_file else no_op(): with open(path) as f: return f.read()