2014-07-25 10:47:35 +00:00
|
|
|
#!/usr/bin/python -u
|
2012-04-29 18:47:41 +00:00
|
|
|
# -*- coding: iso-8859-15 -*-
|
|
|
|
|
|
2016-09-16 11:32:27 +00:00
|
|
|
from __future__ import print_function
|
2012-04-29 18:47:41 +00:00
|
|
|
import os
|
2012-04-30 08:40:33 +00:00
|
|
|
import sys
|
2012-04-29 18:47:41 +00:00
|
|
|
import dircache
|
|
|
|
|
import linecache
|
|
|
|
|
import fileinput
|
|
|
|
|
import glob
|
|
|
|
|
import subprocess
|
|
|
|
|
from sets import Set
|
2012-04-30 16:38:11 +00:00
|
|
|
import pwd
|
2013-10-14 14:06:08 +00:00
|
|
|
import argparse
|
2014-06-14 08:32:50 +00:00
|
|
|
import time
|
2014-10-29 17:59:27 +00:00
|
|
|
import datetime
|
2016-09-16 13:15:49 +00:00
|
|
|
import re
|
2012-04-29 18:47:41 +00:00
|
|
|
|
2016-09-16 11:32:27 +00:00
|
|
|
def debug(*objs):
|
|
|
|
|
if args.debug:
|
|
|
|
|
print("DEBUG: ", *objs, file=sys.stderr)
|
|
|
|
|
|
2017-08-31 18:57:13 +00:00
|
|
|
def cache_func(func, args):
|
|
|
|
|
global cache
|
|
|
|
|
d = cache
|
|
|
|
|
depth = 0
|
|
|
|
|
keys = [ func.__name__ ] + args
|
|
|
|
|
l = len(keys)
|
|
|
|
|
for k in keys:
|
|
|
|
|
if k is None:
|
|
|
|
|
k = 'None'
|
|
|
|
|
depth += 1
|
|
|
|
|
#debug('depth = ', depth, 'key = ', k, 'd = ', str(d))
|
|
|
|
|
if k in d:
|
|
|
|
|
if l == depth:
|
|
|
|
|
return d[k]
|
|
|
|
|
d = d[k]
|
|
|
|
|
continue
|
|
|
|
|
if l == depth:
|
|
|
|
|
r = func(*args)
|
|
|
|
|
d[k] = r
|
|
|
|
|
return r
|
|
|
|
|
d[k] = {}
|
|
|
|
|
d = d[k]
|
|
|
|
|
raise Exception("cache algorithm failed for function", func.__name__, "in depth", depth)
|
|
|
|
|
|
2012-04-29 18:47:41 +00:00
|
|
|
def find_proj_path(name):
|
2016-03-08 16:15:45 +00:00
|
|
|
name=name.replace("dspider-", "")
|
|
|
|
|
for sub in search_path:
|
|
|
|
|
path=proj_base + "/" + sub + "/" + name
|
|
|
|
|
if os.path.exists(path):
|
2017-05-07 14:18:18 +00:00
|
|
|
return os.path.abspath(path)
|
2016-03-08 16:15:45 +00:00
|
|
|
raise Exception("module " + name + " not found below " + proj_base)
|
2012-04-29 18:47:41 +00:00
|
|
|
|
2017-08-31 18:57:13 +00:00
|
|
|
def find_proj_path_cached(name):
|
|
|
|
|
return cache_func(find_proj_path, [ name ])
|
|
|
|
|
|
2012-05-01 15:24:45 +00:00
|
|
|
def read_deps(cur, prereq_type):
|
2016-03-08 16:35:58 +00:00
|
|
|
# dep cache doesn't make a difference at all
|
|
|
|
|
if prereq_type in dep_cache:
|
|
|
|
|
if cur in dep_cache[prereq_type]:
|
2017-04-28 11:35:31 +00:00
|
|
|
return dep_cache[prereq_type][cur]
|
2016-03-08 16:35:58 +00:00
|
|
|
else:
|
|
|
|
|
dep_cache[prereq_type] = {}
|
2017-06-19 21:10:35 +00:00
|
|
|
cmd = projects_py + " prereq " + prereq_type + " " + cur
|
2017-08-31 18:57:13 +00:00
|
|
|
debug('running', cmd)
|
2017-06-19 21:10:35 +00:00
|
|
|
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
|
2016-03-08 16:15:45 +00:00
|
|
|
p.wait()
|
2016-09-16 13:15:49 +00:00
|
|
|
if p.returncode:
|
2016-03-08 16:15:45 +00:00
|
|
|
raise Exception("failed to get " + prereq_type + " prerequisites from " + path)
|
|
|
|
|
r = Set()
|
2017-04-28 11:35:31 +00:00
|
|
|
pattern = re.compile(r'.*') # might be useful at a later point, currently pointless
|
2016-09-16 13:15:49 +00:00
|
|
|
for line in iter(p.stdout.readline,''):
|
2017-06-19 21:10:35 +00:00
|
|
|
debug(cmd + ' returned: ', line)
|
2016-09-16 13:15:49 +00:00
|
|
|
if not pattern.match(line):
|
|
|
|
|
continue
|
2017-04-28 11:35:31 +00:00
|
|
|
for d in line.split():
|
2016-09-16 13:15:49 +00:00
|
|
|
r.add(d)
|
2016-03-08 16:15:45 +00:00
|
|
|
if cur in r:
|
|
|
|
|
r.remove(cur)
|
2016-09-16 11:32:27 +00:00
|
|
|
debug('inserting', prereq_type, "prerequisites of", cur, ":", ' '.join(r))
|
2016-03-08 16:35:58 +00:00
|
|
|
dep_cache[prereq_type][cur] = r
|
2016-03-08 16:15:45 +00:00
|
|
|
return r
|
2012-04-29 18:47:41 +00:00
|
|
|
|
2017-08-31 18:57:13 +00:00
|
|
|
def read_deps_cached(cur, prereq_type):
|
|
|
|
|
return cache_func(read_deps, [ cur, prereq_type ])
|
|
|
|
|
|
2017-06-19 21:10:35 +00:00
|
|
|
def add_tree(cur, prereq_types):
|
|
|
|
|
debug("adding prerequisites " + ' '.join(prereq_types) + " of module " + cur)
|
2016-03-08 16:15:45 +00:00
|
|
|
if cur in all_deps:
|
2017-06-19 21:10:35 +00:00
|
|
|
debug('already handled module ' + cur)
|
2016-03-08 16:15:45 +00:00
|
|
|
return 0
|
2017-06-19 21:10:35 +00:00
|
|
|
|
|
|
|
|
deps = Set()
|
2016-03-08 16:15:45 +00:00
|
|
|
all_deps.add(cur)
|
2017-06-19 21:10:35 +00:00
|
|
|
for t in prereq_types:
|
|
|
|
|
debug("checking prereqisites of type " + t)
|
2017-08-31 18:57:13 +00:00
|
|
|
deps.update(read_deps_cached(cur, t))
|
2016-03-08 16:15:45 +00:00
|
|
|
for d in deps:
|
2017-06-19 21:10:35 +00:00
|
|
|
add_tree(d, prereq_types)
|
2016-03-08 16:15:45 +00:00
|
|
|
dep_tree[cur] = deps
|
|
|
|
|
return len(deps)
|
2012-04-29 18:47:41 +00:00
|
|
|
|
2017-04-28 11:35:31 +00:00
|
|
|
def calculate_order(order, modules, prereq_types):
|
2017-06-19 21:10:35 +00:00
|
|
|
for m in modules:
|
|
|
|
|
debug("--- adding dependency tree of module " + m)
|
|
|
|
|
add_tree(m, prereq_types)
|
2016-03-08 16:15:45 +00:00
|
|
|
while len(all_deps):
|
|
|
|
|
for d in all_deps:
|
|
|
|
|
if not len(dep_tree[d]):
|
|
|
|
|
break
|
|
|
|
|
else:
|
2016-09-16 11:32:27 +00:00
|
|
|
print(all_deps)
|
2016-03-08 16:15:45 +00:00
|
|
|
raise Exception("fatal: the dependencies between these modules are unresolvable")
|
|
|
|
|
order.append(d)
|
|
|
|
|
all_deps.remove(d)
|
|
|
|
|
for k in dep_tree.keys():
|
|
|
|
|
if d in dep_tree[k]:
|
|
|
|
|
dep_tree[k].remove(d)
|
|
|
|
|
return 1
|
2012-04-29 18:47:41 +00:00
|
|
|
|
2012-04-30 08:40:33 +00:00
|
|
|
def run_make(module, target):
|
2017-04-21 10:44:36 +00:00
|
|
|
global cur_project
|
2017-04-21 10:37:11 +00:00
|
|
|
cur_project=cur_project+1
|
2017-12-26 22:27:25 +00:00
|
|
|
#make_cmd = "make " + target + " 2>&1"
|
|
|
|
|
make_cmd = [ "make", target ]
|
2017-08-31 18:57:13 +00:00
|
|
|
path = find_proj_path_cached(module)
|
2017-05-07 14:18:18 +00:00
|
|
|
delim_len=120
|
|
|
|
|
delim='---- %d/%d: running %s in %s -' % (cur_project, len(order), make_cmd, path)
|
|
|
|
|
delim = delim + '-' * (delim_len - len(delim))
|
|
|
|
|
|
|
|
|
|
print(',' + delim + ' >')
|
2016-03-08 16:15:45 +00:00
|
|
|
os.chdir(path)
|
2017-12-26 22:27:25 +00:00
|
|
|
p = subprocess.Popen(make_cmd, shell=False, stdout=subprocess.PIPE, stderr=None, close_fds=True)
|
2016-09-16 13:34:00 +00:00
|
|
|
for line in iter(p.stdout.readline, ''):
|
2016-09-16 13:15:49 +00:00
|
|
|
sys.stdout.write('| ' + line) # avoid extra newlines from print()
|
2016-09-16 13:34:00 +00:00
|
|
|
sys.stdout.flush()
|
|
|
|
|
p.wait()
|
2017-05-07 14:18:18 +00:00
|
|
|
print('`' + delim + ' <')
|
2016-09-16 13:15:49 +00:00
|
|
|
if p.returncode:
|
|
|
|
|
print(make_cmd + ' failed')
|
2016-03-08 16:15:45 +00:00
|
|
|
raise Exception(time.strftime("%Y-%m-%d %H:%M") + ": failed to make target " + target + " in module " + module + " below base " + proj_base)
|
2012-04-30 08:40:33 +00:00
|
|
|
|
2014-11-28 13:49:56 +00:00
|
|
|
def build(modules, order, target):
|
2016-03-08 16:15:45 +00:00
|
|
|
if target in ["clean", "distclean"]:
|
|
|
|
|
for m in reversed(order):
|
|
|
|
|
run_make(m, target)
|
|
|
|
|
if m in modules:
|
|
|
|
|
modules.remove(m)
|
|
|
|
|
if not len(modules):
|
2016-09-16 11:32:27 +00:00
|
|
|
print("all modules cleaned")
|
2016-03-08 16:15:45 +00:00
|
|
|
return
|
|
|
|
|
else:
|
|
|
|
|
for m in order:
|
|
|
|
|
run_make(m, target)
|
2012-04-30 08:40:33 +00:00
|
|
|
|
2017-04-28 11:35:31 +00:00
|
|
|
# ------------ here we go
|
|
|
|
|
|
|
|
|
|
all_deps = Set()
|
2017-08-31 18:57:13 +00:00
|
|
|
cache = {}
|
2017-06-19 21:10:35 +00:00
|
|
|
visited = {}
|
2017-04-28 11:35:31 +00:00
|
|
|
dep_tree = {}
|
|
|
|
|
glob_order = []
|
|
|
|
|
proj_base=pwd.getpwuid(os.getuid()).pw_dir + "/local/src/jw.dev/proj"
|
|
|
|
|
search_path=[".", "dspc/src", "dspc/src/dspcd-plugins", "dspc/src/io" ]
|
|
|
|
|
dep_cache = {}
|
|
|
|
|
my_dir=os.path.dirname(os.path.realpath(__file__))
|
|
|
|
|
|
2012-05-05 13:15:40 +00:00
|
|
|
# -- parse command line
|
2017-06-19 21:10:35 +00:00
|
|
|
parser = argparse.ArgumentParser(description='janware software project build tool')
|
2013-10-14 14:06:08 +00:00
|
|
|
parser.add_argument('--base', '-b', nargs='?', default=proj_base, help='Project base directory')
|
2017-02-25 11:34:11 +00:00
|
|
|
parser.add_argument('--exclude', default='', help='Space seperated ist of modules to be excluded from build')
|
2016-09-16 11:32:27 +00:00
|
|
|
parser.add_argument('--debug', '-d', action='store_true',
|
|
|
|
|
default=False, help='Output debug information to stderr')
|
2017-06-19 21:10:35 +00:00
|
|
|
parser.add_argument('--dry-run', '-n', action='store_true',
|
|
|
|
|
default=False, help='Don\'t build anything, just print what would be done.')
|
2017-04-24 12:43:02 +00:00
|
|
|
parser.add_argument('--ignore-deps', '-I', action='store_true',
|
|
|
|
|
default=False, help='Don\'t build dependencies, i.e. build only modules specified on the command line')
|
2013-10-14 14:06:08 +00:00
|
|
|
parser.add_argument('target', default='all', help='Build target')
|
|
|
|
|
parser.add_argument('modules', nargs='+', default='', help='Modules to be built')
|
|
|
|
|
|
|
|
|
|
args=parser.parse_args()
|
2016-09-16 11:32:27 +00:00
|
|
|
|
|
|
|
|
debug("----------------------------------------- running ", ' '.join(sys.argv))
|
|
|
|
|
|
2017-02-25 11:34:11 +00:00
|
|
|
modules=args.modules
|
|
|
|
|
exclude=args.exclude.split()
|
2013-10-14 14:06:08 +00:00
|
|
|
proj_base=args.base
|
|
|
|
|
target=args.target
|
2017-08-31 18:57:13 +00:00
|
|
|
|
|
|
|
|
projects_py="/usr/bin/python " + my_dir + "/projects.py --prefix " + proj_base + " " + os.getenv('PROJECTS_PY_EXTRA_ARGS', "")
|
2012-05-05 13:15:40 +00:00
|
|
|
|
2014-07-08 18:23:46 +00:00
|
|
|
env_exclude=os.getenv('BUILD_EXCLUDE', '')
|
|
|
|
|
if len(env_exclude):
|
2016-09-16 11:32:27 +00:00
|
|
|
print("exluding modules from environment: " + env_exclude)
|
2016-03-08 16:15:45 +00:00
|
|
|
exclude += " " + env_exclude
|
2014-07-08 18:23:46 +00:00
|
|
|
|
2012-05-05 13:15:40 +00:00
|
|
|
# -- build
|
2016-03-06 16:03:46 +00:00
|
|
|
if target != 'order':
|
2017-04-28 11:35:31 +00:00
|
|
|
print("calculating order for modules ... ")
|
2012-05-05 13:15:40 +00:00
|
|
|
order = []
|
2017-04-28 11:35:31 +00:00
|
|
|
|
|
|
|
|
glob_prereq_types = [ "build" ]
|
2017-06-27 21:43:30 +00:00
|
|
|
if re.match("pkg-.*", target) is not None:
|
2017-06-19 21:10:35 +00:00
|
|
|
glob_prereq_types = [ "build", "run", "release", "devel" ]
|
2017-06-28 12:28:59 +00:00
|
|
|
print("using prerequisite types " + ' '.join(glob_prereq_types))
|
2017-04-28 11:35:31 +00:00
|
|
|
|
|
|
|
|
calculate_order(order, modules, glob_prereq_types)
|
2017-04-24 12:43:02 +00:00
|
|
|
if args.ignore_deps:
|
2017-04-24 13:56:14 +00:00
|
|
|
order = [m for m in order if m in args.modules]
|
2014-07-08 14:26:29 +00:00
|
|
|
order = [m for m in order if m not in exclude]
|
2016-03-06 16:03:46 +00:00
|
|
|
if target == 'order':
|
2016-09-16 11:32:27 +00:00
|
|
|
print(' '.join(order))
|
2016-03-06 16:03:46 +00:00
|
|
|
exit(0)
|
|
|
|
|
|
2017-04-21 10:37:11 +00:00
|
|
|
cur_project=0
|
|
|
|
|
print("Building target %s in %d projects:" % (target, len(order)))
|
|
|
|
|
for m in order:
|
|
|
|
|
cur_project=cur_project+1
|
|
|
|
|
print(" %3d %s" % (cur_project, m))
|
|
|
|
|
cur_project=0
|
|
|
|
|
|
2017-06-19 21:10:35 +00:00
|
|
|
if args.dry_run:
|
|
|
|
|
exit(0)
|
|
|
|
|
|
2014-11-28 13:49:56 +00:00
|
|
|
build(modules, order, target)
|
2012-04-29 18:47:41 +00:00
|
|
|
|
2016-09-16 11:32:27 +00:00
|
|
|
print(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
|
2014-10-29 17:59:27 +00:00
|
|
|
|