Commit fb5f6d1d authored by William Kamp's avatar William Kamp

Allow an override of the library from the manifest that imports a git/svn module.

Override the library variable by specifying the git/svn module as a tuple (url, library) instead of just the url string.
The module path (checkout directory) is modified by appending the repository basename with the library. 
Backwards compatibility with plain url is maintained.
This allows multiple versions of the same repository to be imported into the project, with them separated into different library namespaces.
parent a548cdac
......@@ -70,17 +70,17 @@ class Git(Fetcher):
if not os.path.exists(fetchto):
os.mkdir(fetchto)
basename = path_utils.url_basename(module.url)
mod_path = os.path.join(fetchto, basename)
if basename.endswith(".git"):
basename = basename[:-4] # remove trailing .git
if not module.isfetched:
logging.info("Fetching git module %s", mod_path)
cmd = "(cd {0} && git clone {1})"
cmd = cmd.format(fetchto, module.url)
logging.info("Fetching git module %s to %s", module.url, module.path)
cmd = "(git clone {1} {2})"
cmd = cmd.format(fetchto, module.url, module.path)
logging.info(cmd)
if os.system(cmd) != 0:
return False
else:
logging.info("Updating git module %s", mod_path)
logging.info("Updating git module %s", module.path)
checkout_id = None
if module.branch is not None:
checkout_id = module.branch
......@@ -94,17 +94,16 @@ class Git(Fetcher):
if checkout_id is not None:
logging.info("Checking out version %s", checkout_id)
cmd = "(cd {0} && git checkout {1})"
cmd = cmd.format(mod_path, checkout_id)
cmd = cmd.format(module.path, checkout_id)
if os.system(cmd) != 0:
return False
if self.submodule and not module.isfetched:
cmd = ("(cd {0} && git submodule init &&"
"git submodule update --recursive)")
cmd = cmd.format(mod_path)
cmd = cmd.format(module.path)
if os.system(cmd) != 0:
return False
module.isfetched = True
module.path = mod_path
return True
@staticmethod
......
......@@ -22,6 +22,7 @@ class ModuleConfig(object):
self.revision = None
self.path = None
self.isfetched = False
self.library_overide = None
def process_manifest(self):
"""process_manifest does nothing for ModuleConfig"""
......@@ -51,12 +52,14 @@ class ModuleConfig(object):
if self.source != fetch.LOCAL:
if self.source == fetch.SVN:
self.url, self.revision = \
self.url, self.revision, self.library_overide = \
path_mod.svn_parse(url)
else:
self.url, self.branch, self.revision = \
self.url, self.branch, self.revision, self.library_overide = \
path_mod.url_parse(url)
basename = self.basename()
if self.library_overide:
basename += "-" + self.library_overide
path = path_mod.relpath(os.path.abspath(
os.path.join(fetchto, basename)))
......@@ -141,7 +144,9 @@ class ModuleCore(ModuleConfig):
# if "top_module" in self.manifest_dict:
# self.top_module = self.manifest_dict["top_module"]
# Libraries
if "library" in self.manifest_dict:
if self.library_overide is not None:
self.library = self.library_overide
elif "library" in self.manifest_dict:
self.library = self.manifest_dict["library"]
elif self.parent:
self.library = self.parent.library
......
......@@ -53,11 +53,11 @@ class Module(ModuleContent):
super(Module, self).__init__()
self.init_config(module_args)
self.set_pool(pool)
self.module_args = ModuleArgs()
self.module_args = module_args
#self.module_args = ModuleArgs()
#self.module_args = module_args
def __str__(self):
return self.module_args.url
return self.url
@property
def is_fetched_to(self):
......
......@@ -26,21 +26,23 @@ from __future__ import print_function
from __future__ import absolute_import
import os
def url_parse(url):
"""
Check if link to a Git repo seems to be correct. Filter revision
number and branch
"""
url_clean, branch, rev = None, None, None
if "@@" in url:
url_clean, rev = url.split("@@")
elif "::" in url:
url_clean, branch = url.split("::")
url_clean, branch, rev, lib = None, None, None, None
if isinstance(url,tuple):
url_clean, lib = url
else:
url_clean = url
return (url_clean, branch, rev)
if "@@" in url_clean:
url_clean, rev = url_clean.split("@@")
elif "::" in url_clean:
url_clean, branch = url_clean.split("::")
return (url_clean, branch, rev, lib)
def svn_parse(url):
......@@ -48,14 +50,16 @@ def svn_parse(url):
Check if link to a SVN repo seems to be correct. Filter revision
number
"""
url_clean, rev = None, None
if "@" in url:
url_clean, rev = url.split("@")
url_clean, rev, lib = None, None, None
if isinstance(url,tuple):
url_clean, lib = url
else:
url_clean = url
return (url_clean, rev)
if "@" in url_clean:
url_clean, rev = url_clean.split("@")
return (url_clean, rev, lib)
def url_basename(url):
"""
......
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