def Clean(self): pkg = self.PackageFile() Log('removing %s' % pkg) if os.path.exists(pkg): os.remove(pkg) stamp_dir = os.path.join(paths.STAMP_DIR, self.NAME) Log('removing %s' % stamp_dir) util.RemoveTree(stamp_dir)
def Extract(self): """Extract the package archive into its build location. This method assumes the package has already been downloaded. """ if self.IsGitUpstream(): self.GitClone() return archive = self.DownloadLocation() if not archive: self.Log('Skipping extract; No upstream archive') return dest = self.GetBuildLocation() output_path, new_foldername = os.path.split(dest) util.Makedirs(output_path) # Check existing stamp file contents stamp_file = self.GetExtractStamp() stamp_contents = self.GetExtractStampContent() if os.path.exists(dest): if StampContentsMatch(stamp_file, stamp_contents): Log('Already up-to-date: %s' % util.RelPath(dest)) return raise Error("Upstream archive or patch has changed.\n" + "Please remove existing checkout and try again: '%s'" % dest) util.LogHeading('Extracting') util.Makedirs(paths.OUT_DIR) tmp_output_path = tempfile.mkdtemp(dir=paths.OUT_DIR) try: ExtractArchive(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) LogVerbose("renaming '%s' -> '%s'" % (src, dest)) os.rename(src, dest) finally: util.RemoveTree(tmp_output_path) self.RemoveStamps() WriteStamp(stamp_file, stamp_contents)
def InitGitRepo(directory): """Initialize the source git repository for a given package directory. This function works for unpacked tar files as well as cloned git repositories. It sets up an 'upstream' branch pointing and the pristine upstream sources and a 'master' branch will contain changes specific to naclports (normally the result of applying nacl.patch). Args: directory: Directory containing unpacked package sources. """ git_dir = os.path.join(directory, '.git') # If the upstream ref exists then we've already initialized this repo if os.path.exists(os.path.join(git_dir, 'refs', 'heads', 'upstream')): return if os.path.exists(git_dir): Log('Init existing git repo: %s' % directory) RunGitCmd(directory, ['checkout', '-b', 'placeholder']) RunGitCmd(directory, ['branch', '-D', 'upstream'], error_ok=True) RunGitCmd(directory, ['branch', '-D', 'master'], error_ok=True) RunGitCmd(directory, ['checkout', '-b', 'upstream']) RunGitCmd(directory, ['checkout', '-b', 'master']) RunGitCmd(directory, ['branch', '-D', 'placeholder']) else: Log('Init new git repo: %s' % directory) RunGitCmd(directory, ['init']) try: # Setup a bogus identity on the buildbots. if os.environ.get('BUILDBOT_BUILDERNAME'): RunGitCmd(directory, ['config', 'user.name', 'Naclports']) RunGitCmd(directory, ['config', 'user.email', '*****@*****.**']) RunGitCmd(directory, ['add', '-f', '.']) RunGitCmd(directory, ['commit', '-m', 'Upstream version']) RunGitCmd(directory, ['checkout', '-b', 'upstream']) RunGitCmd(directory, ['checkout', 'master']) except: # pylint: disable=bare-except # If git setup fails or is interrupted then remove the partially # initialized repository. util.RemoveTree(os.path.join(git_dir))
def RemoveStamps(self): util.RemoveTree(self.GetStampDir())
def rmtree(path): util.Log('removing %s' % path) util.RemoveTree(path)