-#!/usr/bin/env python2
-# -*- coding: utf-8 -*-
+#!/usr/bin/env python3
#
# build.py - part of the FDroid server tools
# Copyright (C) 2010-2014, Ciaran Gultnieks, ciaran@ciarang.com
import traceback
import time
import json
-from ConfigParser import ConfigParser
+from configparser import ConfigParser
from argparse import ArgumentParser
import logging
-import common
-import net
-import metadata
-import scanner
-from common import FDroidException, BuildException, VCSException, FDroidPopen, SdkToolsPopen
+from . import common
+from . import net
+from . import metadata
+from . import scanner
+from .common import FDroidException, BuildException, VCSException, FDroidPopen, SdkToolsPopen
try:
import paramiko
os.mkdir('builder')
p = subprocess.Popen(['vagrant', '--version'],
+ universal_newlines=True,
stdout=subprocess.PIPE)
vver = p.communicate()[0].strip().split(' ')[1]
if vver.split('.')[0] != '1' or int(vver.split('.')[1]) < 4:
# Get an SFTP connection...
ftp = sshs.open_sftp()
- ftp.get_channel().settimeout(15)
+ ftp.get_channel().settimeout(60)
# Put all the necessary files in place...
ftp.chdir(homedir)
if options.verbose:
cmdline += ' --verbose'
cmdline += " %s:%s" % (app.id, build.vercode)
- chan.exec_command('bash -c ". ~/.bsenv && ' + cmdline + '"')
- output = ''
+ chan.exec_command('bash --login -c "' + cmdline + '"')
+ output = bytes()
while not chan.exit_status_ready():
while chan.recv_ready():
output += chan.recv(1024)
if returncode != 0:
raise BuildException(
"Build.py failed on server for {0}:{1}".format(
- app.id, build.version), output)
+ app.id, build.version), str(output, 'utf-8'))
# Retrieve the built files...
logging.info("Retrieving build output...")
release_vm()
-def adapt_gradle(build_dir):
- filename = 'build.gradle'
+def force_gradle_build_tools(build_dir, build_tools):
for root, dirs, files in os.walk(build_dir):
for filename in files:
if not filename.endswith('.gradle'):
path = os.path.join(root, filename)
if not os.path.isfile(path):
continue
- logging.debug("Adapting %s at %s" % (filename, path))
+ logging.debug("Forcing build-tools %s in %s" % (build_tools, path))
common.regsub_file(r"""(\s*)buildToolsVersion([\s=]+).*""",
- r"""\1buildToolsVersion\2'%s'""" % config['build_tools'],
+ r"""\1buildToolsVersion\2'%s'""" % build_tools,
path)
"""Do a build locally."""
ndk_path = build.ndk_path()
- if build.buildjni and build.buildjni != ['no']:
+ if build.ndk or (build.buildjni and build.buildjni != ['no']):
if not ndk_path:
- logging.critical("Android NDK version '%s' could not be found!" % build.ndk or 'r10e')
+ logging.critical("Android NDK version '%s' could not be found!" % build.ndk or 'r12b')
logging.critical("Configured versions:")
- for k, v in config['ndk_paths'].iteritems():
+ for k, v in config['ndk_paths'].items():
if k.endswith("_orig"):
continue
logging.critical(" %s: %s" % (k, v))
logging.critical("Android NDK '%s' is not a directory!" % ndk_path)
sys.exit(3)
- # Set up environment vars that depend on each build
- for n in ['ANDROID_NDK', 'NDK', 'ANDROID_NDK_HOME']:
- common.env[n] = ndk_path
-
- common.reset_env_path()
- # Set up the current NDK to the PATH
- common.add_to_env_path(ndk_path)
+ common.set_FDroidPopen_env(build)
# Prepare the source code...
root_dir, srclibpaths = common.prepare_source(vcs, app, build,
gradletasks += ['assemble' + flavours_cmd + 'Release']
- adapt_gradle(build_dir)
- for name, number, libpath in srclibpaths:
- adapt_gradle(libpath)
+ if config['force_build_tools']:
+ force_gradle_build_tools(build_dir, config['build_tools'])
+ for name, number, libpath in srclibpaths:
+ force_gradle_build_tools(libpath, config['build_tools'])
cmd = [config['gradle']]
if build.gradleprops:
# .gradle/ as binary files. To avoid overcomplicating the scanner,
# manually delete them, just like `gradle clean` should have removed
# the build/ dirs.
- del_dirs(['build', '.gradle', 'gradle'])
+ del_dirs(['build', '.gradle'])
del_files(['gradlew', 'gradlew.bat'])
if 'pom.xml' in files:
options, parser = parse_commandline()
- metadata_files = glob.glob('.fdroid.*[a-z]') # ignore files ending in ~
- if os.path.isdir('metadata'):
- pass
- elif len(metadata_files) == 0:
- raise FDroidException("No app metadata found, nothing to process!")
- elif len(metadata_files) > 1:
+ # The defaults for .fdroid.* metadata that is included in a git repo are
+ # different than for the standard metadata/ layout because expectations
+ # are different. In this case, the most common user will be the app
+ # developer working on the latest update of the app on their own machine.
+ local_metadata_files = common.get_local_metadata_files()
+ if len(local_metadata_files) == 1: # there is local metadata in an app's source
+ config = dict(common.default_config)
+ # `fdroid build` should build only the latest version by default since
+ # most of the time the user will be building the most recent update
+ if not options.all:
+ options.latest = True
+ elif len(local_metadata_files) > 1:
raise FDroidException("Only one local metadata file allowed! Found: "
- + " ".join(metadata_files))
-
- if not options.appid and not options.all:
- parser.error("option %s: If you really want to build all the apps, use --all" % "all")
+ + " ".join(local_metadata_files))
+ else:
+ if not os.path.isdir('metadata') and len(local_metadata_files) == 0:
+ raise FDroidException("No app metadata found, nothing to process!")
+ if not options.appid and not options.all:
+ parser.error("option %s: If you really want to build all the apps, use --all" % "all")
config = common.read_config(options)
allapps = metadata.read_metadata(xref=not options.onserver)
apps = common.read_app_args(options.appid, allapps, True)
- for appid, app in apps.items():
+ for appid, app in list(apps.items()):
if (app.Disabled and not options.force) or not app.RepoType or not app.builds:
del apps[appid]
raise FDroidException("No apps to process.")
if options.latest:
- for app in apps.itervalues():
+ for app in apps.values():
for build in reversed(app.builds):
if build.disable and not options.force:
continue
# Build applications...
failed_apps = {}
build_succeeded = []
- for appid, app in apps.iteritems():
+ for appid, app in apps.items():
first = True