diff options
Diffstat (limited to 'bestflags/builder.py')
-rw-r--r-- | bestflags/builder.py | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/bestflags/builder.py b/bestflags/builder.py new file mode 100644 index 00000000..a75bd425 --- /dev/null +++ b/bestflags/builder.py @@ -0,0 +1,59 @@ +"""The Build stage of the framework. + +Build the image according to the flag set. This stage sets up a number of +processes, calls the actual build method and caches the results. +""" + +__author__ = 'yuhenglong@google.com (Yuheng Long)' + +import multiprocessing + + +class Builder(object): + """Compiling the source code to generate images using multiple processes.""" + + def __init__(self, numProcess, images): + """Set up the process pool and the images cached. + + Args: + numProcess: Maximum number of builds to run in parallel + images: Images that have been generated before + """ + if numProcess <= 0: + numProcess = 1 + self._pool = multiprocessing.Pool(numProcess) + self._images = images + + def _set_cost(self, flag_set, image, cost): + """Record the build result for the current flag_set. + + Args: + flag_set: The optimization combination + image: The result image for the build + cost: the time it takes to build the image + """ + + pass + + def _build_task(self, task): + """Compile the task and generate output. + + This stage includes compiling the input task, generating an image for the + task and computing the checksum for the image. + + Args: + task: The task to be compiled + """ + + pass + + def build(self, generation): + """Build the images for all entities in a generation. + + Call them in parallel in processes. + + Args: + generation: A new generation to be built. + """ + + self._pool.map(self._build_task, generation.task, 1) |