def make(self, recipe, try_again=False): """ Build this recipe. If try_again is set, it will assume the build failed before and we're trying to run it again. In this case, reduce the makewidth to 1 and show the build output. """ self.log.debug("Building recipe {}".format(recipe.id)) self.log.debug("In cwd - {}".format(os.getcwd())) o_proc = None if self.log.getEffectiveLevel( ) >= pb_logging.DEBUG and not try_again and not recipe.make_interactive: o_proc = output_proc.OutputProcessorMake(preamble="Building: ") cmd = recipe.var_replace_all(self.get_command('make', recipe)) cmd = self.filter_cmd(cmd, recipe, 'make_filter') if subproc.monitor_process(cmd, shell=True, o_proc=o_proc) == 0: self.log.debug("Make successful") return True # OK, something bad happened. if try_again == False: recipe.vars['makewidth'] = '1' self.make(recipe, try_again=True) else: self.log.error( "Build failed. See output above for error messages.") raise PBException("Build failed.")
def configure(self, recipe, try_again=False): """ Run the configuration step for this recipe. If try_again is set, it will assume the configuration failed before and we're trying to run it again. """ self.log.debug("Configuring recipe {}".format(recipe.id)) self.log.debug("Using vars - {}".format(recipe.vars)) self.log.debug("In cwd - {}".format(os.getcwd())) pre_cmd = recipe.var_replace_all(self.get_command('configure', recipe)) cmd = self.filter_cmd(pre_cmd, recipe, 'config_filter') o_proc = None if self.log.getEffectiveLevel() >= pb_logging.DEBUG and not try_again: o_proc = output_proc.OutputProcessorMake(preamble="Configuring: ") if subproc.monitor_process(cmd, shell=True, o_proc=o_proc) == 0: self.log.debug("Configure successful.") return True # OK, something went wrong. if try_again == False: self.log.warning( "Configuration failed. Re-trying with higher verbosity.") return self.configure(recipe, try_again=True) else: self.log.error( "Configuration failed after running at least twice.") raise PBException("Configuration failed")
def update_src(self, url, dest, dirname, args=None): """ git pull / git checkout """ args = args or {} self.log.debug("Using url {0}".format(url)) cwd = os.getcwd() src_dir = os.path.join(dest, dirname) self.log.obnoxious("Switching cwd to: {0}".format(src_dir)) os.chdir(src_dir) if args.get('gitrev'): # If we have a rev or tag specified, fetch, then checkout. git_cmds = [ ['git', 'fetch', '--tags', '--all', '--prune'], ['git', 'checkout', '--force', args.get('gitrev')], ] elif args.get('gitbranch'): # Branch is similar, only we make sure we're up to date # with the remote branch git_cmds = [ ['git', 'fetch', '--tags', '--all', '--prune'], ['git', 'checkout', '--force', args.get('gitbranch')], ['git', 'reset', '--hard', '@{u}'], ] else: # Without a git rev, all we can do is try and pull git_cmds = [ ['git', 'pull', '--rebase'], ] git_cmds.append(['git', 'submodule', 'update', '--recursive']) o_proc = None if self.log.getEffectiveLevel() >= pb_logging.DEBUG: o_proc = output_proc.OutputProcessorMake(preamble="Updating: ") for cmd in git_cmds: try: if subproc.monitor_process( args=cmd, o_proc=o_proc, throw_ex=True) != 0: self.log.error("Could not run command `{0}`".format( " ".join(cmd))) return False except Exception: self.log.error("Could not run command `{0}`".format( " ".join(cmd))) raise PBException("git commands failed.") self.log.obnoxious("Switching cwd back to: {0}".format(cwd)) os.chdir(cwd) return True
def make_install(self, recipe): """ Run 'make install' or whatever copies the files to the right place. """ self.log.debug("Installing package {}".format(recipe.id)) self.log.debug("In cwd - {}".format(os.getcwd())) pre_cmd = recipe.var_replace_all(self.get_command('install', recipe)) cmd = self.filter_cmd(pre_cmd, recipe, 'install_filter') o_proc = None if self.log.getEffectiveLevel() >= pb_logging.DEBUG: o_proc = output_proc.OutputProcessorMake(preamble="Installing: ") if subproc.monitor_process(cmd, shell=True, o_proc=o_proc) == 0: self.log.debug("Installation successful") return True raise PBException("Installation failed")
def fetch_url(self, url, dest, dirname, args=None): """ git clone """ url, args = parse_git_url(url, args or {}) self.log.debug("Using url - {0}".format(url)) git_cmd = ['git', 'clone', url, dirname] if args.get('gitargs'): for arg in args.get('gitargs').split(): git_cmd.append(arg) if self.cfg.get("git-cache", False): from pybombs import gitcache_manager gcm = gitcache_manager.GitCacheManager(self.cfg.get("git-cache")) self.log.debug("Adding remote into git ref") gcm.add_remote(dirname, url, True) git_cmd.append('--reference') git_cmd.append(self.cfg.get("git-cache")) if args.get('gitbranch'): git_cmd.append('-b') git_cmd.append(args.get('gitbranch')) o_proc = None if self.log.getEffectiveLevel() >= pb_logging.DEBUG: o_proc = output_proc.OutputProcessorMake(preamble="Cloning: ") subproc.monitor_process( args=git_cmd, o_proc=o_proc, throw_ex=True, throw=True, ) # If we have a specific revision, checkout that if args.get('gitrev'): cwd = os.getcwd() src_dir = os.path.join(dest, dirname) self.log.obnoxious("Switching cwd to: {0}".format(src_dir)) os.chdir(src_dir) git_co_cmd = ["git", "checkout", "--force", args.get('gitrev')] subproc.monitor_process( args=git_co_cmd, o_proc=o_proc, throw_ex=True, ) self.log.obnoxious("Switching cwd to: {0}".format(cwd)) os.chdir(cwd) return True
def update_src(self, url, dest, dirname, args=None): """ git pull / git checkout """ args = args or {} self.log.debug("Using url {0}".format(url)) cwd = os.getcwd() src_dir = os.path.join(dest, dirname) self.log.obnoxious("Switching cwd to: {}".format(src_dir)) os.chdir(src_dir) if args.get('gitrev'): # If we have a rev or tag specified, fetch, then checkout. git_cmds = [ ['git', 'fetch', '--tags', '--all', '--prune'], ['git', 'checkout', '--force', args.get('gitrev')], ] elif args.get('gitbranch'): # Branch is similar, only we make sure we're up to date # with the remote branch git_cmds = [ ['git', 'fetch', '--tags', '--all', '--prune'], ['git', 'checkout', '--force', args.get('gitbranch')], ['git', 'reset', '--hard', '@{u}'], ] else: # Without a git rev, all we can do is try and pull git_cmds = [ ['git', 'pull', '--rebase'], ] o_proc = None if self.log.getEffectiveLevel() >= pb_logging.DEBUG: o_proc = output_proc.OutputProcessorMake(preamble="Updating: ") for cmd in git_cmds: subproc.monitor_process( args=cmd, o_proc=o_proc, ) self.log.obnoxious("Switching cwd back to: {0}".format(cwd)) os.chdir(cwd) return True
def make_clean(self, recipe, try_again=False): """ Run 'make clean' or whatever clears a build before recompiling """ self.log.debug("Uninstalling from recipe {}".format(recipe.id)) self.log.debug("In cwd - {}".format(os.getcwd())) o_proc = None if self.log.getEffectiveLevel() >= pb_logging.DEBUG and not try_again: o_proc = output_proc.OutputProcessorMake(preamble="Uninstalling: ") cmd = recipe.var_replace_all(self.get_command('uninstall', recipe)) cmd = self.filter_cmd(cmd, recipe, 'uninstall_filter') if subproc.monitor_process(cmd, shell=True, o_proc=o_proc) == 0: self.log.debug("Uninstall successful") return True # OK, something bad happened. if try_again == False: recipe.vars['makewidth'] = '1' self.make_clean(recipe, try_again=True) else: self.log.error("Uninstall failed. See output above for error messages.") raise PBException("Uninstall failed.")
def verify(self, recipe, try_again=False): """ Run 'make test' or whatever checks a build was successful """ self.log.debug("Verifying package {}".format(recipe.id)) self.log.debug("In cwd - {}".format(os.getcwd())) o_proc = None if self.log.getEffectiveLevel() >= pb_logging.DEBUG and not try_again: o_proc = output_proc.OutputProcessorMake(preamble="Verifying: ") cmd = recipe.var_replace_all(self.get_command('verify', recipe)) cmd = self.filter_cmd(cmd, recipe, 'make_filter') if subproc.monitor_process(cmd, shell=True, o_proc=o_proc) == 0: self.log.debug("Verification successful") return True # OK, something bad happened. if try_again == False: self.log.warning("Verification failed. Retrying...") recipe.vars['makewidth'] = '1' self.verify(recipe, try_again=True) else: self.log.error("Verification failed. See output above for error messages.") raise PBException("Verification failed.")