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
|
|
|
|
|
|
|
|
all_deps = Set()
|
|
|
|
|
dep_tree = {}
|
2012-05-05 13:15:40 +00:00
|
|
|
glob_order = []
|
2012-04-30 16:38:11 +00:00
|
|
|
proj_base=pwd.getpwuid(os.getuid()).pw_dir + "/local/src/cvs.stable/proj"
|
|
|
|
|
search_path=[".", "dspc/src", "dspc/src/dspcd-plugins", "dspc/src/io" ]
|
2012-09-02 16:06:47 +00:00
|
|
|
glob_prereq_type="BUILD"
|
2016-03-08 16:15:45 +00:00
|
|
|
dep_cache = {}
|
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)
|
|
|
|
|
|
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):
|
|
|
|
|
return path
|
|
|
|
|
raise Exception("module " + name + " not found below " + proj_base)
|
2012-04-29 18:47:41 +00:00
|
|
|
|
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]:
|
|
|
|
|
return dep_cache[cur][prereq_type]
|
|
|
|
|
else:
|
|
|
|
|
dep_cache[prereq_type] = {}
|
2016-03-08 16:15:45 +00:00
|
|
|
path = find_proj_path(cur)
|
|
|
|
|
os.chdir(path)
|
2016-09-16 13:15:49 +00:00
|
|
|
# ignoring prereq_type, as it has never been anything but BUILD, now
|
|
|
|
|
# only looking for PREREQ without anything
|
|
|
|
|
# p = subprocess.Popen("LD_LIBRARY_PATH= make echo-prereq | sed '/PREREQ " + " *=/ !d; s/.*=//'", shell=True, stdout=subprocess.PIPE)
|
|
|
|
|
p = subprocess.Popen("LD_LIBRARY_PATH= make echo-prereq", 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()
|
2016-09-16 13:15:49 +00:00
|
|
|
pattern = re.compile(r'^ *PREREQ.*=')
|
|
|
|
|
for line in iter(p.stdout.readline,''):
|
|
|
|
|
if not pattern.match(line):
|
|
|
|
|
continue
|
|
|
|
|
for d in re.sub(pattern, '', line) .split():
|
|
|
|
|
r.add(d)
|
|
|
|
|
# for d in p.stdout.read().split():
|
|
|
|
|
# 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
|
|
|
|
2012-05-05 13:15:40 +00:00
|
|
|
def add_tree(cur, prereq_type):
|
2016-03-08 16:15:45 +00:00
|
|
|
if cur in all_deps:
|
|
|
|
|
return 0
|
|
|
|
|
all_deps.add(cur)
|
|
|
|
|
deps = read_deps(cur, prereq_type)
|
|
|
|
|
for d in deps:
|
|
|
|
|
add_tree(d, prereq_type)
|
|
|
|
|
dep_tree[cur] = deps
|
|
|
|
|
return len(deps)
|
2012-04-29 18:47:41 +00:00
|
|
|
|
2012-05-05 13:15:40 +00:00
|
|
|
def calculate_order(order, modules, prereq_type):
|
2016-03-08 16:15:45 +00:00
|
|
|
for m in modules:
|
|
|
|
|
add_tree(m, prereq_type)
|
|
|
|
|
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):
|
2016-09-16 13:15:49 +00:00
|
|
|
make_cmd = "make " + target + " 2>&1"
|
2016-03-08 16:15:45 +00:00
|
|
|
path = find_proj_path(module)
|
2016-09-16 13:15:49 +00:00
|
|
|
print(',---------- running ' + make_cmd + ' in ' + path + ' -------------------------- >')
|
2016-03-08 16:15:45 +00:00
|
|
|
os.chdir(path)
|
2016-09-16 13:15:49 +00:00
|
|
|
p = subprocess.Popen(make_cmd, shell=True, stdout=subprocess.PIPE)
|
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()
|
2016-09-16 13:15:49 +00:00
|
|
|
print('`---------- running ' + make_cmd + ' in ' + path + ' -------------------------- <')
|
|
|
|
|
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
|
|
|
|
2012-05-05 13:15:40 +00:00
|
|
|
# -- parse command line
|
|
|
|
|
modules = Set()
|
2013-10-14 14:06:08 +00:00
|
|
|
|
|
|
|
|
parser = argparse.ArgumentParser(description='jannet software project build tool')
|
|
|
|
|
parser.add_argument('--base', '-b', nargs='?', default=proj_base, help='Project base directory')
|
2014-07-08 14:26:29 +00:00
|
|
|
parser.add_argument('--exclude', nargs='?', default='', help='List 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')
|
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))
|
|
|
|
|
|
2013-10-14 14:06:08 +00:00
|
|
|
proj_base=args.base
|
2014-07-08 14:26:29 +00:00
|
|
|
exclude=args.exclude
|
2013-10-14 14:06:08 +00:00
|
|
|
target=args.target
|
|
|
|
|
modules=args.modules
|
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':
|
2016-09-16 11:32:27 +00:00
|
|
|
print("calculating order for modules: " + ' '.join(modules))
|
2012-05-05 13:15:40 +00:00
|
|
|
order = []
|
|
|
|
|
calculate_order(order, modules, glob_prereq_type)
|
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)
|
|
|
|
|
|
2016-09-16 11:32:27 +00:00
|
|
|
print("order is: " + ' '.join(order))
|
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
|
|
|
|