build.py: Fix dependency tree for multiple prerequisite types

build.py calculated a wrong build order because it doesn\'t take all build
prerequisite types correctly into account. Fixed that. Implemented the option
--dry-run along the way.

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2017-06-19 21:10:35 +00:00
commit 056558bb27

View file

@ -35,14 +35,15 @@ def read_deps(cur, prereq_type):
return dep_cache[prereq_type][cur]
else:
dep_cache[prereq_type] = {}
p = subprocess.Popen(projects_py + " prereq " + prereq_type + " " + cur, shell=True, stdout=subprocess.PIPE)
cmd = projects_py + " prereq " + prereq_type + " " + cur
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
p.wait()
if p.returncode:
raise Exception("failed to get " + prereq_type + " prerequisites from " + path)
r = Set()
pattern = re.compile(r'.*') # might be useful at a later point, currently pointless
for line in iter(p.stdout.readline,''):
debug('evaluating line:', line)
debug(cmd + ' returned: ', line)
if not pattern.match(line):
continue
for d in line.split():
@ -53,20 +54,26 @@ def read_deps(cur, prereq_type):
dep_cache[prereq_type][cur] = r
return r
def add_tree(cur, prereq_type):
def add_tree(cur, prereq_types):
debug("adding prerequisites " + ' '.join(prereq_types) + " of module " + cur)
if cur in all_deps:
debug('already handled module ' + cur)
return 0
deps = Set()
all_deps.add(cur)
deps = read_deps(cur, prereq_type)
for t in prereq_types:
debug("checking prereqisites of type " + t)
deps.update(read_deps(cur, t))
for d in deps:
add_tree(d, prereq_type)
add_tree(d, prereq_types)
dep_tree[cur] = deps
return len(deps)
def calculate_order(order, modules, prereq_types):
for t in prereq_types:
for m in modules:
add_tree(m, t)
for m in modules:
debug("--- adding dependency tree of module " + m)
add_tree(m, prereq_types)
while len(all_deps):
for d in all_deps:
if not len(dep_tree[d]):
@ -118,6 +125,7 @@ def build(modules, order, target):
# ------------ here we go
all_deps = Set()
visited = {}
dep_tree = {}
glob_order = []
proj_base=pwd.getpwuid(os.getuid()).pw_dir + "/local/src/jw.dev/proj"
@ -126,11 +134,13 @@ dep_cache = {}
my_dir=os.path.dirname(os.path.realpath(__file__))
# -- parse command line
parser = argparse.ArgumentParser(description='jannet software project build tool')
parser = argparse.ArgumentParser(description='janware software project build tool')
parser.add_argument('--base', '-b', nargs='?', default=proj_base, help='Project base directory')
parser.add_argument('--exclude', default='', help='Space seperated ist of modules to be excluded from build')
parser.add_argument('--debug', '-d', action='store_true',
default=False, help='Output debug information to stderr')
parser.add_argument('--dry-run', '-n', action='store_true',
default=False, help='Don\'t build anything, just print what would be done.')
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')
parser.add_argument('target', default='all', help='Build target')
@ -158,7 +168,7 @@ order = []
glob_prereq_types = [ "build" ]
if target == 'pkg-rebuild-reinstall':
glob_prereq_types == [ "build", "run", "release" ]
glob_prereq_types = [ "build", "run", "release", "devel" ]
calculate_order(order, modules, glob_prereq_types)
if args.ignore_deps:
@ -175,6 +185,9 @@ for m in order:
print(" %3d %s" % (cur_project, m))
cur_project=0
if args.dry_run:
exit(0)
build(modules, order, target)
print(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))