diff --git a/tools/export/iar/__init__.py b/tools/export/iar/__init__.py index d9b92db4f3..475f86615e 100644 --- a/tools/export/iar/__init__.py +++ b/tools/export/iar/__init__.py @@ -122,12 +122,11 @@ class IAR(Exporter): self.gen_file(self.get_ewp_template(), ctx, self.project_name + ".ewp") @staticmethod - def build(project_name, cleanup=True): + def build(project_name, log_name="build_log.txt", cleanup=True): """ Build IAR project """ # > IarBuild [project_path] -build [project_name] - proj_file = project_name + ".ewp" - cmd = ["IarBuild.exe", proj_file, '-build', project_name] + cmd = ["IarBuild", proj_file, '-build', project_name] # IAR does not support a '0' option to automatically use all # available CPUs, so we use Python's multiprocessing library @@ -139,23 +138,38 @@ class IAR(Exporter): if jobs: cmd += ['-parallel', str(jobs)] + # Build the project p = Popen(cmd, stdout=PIPE, stderr=PIPE) - num_errors = 0 - #Parse the output for printing and errors - for line in p.stdout.readlines(): - sys.stdout.write(line) - error_re = '\s*Total number of errors:\s*(\d+)\s*' - m = re.match(error_re, line) - if m is not None: - num_errors = int(m.group(1)) + out, err = p.communicate() + ret_code = p.returncode + out_string = "=" * 10 + "STDOUT" + "=" * 10 + "\n" + out_string += out + out_string += "=" * 10 + "STDERR" + "=" * 10 + "\n" + out_string += err + + if ret_code == 0: + out_string += "SUCCESS" + else: + out_string += "FAILURE" + + print out_string + + if log_name: + # Write the output to the log file + with open(log_name, 'w+') as f: + f.write(out_string) + + # Cleanup the exported and built files if cleanup: os.remove(project_name + ".ewp") os.remove(project_name + ".ewd") os.remove(project_name + ".eww") - shutil.rmtree('.build') + if exists('.build'): + shutil.rmtree('.build') - if num_errors !=0: + if ret_code !=0: # Seems like something went wrong. return -1 - return 0 + else: + return 0 diff --git a/tools/export/makefile/__init__.py b/tools/export/makefile/__init__.py index 816ec8785d..05200bfb8d 100644 --- a/tools/export/makefile/__init__.py +++ b/tools/export/makefile/__init__.py @@ -110,32 +110,41 @@ class Makefile(Exporter): """ Build Make project """ # > Make -j cmd = ["make", "-j"] - p = Popen(cmd, stdout=PIPE, stderr=PIPE) - ret = p.communicate() - out, err = ret[0], ret[1] - ret_code = p.returncode - with open(log_name, 'w+') as f: - f.write("=" * 10 + "OUT" + "=" * 10 + "\n") - f.write(out) - f.write("=" * 10 + "ERR" + "=" * 10 + "\n") - f.write(err) - if ret_code == 0: - f.write("SUCCESS") - else: - f.write("FAILURE") - with open(log_name, 'r') as f: - print "\n".join(f.readlines()) - sys.stdout.flush() + # Build the project + p = Popen(cmd, stdout=PIPE, stderr=PIPE) + out, err = p.communicate() + ret_code = p.returncode + + out_string = "=" * 10 + "STDOUT" + "=" * 10 + "\n" + out_string += out + out_string += "=" * 10 + "STDERR" + "=" * 10 + "\n" + out_string += err + + if ret_code == 0: + out_string += "SUCCESS" + else: + out_string += "FAILURE" + + print out_string + + if log_name: + # Write the output to the log file + with open(log_name, 'w+') as f: + f.write(out_string) + + # Cleanup the exported and built files if cleanup: remove("Makefile") remove(log_name) if exists('.build'): shutil.rmtree('.build') + if ret_code != 0: # Seems like something went wrong. return -1 - return 0 + else: + return 0 class GccArm(Makefile): diff --git a/tools/export/uvision/__init__.py b/tools/export/uvision/__init__.py index 14eedbc637..e815a00d53 100644 --- a/tools/export/uvision/__init__.py +++ b/tools/export/uvision/__init__.py @@ -4,7 +4,7 @@ import ntpath import copy from collections import namedtuple import shutil -import subprocess +from subprocess import Popen, PIPE import re from tools.arm_pack_manager import Cache @@ -208,21 +208,30 @@ class Uvision(Exporter): @staticmethod def build(project_name, log_name='build_log.txt', cleanup=True): """ Build Uvision project """ - # > UV4.exe -r -j0 -o [log_name] [project_name].uvprojx - success = 0 - warn = 1 - cmd = ["UV4.exe", '-r', '-j0', '-o', log_name, project_name+".uvprojx"] - ret_code = subprocess.call(cmd) - with open(log_name, 'r') as build_log: - print build_log.read() + # > UV4 -r -j0 -o [log_name] [project_name].uvprojx + proj_file = project_name + ".uvprojx" + cmd = ['UV4', '-r', '-j0', '-o', log_name, proj_file] + + # Build the project + p = Popen(cmd, stdout=PIPE, stderr=PIPE) + out, err = p.communicate() + ret_code = p.returncode + + # Print the log file to stdout + with open(log_name, 'r') as f: + print f.read() + + # Cleanup the exported and built files if cleanup: os.remove(log_name) os.remove(project_name+".uvprojx") os.remove(project_name+".uvoptx") - shutil.rmtree(".build") + if exists('.build'): + shutil.rmtree(".build") - - if ret_code != success and ret_code != warn: + # Returns 0 upon success, 1 upon a warning, and neither upon an error + if ret_code != 0 and ret_code != 1: # Seems like something went wrong. return -1 - return 0 + else: + return 0