def git_clone(self): """Create a clone of the upstream repo in the build directory. This operation will only require a network connection if the local git mirror is out-of-date.""" stamp_file = self.get_extract_stamp() stamp_content = 'GITURL=%s' % self.URL patch_file = self.get_patch_file() if os.path.exists(patch_file): patch_checksum = util.hash_file(patch_file) stamp_content += ' PATCH=%s' % patch_checksum stamp_content += '\n' dest = self.get_build_location() if os.path.exists(self.get_build_location()): if stamp_contents_match(stamp_file, stamp_content): return raise Error('Upstream archive or patch has changed.\n' + "Please remove existing checkout and try again: '%s'" % dest) util.log_heading('Cloning') # Ensure local mirror is up-to-date git_mirror, git_commit = self.git_clone_to_mirror() # Clone from the local mirror. run_git_cmd(None, ['clone', git_mirror, dest]) run_git_cmd(dest, ['reset', '--hard', git_commit]) # Set the origing to the original URL so it is possible to push directly # from the build tree. run_git_cmd(dest, ['remote', 'set-url', 'origin', self.URL.split('@')[0]]) self.remove_stamps() write_stamp(stamp_file, stamp_content)
def patch(self): stamp_file = os.path.join(self.get_stamp_dir(), 'nacl_patch') src_dir = self.get_build_location() if self.URL is None: return if os.path.exists(stamp_file): self.log('Skipping patch step (cleaning source tree)') cmd = ['git', 'clean', '-f', '-d'] if not util.log_level > util.LOG_INFO: cmd.append('-q') self.run_cmd(cmd) return util.log_heading('Patching') init_git_repo(src_dir) if os.path.exists(self.get_patch_file()): log_verbose('applying patch to: %s' % src_dir) cmd = ['patch', '-p1', '-g0', '--no-backup-if-mismatch'] with open(self.get_patch_file()) as f: self.run_cmd(cmd, stdin=f) self.run_cmd(['git', 'add', '.']) self.run_cmd(['git', 'commit', '-m', 'Apply webports patch']) write_stamp(stamp_file, '')
def build(self, build_deps, force=None): self.check_buildable() if build_deps: self.install_deps(force) if not force and self.is_built(): self.log_status('Already built') return log_root = os.path.join(paths.OUT_DIR, 'logs') util.makedirs(log_root) self.log_status('Building') if util.log_level > util.LOG_INFO: log_filename = None else: log_filename = os.path.join( log_root, '%s_%s.log' % (self.NAME, str(self.config).replace('/', '_'))) if os.path.exists(log_filename): os.remove(log_filename) start = time.time() with util.DirLock(self.root): try: with redirect_stdout_stderr(log_filename): old_log_level = util.log_level util.log_level = util.LOG_VERBOSE try: self.download() self.extract() self.patch() self.run_build_sh() self.create_pkg_file() finally: util.log_level = old_log_level except KeyboardInterrupt: # Treat KeyboardInterrupt as special, and not an actual failure. This # avoid log spew to stdout when they user interupts a quit build. raise except: if log_filename: with open(log_filename) as log_file: sys.stdout.write(log_file.read()) raise duration = format_time_delta(time.time() - start) util.log_heading('Build complete', ' [took %s]' % duration)
def build(self, build_deps, force=None): self.check_buildable() if build_deps: self.install_deps(force) if not force and self.is_built(): self.log_status('Already built') return log_root = os.path.join(paths.OUT_DIR, 'logs') util.makedirs(log_root) self.log_status('Building') if util.log_level > util.LOG_INFO: log_filename = None else: log_filename = os.path.join(log_root, '%s_%s.log' % (self.NAME, str(self.config).replace('/', '_'))) if os.path.exists(log_filename): os.remove(log_filename) start = time.time() with util.DirLock(self.root): try: with redirect_stdout_stderr(log_filename): old_log_level = util.log_level util.log_level = util.LOG_VERBOSE try: self.download() self.extract() self.patch() self.run_build_sh() self.create_pkg_file() finally: util.log_level = old_log_level except KeyboardInterrupt: # Treat KeyboardInterrupt as special, and not an actual failure. This # avoid log spew to stdout when they user interupts a quit build. raise except: if log_filename: with open(log_filename) as log_file: sys.stdout.write(log_file.read()) raise duration = format_time_delta(time.time() - start) util.log_heading('Build complete', ' [took %s]' % duration)
def extract(self): """Extract the package archive into its build location. This method assumes the package has already been downloaded. """ if self.is_git_upstream(): self.git_clone() return archive = self.download_location() if not archive: self.log('Skipping extract; No upstream archive') return dest = self.get_build_location() output_path, new_foldername = os.path.split(dest) util.makedirs(output_path) # Check existing stamp file contents stamp_file = self.get_extract_stamp() stamp_contents = self.get_extract_stamp_content() if os.path.exists(dest): if stamp_contents_match(stamp_file, stamp_contents): log('Already up-to-date: %s' % util.rel_path(dest)) return raise Error("Upstream archive or patch has changed.\n" + "Please remove existing checkout and try again: '%s'" % dest) util.log_heading('Extracting') util.makedirs(paths.OUT_DIR) tmp_output_path = tempfile.mkdtemp(dir=paths.OUT_DIR) try: extract_archive(archive, tmp_output_path) src = os.path.join(tmp_output_path, new_foldername) if not os.path.isdir(src): raise Error('Archive contents not found: %s' % src) log_verbose("renaming '%s' -> '%s'" % (src, dest)) os.rename(src, dest) finally: util.remove_tree(tmp_output_path) self.remove_stamps() write_stamp(stamp_file, stamp_contents)
def log_status(self, message, suffix=''): util.log_heading(message, " " + self.info_string())