# Execute the build script...
print "Starting build..."
chan = sshs.get_transport().open_session()
+ chan.get_pty()
cmdline = 'python build.py --on-server'
if force:
cmdline += ' --force --test'
cmdline += " %s:%s" % (app['id'], thisbuild['vercode'])
chan.exec_command('bash -c ". ~/.bsenv && ' + cmdline + '"')
output = ''
- error = ''
while not chan.exit_status_ready():
while chan.recv_ready():
output += chan.recv(1024)
- while chan.recv_stderr_ready():
- error += chan.recv_stderr(1024)
time.sleep(0.1)
print "...getting exit status"
returncode = chan.recv_exit_status()
if len(get) == 0:
break
output += get
- while True:
- get = chan.recv_stderr(1024)
- if len(get) == 0:
- break
- error += get
if returncode != 0:
- raise BuildException("Build.py failed on server for %s:%s" % (app['id'], thisbuild['version']), output, error)
+ raise BuildException("Build.py failed on server for %s:%s" % (app['id'], thisbuild['version']), output)
# Retrieve the built files...
print "Retrieving build output..."
ftp.get(apkfile, os.path.join(output_dir, apkfile))
ftp.get(tarball, os.path.join(output_dir, tarball))
except:
- raise BuildException("Build failed for %s:%s - missing output files" % (app['id'], thisbuild['version']), output, error)
+ raise BuildException("Build failed for %s:%s - missing output files" % (app['id'], thisbuild['version']), output)
ftp.close()
finally:
if p is not None and p.returncode != 0:
raise BuildException("Error cleaning %s:%s" %
- (app['id'], thisbuild['version']), p.stdout, p.stderr)
+ (app['id'], thisbuild['version']), p.stdout)
# Scan before building...
print "Scanning source for common problems..."
if p.returncode != 0:
raise BuildException("Error running build command for %s:%s" %
- (app['id'], thisbuild['version']), p.stdout, p.stderr)
+ (app['id'], thisbuild['version']), p.stdout)
# Build native stuff if required...
if thisbuild.get('buildjni') not in (None, 'no'):
del manifest_text
p = FDroidPopen([ndkbuild], cwd=os.path.join(root_dir,d))
if p.returncode != 0:
- raise BuildException("NDK build failed for %s:%s" % (app['id'], thisbuild['version']), p.stdout, p.stderr)
+ raise BuildException("NDK build failed for %s:%s" % (app['id'], thisbuild['version']), p.stdout)
p = None
# Build the release...
bindir = os.path.join(root_dir, 'bin')
if p.returncode != 0:
- raise BuildException("Build failed for %s:%s" % (app['id'], thisbuild['version']), p.stdout, p.stderr)
+ raise BuildException("Build failed for %s:%s" % (app['id'], thisbuild['version']), p.stdout)
print "Successfully built version " + thisbuild['version'] + ' of ' + app['id']
# Find the apk name in the output...
if len(txt) > 8192:
txt = txt[-8192:]
txt = "Build completed at " + time.strftime("%Y-%m-%d %H:%M:%SZ", time.gmtime()) + "\n\n" + txt
- newpage.save(wikilog, summary='Build log')
+ newpage.save(txt, summary='Build log')
except:
print "Error while attempting to publish build log"
return (max_version, max_vercode, max_package)
class BuildException(Exception):
- def __init__(self, value, stdout = None, stderr = None):
+ def __init__(self, value, detail = None):
self.value = value
- self.stdout = stdout
- self.stderr = stderr
+ self.detail = detail
def get_wikitext(self):
ret = repr(self.value) + "\n"
- if self.stdout:
- ret += "=stdout=\n"
+ if self.detail:
+ ret += "=detail=\n"
ret += "<pre>\n"
- ret += str(self.stdout)
- ret += "</pre>\n"
- if self.stderr:
- ret += "=stderr=\n"
- ret += "<pre>\n"
- ret += str(self.stderr)
+ ret += str(self.detail)
ret += "</pre>\n"
return ret
def __str__(self):
ret = repr(self.value)
- if self.stdout:
- ret += "\n==== stdout begin ====\n%s\n==== stdout end ====" % self.stdout.strip()
- if self.stderr:
- ret += "\n==== stderr begin ====\n%s\n==== stderr end ====" % self.stderr.strip()
+ if self.detail:
+ ret += "\n==== detail begin ====\n%s\n==== detail end ====" % self.detail.strip()
return ret
class VCSException(Exception):
p = FDroidPopen(['bash', '-x', '-c', cmd], cwd=libdir)
if p.returncode != 0:
raise BuildException("Error running prepare command for srclib %s"
- % name, p.stdout, p.stderr)
+ % name, p.stdout)
if srclib["Update Project"] == "Yes":
print "Updating srclib %s at path %s" % (name, libdir)
# Check to see whether an error was returned without a proper exit
# code (this is the case for the 'no target set or target invalid'
# error)
- if p.returncode != 0 or (p.stderr != "" and
- p.stderr.startswith("Error: ")):
+ if p.returncode != 0 or p.stdout.startswith("Error: "):
raise BuildException("Failed to update srclib project {0}"
- .format(name), p.stdout, p.stderr)
+ .format(name), p.stdout)
remove_signing_keys(libdir)
p = FDroidPopen(['bash', '-x', '-c', cmd], cwd=root_dir)
if p.returncode != 0:
raise BuildException("Error running init command for %s:%s" %
- (app['id'], build['version']), p.stdout, p.stderr)
+ (app['id'], build['version']), p.stdout)
# Generate (or update) the ant build file, build.xml...
updatemode = build.get('update', 'auto')
# Check to see whether an error was returned without a proper exit
# code (this is the case for the 'no target set or target invalid'
# error)
- if p.returncode != 0 or (p.stderr != "" and
- p.stderr.startswith("Error: ")):
+ if p.returncode != 0 or p.stdout.startswith("Error: "):
raise BuildException("Failed to update project at %s" % d,
- p.stdout, p.stderr)
+ p.stdout)
# Update the local.properties file...
localprops = [ os.path.join(build_dir, 'local.properties') ]
p = FDroidPopen(['bash', '-x', '-c', cmd], cwd=root_dir)
if p.returncode != 0:
raise BuildException("Error running prebuild command for %s:%s" %
- (app['id'], build['version']), p.stdout, p.stderr)
+ (app['id'], build['version']), p.stdout)
return (root_dir, srclibpaths)
def FDroidPopen(commands, cwd=None):
"""
- Runs a command the FDroid way and returns return code and output
+ Run a command and capture the output.
- :param commands and cwd like in subprocess.Popen
+ :param commands: command and argument list like in subprocess.Popen
+ :param cwd: optionally specifies a working directory
+ :returns: A PopenResult.
"""
if options.verbose:
result = PopenResult()
p = subprocess.Popen(commands, cwd=cwd,
- stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
stdout_queue = Queue.Queue()
stdout_reader = AsynchronousFileReader(p.stdout, stdout_queue)
stdout_reader.start()
- stderr_queue = Queue.Queue()
- stderr_reader = AsynchronousFileReader(p.stderr, stderr_queue)
- stderr_reader.start()
- # Check the queues for output (until there is no more to get)
- while not stdout_reader.eof() or not stderr_reader.eof():
- # Show what we received from standard output
+ # Check the queue for output (until there is no more to get)
+ while not stdout_reader.eof():
while not stdout_queue.empty():
line = stdout_queue.get()
if options.verbose:
sys.stdout.flush()
result.stdout += line
- # Show what we received from standard error
- while not stderr_queue.empty():
- line = stderr_queue.get()
- if options.verbose:
- # Output directly to console
- sys.stderr.write(line)
- sys.stderr.flush()
- result.stderr += line
time.sleep(0.1)
p.communicate()