def _handle_ise_project(self, update=False): top_mod = self.modules_pool.get_top_module() fileset = self.modules_pool.build_file_set() flist = dep_solver.make_dependency_sorted_list(fileset) assert isinstance(flist, list) prj = ISEProject(ise=self.env["ise_version"], top_mod=self.modules_pool.get_top_module()) prj.add_files(flist) sff = SourceFileFactory() logging.debug(top_mod.vlog_opt) if self.options.generate_project_vhd: self._write_project_vhd() prj.add_files([sff.new(path=path.rel2abs("project.vhd"), module=self.modules_pool.get_module_by_path("."))])\ prj.add_libs(fileset.get_libs()) if update is True: try: prj.load_xml(top_mod.syn_project) except: logging.error("Error while reading the project file.\n" "Are you sure that syn_project indicates a correct ISE project file?") raise else: prj.add_initial_properties() logging.info("Writing down .xise project file") prj.emit_xml(top_mod.syn_project)
def get_module_by_path(self, path): """Get instance of Module being stored at a given location""" path = path_mod.rel2abs(path) for module in self: if module.path == path: return module return None
def _generate_synthesis_project(self, tool_object): tool_info = tool_object.get_keys() if sys.platform == 'cygwin': bin_name = tool_info['windows_bin'] else: bin_name = tool_info['linux_bin'] path_key = tool_info['id'] + '_path' version_key = tool_info['id'] + '_version' name = tool_info['name'] id_value = tool_info['id'] ext_value = tool_info['project_ext'] env = self.env if not self.options.force: if self.env[path_key] is None: logging.error("Can't generate the " + name + " project. " + name + " not found.") quit() if not env[version_key]: logging.error(name + " version cannot be deduced. Cannot generate " + name + " " "project file properly. Please use syn_" + id_value + "_version in the manifest " "or set") sys.exit("Exiting") logging.info("Generating project for " + name + " v. %s" % env[version_key]) if os.path.exists(self.top_module.syn_project) or os.path.exists( self.top_module.syn_project + "." + ext_value): logging.info("Existing project detected: updating...") update = True else: logging.info("No previous project: creating a new one...") update = False top_mod = self.modules_pool.get_top_module() fileset = self.modules_pool.build_file_set() non_dependable = fileset.inversed_filter(DependableFile) fileset.add(non_dependable) sff = SourceFileFactory() if self.options.generate_project_vhd: self._write_project_vhd(id_value, env[version_key]) fileset.add([sff.new(path=path.rel2abs("project.vhd"), module=self.modules_pool.get_module_by_path("."))])\ tool_object.generate_synthesis_project( update=update, tool_version=self.env[version_key], top_mod=self.modules_pool.get_top_module(), fileset=fileset) logging.info(name + " project file generated.")
def _generate_synthesis_project(self, tool_object): tool_info = tool_object.get_keys() if sys.platform == "cygwin": bin_name = tool_info["windows_bin"] else: bin_name = tool_info["linux_bin"] path_key = tool_info["id"] + "_path" version_key = tool_info["id"] + "_version" name = tool_info["name"] id_value = tool_info["id"] ext_value = tool_info["project_ext"] env = self.env if not self.options.force: if self.env[path_key] is None: logging.error("Can't generate the " + name + " project. " + name + " not found.") quit() if not env[version_key]: logging.error( name + " version cannot be deduced. Cannot generate " + name + " " "project file properly. Please use syn_" + id_value + "_version in the manifest " "or set" ) sys.exit("Exiting") logging.info("Generating project for " + name + " v. %s" % env[version_key]) if os.path.exists(self.top_module.syn_project) or os.path.exists(self.top_module.syn_project + "." + ext_value): logging.info("Existing project detected: updating...") update = True else: logging.info("No previous project: creating a new one...") update = False top_mod = self.modules_pool.get_top_module() fileset = self.modules_pool.build_file_set() non_dependable = fileset.inversed_filter(DependableFile) fileset.add(non_dependable) sff = SourceFileFactory() if self.options.generate_project_vhd: self._write_project_vhd(id_value, env[version_key]) fileset.add([sff.new(path=path.rel2abs("project.vhd"), module=self.modules_pool.get_module_by_path("."))]) tool_object.generate_synthesis_project( update=update, tool_version=self.env[version_key], top_mod=self.modules_pool.get_top_module(), fileset=fileset, ) logging.info(name + " project file generated.")
def get_git_submodules(module): submodule_dir = path.rel2abs(module.path) logging.debug("Checking git submodules in %s" % submodule_dir) cur_dir = os.getcwd() try: os.chdir(submodule_dir) if not os.path.exists(".gitmodules"): return {} #"git config --list" | grep submodule | sed 's/.*=//')" % submodule_dir config_submodules = {} config_content = Popen("git config -f .gitmodules --list", stdout=PIPE, stdin=PIPE, shell=True) config_lines = [line.strip() for line in config_content.stdout.readlines()] """try to parse sth like this: paszoste@oplarra1:~/beco/hdlmake-tests/wr-switch-hdl$ git config -f .gitmodules --list submodule.ip_cores/general-cores.path=ip_cores/general-cores submodule.ip_cores/general-cores.url=git://ohwr.org/hdl-core-lib/general-cores.git submodule.ip_cores/wr-cores.path=ip_cores/wr-cores submodule.ip_cores/wr-cores.url=git://ohwr.org/hdl-core-lib/wr-cores.git """ config_submodule_lines = [line for line in config_lines if line.startswith("submodule")] for line in config_submodule_lines: line_split = line.split("=") lhs = line_split[0] rhs = line_split[1] lhs_split = lhs.split(".") module_name = '.'.join(lhs_split[1:-1]) if module_name not in config_submodules: config_submodules[module_name] = {} config_submodules[module_name][lhs_split[-1]] = rhs #"(cd %s && cat ./.gitmodules 2>/dev/null | grep url | sed 's/url = //')" % submodule_dir #try: ## dotgitmodules_file = open(".gitmodules", 'r') # dotgitmodules_lines = dotgitmodules_file.readlines() # url_lines = [line for line in dotgitmodules_lines if 'url' in line] # dotgitmodules_submodules = [line.split(" = ")[-1].strip() for line in url_lines] # set(config_submodules).update(set(dotgitmodules_submodules)) #except IOError: # pass # no .gitmodules file if len(list(config_submodules)) > 0: logging.info("Found git submodules in %s: %s" % (module.path, str(config_submodules))) finally: os.chdir(cur_dir) return config_submodules
def get_git_toplevel(module): cur_dir = os.getcwd() try: os.chdir(path.rel2abs(module.path)) if not os.path.exists(".gitmodules"): return None tree_root_cmd = Popen("git rev-parse --show-toplevel", stdout=PIPE, stdin=PIPE, shell=True) tree_root_line = tree_root_cmd.stdout.readlines()[0].strip() return tree_root_line finally: os.chdir(cur_dir)
def _check_filepath(self, filepath): if filepath: if path_mod.is_abs_path(filepath): logging.warning("Specified path seems to be an absolute path: %s\nOmitting." % filepath) return False filepath = os.path.join(self.path, filepath) if not os.path.exists(filepath): logging.error("Path specified in manifest in %s doesn't exist: %s" % (self.path, filepath)) sys.exit("Exiting") filepath = path_mod.rel2abs(filepath, self.path) if os.path.isdir(filepath): logging.warning("Path specified in manifest %s is a directory: %s" % (self.path, filepath)) return True
def _make_list_of_paths(self, list_of_paths): paths = [] for filepath in list_of_paths: if self._check_filepath(filepath): paths.append(path_mod.rel2abs(filepath, self.path)) return paths
def process_manifest(self): from srcfile import TCLFile, VerilogFile, VHDLFile, SourceFileSet if self.isprocessed is True: return if self.manifest_dict is None: logging.debug("There is no manifest to be processed in: %s" % self.url) return logging.debug("Process manifest in: %s" % self.path) if self.manifest_dict["syn_ise_version"] is not None: version = self.manifest_dict["syn_ise_version"] self.syn_ise_version = str(version) if self.manifest_dict["fetchto"] is not None: fetchto = path_mod.rel2abs(self.manifest_dict["fetchto"], self.path) self.fetchto = fetchto else: fetchto = self.fetchto if "local" in self.manifest_dict["modules"]: local_paths = self._flatten_list(self.manifest_dict["modules"]["local"]) local_mods = [] for path in local_paths: if path_mod.is_abs_path(path): logging.error("Found an absolute path (" + path + ") in a manifest" "(" + self.path + ")") quit() path = path_mod.rel2abs(path, self.path) local_mods.append(self.pool.new_module(parent=self, url=path, source=fetch.LOCAL, fetchto=fetchto)) self.local = local_mods else: self.local = [] self.vmap_opt = self.manifest_dict["vmap_opt"] self.vcom_opt = self.manifest_dict["vcom_opt"] self.vsim_opt = self.manifest_dict["vsim_opt"] self.vlog_opt = self.manifest_dict["vlog_opt"] self.iverilog_opt = self.manifest_dict["iverilog_opt"] self.sim_tool = self.manifest_dict["sim_tool"] if self.manifest_dict["force_tool"]: ft = self.manifest_dict["force_tool"] self.force_tool = ft.split(' ') if len(self.force_tool) != 3: logging.warning("Incorrect force_tool format %s. Ignoring" % self.force_tool) self.force_tool = None if "top_module" in self.manifest_dict: self.top_module = self.manifest_dict["top_module"] mkFileList = [] if isinstance(self.manifest_dict["incl_makefiles"], basestring): mkFileList.append(self.manifest_dict["incl_makefiles"]) else: # list mkFileList = self.manifest_dict["incl_makefiles"][:] makefiles_paths = self._make_list_of_paths(mkFileList) self.incl_makefiles.extend(makefiles_paths) #if self.vlog_opt == "": # self.vlog_opt = global_mod.top_module.vlog_opt #if self.vcom_opt == "": # self.vcom_opt = global_mod.top_module.vcom_opt #if self.vsim_opt == "": # self.vsim_opt = global_mod.top_module.vsim_opt # if self.vmap_opt == "": # self.vmap_opt = global_mod.top_module.vmap_opt self.library = self.manifest_dict["library"] self.include_dirs = [] if self.manifest_dict["include_dirs"] is not None: if isinstance(self.manifest_dict["include_dirs"], basestring): # self.include_dirs.append(self.manifest_dict["include_dirs"]) ll = os.path.relpath(os.path.abspath(os.path.join(self.path, self.manifest_dict["include_dirs"]))) self.include_dirs.append(ll) else: # self.include_dirs.extend(self.manifest_dict["include_dirs"]) ll = map(lambda x: os.path.relpath(os.path.abspath(os.path.join(self.path, x))), self.manifest_dict["include_dirs"]) self.include_dirs.extend(ll) for dir_ in self.include_dirs: if path_mod.is_abs_path(dir_): logging.warning("%s contains absolute path to an include directory: %s" % (self.path, dir_)) if not os.path.exists(dir_): logging.warning(self.path + " has an unexisting include directory: " + dir_) if self.manifest_dict["files"] == []: self.files = SourceFileSet() try: logging.debug("No files in the manifest %s" % self.manifest.path) except AttributeError: pass else: self.manifest_dict["files"] = self._flatten_list(self.manifest_dict["files"]) logging.debug("Files in %s: %s" % (self.path, str(self.manifest_dict["files"]))) paths = self._make_list_of_paths(self.manifest_dict["files"]) self.files = self._create_file_list_from_paths(paths=paths) for f in self.files: if isinstance(f, VerilogFile): f.vsim_opt = self.vsim_opt elif isinstance(f, VHDLFile): f.vcom_opt = self.vcom_opt if len(self.manifest_dict["sim_only_files"]) == 0: self.sim_only_files = SourceFileSet() else: self.manifest_dict["sim_only_files"] = self._flatten_list(self.manifest_dict["sim_only_files"]) paths = self._make_list_of_paths(self.manifest_dict["sim_only_files"]) self.sim_only_files = self._create_file_list_from_paths(paths=paths) self.syn_pre_cmd = self.manifest_dict["syn_pre_cmd"] self.syn_post_cmd = self.manifest_dict["syn_post_cmd"] self.sim_pre_cmd = self.manifest_dict["sim_pre_cmd"] self.sim_post_cmd = self.manifest_dict["sim_post_cmd"] self.bit_file_targets = SourceFileSet() if len(self.manifest_dict["bit_file_targets"]) != 0: paths = self._make_list_of_paths(self.manifest_dict["bit_file_targets"]) self.bit_file_targets = self._create_file_list_from_paths(paths=paths) if "svn" in self.manifest_dict["modules"]: self.manifest_dict["modules"]["svn"] = self._flatten_list(self.manifest_dict["modules"]["svn"]) svn_mods = [] for url in self.manifest_dict["modules"]["svn"]: svn_mods.append(self.pool.new_module(parent=self, url=url, source=fetch.SVN, fetchto=fetchto)) self.svn = svn_mods else: self.svn = [] if "git" in self.manifest_dict["modules"]: self.manifest_dict["modules"]["git"] = self._flatten_list(self.manifest_dict["modules"]["git"]) git_mods = [] for url in self.manifest_dict["modules"]["git"]: git_mods.append(self.pool.new_module(parent=self, url=url, source=fetch.GIT, fetchto=fetchto)) self.git = git_mods else: self.git = [] git_submodule_dict = fetch.Git.get_git_submodules(self) git_toplevel = fetch.Git.get_git_toplevel(self) for submodule_key in git_submodule_dict.keys(): url = git_submodule_dict[submodule_key]["url"] path = git_submodule_dict[submodule_key]["path"] path = os.path.join(git_toplevel, path) fetchto = os.path.sep.join(path.split(os.path.sep)[:-1]) self.git_submodules.append(self.pool.new_module(parent=self, url=url, fetchto=fetchto, source=fetch.GITSUBMODULE)) self.target = self.manifest_dict["target"].lower() self.action = self.manifest_dict["action"].lower() if self.manifest_dict["syn_name"] is None and self.manifest_dict["syn_project"] is not None: self.syn_name = self.manifest_dict["syn_project"][:-5] # cut out .xise from the end else: self.syn_name = self.manifest_dict["syn_name"] self.syn_tool = self.manifest_dict["syn_tool"] self.syn_device = self.manifest_dict["syn_device"] self.syn_grade = self.manifest_dict["syn_grade"] self.syn_package = self.manifest_dict["syn_package"] self.syn_project = self.manifest_dict["syn_project"] self.syn_top = self.manifest_dict["syn_top"] if self.manifest_dict["quartus_preflow"] != None: path = path_mod.rel2abs(self.manifest_dict["quartus_preflow"], self.path); if not os.path.exists(path): p.error("quartus_preflow file listed in " + self.manifest.path + " doesn't exist: " + path + ".\nExiting.") quit() self.quartus_preflow = TCLFile(path) if self.manifest_dict["quartus_postflow"] != None: path = path_mod.rel2abs(self.manifest_dict["quartus_postflow"], self.path); if not os.path.exists(path): p.error("quartus_postflow file listed in " + self.manifest.path + " doesn't exist: " + path + ".\nExiting.") quit() self.quartus_postflow = TCLFile(path) self.isparsed = True self.isprocessed = True for m in self.submodules(): m.parse_manifest() m.process_manifest() if self == global_mod.top_module: revision = fetch.Svn.check_revision_number(self.path) if revision is None: commit = fetch.Git.check_commit_id(self.path) self.revision = commit else: self.revision = revision else: if self.source == fetch.SVN: self.revision = fetch.Svn.check_revision_number(self.path) elif self.source == fetch.GIT: self.revision = fetch.Git.check_commit_id(self.path)
def process_manifest(self): from srcfile import TCLFile, VerilogFile, VHDLFile, SourceFileSet if self.isprocessed is True: return if self.manifest_dict is None: logging.debug("There is no manifest to be processed in: %s" % self.url) return logging.debug("Process manifest in: %s" % self.path) if self.manifest_dict["syn_ise_version"] is not None: version = self.manifest_dict["syn_ise_version"] self.syn_ise_version = str(version) if self.manifest_dict["fetchto"] is not None: fetchto = path_mod.rel2abs(self.manifest_dict["fetchto"], self.path) self.fetchto = fetchto else: fetchto = self.fetchto if "local" in self.manifest_dict["modules"]: local_paths = self._flatten_list(self.manifest_dict["modules"]["local"]) local_mods = [] for path in local_paths: if path_mod.is_abs_path(path): logging.error("Found an absolute path (" + path + ") in a manifest" "(" + self.path + ")") quit() path = path_mod.rel2abs(path, self.path) local_mods.append(self.pool.new_module(parent=self, url=path, source=fetch.LOCAL, fetchto=fetchto)) self.local = local_mods else: self.local = [] self.vmap_opt = self.manifest_dict["vmap_opt"] self.vcom_opt = self.manifest_dict["vcom_opt"] self.vsim_opt = self.manifest_dict["vsim_opt"] self.vlog_opt = self.manifest_dict["vlog_opt"] self.iverilog_opt = self.manifest_dict["iverilog_opt"] self.sim_tool = self.manifest_dict["sim_tool"] if self.manifest_dict["force_tool"]: ft = self.manifest_dict["force_tool"] self.force_tool = ft.split(' ') if len(self.force_tool) != 3: logging.warning("Incorrect force_tool format %s. Ignoring" % self.force_tool) self.force_tool = None if "top_module" in self.manifest_dict: self.top_module = self.manifest_dict["top_module"] mkFileList = [] if isinstance(self.manifest_dict["incl_makefiles"], basestring): mkFileList.append(self.manifest_dict["incl_makefiles"]) else: # list mkFileList = self.manifest_dict["incl_makefiles"][:] makefiles_paths = self._make_list_of_paths(mkFileList) self.incl_makefiles.extend(makefiles_paths) #if self.vlog_opt == "": # self.vlog_opt = global_mod.top_module.vlog_opt #if self.vcom_opt == "": # self.vcom_opt = global_mod.top_module.vcom_opt #if self.vsim_opt == "": # self.vsim_opt = global_mod.top_module.vsim_opt # if self.vmap_opt == "": # self.vmap_opt = global_mod.top_module.vmap_opt self.library = self.manifest_dict["library"] self.include_dirs = [] if self.manifest_dict["include_dirs"] is not None: if isinstance(self.manifest_dict["include_dirs"], basestring): # self.include_dirs.append(self.manifest_dict["include_dirs"]) ll = os.path.relpath(os.path.abspath(os.path.join(self.path, self.manifest_dict["include_dirs"]))) self.include_dirs.append(ll) else: # self.include_dirs.extend(self.manifest_dict["include_dirs"]) ll = map(lambda x: os.path.relpath(os.path.abspath(os.path.join(self.path, x))), self.manifest_dict["include_dirs"]) self.include_dirs.extend(ll) for dir_ in self.include_dirs: if path_mod.is_abs_path(dir_): logging.warning("%s contains absolute path to an include directory: %s" % (self.path, dir_)) if not os.path.exists(dir_): logging.warning(self.path + " has an unexisting include directory: " + dir_) if self.manifest_dict["files"] == []: self.files = SourceFileSet() try: logging.debug("No files in the manifest %s" % self.manifest.path) except AttributeError: pass else: self.manifest_dict["files"] = self._flatten_list(self.manifest_dict["files"]) logging.debug("Files in %s: %s" % (self.path, str(self.manifest_dict["files"]))) paths = self._make_list_of_paths(self.manifest_dict["files"]) self.files = self._create_file_list_from_paths(paths=paths) for f in self.files: if isinstance(f, VerilogFile): f.vsim_opt = self.vsim_opt elif isinstance(f, VHDLFile): f.vcom_opt = self.vcom_opt if len(self.manifest_dict["sim_only_files"]) == 0: self.sim_only_files = SourceFileSet() else: self.manifest_dict["sim_only_files"] = self._flatten_list(self.manifest_dict["sim_only_files"]) paths = self._make_list_of_paths(self.manifest_dict["sim_only_files"]) self.sim_only_files = self._create_file_list_from_paths(paths=paths) self.syn_pre_cmd = self.manifest_dict["syn_pre_cmd"] self.syn_post_cmd = self.manifest_dict["syn_post_cmd"] self.sim_pre_cmd = self.manifest_dict["sim_pre_cmd"] self.sim_post_cmd = self.manifest_dict["sim_post_cmd"] self.bit_file_targets = SourceFileSet() if len(self.manifest_dict["bit_file_targets"]) != 0: paths = self._make_list_of_paths(self.manifest_dict["bit_file_targets"]) self.bit_file_targets = self._create_file_list_from_paths(paths=paths) if "svn" in self.manifest_dict["modules"]: self.manifest_dict["modules"]["svn"] = self._flatten_list(self.manifest_dict["modules"]["svn"]) svn_mods = [] for url in self.manifest_dict["modules"]["svn"]: svn_mods.append(self.pool.new_module(parent=self, url=url, source=fetch.SVN, fetchto=fetchto)) self.svn = svn_mods else: self.svn = [] if "git" in self.manifest_dict["modules"]: self.manifest_dict["modules"]["git"] = self._flatten_list(self.manifest_dict["modules"]["git"]) git_mods = [] for url in self.manifest_dict["modules"]["git"]: git_mods.append(self.pool.new_module(parent=self, url=url, source=fetch.GIT, fetchto=fetchto)) self.git = git_mods else: self.git = [] git_submodule_dict = fetch.Git.get_git_submodules(self) git_toplevel = fetch.Git.get_git_toplevel(self) for submodule_key in git_submodule_dict.keys(): url = git_submodule_dict[submodule_key]["url"] path = git_submodule_dict[submodule_key]["path"] path = os.path.join(git_toplevel, path) fetchto = os.path.sep.join(path.split(os.path.sep)[:-1]) self.git_submodules.append(self.pool.new_module(parent=self, url=url, fetchto=fetchto, source=fetch.GITSUBMODULE)) self.target = self.manifest_dict["target"].lower() self.action = self.manifest_dict["action"].lower() if self.manifest_dict["syn_name"] is None and self.manifest_dict["syn_project"] is not None: self.syn_name = self.manifest_dict["syn_project"][:-5] # cut out .xise from the end else: self.syn_name = self.manifest_dict["syn_name"] self.syn_tool = self.manifest_dict["syn_tool"] self.syn_device = self.manifest_dict["syn_device"] self.syn_grade = self.manifest_dict["syn_grade"] self.syn_package = self.manifest_dict["syn_package"] self.syn_project = self.manifest_dict["syn_project"] self.syn_top = self.manifest_dict["syn_top"] if self.manifest_dict["quartus_preflow"] != None: path = path_mod.rel2abs(self.manifest_dict["quartus_preflow"], self.path); if not os.path.exists(path): p.error("quartus_preflow file listed in " + self.manifest.path + " doesn't exist: " + path + ".\nExiting.") quit() self.quartus_preflow = TCLFile(path) if self.manifest_dict["quartus_postmodule"] != None: path = path_mod.rel2abs(self.manifest_dict["quartus_postmodule"], self.path); if not os.path.exists(path): p.error("quartus_postmodule file listed in " + self.manifest.path + " doesn't exist: " + path + ".\nExiting.") quit() self.quartus_postmodule = TCLFile(path) if self.manifest_dict["quartus_postflow"] != None: path = path_mod.rel2abs(self.manifest_dict["quartus_postflow"], self.path); if not os.path.exists(path): p.error("quartus_postflow file listed in " + self.manifest.path + " doesn't exist: " + path + ".\nExiting.") quit() self.quartus_postflow = TCLFile(path) self.isparsed = True self.isprocessed = True for m in self.submodules(): m.parse_manifest() m.process_manifest() if self == global_mod.top_module: revision = fetch.Svn.check_revision_number(self.path) if revision is None: commit = fetch.Git.check_commit_id(self.path) self.revision = commit else: self.revision = revision else: if self.source == fetch.SVN: self.revision = fetch.Svn.check_revision_number(self.path) elif self.source == fetch.GIT: self.revision = fetch.Git.check_commit_id(self.path)