<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def build_project(self):
 """ Build IAR project """

        # > IarBuild [project_path] -build [project_name]
        proj_path = join(getcwd(), self.workspace['files']['ewp'])
        if proj_path.split('.')[-1] != 'ewp':
            proj_path += '.ewp'
        if not os.path.exists(proj_path):
            logger.debug("The file: %s does not exists, exported prior building?" % proj_path)
            return -1
        logger.debug("Building IAR project: %s" % proj_path)

        args = [join(self.env_settings.get_env_settings('iar'), 'IarBuild.exe'), proj_path, '-build', os.path.splitext(os.path.basename(self.workspace['files']['ewp']))[0]]
        logger.debug(args)

        try:
            p = Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE)
            output, err = p.communicate()
        except:
            logger.error("Project: %s build failed. Please check IARBUILD path in the user_settings.py file." % self.workspace['files']['ewp'])
            return -1
        else:
            build_log_path = os.path.join(os.path.dirname(proj_path),'build_log.txt')
            with open(build_log_path, 'w') as f:
                f.write(output)
            num_errors = self._parse_subprocess_output(output)
            if num_errors == 0:
                logger.info("Project: %s build completed." % self.workspace['files']['ewp'])
                return 0
            else:
                logger.error("Project: %s build failed with %d errors" %
                             (self.workspace['files']['ewp'], num_errors))
                return -1