Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def parse_options(self):
if 'OPTIONS' in self.variables:
self.options = {}
mode = 'normal'
for line in self['OPTIONS'].split('\n'):
if mode == 'doc':
if len(line) and line[0] in string.whitespace:
docs += line.split()
else:
self.options[name] = Script.Option(name, arg, docs)
mode = 'normal'
if mode == 'normal':
if not len(line):
continue
parts = line.split()
name = parts[0]
arg = parts[1]
docs = parts[2:]
if arg == '-':
arg = None
mode = 'doc'
else:
self.options = None
if 'MODULES' in self.variables:
for name in self.variables['MODULES'].split(" "):
module = modules[name]
for item in module.closure_order:
if item not in self.module_set:
self.module_set.add(item)
self.module_order.append(item)
def resolve_phases(self):
self.phase_closure = set()
for module in self.module_set:
self.phase_closure.update(module.phase_closure)
class Project(Script):
def manifest_prefix(self):
return "MK_"
class Settings:
mk_dir = os.path.abspath(os.environ['MK_HOME'])
root_dir = os.path.abspath(os.getcwd())
constants = Script("constants", os.path.join(mk_dir, 'shlib', 'constants.sh'))
module_dirname = constants['MK_MODULE_DIRNAME']
component_dirname = constants['MK_COMPONENT_DIRNAME']
configure_filename = constants['MK_CONFIGURE_FILENAME']
action_filename = constants['MK_ACTION_FILENAME']
makefile_filename = constants['MK_MAKEFILE_FILENAME']
manifest_filename = constants['MK_MANIFEST_FILENAME']
project_filename = constants['MK_PROJECT_FILENAME']
def manifest_name(name):
self.phase_closure.update(module['PHASES'].split(" "))
def resolve_components(self, components):
self.component_order = []
for component in order_depends(components):
if self in component.module_set:
self.component_order.append(component)
self.variables['COMPONENTS'] = " ".join([x.name for x in self.component_order])
def phase_is_always(self, phase, timing):
name = manifest_name(timing + "_" + phase + "_ALWAYS")
return name in self.variables
class Component(Script):
"""Represents a component"""
def __init__(self, name, filename):
Script.__init__(self, name, filename)
self.module_set = None
self.module_order = None
def manifest_prefix(self):
return "MK_COMPONENT_"
def emit_manifest(self, out):
Script.emit_manifest(self, out)
prefix = "%s%s" % (self.manifest_prefix(), manifest_name(self.name))
closure = " ".join([x.name for x in self.closure_order])
out.write("%s_CLOSURE='%s'\n" % (prefix, closure))
def parse_file(self):
var_names = []
mode = "normal"
with open(self.filename) as file:
for line in file:
if (mode == "normal"):
match = Script.var_pat.match(line)
if (match != None):
var_names.append(match.group(1))
match = Script.func_pat.match(line)
if (match != None):
body = ""
name = match.group(1)
mode = "func"
elif (mode == "func"):
if (line == "{\n"):
continue
elif (line == "}\n" or line == "}"):
self.functions[name] = body
mode="normal"
continue
else:
body += line
echos = ". '%s' && " % self.filename
echos += ";".join(['echo "self.variables[\'%s\'] = r\\"\\"\\"${%s} \\"\\"\\""[0:-1]' % (x,x) for x in var_names])
def parse_file(self):
var_names = []
mode = "normal"
with open(self.filename) as file:
for line in file:
if (mode == "normal"):
match = Script.var_pat.match(line)
if (match != None):
var_names.append(match.group(1))
match = Script.func_pat.match(line)
if (match != None):
body = ""
name = match.group(1)
mode = "func"
elif (mode == "func"):
if (line == "{\n"):
continue
elif (line == "}\n" or line == "}"):
self.functions[name] = body
mode="normal"
continue
else:
body += line
self.module_order.append(item)
def resolve_phases(self):
self.phase_closure = set()
for module in self.module_set:
self.phase_closure.update(module.phase_closure)
class Project(Script):
def manifest_prefix(self):
return "MK_"
class Settings:
mk_dir = os.path.abspath(os.environ['MK_HOME'])
root_dir = os.path.abspath(os.getcwd())
constants = Script("constants", os.path.join(mk_dir, 'shlib', 'constants.sh'))
module_dirname = constants['MK_MODULE_DIRNAME']
component_dirname = constants['MK_COMPONENT_DIRNAME']
configure_filename = constants['MK_CONFIGURE_FILENAME']
action_filename = constants['MK_ACTION_FILENAME']
makefile_filename = constants['MK_MAKEFILE_FILENAME']
manifest_filename = constants['MK_MANIFEST_FILENAME']
project_filename = constants['MK_PROJECT_FILENAME']
def manifest_name(name):
return name.upper().replace('-', '_')
def function_name(name):
return name.lower().replace('-', '_')
def order_depends(scripts):
seen = set([])
def __init__(self, name, filename):
Script.__init__(self, name, filename)
self.module_set = None
self.module_order = None
def emit_manifest(self, out):
Script.emit_manifest(self, out)
prefix = "%s%s" % (self.manifest_prefix(), manifest_name(self.name))
closure = " ".join([x.name for x in self.closure_order])
out.write("%s_CLOSURE='%s'\n" % (prefix, closure))
module_closure = " ".join([x.name for x in self.module_order])
out.write("%s_MODULE_CLOSURE='%s'\n" % (prefix, module_closure))
self.closure_order.append(item)
self.closure_set.add(item)
self.resolving = False
self.closure_set.add(self);
self.closure_order.append(self);
def emit_manifest(self, out):
prefix = "%s%s" % (self.manifest_prefix(), manifest_name(self.name))
out.write("%s_FUNCS='%s'\n" % (prefix, " ".join(self.functions.keys())))
for (name,value) in self.variables.iteritems():
out.write("%s_%s='%s'\n" % (prefix, name, value))
class Module(Script):
"""Represents a module"""
def manifest_prefix(self):
return "MK_MODULE_"
def emit_manifest(self, out):
Script.emit_manifest(self, out)
prefix = "%s%s" % (self.manifest_prefix(), manifest_name(self.name))
closure = " ".join([x.name for x in self.closure_order])
out.write("%s_CLOSURE='%s'\n" % (prefix, closure))
def resolve_phases(self):
self.phase_closure = set()