mirror of
ssh://git.janware.com/srv/git/janware/proj/jw-pkg
synced 2026-01-23 22:40:38 +01:00
build.py, projects.py: Streamline both scripts
Make build.py and projects.py even more similar in preparation for merging them. Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
f996726bae
commit
f7db567bff
2 changed files with 45 additions and 38 deletions
|
|
@ -17,34 +17,40 @@ import datetime
|
||||||
import re
|
import re
|
||||||
from os.path import expanduser
|
from os.path import expanduser
|
||||||
|
|
||||||
|
class ResultCache(object):
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.__cache = {}
|
||||||
|
|
||||||
|
def run(self, func, args):
|
||||||
|
d = self.__cache
|
||||||
|
depth = 0
|
||||||
|
keys = [ func.__name__ ] + args
|
||||||
|
l = len(keys)
|
||||||
|
for k in keys:
|
||||||
|
if k is None:
|
||||||
|
k = 'None'
|
||||||
|
else:
|
||||||
|
k = str(k)
|
||||||
|
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 = d[k] = {}
|
||||||
|
#d = d[k]
|
||||||
|
raise Exception("cache algorithm failed for function", func.__name__, "in depth", depth)
|
||||||
|
|
||||||
def debug(*objs):
|
def debug(*objs):
|
||||||
if args.debug:
|
if args.debug:
|
||||||
print("DEBUG: ", *objs, file=sys.stderr)
|
print("DEBUG: ", *objs, file=sys.stderr)
|
||||||
|
|
||||||
def build_cache_func(func, args):
|
|
||||||
global build_cache
|
|
||||||
d = build_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)
|
|
||||||
|
|
||||||
def build_find_proj_path(name):
|
def build_find_proj_path(name):
|
||||||
name=name.replace("dspider-", "")
|
name=name.replace("dspider-", "")
|
||||||
search_path=[".", "dspc/src", "dspc/src/dspcd-plugins", "dspc/src/io" ]
|
search_path=[".", "dspc/src", "dspc/src/dspcd-plugins", "dspc/src/io" ]
|
||||||
|
|
@ -55,10 +61,11 @@ def build_find_proj_path(name):
|
||||||
raise Exception("module " + name + " not found below " + projs_root)
|
raise Exception("module " + name + " not found below " + projs_root)
|
||||||
|
|
||||||
def build_find_proj_path_cached(name):
|
def build_find_proj_path_cached(name):
|
||||||
return build_cache_func(build_find_proj_path, [ name ])
|
return res_cache.run(build_find_proj_path, [ name ])
|
||||||
|
|
||||||
def build_read_deps(cur, prereq_type):
|
def build_read_deps(cur, prereq_type):
|
||||||
# dep cache doesn't make a difference at all
|
# dep cache doesn't make a difference at all
|
||||||
|
projects_py="/usr/bin/python2 " + my_dir + "/projects.py --prefix " + projs_root + " " + os.getenv('PROJECTS_PY_EXTRA_ARGS', "")
|
||||||
if prereq_type in dep_cache:
|
if prereq_type in dep_cache:
|
||||||
if cur in dep_cache[prereq_type]:
|
if cur in dep_cache[prereq_type]:
|
||||||
return dep_cache[prereq_type][cur]
|
return dep_cache[prereq_type][cur]
|
||||||
|
|
@ -85,7 +92,7 @@ def build_read_deps(cur, prereq_type):
|
||||||
return r
|
return r
|
||||||
|
|
||||||
def build_read_deps_cached(cur, prereq_type):
|
def build_read_deps_cached(cur, prereq_type):
|
||||||
return build_cache_func(build_read_deps, [ cur, prereq_type ])
|
return res_cache.run(build_read_deps, [ cur, prereq_type ])
|
||||||
|
|
||||||
def build_add_dep_tree(cur, prereq_types, tree, all_deps):
|
def build_add_dep_tree(cur, prereq_types, tree, all_deps):
|
||||||
debug("adding prerequisites " + ' '.join(prereq_types) + " of module " + cur)
|
debug("adding prerequisites " + ' '.join(prereq_types) + " of module " + cur)
|
||||||
|
|
@ -225,7 +232,7 @@ def cmd_build(args_):
|
||||||
# -------------------------------------------------------------------- here we go
|
# -------------------------------------------------------------------- here we go
|
||||||
|
|
||||||
global_args = []
|
global_args = []
|
||||||
#cache = ResultCache()
|
#res_cache = ResultCache()
|
||||||
|
|
||||||
skip = 0
|
skip = 0
|
||||||
for a in sys.argv[1::]:
|
for a in sys.argv[1::]:
|
||||||
|
|
@ -255,18 +262,15 @@ args=parser.parse_args(global_args)
|
||||||
debug("----------------------------------------- running ", ' '.join(sys.argv))
|
debug("----------------------------------------- running ", ' '.join(sys.argv))
|
||||||
|
|
||||||
projs_root = args.prefix
|
projs_root = args.prefix
|
||||||
|
res_cache = ResultCache()
|
||||||
|
dep_cache = {}
|
||||||
|
my_dir=os.path.dirname(os.path.realpath(__file__))
|
||||||
|
|
||||||
if args.topdir:
|
if args.topdir:
|
||||||
topdir = args.topdir
|
topdir = args.topdir
|
||||||
top_name = cache.run(read_value, [topdir + '/make/project.conf', 'build', 'name'])
|
top_name = res_cache.run(read_value, [topdir + '/make/project.conf', 'build', 'name'])
|
||||||
if not top_name:
|
if not top_name:
|
||||||
top_name = re.sub('-[0-9.-]*$', '', basename(realpath(topdir)))
|
top_name = re.sub('-[0-9.-]*$', '', basename(realpath(topdir)))
|
||||||
|
|
||||||
# ---- global variables
|
|
||||||
build_cache = {}
|
|
||||||
dep_cache = {}
|
|
||||||
my_dir=os.path.dirname(os.path.realpath(__file__))
|
|
||||||
projects_py="/usr/bin/python2 " + my_dir + "/projects.py --prefix " + projs_root + " " + os.getenv('PROJECTS_PY_EXTRA_ARGS', "")
|
|
||||||
|
|
||||||
cmd = getattr(sys.modules[__name__], 'cmd_' + args.cmd.replace('-', '_'))
|
cmd = getattr(sys.modules[__name__], 'cmd_' + args.cmd.replace('-', '_'))
|
||||||
cmd(sys.argv[(len(global_args) + 1)::])
|
cmd(sys.argv[(len(global_args) + 1)::])
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
#!/usr/bin/python2 -u
|
#!/usr/bin/python2 -u
|
||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
import os
|
||||||
import sys
|
import sys
|
||||||
import argparse
|
import argparse
|
||||||
from sets import Set
|
from sets import Set
|
||||||
|
|
@ -100,7 +101,7 @@ def htdocs_dir(name):
|
||||||
|
|
||||||
def os_cascade():
|
def os_cascade():
|
||||||
r = [ 'os', platform.system().lower() ]
|
r = [ 'os', platform.system().lower() ]
|
||||||
os = cache.run(get_os, [])
|
os = res_cache.run(get_os, [])
|
||||||
name = re.sub('-.*', '', os)
|
name = re.sub('-.*', '', os)
|
||||||
series = os
|
series = os
|
||||||
while True:
|
while True:
|
||||||
|
|
@ -190,7 +191,7 @@ def get_value(name, section, key):
|
||||||
|
|
||||||
path = proj_root + '/make/project.conf'
|
path = proj_root + '/make/project.conf'
|
||||||
#print('path = ', path, 'top_name = ', top_name, 'name = ', name)
|
#print('path = ', path, 'top_name = ', top_name, 'name = ', name)
|
||||||
return cache.run(read_value, [path, section, key])
|
return res_cache.run(read_value, [path, section, key])
|
||||||
|
|
||||||
def collect_values(names, section, key):
|
def collect_values(names, section, key):
|
||||||
r = ""
|
r = ""
|
||||||
|
|
@ -206,7 +207,7 @@ def collect_values(names, section, key):
|
||||||
|
|
||||||
def add_modules_from_project_txt_cached(buf, visited, spec, section, key, add_self, scope,
|
def add_modules_from_project_txt_cached(buf, visited, spec, section, key, add_self, scope,
|
||||||
names_only):
|
names_only):
|
||||||
return cache.run(add_modules_from_project_txt, [buf, visited, spec, section, key,
|
return res_cache.run(add_modules_from_project_txt, [buf, visited, spec, section, key,
|
||||||
add_self, scope, names_only])
|
add_self, scope, names_only])
|
||||||
|
|
||||||
def add_modules_from_project_txt(buf, visited, spec, section, key, add_self, scope,
|
def add_modules_from_project_txt(buf, visited, spec, section, key, add_self, scope,
|
||||||
|
|
@ -606,7 +607,9 @@ def cmd_getval(args_):
|
||||||
# -------------------------------------------------------------------- here we go
|
# -------------------------------------------------------------------- here we go
|
||||||
|
|
||||||
global_args = []
|
global_args = []
|
||||||
cache = ResultCache()
|
res_cache = ResultCache()
|
||||||
|
dep_cache = {}
|
||||||
|
my_dir = os.path.dirname(os.path.realpath(__file__))
|
||||||
|
|
||||||
skip = 0
|
skip = 0
|
||||||
for a in sys.argv[1::]:
|
for a in sys.argv[1::]:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue