def get_virtualenv_py_executable(dest_dir): # get virtualenv's python executable bin_dir = get_virtualenv_bin_dir(dest_dir) env = { "PATH": bin_dir, "PATHEXT": os.environ.get("PATHEXT", "") } return bin_dir, which("python", env=env)
def find_executable(cls, name, check_syspaths=False): """Find an executable. Args: name (str): Program name. check_syspaths (bool): If True, check the standard system paths as well, if program was not found on current $PATH. Returns: str: Full filepath of executable. """ exe = which(name) if not exe and check_syspaths: paths = cls.get_syspaths() env = os.environ.copy() env["PATH"] = os.pathsep.join(paths) exe = which(name, env=env) if not exe: raise RuntimeError("Couldn't find executable '%s'." % name) return exe
def _print_tool_info(self, value, buf=sys.stdout, b=False): word = "is also" if b else "is" _pr = Printer(buf) def _load_wrapper(filepath): try: return Wrapper(filepath) except: return # find it on disk filepath = None unpathed = (os.path.basename(value) == value) if unpathed: filepath = which(value) if filepath is None: path = os.path.abspath(value) if os.path.exists(path): filepath = path if not filepath or not os.path.isfile(filepath): return False # is it a suite wrapper? tool_name = os.path.basename(filepath) w = _load_wrapper(filepath) if w: _pr("'%s' %s a suite tool:" % (tool_name, word)) w.print_about() return True # is it a tool in a current context? if self.context: variants = self.context.get_tool_variants(tool_name) if variants: _pr("'%s' %s a tool in the active context:" % (tool_name, word)) _pr("Tool: %s" % tool_name) if self.context.load_path: _pr("Context: %s" % self.context.load_path) if len(variants) > 1: vars_str = " ".join(x.qualified_package_name for x in variants) msg = "Packages (in conflict): %s" % vars_str _pr(msg, critical) else: variant = next(iter(variants)) _pr("Package: %s" % variant.qualified_package_name) return True # is it actually a suite wrapper, but it's being hidden by another tool # on $PATH with the same name? if unpathed: for suite in self.suites: filepath_ = os.path.join(suite.tools_path, tool_name) if os.path.isfile(filepath_): w = _load_wrapper(filepath_) if w: _pr( "'%s' %s a suite tool, but is hidden by an unknown tool '%s':" % (tool_name, word, filepath), warning) w.print_about() return True return False
def print_tools(self, pattern=None, buf=sys.stdout): """Print a list of visible tools. Args: pattern (str): Only list tools that match this glob pattern. """ seen = set() rows = [] context = self.context if context: data = context.get_tools() conflicts = set(context.get_conflicting_tools().keys()) for _, (variant, tools) in sorted(data.items()): pkg_str = variant.qualified_package_name for tool in tools: if pattern and not fnmatch(tool, pattern): continue if tool in conflicts: label = "(in conflict)" color = critical else: label = '' color = None rows.append( [tool, '-', pkg_str, "active context", label, color]) seen.add(tool) for suite in self.suites: for tool, d in suite.get_tools().items(): if tool in seen: continue if pattern and not fnmatch(tool, pattern): continue label = [] color = None path = which(tool) if path: path_ = os.path.join(suite.tools_path, tool) if path != path_: label.append("(hidden by unknown tool '%s')" % path) color = warning variant = d["variant"] if isinstance(variant, set): pkg_str = ", ".join(variant) label.append("(in conflict)") color = critical else: pkg_str = variant.qualified_package_name orig_tool = d["tool_name"] if orig_tool == tool: orig_tool = '-' label = ' '.join(label) source = ("context '%s' in suite '%s'" % (d["context_name"], suite.load_path)) rows.append([tool, orig_tool, pkg_str, source, label, color]) seen.add(tool) _pr = Printer(buf) if not rows: _pr("No matching tools.") return False headers = [["TOOL", "ALIASING", "PACKAGE", "SOURCE", "", None], ["----", "--------", "-------", "------", "", None]] rows = headers + sorted(rows, key=lambda x: x[0].lower()) print_colored_columns(_pr, rows) return True
def build(self, context, variant, build_path, install_path, install=False, build_type=BuildType.local): def _pr(s): if self.verbose: print(s) # find cmake binary if self.settings.cmake_binary: exe = self.settings.cmake_binary else: exe = context.which("cmake", fallback=True) if not exe: raise RezCMakeError("could not find cmake binary") found_exe = which(exe) if not found_exe: raise RezCMakeError("cmake binary does not exist: %s" % exe) sh = create_shell() # assemble cmake command cmd = [found_exe] # cmd.append("-d") # see https://github.com/nerdvegas/rez/issues/1055 cmd.append(self.working_dir) cmd += (self.settings.cmake_args or []) cmd += (self.build_args or []) cmd.append("-DCMAKE_INSTALL_PREFIX=%s" % install_path) cmd.append("-DCMAKE_MODULE_PATH=%s" % sh.get_key_token("CMAKE_MODULE_PATH").replace('\\', '/')) cmd.append("-DCMAKE_BUILD_TYPE=%s" % self.build_target) cmd.append("-DREZ_BUILD_TYPE=%s" % build_type.name) cmd.append("-DREZ_BUILD_INSTALL=%d" % (1 if install else 0)) cmd.extend(["-G", self.build_systems[self.cmake_build_system]]) if config.rez_1_cmake_variables and \ not config.disable_rez_1_compatibility and \ build_type == BuildType.central: cmd.append("-DCENTRAL=1") # execute cmake within the build env _pr("Executing: %s" % ' '.join(cmd)) if not os.path.abspath(build_path): build_path = os.path.join(self.working_dir, build_path) build_path = os.path.realpath(build_path) actions_callback = functools.partial(self._add_build_actions, context=context, package=self.package, variant=variant, build_type=build_type, install=install, build_path=build_path, install_path=install_path) post_actions_callback = functools.partial(self.add_pre_build_commands, variant=variant, build_type=build_type, install=install, build_path=build_path, install_path=install_path) # run the build command and capture/print stderr at the same time retcode, _, _ = context.execute_shell( command=cmd, block=True, cwd=build_path, actions_callback=actions_callback, post_actions_callback=post_actions_callback) ret = {} if retcode: ret["success"] = False return ret if self.write_build_scripts: # write out the script that places the user in a build env, where # they can run make directly themselves. build_env_script = os.path.join(build_path, "build-env") create_forwarding_script(build_env_script, module=("build_system", "cmake"), func_name="_FWD__spawn_build_shell", working_dir=self.working_dir, build_path=build_path, variant_index=variant.index, install=install, install_path=install_path) ret["success"] = True ret["build_env_script"] = build_env_script return ret # assemble make command make_binary = self.settings.make_binary if not make_binary: if self.cmake_build_system == "mingw": make_binary = "mingw32-make" elif self.cmake_build_system == "nmake": make_binary = "nmake" elif self.cmake_build_system == "ninja": make_binary = "ninja" else: make_binary = "make" cmd = [make_binary] + (self.child_build_args or []) # nmake has no -j if make_binary != "nmake": if not any( x.startswith("-j") for x in (self.child_build_args or [])): n = variant.config.build_thread_count cmd.append("-j%d" % n) # execute make within the build env _pr("\nExecuting: %s" % ' '.join(cmd)) retcode, _, _ = context.execute_shell( command=cmd, block=True, cwd=build_path, actions_callback=actions_callback, post_actions_callback=post_actions_callback) if not retcode and install and "install" not in cmd: cmd.append("install") # execute make install within the build env _pr("\nExecuting: %s" % ' '.join(cmd)) retcode, _, _ = context.execute_shell( command=cmd, block=True, cwd=build_path, actions_callback=actions_callback, post_actions_callback=post_actions_callback) ret["success"] = (not retcode) return ret