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