Commit fba34965 authored by Paweł Szostek's avatar Paweł Szostek

fetch: add --flatten and --update options

parent 4ecc0baa
misc
src/build_hash.py
examples
hdlmake.aux
hdlmake.pdf
hdlmake.log
hdlmake
*~
*.swp
*.swap
......
......@@ -34,6 +34,9 @@ def main():
manifest_help = subparsers.add_parser("manifest-help", help="print manifest file variables description")
auto = subparsers.add_parser("auto", help="default action for hdlmake. Run when no args are given")
fetch = subparsers.add_parser("fetch", help="fetch and/or update remote modules listed in Manifest")
fetch.add_argument("--flatten", help="`flatten' modules' hierarchy by storing everything in top module's fetchto direactoru",
default=False, action="store_true")
fetch.add_argument("--update", help="force updating of the fetched modules", default=False, action="store_true")
clean = subparsers.add_parser("clean", help="remove all modules fetched for this one")
listmod = subparsers.add_parser("list-mods", help="List all modules together with their files")
listmod.add_argument("--with-files", help="list modules together with their files", default=False, action="store_true", dest="withfiles")
......
import logging
import sys
from action import Action
class FetchModules(Action):
def run(self, unfetched_only=False):
def _check_options(self):
if self.options.flatten is True and self.env["coredir"] is not None:
logging.error("Options clash: --flatten and HDLMAKE_COREDIR set at a time\n"
"Take one out of the two")
sys.exit("\nExiting")
def run(self):
logging.info("Fetching needed modules.")
self.modules_pool.fetch_all(unfetched_only)
self.modules_pool.fetch_all(unfetched_only=not self.options.update, flatten=self.options.flatten)
logging.debug(str(self.modules_pool))
......@@ -11,8 +11,5 @@ class GenerateFetchMakefile(Action):
"No fetch makefile is produced")
quit()
if not pool.is_everything_fetched():
logging.error("A module remains unfetched. "
"Fetching must be done prior to makefile generation")
quit()
self._check_all_fetched_or_quit()
self.make_writer.generate_fetch_makefile(pool)
......@@ -35,9 +35,8 @@ class GenerateISEProject(Action):
logging.info("Generating project for ISE v. %s.%s" % (env["ise_version"][0], env["ise_version"][1]))
def run(self):
self._check_all_fetched_or_quit()
logging.info("Generating/updating ISE project file.")
if os.path.exists(self.top_module.syn_project) or os.path.exists(self.top_module.syn_project + ".xise"):
self._handle_ise_project(update=True)
else:
......
......@@ -100,7 +100,7 @@ class Module(object):
self.isfetched = False
if self.path is not None:
self.manifest = self.__search_for_manifest()
self.manifest = self._search_for_manifest()
else:
self.manifest = None
......@@ -120,7 +120,7 @@ class Module(object):
return __nonull(self.local) + __nonull(self.git) + __nonull(self.svn)
def __search_for_manifest(self):
def _search_for_manifest(self):
"""
Look for manifest in the given folder
"""
......@@ -128,7 +128,7 @@ class Module(object):
dir_files = os.listdir(self.path)
if "manifest.py" in dir_files and "Manifest.py" in dir_files:
logging.error("Both manifest.py and Manifest.py found in the module directory: %s" % self.path)
quit()
sys.exit("\nExiting")
for filename in dir_files:
if filename == "manifest.py" or filename == "Manifest.py":
if not os.path.isdir(filename):
......@@ -169,7 +169,7 @@ class Module(object):
if self.isparsed is True or self.isfetched is False:
return
if self.manifest is None:
self.manifest = self.__search_for_manifest()
self.manifest = self._search_for_manifest()
if self.path is None:
raise RuntimeError()
......
......@@ -28,6 +28,7 @@ import dep_solver
from srcfile import SourceFileSet
from fetch import BackendFactory
import fetch
from subprocess import PIPE, Popen
class ModulePool(list):
......@@ -72,13 +73,27 @@ class ModulePool(list):
def new_module(self, parent, url, source, fetchto, process_manifest=True):
from module import Module
if url in [m.url for m in self]: # check if module is not already in the pool
if source != "local":
clean_url, branch, revision = path.parse_url(url)
else:
clean_url, branch, revision = url, None, None
if clean_url in [m.url for m in self]: # check if module is not already in the pool
same_url_mod = [m for m in self if m.url == url][0]
if branch != same_url_mod.branch:
logging.error("Requested the same module, but different branches."
"URL: %s\n" % clean_url +
"branches: %s and %s\n" % (branch, same_url_mod.branch))
sys.exit("\nExiting")
if revision != same_url_mod.revision:
logging.error("Requested the same module, but different revisions."
"URL: %s\n" % clean_url +
"revisions: %s and %s\n" % (revision, same_url_mod.revision))
sys.exit("\nExiting")
return [m for m in self if m.url == url][0]
else:
if self.global_fetch: # if there is global fetch parameter (HDLMAKE_COREDIR env variable)
fetchto = self.global_fetch # screw module's particular fetchto
elif global_mod.top_module:
fetchto = global_mod.top_module.fetchto
new_module = Module(parent=parent, url=url, source=source, fetchto=fetchto, pool=self)
self._add(new_module)
......@@ -91,8 +106,28 @@ class ModulePool(list):
return new_module
def process_top_module_manifest(self):
url = self._guess_origin(global_mod.top_module.path)
if url:
global_mod.top_module.url = url
global_mod.top_module.process_manifest()
def _guess_origin(self, path):
cwd = os.getcwd()
try:
os.chdir(path)
git_out = Popen("git config --get remote.origin.url", stdout=PIPE, shell=True, close_fds=True)
url = git_out.stdout.readlines()[0].strip()
if not url: # try svn
svn_out = Popen("svn info | grep 'Repository Root' | awk '{print $NF}'", stdout=PIPE, shell=True, close_fds=True)
url = svn_out.stdout.readlines()[0].strip()
if url:
return url
else:
return None
else:
return url
finally:
os.chdir(cwd)
def _add(self, new_module):
from module import Module
if not isinstance(new_module, Module):
......@@ -105,11 +140,13 @@ class ModulePool(list):
self.append(new_module)
return True
def fetch_all(self, unfetched_only=False):
def fetch_all(self, unfetched_only=False, flatten=False):
fetch_queue = [m for m in self]
while len(fetch_queue) > 0:
cur_mod = fetch_queue.pop()
if flatten is True:
cur_mod.fetchto = global_mod.top_module.fetchto
new_modules = []
if unfetched_only:
if cur_mod.isfetched:
......
......@@ -283,6 +283,7 @@ class ConfigParser(object):
quit()
except:
logging.error("Encountered unexpected error while parsing " + self.config_file)
logging.error(content)
print(str(sys.exc_info()[0]) + ':' + str(sys.exc_info()[1]))
raise
......
Markdown is supported
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