projects.py: Fix infinite recursion and project mixup

Apply two fixes:

  - Config files of wrong projects are queried
  - add_modules_from_project_txt() recurses into stack overflow

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2016-01-29 14:02:29 +00:00
commit 92e49e97a9

View file

@ -4,6 +4,8 @@ import sys
import argparse
from sets import Set
from os.path import expanduser
from os.path import basename
from os.path import realpath
import re
def re_section(name):
@ -36,53 +38,47 @@ def get_section(path, section):
return r.rstrip()
def get_value(name, section, key):
proj_root = proj_dir(name)
dirs = []
if topdir:
dirs.append(topdir)
dirs.append(projs_root + '/' + name)
if section == 'version':
for d in dirs:
with open(d + '/VERSION', 'r') as file:
r=file.read().replace('\n', '').replace('-dev', '')
file.close()
return r
raise Exception("failed to find version of " + name)
if topdir and name == basename(realpath(topdir)):
proj_root = topdir
else:
proj_root = projs_root + '/' + name
dirs = []
if topdir:
dirs.append(topdir)
dirs.append(projs_root + '/' + name)
if section == 'version':
file = open(proj_root + '/VERSION', 'r')
r=file.read().replace('\n', '').replace('-dev', '')
file.close()
return r
r = ()
for conf in [ '/make/project.conf', '/doc/share/project.txt' ]:
for d in dirs:
path = d + conf
r = ()
try:
file = open(path)
except:
continue
if not len(section):
for line in file:
path = proj_root + conf
try:
file = open(path)
except:
continue
if not len(section):
for line in file:
r = re.findall('^ *' + key + ' *= *(.*)', line)
if (len(r) > 0):
break
else:
in_section = False
pat = '[' + section + ']'
for line in file:
if (line.rstrip() == pat):
in_section = True
continue
if in_section:
if len(line) and line[0] == '[':
break
r = re.findall('^ *' + key + ' *= *(.*)', line)
if (len(r) > 0):
break
else:
in_section = False
pat = '[' + section + ']'
for line in file:
if (line.rstrip() == pat):
in_section = True
continue
if in_section:
if len(line) and line[0] == '[':
break
r = re.findall('^ *' + key + ' *= *(.*)', line)
if (len(r) > 0):
break
file.close()
if len(r):
return r[0]
return ''
file.close()
if len(r):
return r[0]
return ''
return None
@ -90,13 +86,16 @@ def get_value(name, section, key):
# scope 1: children
# scope 2: recursive
def add_modules_from_project_txt(buf, spec, section, key, add_self, scope,
def add_modules_from_project_txt(buf, visited, spec, section, key, add_self, scope,
names_only):
name = strip_module_from_spec(spec)
if names_only:
spec = name
if spec in buf:
return
if spec in visited:
return
visited.add(spec)
deps = get_value(name, section, key)
if deps and scope > 0:
if scope == 1:
@ -105,7 +104,7 @@ def add_modules_from_project_txt(buf, spec, section, key, add_self, scope,
subscope = 2
deps = deps.split(',')
for dep in deps:
add_modules_from_project_txt(buf, dep,
add_modules_from_project_txt(buf, visited, dep,
section, key, add_self=True, scope=subscope,
names_only=names_only)
if add_self:
@ -115,8 +114,9 @@ def get_modules_from_project_txt(names, section, key, add_self, scope,
names_only = True):
#r = Set()
r = []
visited = Set()
for name in names:
add_modules_from_project_txt(r, name, section, key, add_self, scope,
add_modules_from_project_txt(r, visited, name, section, key, add_self, scope,
names_only)
return r