Skip to content

Using Popen for uVision and unifying the structure of the build function #3200

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 28 additions & 14 deletions tools/export/iar/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,11 @@ def generate(self):
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
Expand All @@ -139,23 +138,38 @@ def build(project_name, cleanup=True):
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
39 changes: 24 additions & 15 deletions tools/export/makefile/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,32 +110,41 @@ def build(project_name, log_name="build_log.txt", cleanup=True):
""" Build Make project """
# > Make -j
cmd = ["make", "-j"]

# Build the project
p = Popen(cmd, stdout=PIPE, stderr=PIPE)
ret = p.communicate()
out, err = ret[0], ret[1]
out, err = p.communicate()
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()

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):
Expand Down
33 changes: 21 additions & 12 deletions tools/export/uvision/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import copy
from collections import namedtuple
import shutil
import subprocess
from subprocess import Popen, PIPE
import re

from tools.arm_pack_manager import Cache
Expand Down Expand Up @@ -208,21 +208,30 @@ def generate(self):
@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