Skip to content
Snippets Groups Projects
Commit cb6ce3fc authored by Paweł Szostek's avatar Paweł Szostek
Browse files

Clean up module's constructor and built-in logic

parent 9f7999dd
Branches
Tags
No related merge requests found
...@@ -24,7 +24,7 @@ srcfile.py ...@@ -24,7 +24,7 @@ srcfile.py
ARCH := hdlmake ARCH := hdlmake
../$(ARCH): check $(SRC) ../$(ARCH): $(SRC)
zip $(ARCH) $(SRC) zip $(ARCH) $(SRC)
echo '#!/usr/bin/python' > ../$(ARCH) echo '#!/usr/bin/python' > ../$(ARCH)
cat $(ARCH).zip >> ../$(ARCH) cat $(ARCH).zip >> ../$(ARCH)
......
...@@ -27,7 +27,6 @@ import global_mod ...@@ -27,7 +27,6 @@ import global_mod
import msg as p import msg as p
import optparse import optparse
from module import Module from module import Module
from helper_classes import Manifest, ManifestParser
from fetch import ModulePool from fetch import ModulePool
def main(): def main():
...@@ -53,6 +52,9 @@ def main(): ...@@ -53,6 +52,9 @@ def main():
parser.add_option("-f", "--fetch", action="store_true", dest="fetch", parser.add_option("-f", "--fetch", action="store_true", dest="fetch",
help="fetch and/or update remote modules listed in Manifet") help="fetch and/or update remote modules listed in Manifet")
parser.add_option("--clean", action="store_true", dest="clean",
help="remove all modules fetched for this one")
parser.add_option("--ise-proj", action="store_true", dest="ise_proj", parser.add_option("--ise-proj", action="store_true", dest="ise_proj",
help="create/update an ise project including list of project files") help="create/update an ise project including list of project files")
...@@ -78,20 +80,14 @@ def main(): ...@@ -78,20 +80,14 @@ def main():
global_mod.options = options global_mod.options = options
if options.manifest_help == True: if options.manifest_help == True:
from helper_classes import ManifestParser
ManifestParser().help() ManifestParser().help()
quit() quit()
file = None
if os.path.exists("manifest.py"):
file = "manifest.py"
elif os.path.exists("Manifest.py"):
file = "Manifest.py"
if file != None: if file != None:
p.vprint("LoadTopManifest"); p.vprint("LoadTopManifest");
top_manifest = Manifest(path=os.path.abspath(file)) m = Module(parent=None, url=os.getcwd(), source="local", fetchto=".", )
global_mod.top_module = Module(manifest=top_manifest, parent=None, source="local", fetchto=".") global_mod.top_module = m
global_mod.top_module.parse_manifest() global_mod.top_module.parse_manifest()
global_mod.global_target = global_mod.top_module.target global_mod.global_target = global_mod.top_module.target
else: else:
...@@ -122,6 +118,8 @@ def main(): ...@@ -122,6 +118,8 @@ def main():
kernel.generate_ise_makefile() kernel.generate_ise_makefile()
elif options.make_remote == True: elif options.make_remote == True:
kernel.generate_remote_synthesis_makefile() kernel.generate_remote_synthesis_makefile()
elif options.clean == True:
kernel.clean_modules()
else: else:
p.echo("Running automatic flow") p.echo("Running automatic flow")
kernel.run() kernel.run()
......
...@@ -29,8 +29,9 @@ class ModulePool(list): ...@@ -29,8 +29,9 @@ class ModulePool(list):
pass pass
def fetch_single_module(self, module): def fetch_single_module(self, module):
import global_mod
new_modules = [] new_modules = []
p.vprint("Fetching manifest: " + str(module.manifest)) p.vprint("Fetching module: " + str(module))
if module.source == "local": if module.source == "local":
p.vprint("ModPath: " + module.path); p.vprint("ModPath: " + module.path);
...@@ -43,9 +44,9 @@ class ModulePool(list): ...@@ -43,9 +44,9 @@ class ModulePool(list):
module.parse_manifest() module.parse_manifest()
if module.root_module != None: # if module.root_module != None:
p.vprint("Encountered root manifest: " + str(module.root_module)) # p.vprint("Encountered root manifest: " + str(module.root_module))
new_modules.append(module.root_module) # new_modules.append(module.root_module)
new_modules.extend(module.local) new_modules.extend(module.local)
new_modules.extend(module.svn) new_modules.extend(module.svn)
...@@ -95,10 +96,10 @@ class ModulePool(list): ...@@ -95,10 +96,10 @@ class ModulePool(list):
if basename.endswith(".git"): if basename.endswith(".git"):
basename = basename[:-4] #remove trailing .git basename = basename[:-4] #remove trailing .git
if not os.path.exists(os.path.join(fetchto, basename)): if module.isfetched:
update_only = False
else:
update_only = True update_only = True
else:
update_only = False
if update_only: if update_only:
cmd = "git --git-dir="+basename+"/.git pull" cmd = "git --git-dir="+basename+"/.git pull"
...@@ -195,7 +196,8 @@ class ModulePool(list): ...@@ -195,7 +196,8 @@ class ModulePool(list):
def fetch_all(self): def fetch_all(self):
fetcher = self.ModuleFetcher() fetcher = self.ModuleFetcher()
fetch_queue = [mod for mod in self.modules if not mod.isfetched] from copy import copy
fetch_queue = copy(self.modules)
while len(fetch_queue) > 0: while len(fetch_queue) > 0:
cur_mod = fetch_queue.pop() cur_mod = fetch_queue.pop()
...@@ -203,6 +205,7 @@ class ModulePool(list): ...@@ -203,6 +205,7 @@ class ModulePool(list):
for mod in new_modules: for mod in new_modules:
if not self.__contains(mod): if not self.__contains(mod):
self.add(mod)
fetch_queue.append(mod) fetch_queue.append(mod)
else: else:
pass pass
......
...@@ -63,6 +63,7 @@ class HdlmakeKernel(object): ...@@ -63,6 +63,7 @@ class HdlmakeKernel(object):
pool = self.modules_pool pool = self.modules_pool
if not pool.is_everything_fetched(): if not pool.is_everything_fetched():
p.echo("A module remains unfetched. Fetching must be done prior to makefile generation") p.echo("A module remains unfetched. Fetching must be done prior to makefile generation")
p.echo(str([str(m) for m in self.modules_pool.modules if not m.isfetched]))
quit() quit()
tm = pool.get_top_module() tm = pool.get_top_module()
flist = pool.build_global_file_list(); flist = pool.build_global_file_list();
...@@ -104,6 +105,7 @@ class HdlmakeKernel(object): ...@@ -104,6 +105,7 @@ class HdlmakeKernel(object):
quit() quit()
if not self.modules_pool.is_everything_fetched(): if not self.modules_pool.is_everything_fetched():
p.echo("A module remains unfetched. Fetching must be done prior to makefile generation") p.echo("A module remains unfetched. Fetching must be done prior to makefile generation")
p.echo(str([str(m) for m in self.modules_pool.modules if not m.isfetched]))
quit() quit()
ise = self.__check_ise_version() ise = self.__check_ise_version()
if os.path.exists(self.top_module.syn_project): if os.path.exists(self.top_module.syn_project):
......
...@@ -25,119 +25,93 @@ import global_mod ...@@ -25,119 +25,93 @@ import global_mod
from helper_classes import Manifest, ManifestParser from helper_classes import Manifest, ManifestParser
from srcfile import SourceFileSet, SourceFileFactory from srcfile import SourceFileSet, SourceFileFactory
class ManifestOptions(object):
def __init__(self):
self.items = { "files" : None, #files from the module that should be taken
"fetchto" : None, #where this module should be fetched to, when fetching
"path" : None, #where the module is storek
"url" : None, #URL to the module
"manifest" : None, #manifest object
"source" : None, #where it should be fetched from
"isparsed" : None, #
"isfetched" : None,
"library" : None, #target library for the vhdl compilation
"root_module" : None, #root module object
"local" : None, #local modules
"target" : None,
"action" : None,
"git" : None, #git modules
"svn" : None, #svn modules
"ise" : None,
"tcl" : None,
"vmap_opt" : None,
"vlog_opt" : None,
"vcom_opt" : None
}
def __setitem__(self, key, value):
if key in self.items:
self.items[key] = value
else:
raise KeyError("__setitem__: there is no such key: "+str(key))
def __getitem__(self, key):
if key in self.items:
return self.items[key]
else:
raise KeyError("__getitem__:there is no such key: "+str(key))
class Module(object): class Module(object):
def __init__(self, parent, url=None, files=None, manifest=None, # @property
path=None, isfetched=False, source=None, fetchto=None): # def manifest(self):
self.options = ManifestOptions() # return self._manifest
if source == "local" and path != None: # @manifest.setter
if not os.path.exists(path): # def manifest(self, value):
p.rawprint("Path to the local module doesn't exist:\n" + path) # self._manifest = value
p.rawprint("This module was instantiated in: " + str(parent)) # if value != None:
# self.url = os.path.dirname(manifest.path)
## self.path = os.path.dirname(manifest.path)
# @manifest.deleter
# def manifest(self):
# del self._manifest
###
# @property
# def files(self):
# return self._files
# @files.setter
# def files(self, value):
# if value == None:
## self._files = []
# elif not isinstance(value, list):
# self._files = [value]
# else:
## self._files = value
# @files.deleter
# def files(self):
# del self._files
###
@property
def source(self):
return self._source
@source.setter
def source(self, value):
if value not in ["svn","git","local"]:
raise ValueError("Inproper source: " + value)
self._source = value
@source.deleter
def source(self):
del self._source
###
@property
def basename(self):
return path_mod.url_basename(self.url)
def __init__(self, parent, url, source, fetchto):
#self.options = ManifestOptions()
self.fetchto = fetchto
self.source = source
self.parent = parent self.parent = parent
self.isparsed = False
self.library = "work"
self.local = []
self.git = []
self.svn = []
self.ise = []
self.target = None
self.action = None
self.vmap_opt = None
self.vlog_opt = None
self.vcom_opt = None
self.revision = None self.revision = None
self._files = None
self.manifest = None
self.url = url
if files == None: if source == "local" and not os.path.exists(url):
self.files = [] p.rawprint("Path to the local module doesn't exist:\n" + url)
elif not isinstance(files, list): p.rawprint("This module was instantiated in: " + str(parent))
self.files = [files]
else:
self.files = files
if manifest != None and fetchto == None:
self.fetchto = os.path.dirname(manifest.path)
if manifest != None and url == None and path == None:
self.url = os.path.dirname(manifest.path)
self.path = os.path.dirname(manifest.path)
else:
if path != None and url == None:
self.path = path
self.url = path
else:
self.path = path
self.url = url
if manifest == None:
if path != None:
self.manifest = self.__search_for_manifest()
else:
self.manifest = None
else:
self.manifest = manifest
if source == "local": if source == "local":
self.path = self.url self.path = url
self.isfetched = True self.isfetched = True
else: else:
self.isfetched = isfetched if os.path.exists(os.path.join(fetchto, self.basename())):
self.path = os.path.join(fetchto, self.basename())
if source != None: self.isfetched = True
if source not in ["local", "svn", "git"]:
raise ValueError("Inproper source: " + source)
self.source = source
else:
self.source = "local"
if fetchto != None:
self.fetchto = fetchto
else:
if parent == None:
self.fetchto = self.path
else: else:
self.fetchto = parent.fetchto self.path = None
self.isfetched = False
self.isparsed = False if self.path != None:
basename = path_mod.url_basename(self.url)
if source == "local":
self.isfetched = True
elif self.path != None:
self.isfetched = True
elif os.path.exists(os.path.join(self.fetchto, basename)):
self.isfetched = True
self.path = os.path.join(self.fetchto, basename)
self.manifest = self.__search_for_manifest() self.manifest = self.__search_for_manifest()
self.parse_manifest()
self.library = "work" else:
self.parse_manifest() self.manifest = None
def __getattr__(self, attr):
#options = object.__getattribute__(self, "options")
return self.options[attr]
def __str__(self): def __str__(self):
return self.url return self.url
...@@ -187,7 +161,8 @@ class Module(object): ...@@ -187,7 +161,8 @@ class Module(object):
return return
if self.manifest == None: if self.manifest == None:
self.manifest = self.__search_for_manifest() self.manifest = self.__search_for_manifest()
if self.path == None:
raise RuntimeError()
manifest_parser = ManifestParser() manifest_parser = ManifestParser()
if(self.parent != None): if(self.parent != None):
manifest_parser.add_arbitrary_code("target=\""+str(global_mod.top_module.target)+"\"") manifest_parser.add_arbitrary_code("target=\""+str(global_mod.top_module.target)+"\"")
...@@ -209,15 +184,14 @@ class Module(object): ...@@ -209,15 +184,14 @@ class Module(object):
except NameError as ne: except NameError as ne:
p.echo("Error while parsing {0}:\n{1}: {2}.".format(self.manifest, type(ne), ne)) p.echo("Error while parsing {0}:\n{1}: {2}.".format(self.manifest, type(ne), ne))
quit() quit()
if opt_map["root_module"] != None: #if opt_map["root_module"] != None:
root_path = path_mod.rel2abs(opt_map["root_module"], self.path) # root_path = path_mod.rel2abs(opt_map["root_module"], self.path)
self.root_module = Module(path=root_path, source="local", isfetched=True, parent=self) # self.root_module = Module(path=root_path, source="local", isfetched=True, parent=self)
self.root_module.parse_manifest() # self.root_module.parse_manifest()
self.target = opt_map["target"] self.target = opt_map["target"]
if(opt_map["fetchto"] != None): if(opt_map["fetchto"] != None):
print ">>>" + opt_map["fetchto"]
fetchto = path_mod.rel2abs(opt_map["fetchto"], self.path) fetchto = path_mod.rel2abs(opt_map["fetchto"], self.path)
else: else:
if self.fetchto == None: if self.fetchto == None:
...@@ -227,19 +201,20 @@ class Module(object): ...@@ -227,19 +201,20 @@ class Module(object):
if self.ise == None: if self.ise == None:
self.ise = "13.1" self.ise = "13.1"
if "local" in opt_map["modules"]: if "local" in opt_map["modules"]:
local_paths = self.__make_list(opt_map["modules"]["local"]) local_paths = self.__make_list(opt_map["modules"]["local"])
local_mods = [] local_mods = []
for path in local_paths: for path in local_paths:
path = path_mod.rel2abs(path, self.path) path = path_mod.rel2abs(path, self.path)
local_mods.append(Module(path=path, source="local", parent=self, fetchto=fetchto)) local_mods.append(Module(parent=self, url=path, source="local", fetchto=fetchto))
self.local = local_mods self.local = local_mods
else: else:
self.local = [] self.local = []
self.library = opt_map["library"] self.library = opt_map["library"]
if opt_map["files"] == []: if opt_map["files"] == []:
self.fileset = SourceFileSet() self.files = SourceFileSet()
else: else:
opt_map["files"] = self.__make_list(opt_map["files"]) opt_map["files"] = self.__make_list(opt_map["files"])
paths = [] paths = []
...@@ -254,23 +229,23 @@ class Module(object): ...@@ -254,23 +229,23 @@ class Module(object):
+ path +".\nExiting.") + path +".\nExiting.")
quit() quit()
self.fileset = self.__create_flat_file_list(paths=paths); self.files = self.__create_flat_file_list(paths=paths);
if "svn" in opt_map["modules"]: if "svn" in opt_map["modules"]:
opt_map["modules"]["svn"] = self.__make_list(opt_map["modules"]["svn"]) opt_map["modules"]["svn"] = self.__make_list(opt_map["modules"]["svn"])
svn = [] svn_mods = []
for url in opt_map["modules"]["svn"]: for url in opt_map["modules"]["svn"]:
svn.append(Module(url=url, source="svn", fetchto=fetchto, parent=self)) svn_mods.append(Module(parent=self, url=url, source="svn", fetchto=fetchto))
self.svn = svn self.svn = svn_mods
else: else:
self.svn = [] self.svn = []
if "git" in opt_map["modules"]: if "git" in opt_map["modules"]:
opt_map["modules"]["git"] = self.__make_list(opt_map["modules"]["git"]) opt_map["modules"]["git"] = self.__make_list(opt_map["modules"]["git"])
git = [] git_mods = []
for url in opt_map["modules"]["git"]: for url in opt_map["modules"]["git"]:
git.append(Module(url=url, source="git", fetchto=fetchto, parent=self)) git_mods.append(Module(parent=self, url=url, source="git", fetchto=fetchto))
self.git = git self.git = git_mods
else: else:
self.git = [] self.git = []
...@@ -316,10 +291,10 @@ class Module(object): ...@@ -316,10 +291,10 @@ class Module(object):
p.vprint("No manifest in " + str(cur_module)) p.vprint("No manifest in " + str(cur_module))
continue continue
cur_module.parse_manifest() cur_module.parse_manifest()
if cur_module.root_module != None: # if cur_module.root_module != None:
root_module = cur_module.root_module # root_module = cur_module.root_module
modules_from_root = root_module.make_list_of_modules() # modules_from_root = root_module.make_list_of_modules()
modules.extend(modules_from_root) # modules.extend(modules_from_root)
for module in cur_module.local: for module in cur_module.local:
modules.append(module) modules.append(module)
......
...@@ -273,7 +273,7 @@ class SourceFileFactory: ...@@ -273,7 +273,7 @@ class SourceFileFactory:
path = os.path.abspath(path) path = os.path.abspath(path)
tmp = path.rsplit('.') tmp = path.rsplit('.')
extension = tmp[len(tmp)-1] extension = tmp[len(tmp)-1]
p.vprint("SFF> " + path); #p.vprint("SFF> " + path);
nf = None nf = None
if extension == 'vhd' or extension == 'vhdl': if extension == 'vhd' or extension == 'vhdl':
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment