Start doing logging properly

This commit is contained in:
Daniel Martí 2014-01-27 15:59:40 +01:00
parent 3f43c121e5
commit caa3d4eace
3 changed files with 81 additions and 87 deletions

6
fdroid
View File

@ -19,6 +19,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
import sys import sys
import logging
commands = [ commands = [
"build", "build",
@ -54,6 +55,11 @@ def main():
print_help() print_help()
sys.exit(1) sys.exit(1)
verbose = any(s in sys.argv for s in ['-v', '--verbose'])
logging.basicConfig(format='%(levelname)s: %(message)s',
level=logging.DEBUG if verbose else logging.INFO)
# Trick optparse into displaying the right usage when --help is used. # Trick optparse into displaying the right usage when --help is used.
sys.argv[0] += ' ' + command sys.argv[0] += ' ' + command

View File

@ -662,7 +662,7 @@ def build_local(app, thisbuild, vcs, build_dir, output_dir, srclib_dir, extlib_d
else: else:
name = '-'.join([os.path.basename(dd), '-'.join(flavours), 'release', 'unsigned']) name = '-'.join([os.path.basename(dd), '-'.join(flavours), 'release', 'unsigned'])
src = os.path.join(dd, 'build', 'apk', name+'.apk') src = os.path.join(dd, 'build', 'apk', name+'.apk')
else: elif thisbuild['type'] == 'ant':
stdout_apk = '\n'.join([ stdout_apk = '\n'.join([
line for line in p.stdout.splitlines() if '.apk' in line]) line for line in p.stdout.splitlines() if '.apk' in line])
src = re.match(r".*^.*Creating (.+) for release.*$.*", stdout_apk, src = re.match(r".*^.*Creating (.+) for release.*$.*", stdout_apk,

View File

@ -26,6 +26,7 @@ import operator
import Queue import Queue
import threading import threading
import magic import magic
import logging
import metadata import metadata
@ -43,7 +44,7 @@ def read_config(opts, config_file='config.py'):
if config is not None: if config is not None:
return config return config
if not os.path.isfile(config_file): if not os.path.isfile(config_file):
print "Missing config file - is this a repo directory?" logging.critical("Missing config file - is this a repo directory?")
sys.exit(2) sys.exit(2)
options = opts options = opts
@ -69,14 +70,13 @@ def read_config(opts, config_file='config.py'):
} }
config = {} config = {}
if options.verbose: logging.info("Reading %s" % config_file)
print "Reading %s..." % config_file
execfile(config_file, config) execfile(config_file, config)
if any(k in config for k in ["keystore", "keystorepass", "keypass"]): if any(k in config for k in ["keystore", "keystorepass", "keypass"]):
st = os.stat(config_file) st = os.stat(config_file)
if st.st_mode & stat.S_IRWXG or st.st_mode & stat.S_IRWXO: if st.st_mode & stat.S_IRWXG or st.st_mode & stat.S_IRWXO:
print "WARNING: unsafe permissions on {0} (should be 0600)!".format(config_file) logging.warn("unsafe permissions on {0} (should be 0600)!".format(config_file))
for k, v in defconfig.items(): for k, v in defconfig.items():
if k not in config: if k not in config:
@ -129,7 +129,7 @@ def read_app_args(args, allapps, allow_vercodes=False):
allids = [app["id"] for app in allapps] allids = [app["id"] for app in allapps]
for p in vercodes: for p in vercodes:
if p not in allids: if p not in allids:
print "No such package: %s" % p logging.critical("No such package: %s" % p)
raise Exception("Found invalid app ids in arguments") raise Exception("Found invalid app ids in arguments")
error = False error = False
@ -143,7 +143,7 @@ def read_app_args(args, allapps, allow_vercodes=False):
allvcs = [b['vercode'] for b in app['builds']] allvcs = [b['vercode'] for b in app['builds']]
for v in vercodes[app['id']]: for v in vercodes[app['id']]:
if v not in allvcs: if v not in allvcs:
print "No such vercode %s for app %s" % (v, app['id']) logging.critical("No such vercode %s for app %s" % (v, app['id']))
if error: if error:
raise Exception("Found invalid vercodes for some apps") raise Exception("Found invalid vercodes for some apps")
@ -250,10 +250,10 @@ class vcs:
writeback = False writeback = False
else: else:
deleterepo = True deleterepo = True
print "*** Repository details changed - deleting ***" logging.info("Repository details changed - deleting")
else: else:
deleterepo = True deleterepo = True
print "*** Repository details missing - deleting ***" logging.info("Repository details missing - deleting")
if deleterepo: if deleterepo:
shutil.rmtree(self.local) shutil.rmtree(self.local)
@ -304,21 +304,21 @@ class vcs_git(vcs):
def gotorevisionx(self, rev): def gotorevisionx(self, rev):
if not os.path.exists(self.local): if not os.path.exists(self.local):
# Brand new checkout... # Brand new checkout
if subprocess.call(['git', 'clone', self.remote, self.local]) != 0: if subprocess.call(['git', 'clone', self.remote, self.local]) != 0:
raise VCSException("Git clone failed") raise VCSException("Git clone failed")
self.checkrepo() self.checkrepo()
else: else:
self.checkrepo() self.checkrepo()
# Discard any working tree changes... # Discard any working tree changes
if subprocess.call(['git', 'reset', '--hard'], cwd=self.local) != 0: if subprocess.call(['git', 'reset', '--hard'], cwd=self.local) != 0:
raise VCSException("Git reset failed") raise VCSException("Git reset failed")
# Remove untracked files now, in case they're tracked in the target # Remove untracked files now, in case they're tracked in the target
# revision (it happens!)... # revision (it happens!)
if subprocess.call(['git', 'clean', '-dffx'], cwd=self.local) != 0: if subprocess.call(['git', 'clean', '-dffx'], cwd=self.local) != 0:
raise VCSException("Git clean failed") raise VCSException("Git clean failed")
if not self.refreshed: if not self.refreshed:
# Get latest commits and tags from remote... # Get latest commits and tags from remote
if subprocess.call(['git', 'fetch', 'origin'], if subprocess.call(['git', 'fetch', 'origin'],
cwd=self.local) != 0: cwd=self.local) != 0:
raise VCSException("Git fetch failed") raise VCSException("Git fetch failed")
@ -326,11 +326,11 @@ class vcs_git(vcs):
cwd=self.local) != 0: cwd=self.local) != 0:
raise VCSException("Git fetch failed") raise VCSException("Git fetch failed")
self.refreshed = True self.refreshed = True
# Check out the appropriate revision... # Check out the appropriate revision
rev = str(rev if rev else 'origin/master') rev = str(rev if rev else 'origin/master')
if subprocess.call(['git', 'checkout', '-f', rev], cwd=self.local) != 0: if subprocess.call(['git', 'checkout', '-f', rev], cwd=self.local) != 0:
raise VCSException("Git checkout failed") raise VCSException("Git checkout failed")
# Get rid of any uncontrolled files left behind... # Get rid of any uncontrolled files left behind
if subprocess.call(['git', 'clean', '-dffx'], cwd=self.local) != 0: if subprocess.call(['git', 'clean', '-dffx'], cwd=self.local) != 0:
raise VCSException("Git clean failed") raise VCSException("Git clean failed")
@ -383,7 +383,7 @@ class vcs_gitsvn(vcs):
def gotorevisionx(self, rev): def gotorevisionx(self, rev):
if not os.path.exists(self.local): if not os.path.exists(self.local):
# Brand new checkout... # Brand new checkout
gitsvn_cmd = '%sgit svn clone %s' % self.userargs() gitsvn_cmd = '%sgit svn clone %s' % self.userargs()
if ';' in self.remote: if ';' in self.remote:
remote_split = self.remote.split(';') remote_split = self.remote.split(';')
@ -404,15 +404,15 @@ class vcs_gitsvn(vcs):
self.checkrepo() self.checkrepo()
else: else:
self.checkrepo() self.checkrepo()
# Discard any working tree changes... # Discard any working tree changes
if subprocess.call(['git', 'reset', '--hard'], cwd=self.local) != 0: if subprocess.call(['git', 'reset', '--hard'], cwd=self.local) != 0:
raise VCSException("Git reset failed") raise VCSException("Git reset failed")
# Remove untracked files now, in case they're tracked in the target # Remove untracked files now, in case they're tracked in the target
# revision (it happens!)... # revision (it happens!)
if subprocess.call(['git', 'clean', '-dffx'], cwd=self.local) != 0: if subprocess.call(['git', 'clean', '-dffx'], cwd=self.local) != 0:
raise VCSException("Git clean failed") raise VCSException("Git clean failed")
if not self.refreshed: if not self.refreshed:
# Get new commits and tags from repo... # Get new commits and tags from repo
if subprocess.call(['%sgit svn rebase %s' % self.userargs()], if subprocess.call(['%sgit svn rebase %s' % self.userargs()],
cwd=self.local, shell=True) != 0: cwd=self.local, shell=True) != 0:
raise VCSException("Git svn rebase failed") raise VCSException("Git svn rebase failed")
@ -464,7 +464,7 @@ class vcs_gitsvn(vcs):
else: else:
raise VCSException("Git svn checkout failed") raise VCSException("Git svn checkout failed")
# Get rid of any uncontrolled files left behind... # Get rid of any uncontrolled files left behind
if subprocess.call(['git', 'clean', '-dffx'], cwd=self.local) != 0: if subprocess.call(['git', 'clean', '-dffx'], cwd=self.local) != 0:
raise VCSException("Git clean failed") raise VCSException("Git clean failed")
@ -666,8 +666,7 @@ def ant_subprojects(root_dir):
relpath = os.path.join(root_dir, path) relpath = os.path.join(root_dir, path)
if not os.path.isdir(relpath): if not os.path.isdir(relpath):
continue continue
if options.verbose: logging.info("Found subproject at %s" % path)
print "Found subproject %s..." % path
subprojects.append(path) subprojects.append(path)
return subprojects return subprojects
@ -838,7 +837,7 @@ def getsrclib(spec, srclib_dir, srclibpaths=[], subdir=None, target=None,
% name, p.stdout) % name, p.stdout)
if srclib["Update Project"] == "Yes" and not (autoupdate and number): if srclib["Update Project"] == "Yes" and not (autoupdate and number):
print "Updating srclib %s at path %s" % (name, libdir) logging.info("Updating srclib %s at path %s" % (name, libdir))
cmd = [os.path.join(config['sdk_path'], 'tools', 'android'), cmd = [os.path.join(config['sdk_path'], 'tools', 'android'),
'update', 'project', '-p', libdir] 'update', 'project', '-p', libdir]
if target: if target:
@ -875,32 +874,30 @@ def getsrclib(spec, srclib_dir, srclibpaths=[], subdir=None, target=None,
# 'srclibpaths' is information on the srclibs being used # 'srclibpaths' is information on the srclibs being used
def prepare_source(vcs, app, build, build_dir, srclib_dir, extlib_dir, onserver=False): def prepare_source(vcs, app, build, build_dir, srclib_dir, extlib_dir, onserver=False):
# Optionally, the actual app source can be in a subdirectory... # Optionally, the actual app source can be in a subdirectory
if 'subdir' in build: if 'subdir' in build:
root_dir = os.path.join(build_dir, build['subdir']) root_dir = os.path.join(build_dir, build['subdir'])
else: else:
root_dir = build_dir root_dir = build_dir
# Get a working copy of the right revision... # Get a working copy of the right revision
print "Getting source for revision " + build['commit'] logging.info("Getting source for revision " + build['commit'])
vcs.gotorevision(build['commit']) vcs.gotorevision(build['commit'])
# Check that a subdir (if we're using one) exists. This has to happen # Check that a subdir (if we're using one) exists. This has to happen
# after the checkout, since it might not exist elsewhere... # after the checkout, since it might not exist elsewhere
if not os.path.exists(root_dir): if not os.path.exists(root_dir):
raise BuildException('Missing subdir ' + root_dir) raise BuildException('Missing subdir ' + root_dir)
# Initialise submodules if requred... # Initialise submodules if requred
if build['submodules']: if build['submodules']:
if options.verbose: logging.info("Initialising submodules")
print "Initialising submodules..."
vcs.initsubmodules() vcs.initsubmodules()
# Run an init command if one is required... # Run an init command if one is required
if 'init' in build: if 'init' in build:
cmd = replace_config_vars(build['init']) cmd = replace_config_vars(build['init'])
if options.verbose: logging.info("Running 'init' commands in %s" % root_dir)
print "Running 'init' commands in %s" % root_dir
p = FDroidPopen(['bash', '-x', '-c', cmd], cwd=root_dir) p = FDroidPopen(['bash', '-x', '-c', cmd], cwd=root_dir)
if p.returncode != 0: if p.returncode != 0:
@ -911,18 +908,18 @@ def prepare_source(vcs, app, build, build_dir, srclib_dir, extlib_dir, onserver=
if 'patch' in build: if 'patch' in build:
for patch in build['patch'].split(';'): for patch in build['patch'].split(';'):
patch = patch.strip() patch = patch.strip()
print "Applying " + patch logging.info("Applying " + patch)
patch_path = os.path.join('metadata', app['id'], patch) patch_path = os.path.join('metadata', app['id'], patch)
if subprocess.call(['patch', '-p1', if subprocess.call(['patch', '-p1',
'-i', os.path.abspath(patch_path)], cwd=build_dir) != 0: '-i', os.path.abspath(patch_path)], cwd=build_dir) != 0:
raise BuildException("Failed to apply patch %s" % patch_path) raise BuildException("Failed to apply patch %s" % patch_path)
# Get required source libraries... # Get required source libraries
srclibpaths = [] srclibpaths = []
updatemode = build.get('update', 'auto') updatemode = build.get('update', 'auto')
if 'srclibs' in build: if 'srclibs' in build:
target=build['target'] if 'target' in build else None target=build['target'] if 'target' in build else None
print "Collecting source libraries..." logging.info("Collecting source libraries")
for lib in build['srclibs'].split(';'): for lib in build['srclibs'].split(';'):
srclibpaths.append(getsrclib(lib, srclib_dir, srclibpaths, srclibpaths.append(getsrclib(lib, srclib_dir, srclibpaths,
target=target, preponly=onserver, autoupdate=(updatemode=='auto'))) target=target, preponly=onserver, autoupdate=(updatemode=='auto')))
@ -936,7 +933,7 @@ def prepare_source(vcs, app, build, build_dir, srclib_dir, extlib_dir, onserver=
srclibpaths.append(basesrclib) srclibpaths.append(basesrclib)
# Generate (or update) the ant build file, build.xml... # Generate (or update) the ant build file, build.xml
if (updatemode != 'no' and build['type'] == 'ant'): if (updatemode != 'no' and build['type'] == 'ant'):
parms = [os.path.join(config['sdk_path'], 'tools', 'android'), parms = [os.path.join(config['sdk_path'], 'tools', 'android'),
'update', 'project'] 'update', 'project']
@ -947,13 +944,13 @@ def prepare_source(vcs, app, build, build_dir, srclib_dir, extlib_dir, onserver=
update_dirs = ['.'] + ant_subprojects(root_dir) update_dirs = ['.'] + ant_subprojects(root_dir)
else: else:
update_dirs = [d.strip() for d in updatemode.split(';')] update_dirs = [d.strip() for d in updatemode.split(';')]
# Force build.xml update if necessary... # Force build.xml update if necessary
if updatemode == 'force' or 'target' in build: if updatemode == 'force' or 'target' in build:
if updatemode == 'force': if updatemode == 'force':
update_dirs = ['.'] update_dirs = ['.']
buildxml = os.path.join(root_dir, 'build.xml') buildxml = os.path.join(root_dir, 'build.xml')
if os.path.exists(buildxml): if os.path.exists(buildxml):
print 'Force-removing old build.xml' logging.info('Force-removing old build.xml')
os.remove(buildxml) os.remove(buildxml)
for d in update_dirs: for d in update_dirs:
@ -961,11 +958,10 @@ def prepare_source(vcs, app, build, build_dir, srclib_dir, extlib_dir, onserver=
# Clean update dirs via ant # Clean update dirs via ant
p = FDroidPopen(['ant', 'clean'], cwd=subdir) p = FDroidPopen(['ant', 'clean'], cwd=subdir)
dparms = parms + ['-p', d] dparms = parms + ['-p', d]
if options.verbose: if d == '.':
if d == '.': logging.info("Updating main project")
print "Updating main project..." else:
else: logging.info("Updating subproject %s" % d)
print "Updating subproject %s..." % d
p = FDroidPopen(dparms, cwd=root_dir) p = FDroidPopen(dparms, cwd=root_dir)
# Check to see whether an error was returned without a proper exit # 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' # code (this is the case for the 'no target set or target invalid'
@ -974,21 +970,20 @@ def prepare_source(vcs, app, build, build_dir, srclib_dir, extlib_dir, onserver=
raise BuildException("Failed to update project at %s" % d, raise BuildException("Failed to update project at %s" % d,
p.stdout) p.stdout)
# Update the local.properties file... # Update the local.properties file
localprops = [ os.path.join(build_dir, 'local.properties') ] localprops = [ os.path.join(build_dir, 'local.properties') ]
if 'subdir' in build: if 'subdir' in build:
localprops += [ os.path.join(root_dir, 'local.properties') ] localprops += [ os.path.join(root_dir, 'local.properties') ]
for path in localprops: for path in localprops:
if not os.path.isfile(path): if not os.path.isfile(path):
continue continue
if options.verbose: logging.info("Updating properties file at %s" % path)
print "Updating properties file at %s" % path
f = open(path, 'r') f = open(path, 'r')
props = f.read() props = f.read()
f.close() f.close()
props += '\n' props += '\n'
# Fix old-fashioned 'sdk-location' by copying # Fix old-fashioned 'sdk-location' by copying
# from sdk.dir, if necessary... # from sdk.dir, if necessary
if build['oldsdkloc']: if build['oldsdkloc']:
sdkloc = re.match(r".*^sdk.dir=(\S+)$.*", props, sdkloc = re.match(r".*^sdk.dir=(\S+)$.*", props,
re.S|re.M).group(1) re.S|re.M).group(1)
@ -997,10 +992,10 @@ def prepare_source(vcs, app, build, build_dir, srclib_dir, extlib_dir, onserver=
props += "sdk.dir=%s\n" % config['sdk_path'] props += "sdk.dir=%s\n" % config['sdk_path']
props += "sdk-location=%s\n" % ['sdk_path'] props += "sdk-location=%s\n" % ['sdk_path']
if 'ndk_path' in config: if 'ndk_path' in config:
# Add ndk location... # Add ndk location
props += "ndk.dir=%s\n" % config['ndk_path'] props += "ndk.dir=%s\n" % config['ndk_path']
props += "ndk-location=%s\n" % config['ndk_path'] props += "ndk-location=%s\n" % config['ndk_path']
# Add java.encoding if necessary... # Add java.encoding if necessary
if 'encoding' in build: if 'encoding' in build:
props += "java.encoding=%s\n" % build['encoding'] props += "java.encoding=%s\n" % build['encoding']
f = open(path, 'w') f = open(path, 'w')
@ -1014,7 +1009,7 @@ def prepare_source(vcs, app, build, build_dir, srclib_dir, extlib_dir, onserver=
flavour = None flavour = None
# Remove forced debuggable flags # Remove forced debuggable flags
print "Removing debuggable flags..." logging.info("Removing debuggable flags")
for path in manifest_paths(root_dir, flavour): for path in manifest_paths(root_dir, flavour):
if not os.path.isfile(path): if not os.path.isfile(path):
continue continue
@ -1022,9 +1017,9 @@ def prepare_source(vcs, app, build, build_dir, srclib_dir, extlib_dir, onserver=
's/android:debuggable="[^"]*"//g', path]) != 0: 's/android:debuggable="[^"]*"//g', path]) != 0:
raise BuildException("Failed to remove debuggable flags") raise BuildException("Failed to remove debuggable flags")
# Insert version code and number into the manifest if necessary... # Insert version code and number into the manifest if necessary
if build['forceversion']: if build['forceversion']:
print "Changing the version name..." logging.info("Changing the version name")
for path in manifest_paths(root_dir, flavour): for path in manifest_paths(root_dir, flavour):
if not os.path.isfile(path): if not os.path.isfile(path):
continue continue
@ -1039,7 +1034,7 @@ def prepare_source(vcs, app, build, build_dir, srclib_dir, extlib_dir, onserver=
path]) != 0: path]) != 0:
raise BuildException("Failed to amend build.gradle") raise BuildException("Failed to amend build.gradle")
if build['forcevercode']: if build['forcevercode']:
print "Changing the version code..." logging.info("Changing the version code")
for path in manifest_paths(root_dir, flavour): for path in manifest_paths(root_dir, flavour):
if not os.path.isfile(path): if not os.path.isfile(path):
continue continue
@ -1054,13 +1049,12 @@ def prepare_source(vcs, app, build, build_dir, srclib_dir, extlib_dir, onserver=
path]) != 0: path]) != 0:
raise BuildException("Failed to amend build.gradle") raise BuildException("Failed to amend build.gradle")
# Delete unwanted files... # Delete unwanted files
if 'rm' in build: if 'rm' in build:
for part in build['rm'].split(';'): for part in build['rm'].split(';'):
dest = os.path.join(build_dir, part.strip()) dest = os.path.join(build_dir, part.strip())
rdest = os.path.abspath(dest) rdest = os.path.abspath(dest)
if options.verbose: logging.info("Removing {0}".format(rdest))
print "Removing {0}".format(rdest)
if not rdest.startswith(os.path.abspath(build_dir)): if not rdest.startswith(os.path.abspath(build_dir)):
raise BuildException("rm for {1} is outside build root {0}".format( raise BuildException("rm for {1} is outside build root {0}".format(
os.path.abspath(build_dir),os.path.abspath(dest))) os.path.abspath(build_dir),os.path.abspath(dest)))
@ -1072,10 +1066,9 @@ def prepare_source(vcs, app, build, build_dir, srclib_dir, extlib_dir, onserver=
else: else:
subprocess.call('rm -rf ' + rdest, shell=True) subprocess.call('rm -rf ' + rdest, shell=True)
else: else:
if options.verbose: logging.info("...but it didn't exist")
print "...but it didn't exist"
# Fix apostrophes translation files if necessary... # Fix apostrophes translation files if necessary
if build['fixapos']: if build['fixapos']:
for root, dirs, files in os.walk(os.path.join(root_dir, 'res')): for root, dirs, files in os.walk(os.path.join(root_dir, 'res')):
for filename in files: for filename in files:
@ -1086,7 +1079,7 @@ def prepare_source(vcs, app, build, build_dir, srclib_dir, extlib_dir, onserver=
os.path.join(root, filename)]) != 0: os.path.join(root, filename)]) != 0:
raise BuildException("Failed to amend " + filename) raise BuildException("Failed to amend " + filename)
# Fix translation files if necessary... # Fix translation files if necessary
if build['fixtrans']: if build['fixtrans']:
for root, dirs, files in os.walk(os.path.join(root_dir, 'res')): for root, dirs, files in os.walk(os.path.join(root_dir, 'res')):
for filename in files: for filename in files:
@ -1112,7 +1105,7 @@ def prepare_source(vcs, app, build, build_dir, srclib_dir, extlib_dir, onserver=
else: else:
index += 1 index += 1
# We only want to insert the positional arguments # We only want to insert the positional arguments
# when there is more than one argument... # when there is more than one argument
if oldline != line: if oldline != line:
if num > 2: if num > 2:
changed = True changed = True
@ -1127,33 +1120,31 @@ def prepare_source(vcs, app, build, build_dir, srclib_dir, extlib_dir, onserver=
remove_signing_keys(build_dir) remove_signing_keys(build_dir)
# Add required external libraries... # Add required external libraries
if 'extlibs' in build: if 'extlibs' in build:
print "Collecting prebuilt libraries..." logging.info("Collecting prebuilt libraries")
libsdir = os.path.join(root_dir, 'libs') libsdir = os.path.join(root_dir, 'libs')
if not os.path.exists(libsdir): if not os.path.exists(libsdir):
os.mkdir(libsdir) os.mkdir(libsdir)
for lib in build['extlibs'].split(';'): for lib in build['extlibs'].split(';'):
lib = lib.strip() lib = lib.strip()
if options.verbose: logging.info("...installing extlib {0}".format(lib))
print "...installing extlib {0}".format(lib)
libf = os.path.basename(lib) libf = os.path.basename(lib)
libsrc = os.path.join(extlib_dir, lib) libsrc = os.path.join(extlib_dir, lib)
if not os.path.exists(libsrc): if not os.path.exists(libsrc):
raise BuildException("Missing extlib file {0}".format(libsrc)) raise BuildException("Missing extlib file {0}".format(libsrc))
shutil.copyfile(libsrc, os.path.join(libsdir, libf)) shutil.copyfile(libsrc, os.path.join(libsdir, libf))
# Run a pre-build command if one is required... # Run a pre-build command if one is required
if 'prebuild' in build: if 'prebuild' in build:
cmd = replace_config_vars(build['prebuild']) cmd = replace_config_vars(build['prebuild'])
# Substitute source library paths into prebuild commands... # Substitute source library paths into prebuild commands
for name, number, libpath in srclibpaths: for name, number, libpath in srclibpaths:
libpath = os.path.relpath(libpath, root_dir) libpath = os.path.relpath(libpath, root_dir)
cmd = cmd.replace('$$' + name + '$$', libpath) cmd = cmd.replace('$$' + name + '$$', libpath)
if options.verbose: logging.info("Running 'prebuild' commands in %s" % root_dir)
print "Running 'prebuild' commands in %s" % root_dir
p = FDroidPopen(['bash', '-x', '-c', cmd], cwd=root_dir) p = FDroidPopen(['bash', '-x', '-c', cmd], cwd=root_dir)
if p.returncode != 0: if p.returncode != 0:
@ -1219,7 +1210,7 @@ def scan_source(build_dir, root_dir, thisbuild):
return False return False
def removeproblem(what, fd, fp): def removeproblem(what, fd, fp):
print 'Removing %s at %s' % (what, fd) logging.info('Removing %s at %s' % (what, fd))
os.remove(fp) os.remove(fp)
def handleproblem(what, fd, fp): def handleproblem(what, fd, fp):
@ -1229,20 +1220,20 @@ def scan_source(build_dir, root_dir, thisbuild):
problems.append('Found %s at %s' % (what, fd)) problems.append('Found %s at %s' % (what, fd))
def warnproblem(what, fd, fp): def warnproblem(what, fd, fp):
print 'Warning: Found %s at %s' % (what, fd) logging.info('Warning: Found %s at %s' % (what, fd))
# Iterate through all files in the source code... # Iterate through all files in the source code
for r,d,f in os.walk(build_dir): for r,d,f in os.walk(build_dir):
for curfile in f: for curfile in f:
if '/.hg' in r or '/.git' in r or '/.svn' in r: if '/.hg' in r or '/.git' in r or '/.svn' in r:
continue continue
# Path (relative) to the file... # Path (relative) to the file
fp = os.path.join(r, curfile) fp = os.path.join(r, curfile)
fd = fp[len(build_dir):] fd = fp[len(build_dir):]
# Check if this file has been explicitly excluded from scanning... # Check if this file has been explicitly excluded from scanning
if toignore(fd): if toignore(fd):
continue continue
@ -1270,7 +1261,7 @@ def scan_source(build_dir, root_dir, thisbuild):
ms.close() ms.close()
# Presence of a jni directory without buildjni=yes might # Presence of a jni directory without buildjni=yes might
# indicate a problem... (if it's not a problem, explicitly use # indicate a problem (if it's not a problem, explicitly use
# buildjni=no to bypass this check) # buildjni=no to bypass this check)
if (os.path.exists(os.path.join(root_dir, 'jni')) and if (os.path.exists(os.path.join(root_dir, 'jni')) and
thisbuild.get('buildjni') is None): thisbuild.get('buildjni') is None):
@ -1354,7 +1345,7 @@ def isApkDebuggable(apkfile, config):
stdout=subprocess.PIPE) stdout=subprocess.PIPE)
output = p.communicate()[0] output = p.communicate()[0]
if p.returncode != 0: if p.returncode != 0:
print "ERROR: Failed to get apk manifest information" logging.critical("Failed to get apk manifest information")
sys.exit(1) sys.exit(1)
for line in output.splitlines(): for line in output.splitlines():
if 'android:debuggable' in line and not line.endswith('0x0'): if 'android:debuggable' in line and not line.endswith('0x0'):
@ -1388,8 +1379,6 @@ class AsynchronousFileReader(threading.Thread):
class PopenResult: class PopenResult:
returncode = None returncode = None
stdout = '' stdout = ''
stderr = ''
stdout_apk = ''
def FDroidPopen(commands, cwd=None): def FDroidPopen(commands, cwd=None):
""" """
@ -1400,10 +1389,9 @@ def FDroidPopen(commands, cwd=None):
:returns: A PopenResult. :returns: A PopenResult.
""" """
if options.verbose: if cwd:
if cwd: logging.info("Directory: %s" % cwd)
print "Directory: %s" % cwd logging.info(" > %s" % ' '.join(commands))
print " > %s" % ' '.join(commands)
result = PopenResult() result = PopenResult()
p = subprocess.Popen(commands, cwd=cwd, p = subprocess.Popen(commands, cwd=cwd,
@ -1464,8 +1452,8 @@ def remove_signing_keys(build_dir):
else: else:
o.write(line) o.write(line)
if changed and options.verbose: if changed:
print "Cleaned build.gradle of keysigning configs at %s" % path logging.info("Cleaned build.gradle of keysigning configs at %s" % path)
for propfile in ('build.properties', 'default.properties', 'ant.properties'): for propfile in ('build.properties', 'default.properties', 'ant.properties'):
if propfile in files: if propfile in files:
@ -1482,8 +1470,8 @@ def remove_signing_keys(build_dir):
else: else:
o.write(line) o.write(line)
if changed and options.verbose: if changed:
print "Cleaned %s of keysigning configs at %s" % (propfile,path) logging.info("Cleaned %s of keysigning configs at %s" % (propfile,path))
def replace_config_vars(cmd): def replace_config_vars(cmd):
cmd = cmd.replace('$$SDK$$', config['sdk_path']) cmd = cmd.replace('$$SDK$$', config['sdk_path'])