Skip to content
Snippets Groups Projects
builder.py 46.2 KiB
Newer Older
  • Learn to ignore specific revisions
  • 
            if show_sizes:
                self.PrintSizeSummary(board_selected, board_dict, show_detail,
                                      show_bloat)
    
            # Save our updated information for the next call to this function
            self._base_board_dict = board_dict
            self._base_err_lines = err_lines
    
            self._base_warn_lines = warn_lines
            self._base_err_line_boards = err_line_boards
            self._base_warn_line_boards = warn_line_boards
    
    
            # Get a list of boards that did not get built, if needed
            not_built = []
            for board in board_selected:
                if not board in board_dict:
                    not_built.append(board)
            if not_built:
    
                Print("Boards not built (%d): %s" % (len(not_built),
                      ', '.join(not_built)))
    
        def ProduceResultSummary(self, commit_upto, commits, board_selected):
    
                (board_dict, err_lines, err_line_boards, warn_lines,
                        warn_line_boards) = self.GetResultSummary(
    
                        board_selected, commit_upto,
                        read_func_sizes=self._show_bloat)
    
                if commits:
                    msg = '%02d: %s' % (commit_upto + 1,
                            commits[commit_upto].subject)
    
                    Print(msg, colour=self.col.BLUE)
    
                self.PrintResultSummary(board_selected, board_dict,
    
                        err_lines if self._show_errors else [], err_line_boards,
    
                        warn_lines if self._show_errors else [], warn_line_boards,
    
                        self._show_sizes, self._show_detail, self._show_bloat)
    
        def ShowSummary(self, commits, board_selected):
    
            """Show a build summary for U-Boot for a given board list.
    
            Reset the result summary, then repeatedly call GetResultSummary on
            each commit's results, then display the differences we see.
    
            Args:
                commit: Commit objects to summarise
                board_selected: Dict containing boards to summarise
            """
    
            self.commit_count = len(commits) if commits else 1
    
            self.commits = commits
            self.ResetResultSummary(board_selected)
    
    
            for commit_upto in range(0, self.commit_count, self._step):
    
                self.ProduceResultSummary(commit_upto, commits, board_selected)
    
            if not self._error_lines:
    
                Print('(no errors to report)', colour=self.col.GREEN)
    
    
    
        def SetupBuild(self, board_selected, commits):
            """Set up ready to start a build.
    
            Args:
                board_selected: Selected boards to build
                commits: Selected commits to build
            """
            # First work out how many commits we will build
    
            count = (self.commit_count + self._step - 1) / self._step
    
            self.count = len(board_selected) * count
            self.upto = self.warned = self.fail = 0
            self._timestamps = collections.deque()
    
        def GetThreadDir(self, thread_num):
            """Get the directory path to the working dir for a thread.
    
            Args:
                thread_num: Number of thread to check.
            """
            return os.path.join(self._working_dir, '%02d' % thread_num)
    
    
        def _PrepareThread(self, thread_num, setup_git):
    
            """Prepare the working directory for a thread.
    
            This clones or fetches the repo into the thread's work directory.
    
            Args:
                thread_num: Thread number (0, 1, ...)
    
                setup_git: True to set up a git repo clone
    
            """
            thread_dir = self.GetThreadDir(thread_num)
    
            builderthread.Mkdir(thread_dir)
    
            git_dir = os.path.join(thread_dir, '.git')
    
            # Clone the repo if it doesn't already exist
            # TODO(sjg@chromium): Perhaps some git hackery to symlink instead, so
            # we have a private index but uses the origin repo's contents?
    
            if setup_git and self.git_dir:
    
                src_dir = os.path.abspath(self.git_dir)
                if os.path.exists(git_dir):
                    gitutil.Fetch(git_dir, thread_dir)
                else:
    
                    Print('Cloning repo for thread %d' % thread_num)
    
                    gitutil.Clone(src_dir, thread_dir)
    
    
        def _PrepareWorkingSpace(self, max_threads, setup_git):
    
            """Prepare the working directory for use.
    
            Set up the git repo for each thread.
    
            Args:
                max_threads: Maximum number of threads we expect to need.
    
                setup_git: True to set up a git repo clone
    
            builderthread.Mkdir(self._working_dir)
    
            for thread in range(max_threads):
    
                self._PrepareThread(thread, setup_git)
    
    
        def _PrepareOutputSpace(self):
            """Get the output directories ready to receive files.
    
            We delete any output directories which look like ones we need to
            create. Having left over directories is confusing when the user wants
            to check the output manually.
            """
    
            dir_list = []
            for commit_upto in range(self.commit_count):
                dir_list.append(self._GetOutputDir(commit_upto))
    
            for dirname in glob.glob(os.path.join(self.base_dir, '*')):
                if dirname not in dir_list:
                    shutil.rmtree(dirname)
    
    
        def BuildBoards(self, commits, board_selected, keep_outputs, verbose):
    
            """Build all commits for a list of boards
    
            Args:
                commits: List of commits to be build, each a Commit object
                boards_selected: Dict of selected boards, key is target name,
                        value is Board object
                keep_outputs: True to save build output files
    
                verbose: Display build results as they are completed
    
            Returns:
                Tuple containing:
                    - number of boards that failed to build
                    - number of boards that issued warnings
    
            self.commit_count = len(commits) if commits else 1
    
    
            self.ResetResultSummary(board_selected)
    
            builderthread.Mkdir(self.base_dir, parents = True)
    
            self._PrepareWorkingSpace(min(self.num_threads, len(board_selected)),
                    commits is not None)
    
            self._PrepareOutputSpace()
            self.SetupBuild(board_selected, commits)
            self.ProcessResult(None)
    
            # Create jobs to build all commits for each board
            for brd in board_selected.itervalues():
    
                job = builderthread.BuilderJob()
    
                job.board = brd
                job.commits = commits
                job.keep_outputs = keep_outputs
                job.step = self._step
                self.queue.put(job)
    
            # Wait until all jobs are started
            self.queue.join()
    
            # Wait until we have processed all output
            self.out_queue.join()
    
            return (self.fail, self.warned)