2009-06-11 22:06:17 +00:00
|
|
|
#! /usr/bin/env python
|
|
|
|
|
2014-01-08 01:01:53 +00:00
|
|
|
# Copyright (c) 2009-2014, The Linux Foundation. All rights reserved.
|
2009-06-11 22:06:17 +00:00
|
|
|
#
|
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
# modification, are permitted provided that the following conditions are met:
|
|
|
|
# * Redistributions of source code must retain the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer.
|
|
|
|
# * Redistributions in binary form must reproduce the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer in the
|
|
|
|
# documentation and/or other materials provided with the distribution.
|
|
|
|
# * Neither the name of The Linux Foundation nor
|
|
|
|
# the names of its contributors may be used to endorse or promote
|
|
|
|
# products derived from this software without specific prior written
|
|
|
|
# permission.
|
|
|
|
#
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
# IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
# NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
|
|
|
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
|
|
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
|
|
|
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
|
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
|
|
|
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
|
|
|
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
# Build the kernel for all targets using the Android build environment.
|
|
|
|
|
|
|
|
import glob
|
|
|
|
from optparse import OptionParser
|
|
|
|
import os
|
2012-10-24 01:43:11 +00:00
|
|
|
import re
|
2009-06-11 22:06:17 +00:00
|
|
|
import shutil
|
2013-10-19 16:46:47 +00:00
|
|
|
import subprocess
|
2009-06-11 22:06:17 +00:00
|
|
|
import sys
|
|
|
|
|
2013-10-19 16:46:47 +00:00
|
|
|
version = 'build-all.py, version 1.99'
|
2009-06-11 22:06:17 +00:00
|
|
|
|
|
|
|
build_dir = '../all-kernels'
|
2012-08-23 18:17:01 +00:00
|
|
|
make_command = ["vmlinux", "modules", "dtbs"]
|
2009-06-11 22:06:17 +00:00
|
|
|
all_options = {}
|
2013-10-19 16:46:47 +00:00
|
|
|
compile64 = os.environ.get('CROSS_COMPILE64')
|
2009-06-11 22:06:17 +00:00
|
|
|
|
2010-04-22 00:45:05 +00:00
|
|
|
def error(msg):
|
|
|
|
sys.stderr.write("error: %s\n" % msg)
|
|
|
|
|
2009-06-11 22:06:17 +00:00
|
|
|
def fail(msg):
|
|
|
|
"""Fail with a user-printed message"""
|
2010-04-22 00:45:05 +00:00
|
|
|
error(msg)
|
2009-06-11 22:06:17 +00:00
|
|
|
sys.exit(1)
|
|
|
|
|
2013-10-19 16:46:47 +00:00
|
|
|
if not os.environ.get('CROSS_COMPILE'):
|
|
|
|
fail("CROSS_COMPILE must be set in the environment")
|
|
|
|
|
2009-06-11 22:06:17 +00:00
|
|
|
def check_kernel():
|
|
|
|
"""Ensure that PWD is a kernel directory"""
|
|
|
|
if (not os.path.isfile('MAINTAINERS') or
|
2010-08-04 18:08:38 +00:00
|
|
|
not os.path.isfile('arch/arm/mach-msm/Kconfig')):
|
|
|
|
fail("This doesn't seem to be an MSM kernel dir")
|
2009-06-11 22:06:17 +00:00
|
|
|
|
|
|
|
def check_build():
|
|
|
|
"""Ensure that the build directory is present."""
|
|
|
|
if not os.path.isdir(build_dir):
|
2010-08-04 18:42:20 +00:00
|
|
|
try:
|
|
|
|
os.makedirs(build_dir)
|
|
|
|
except OSError as exc:
|
|
|
|
if exc.errno == errno.EEXIST:
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
raise
|
2009-06-11 22:06:17 +00:00
|
|
|
|
2013-10-19 16:46:47 +00:00
|
|
|
failed_targets = []
|
2009-06-11 22:06:17 +00:00
|
|
|
|
2013-10-19 16:46:47 +00:00
|
|
|
class LogRunner:
|
|
|
|
def __init__(self, logname, make_env):
|
2010-08-04 18:08:38 +00:00
|
|
|
self.logname = logname
|
|
|
|
self.fd = open(logname, 'w')
|
2013-10-19 16:46:47 +00:00
|
|
|
self.make_env = make_env
|
2009-06-11 22:06:17 +00:00
|
|
|
|
|
|
|
def run(self, args):
|
2010-08-04 18:08:38 +00:00
|
|
|
devnull = open('/dev/null', 'r')
|
|
|
|
proc = subprocess.Popen(args, stdin=devnull,
|
2013-10-19 16:46:47 +00:00
|
|
|
env=self.make_env,
|
2010-08-04 18:08:38 +00:00
|
|
|
bufsize=0,
|
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
stderr=subprocess.STDOUT)
|
|
|
|
count = 0
|
|
|
|
# for line in proc.stdout:
|
|
|
|
rawfd = proc.stdout.fileno()
|
|
|
|
while True:
|
|
|
|
line = os.read(rawfd, 1024)
|
|
|
|
if not line:
|
|
|
|
break
|
|
|
|
self.fd.write(line)
|
|
|
|
self.fd.flush()
|
|
|
|
if all_options.verbose:
|
|
|
|
sys.stdout.write(line)
|
|
|
|
sys.stdout.flush()
|
|
|
|
else:
|
|
|
|
for i in range(line.count('\n')):
|
|
|
|
count += 1
|
|
|
|
if count == 64:
|
|
|
|
count = 0
|
|
|
|
print
|
|
|
|
sys.stdout.write('.')
|
|
|
|
sys.stdout.flush()
|
|
|
|
print
|
|
|
|
result = proc.wait()
|
|
|
|
|
2013-11-18 22:53:09 +00:00
|
|
|
self.fd.flush()
|
2010-08-04 18:08:38 +00:00
|
|
|
return result
|
2010-04-22 00:45:05 +00:00
|
|
|
|
2013-10-19 16:46:47 +00:00
|
|
|
class Builder():
|
|
|
|
|
|
|
|
def __init__(self, name, defconfig):
|
|
|
|
self.name = name
|
|
|
|
self.defconfig = defconfig
|
|
|
|
|
|
|
|
self.confname = self.defconfig.split('/')[-1]
|
2009-06-11 22:06:17 +00:00
|
|
|
|
2013-10-19 16:46:47 +00:00
|
|
|
# Determine if this is a 64-bit target based on the location
|
|
|
|
# of the defconfig.
|
|
|
|
self.make_env = os.environ.copy()
|
|
|
|
if "/arm64/" in defconfig:
|
|
|
|
if compile64:
|
|
|
|
self.make_env['CROSS_COMPILE'] = compile64
|
2010-08-04 18:08:38 +00:00
|
|
|
else:
|
2013-10-19 16:46:47 +00:00
|
|
|
fail("Attempting to build 64-bit, without setting CROSS_COMPILE64")
|
|
|
|
self.make_env['ARCH'] = 'arm64'
|
|
|
|
else:
|
|
|
|
self.make_env['ARCH'] = 'arm'
|
|
|
|
self.make_env['KCONFIG_NOTIMESTAMP'] = 'true'
|
|
|
|
|
|
|
|
def build(self):
|
|
|
|
dest_dir = os.path.join(build_dir, self.name)
|
|
|
|
log_name = "%s/log-%s.log" % (build_dir, self.name)
|
|
|
|
print 'Building %s in %s log %s' % (self.name, dest_dir, log_name)
|
|
|
|
if not os.path.isdir(dest_dir):
|
|
|
|
os.mkdir(dest_dir)
|
|
|
|
defconfig = self.defconfig
|
|
|
|
dotconfig = '%s/.config' % dest_dir
|
|
|
|
savedefconfig = '%s/defconfig' % dest_dir
|
|
|
|
# shutil.copyfile(defconfig, dotconfig) # Not really right.
|
|
|
|
|
|
|
|
staging_dir = 'install_staging'
|
|
|
|
modi_dir = '%s' % staging_dir
|
|
|
|
hdri_dir = '%s/usr' % staging_dir
|
|
|
|
shutil.rmtree(os.path.join(dest_dir, staging_dir), ignore_errors=True)
|
|
|
|
|
|
|
|
with open('/dev/null', 'r') as devnull:
|
|
|
|
subprocess.check_call(['make', 'O=%s' % dest_dir,
|
|
|
|
self.confname], env=self.make_env,
|
|
|
|
stdin=devnull)
|
|
|
|
|
|
|
|
if not all_options.updateconfigs:
|
|
|
|
# Build targets can be dependent upon the completion of
|
|
|
|
# previous build targets, so build them one at a time.
|
|
|
|
cmd_line = ['make',
|
|
|
|
'INSTALL_HDR_PATH=%s' % hdri_dir,
|
|
|
|
'INSTALL_MOD_PATH=%s' % modi_dir,
|
|
|
|
'O=%s' % dest_dir]
|
|
|
|
build_targets = []
|
|
|
|
for c in make_command:
|
|
|
|
if re.match(r'^-{1,2}\w', c):
|
|
|
|
cmd_line.append(c)
|
2012-10-24 01:43:11 +00:00
|
|
|
else:
|
2013-10-19 16:46:47 +00:00
|
|
|
build_targets.append(c)
|
2013-11-18 22:53:09 +00:00
|
|
|
build = LogRunner(log_name, self.make_env)
|
2013-10-19 16:46:47 +00:00
|
|
|
for t in build_targets:
|
|
|
|
result = build.run(cmd_line + [t])
|
|
|
|
if result != 0:
|
|
|
|
if all_options.keep_going:
|
|
|
|
failed_targets.append(target)
|
|
|
|
fail_or_error = error
|
|
|
|
else:
|
|
|
|
fail_or_error = fail
|
|
|
|
fail_or_error("Failed to build %s, see %s" %
|
|
|
|
(t, build.logname))
|
|
|
|
|
|
|
|
# Copy the defconfig back.
|
|
|
|
if all_options.configs or all_options.updateconfigs:
|
|
|
|
with open('/dev/null', 'r') as devnull:
|
|
|
|
subprocess.check_call(['make', 'O=%s' % dest_dir,
|
|
|
|
'savedefconfig'], env=self.make_env, stdin=devnull)
|
|
|
|
shutil.copyfile(savedefconfig, defconfig)
|
2009-06-11 22:06:17 +00:00
|
|
|
|
2013-10-19 16:46:47 +00:00
|
|
|
def update_config(file, str):
|
|
|
|
print 'Updating %s with \'%s\'\n' % (file, str)
|
|
|
|
with open(file, 'a') as defconfig:
|
|
|
|
defconfig.write(str + '\n')
|
|
|
|
|
|
|
|
def scan_configs():
|
|
|
|
"""Get the full list of defconfigs appropriate for this tree."""
|
|
|
|
names = []
|
|
|
|
arch_pats = (
|
|
|
|
r'[fm]sm[0-9]*_defconfig',
|
|
|
|
r'apq*_defconfig',
|
|
|
|
r'qsd*_defconfig',
|
|
|
|
r'mdm*_defconfig',
|
|
|
|
r'mpq*_defconfig',
|
|
|
|
)
|
|
|
|
for p in arch_pats:
|
|
|
|
for n in glob.glob('arch/arm/configs/' + p):
|
|
|
|
name = os.path.basename(n)[:-10]
|
|
|
|
names.append(Builder(name, n))
|
|
|
|
if 'CROSS_COMPILE64' in os.environ:
|
|
|
|
for n in glob.glob('arch/arm64/configs/' + p):
|
|
|
|
name = os.path.basename(n)[:-10] + "-64"
|
|
|
|
names.append(Builder(name, n))
|
|
|
|
return names
|
2009-06-11 22:06:17 +00:00
|
|
|
|
2013-10-19 16:46:47 +00:00
|
|
|
def build_many(targets):
|
2009-06-11 22:06:17 +00:00
|
|
|
print "Building %d target(s)" % len(targets)
|
|
|
|
for target in targets:
|
2010-08-04 18:08:38 +00:00
|
|
|
if all_options.updateconfigs:
|
2013-10-19 16:46:47 +00:00
|
|
|
update_config(target.defconfig, all_options.updateconfigs)
|
|
|
|
target.build()
|
2010-04-22 00:45:05 +00:00
|
|
|
if failed_targets:
|
2013-10-19 16:46:47 +00:00
|
|
|
fail("\n ".join(["Failed targets:"] +
|
|
|
|
[target.name for target in failed_targets]))
|
2009-06-11 22:06:17 +00:00
|
|
|
|
|
|
|
def main():
|
2011-04-08 22:10:17 +00:00
|
|
|
global make_command
|
|
|
|
|
2009-06-11 22:06:17 +00:00
|
|
|
check_kernel()
|
|
|
|
check_build()
|
|
|
|
|
|
|
|
configs = scan_configs()
|
|
|
|
|
2010-08-04 18:42:20 +00:00
|
|
|
usage = ("""
|
|
|
|
%prog [options] all -- Build all targets
|
|
|
|
%prog [options] target target ... -- List specific targets
|
|
|
|
%prog [options] perf -- Build all perf targets
|
|
|
|
%prog [options] noperf -- Build all non-perf targets""")
|
2009-06-11 22:06:17 +00:00
|
|
|
parser = OptionParser(usage=usage, version=version)
|
|
|
|
parser.add_option('--configs', action='store_true',
|
2010-08-04 18:08:38 +00:00
|
|
|
dest='configs',
|
|
|
|
help="Copy configs back into tree")
|
2009-06-11 22:06:17 +00:00
|
|
|
parser.add_option('--list', action='store_true',
|
2010-08-04 18:08:38 +00:00
|
|
|
dest='list',
|
|
|
|
help='List available targets')
|
2009-06-11 22:06:17 +00:00
|
|
|
parser.add_option('-v', '--verbose', action='store_true',
|
2010-08-04 18:08:38 +00:00
|
|
|
dest='verbose',
|
|
|
|
help='Output to stdout in addition to log file')
|
2009-06-11 22:06:17 +00:00
|
|
|
parser.add_option('--oldconfig', action='store_true',
|
2010-08-04 18:08:38 +00:00
|
|
|
dest='oldconfig',
|
|
|
|
help='Only process "make oldconfig"')
|
2009-06-11 22:06:17 +00:00
|
|
|
parser.add_option('--updateconfigs',
|
|
|
|
dest='updateconfigs',
|
|
|
|
help="Update defconfigs with provided option setting, "
|
|
|
|
"e.g. --updateconfigs=\'CONFIG_USE_THING=y\'")
|
2010-03-31 22:09:47 +00:00
|
|
|
parser.add_option('-j', '--jobs', type='int', dest="jobs",
|
2010-08-04 18:08:38 +00:00
|
|
|
help="Number of simultaneous jobs")
|
2010-03-31 22:09:47 +00:00
|
|
|
parser.add_option('-l', '--load-average', type='int',
|
2010-08-04 18:08:38 +00:00
|
|
|
dest='load_average',
|
|
|
|
help="Don't start multiple jobs unless load is below LOAD_AVERAGE")
|
2010-04-22 00:45:05 +00:00
|
|
|
parser.add_option('-k', '--keep-going', action='store_true',
|
2010-08-04 18:08:38 +00:00
|
|
|
dest='keep_going', default=False,
|
|
|
|
help="Keep building other targets if a target fails")
|
2011-04-08 22:10:17 +00:00
|
|
|
parser.add_option('-m', '--make-target', action='append',
|
|
|
|
help='Build the indicated make target (default: %s)' %
|
|
|
|
' '.join(make_command))
|
2009-06-11 22:06:17 +00:00
|
|
|
|
|
|
|
(options, args) = parser.parse_args()
|
|
|
|
global all_options
|
|
|
|
all_options = options
|
|
|
|
|
|
|
|
if options.list:
|
2010-08-04 18:08:38 +00:00
|
|
|
print "Available targets:"
|
2013-10-19 16:46:47 +00:00
|
|
|
for target in configs:
|
|
|
|
print " %s" % target.name
|
2010-08-04 18:08:38 +00:00
|
|
|
sys.exit(0)
|
2009-06-11 22:06:17 +00:00
|
|
|
|
|
|
|
if options.oldconfig:
|
2010-08-04 18:08:38 +00:00
|
|
|
make_command = ["oldconfig"]
|
2011-04-08 22:10:17 +00:00
|
|
|
elif options.make_target:
|
|
|
|
make_command = options.make_target
|
2009-06-11 22:06:17 +00:00
|
|
|
|
2010-03-31 22:09:47 +00:00
|
|
|
if options.jobs:
|
2010-08-04 18:08:38 +00:00
|
|
|
make_command.append("-j%d" % options.jobs)
|
2010-03-31 22:09:47 +00:00
|
|
|
if options.load_average:
|
2010-08-04 18:08:38 +00:00
|
|
|
make_command.append("-l%d" % options.load_average)
|
2010-03-01 20:21:24 +00:00
|
|
|
|
2009-06-11 22:06:17 +00:00
|
|
|
if args == ['all']:
|
2013-10-19 16:46:47 +00:00
|
|
|
build_many(configs)
|
2010-08-04 18:42:20 +00:00
|
|
|
elif args == ['perf']:
|
|
|
|
targets = []
|
2013-10-19 16:46:47 +00:00
|
|
|
for t in configs:
|
|
|
|
if "perf" in t.name:
|
2010-08-04 18:42:20 +00:00
|
|
|
targets.append(t)
|
2013-10-19 16:46:47 +00:00
|
|
|
build_many(targets)
|
2010-08-04 18:42:20 +00:00
|
|
|
elif args == ['noperf']:
|
|
|
|
targets = []
|
2013-10-19 16:46:47 +00:00
|
|
|
for t in configs:
|
|
|
|
if "perf" not in t.name:
|
2010-08-04 18:42:20 +00:00
|
|
|
targets.append(t)
|
2013-10-19 16:46:47 +00:00
|
|
|
build_many(targets)
|
2009-06-11 22:06:17 +00:00
|
|
|
elif len(args) > 0:
|
2013-10-19 16:46:47 +00:00
|
|
|
all_configs = {}
|
|
|
|
for t in configs:
|
|
|
|
all_configs[t.name] = t
|
2010-08-04 18:08:38 +00:00
|
|
|
targets = []
|
|
|
|
for t in args:
|
2013-10-19 16:46:47 +00:00
|
|
|
if t not in all_configs:
|
|
|
|
parser.error("Target '%s' not one of %s" % (t, all_configs.keys()))
|
|
|
|
targets.append(all_configs[t])
|
|
|
|
build_many(targets)
|
2009-06-11 22:06:17 +00:00
|
|
|
else:
|
2010-08-04 18:08:38 +00:00
|
|
|
parser.error("Must specify a target to build, or 'all'")
|
2009-06-11 22:06:17 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|