Esempio n. 1
0
    def Patch(self):
        stamp_file = os.path.join(self.GetStampDir(), 'nacl_patch')
        src_dir = self.GetBuildLocation()
        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.RunCmd(cmd)
            return

        util.LogHeading('Patching')
        InitGitRepo(src_dir)
        if os.path.exists(self.GetPatchFile()):
            LogVerbose('applying patch to: %s' % src_dir)
            cmd = ['patch', '-p1', '-g0', '--no-backup-if-mismatch']
            with open(self.GetPatchFile()) as f:
                self.RunCmd(cmd, stdin=f)
            self.RunCmd(['git', 'add', '.'])
            self.RunCmd(['git', 'commit', '-m', 'Apply naclports patch'])

        WriteStamp(stamp_file, '')
Esempio n. 2
0
    def Patch(self):
        stamp_file = os.path.join(self.GetStampDir(), 'nacl_patch')
        src_dir = self.GetBuildLocation()
        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.verbose:
                cmd.append('-q')
            self.RunCmd(cmd)
            return

        util.LogHeading('Patching')
        Log('Init git repo: %s' % src_dir)
        try:
            InitGitRepo(src_dir)
        except subprocess.CalledProcessError as e:
            raise Error(e)
        if os.path.exists(self.GetPatchFile()):
            Trace('applying patch to: %s' % src_dir)
            cmd = ['patch', '-p1', '-g0', '--no-backup-if-mismatch']
            with open(self.GetPatchFile()) as f:
                self.RunCmd(cmd, stdin=f)
            self.RunCmd(['git', 'add', '.'])
            self.RunCmd(['git', 'commit', '-m', 'Apply naclports patch'])

        WriteStamp(stamp_file, '')
Esempio n. 3
0
  def GitClone(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.GetExtractStamp()
    stamp_content = 'GITURL=%s' % self.URL
    patch_file = self.GetPatchFile()
    if os.path.exists(patch_file):
      patch_checksum = util.HashFile(patch_file)
      stamp_content += ' PATCH=%s' % patch_checksum

    stamp_content += '\n'

    dest = self.GetBuildLocation()
    if os.path.exists(self.GetBuildLocation()):
      if StampContentsMatch(stamp_file, stamp_content):
        return

      raise Error('Upstream archive or patch has changed.\n' +
                  "Please remove existing checkout and try again: '%s'" % dest)

    util.LogHeading('Cloning')
    # Ensure local mirror is up-to-date
    git_mirror, git_commit = self.GitCloneToMirror()
    # Clone from the local mirror.
    RunGitCmd(None, ['clone', git_mirror, dest])
    RunGitCmd(dest, ['reset', '--hard', git_commit])

    # Set the origing to the original URL so it is possible to push directly
    # from the build tree.
    RunGitCmd(dest, ['remote', 'set-url', 'origin', '${GIT_URL}'])

    self.RemoveStamps()
    WriteStamp(stamp_file, stamp_content)
Esempio n. 4
0
  def Build(self, build_deps, force=None):
    self.CheckBuildable()

    if build_deps:
      self.InstallDeps(force)

    if not force and self.IsBuilt():
      self.LogStatus('Already built')
      return

    log_root = os.path.join(paths.OUT_DIR, 'logs')
    util.Makedirs(log_root)

    self.LogStatus('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.BuildLock():
      try:
        with RedirectStdoutStderr(log_filename):
          old_log_level = util.log_level
          util.log_level = util.LOG_VERBOSE
          try:
            self.Download()
            self.Extract()
            self.Patch()
            self.RunBuildSh()
            self.CreatePkgFile()
          finally:
            util.log_level = old_log_level
      except:
        if log_filename:
          with open(log_filename) as log_file:
            sys.stdout.write(log_file.read())
        raise

    duration = FormatTimeDelta(time.time() - start)
    util.LogHeading('Build complete', ' [took %s]' % duration)
Esempio n. 5
0
    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)
Esempio n. 6
0
 def LogStatus(self, message, suffix=''):
     util.LogHeading(
         message, " '%s' [%s] %s" % (util.Color(
             self.NAME, 'yellow'), util.Color(self.config, 'blue'), suffix))