def update_submodules(self, ud, d): submodules = [] paths = {} uris = {} local_paths = {} for name in ud.names: try: gitmodules = runfetchcmd("%s show %s:.gitmodules" % (ud.basecmd, ud.revisions[name]), d, quiet=True, workdir=ud.clonedir) except: # No submodules to update continue for m, md in self.parse_gitmodules(gitmodules).items(): submodules.append(m) paths[m] = md['path'] uris[m] = md['url'] if uris[m].startswith('..'): newud = copy.copy(ud) newud.path = os.path.realpath( os.path.join(newud.path, md['url'])) uris[m] = Git._get_repo_url(self, newud) for module in submodules: module_hash = runfetchcmd( "%s ls-tree -z -d %s %s" % (ud.basecmd, ud.revisions[name], paths[module]), d, quiet=True, workdir=ud.clonedir) module_hash = module_hash.split()[2] # Build new SRC_URI proto = uris[module].split(':', 1)[0] url = uris[module].replace('%s:' % proto, 'gitsm:', 1) url += ';protocol=%s' % proto url += ";name=%s" % module url += ";bareclone=1;nocheckout=1;nobranch=1" ld = d.createCopy() # Not necessary to set SRC_URI, since we're passing the URI to # Fetch. #ld.setVar('SRC_URI', url) ld.setVar('SRCREV_%s' % module, module_hash) # Workaround for issues with SRCPV/SRCREV_FORMAT errors # error refer to 'multiple' repositories. Only the repository # in the original SRC_URI actually matters... ld.setVar('SRCPV', d.getVar('SRCPV')) ld.setVar('SRCREV_FORMAT', module) newfetch = Fetch([url], ld, cache=False) newfetch.download() local_paths[module] = newfetch.localpath(url) # Correct the submodule references to the local download version... runfetchcmd("%(basecmd)s config submodule.%(module)s.url %(url)s" % { 'basecmd': ud.basecmd, 'module': module, 'url': local_paths[module] }, d, workdir=ud.clonedir) symlink_path = os.path.join(ud.clonedir, 'modules', paths[module]) if not os.path.exists(symlink_path): try: os.makedirs(os.path.dirname(symlink_path), exist_ok=True) except OSError: pass os.symlink(local_paths[module], symlink_path) return True
def process_submodules(self, ud, workdir, function, d): """ Iterate over all of the submodules in this repository and execute the 'function' for each of them. """ submodules = [] paths = {} revision = {} uris = {} subrevision = {} def parse_gitmodules(gitmodules): modules = {} module = "" for line in gitmodules.splitlines(): if line.startswith('[submodule'): module = line.split('"')[1] modules[module] = {} elif module and line.strip().startswith('path'): path = line.split('=')[1].strip() modules[module]['path'] = path elif module and line.strip().startswith('url'): url = line.split('=')[1].strip() modules[module]['url'] = url return modules # Collect the defined submodules, and their attributes for name in ud.names: try: gitmodules = runfetchcmd("%s show %s:.gitmodules" % (ud.basecmd, ud.revisions[name]), d, quiet=True, workdir=workdir) except: # No submodules to update continue for m, md in parse_gitmodules(gitmodules).items(): try: module_hash = runfetchcmd( "%s ls-tree -z -d %s %s" % (ud.basecmd, ud.revisions[name], md['path']), d, quiet=True, workdir=workdir) except: # If the command fails, we don't have a valid file to check. If it doesn't # fail -- it still might be a failure, see next check... module_hash = "" if not module_hash: logger.debug( 1, "submodule %s is defined, but is not initialized in the repository. Skipping", m) continue submodules.append(m) paths[m] = md['path'] revision[m] = ud.revisions[name] uris[m] = md['url'] subrevision[m] = module_hash.split()[2] # Convert relative to absolute uri based on parent uri if uris[m].startswith('..'): newud = copy.copy(ud) newud.path = os.path.realpath( os.path.join(newud.path, uris[m])) uris[m] = Git._get_repo_url(self, newud) for module in submodules: # Translate the module url into a SRC_URI if "://" in uris[module]: # Properly formated URL already proto = uris[module].split(':', 1)[0] url = uris[module].replace('%s:' % proto, 'gitsm:', 1) else: if ":" in uris[module]: # Most likely an SSH style reference proto = "ssh" if ":/" in uris[module]: # Absolute reference, easy to convert.. url = "gitsm://" + uris[module].replace(':/', '/', 1) else: # Relative reference, no way to know if this is right! logger.warning( "Submodule included by %s refers to relative ssh reference %s. References may fail if not absolute." % (ud.url, uris[module])) url = "gitsm://" + uris[module].replace(':', '/', 1) else: # This has to be a file reference proto = "file" url = "gitsm://" + uris[module] url += ';protocol=%s' % proto url += ";name=%s" % module url += ";subpath=%s" % module ld = d.createCopy() # Not necessary to set SRC_URI, since we're passing the URI to # Fetch. #ld.setVar('SRC_URI', url) ld.setVar('SRCREV_%s' % module, subrevision[module]) # Workaround for issues with SRCPV/SRCREV_FORMAT errors # error refer to 'multiple' repositories. Only the repository # in the original SRC_URI actually matters... ld.setVar('SRCPV', d.getVar('SRCPV')) ld.setVar('SRCREV_FORMAT', module) function(ud, url, module, paths[module], workdir, ld) return submodules != []
def process_submodules(self, ud, workdir, function, d): """ Iterate over all of the submodules in this repository and execute the 'function' for each of them. """ submodules = [] paths = {} revision = {} uris = {} subrevision = {} def parse_gitmodules(gitmodules): modules = {} module = "" for line in gitmodules.splitlines(): if line.startswith('[submodule'): module = line.split('"')[1] modules[module] = {} elif module and line.strip().startswith('path'): path = line.split('=')[1].strip() modules[module]['path'] = path elif module and line.strip().startswith('url'): url = line.split('=')[1].strip() modules[module]['url'] = url return modules # Collect the defined submodules, and their attributes for name in ud.names: try: gitmodules = runfetchcmd("%s show %s:.gitmodules" % (ud.basecmd, ud.revisions[name]), d, quiet=True, workdir=workdir) except: # No submodules to update continue for m, md in parse_gitmodules(gitmodules).items(): try: module_hash = runfetchcmd("%s ls-tree -z -d %s %s" % (ud.basecmd, ud.revisions[name], md['path']), d, quiet=True, workdir=workdir) except: # If the command fails, we don't have a valid file to check. If it doesn't # fail -- it still might be a failure, see next check... module_hash = "" if not module_hash: logger.debug(1, "submodule %s is defined, but is not initialized in the repository. Skipping", m) continue submodules.append(m) paths[m] = md['path'] revision[m] = ud.revisions[name] uris[m] = md['url'] subrevision[m] = module_hash.split()[2] # Convert relative to absolute uri based on parent uri if uris[m].startswith('..'): newud = copy.copy(ud) newud.path = os.path.realpath(os.path.join(newud.path, uris[m])) uris[m] = Git._get_repo_url(self, newud) for module in submodules: # Translate the module url into a SRC_URI if "://" in uris[module]: # Properly formated URL already proto = uris[module].split(':', 1)[0] url = uris[module].replace('%s:' % proto, 'gitsm:', 1) else: if ":" in uris[module]: # Most likely an SSH style reference proto = "ssh" if ":/" in uris[module]: # Absolute reference, easy to convert.. url = "gitsm://" + uris[module].replace(':/', '/', 1) else: # Relative reference, no way to know if this is right! logger.warning("Submodule included by %s refers to relative ssh reference %s. References may fail if not absolute." % (ud.url, uris[module])) url = "gitsm://" + uris[module].replace(':', '/', 1) else: # This has to be a file reference proto = "file" url = "gitsm://" + uris[module] url += ';protocol=%s' % proto url += ";name=%s" % module url += ";subpath=%s" % paths[module] ld = d.createCopy() # Not necessary to set SRC_URI, since we're passing the URI to # Fetch. #ld.setVar('SRC_URI', url) ld.setVar('SRCREV_%s' % module, subrevision[module]) # Workaround for issues with SRCPV/SRCREV_FORMAT errors # error refer to 'multiple' repositories. Only the repository # in the original SRC_URI actually matters... ld.setVar('SRCPV', d.getVar('SRCPV')) ld.setVar('SRCREV_FORMAT', module) function(ud, url, module, paths[module], ld) return submodules != []
def update_submodules(self, ud, d): submodules = [] paths = {} uris = {} local_paths = {} for name in ud.names: try: gitmodules = runfetchcmd("%s show %s:.gitmodules" % (ud.basecmd, ud.revisions[name]), d, quiet=True, workdir=ud.clonedir) except: # No submodules to update continue for m, md in self.parse_gitmodules(gitmodules).items(): submodules.append(m) paths[m] = md['path'] uris[m] = md['url'] if uris[m].startswith('..'): newud = copy.copy(ud) newud.path = os.path.realpath(os.path.join(newud.path, md['url'])) uris[m] = Git._get_repo_url(self, newud) for module in submodules: module_hash = runfetchcmd("%s ls-tree -z -d %s %s" % (ud.basecmd, ud.revisions[name], paths[module]), d, quiet=True, workdir=ud.clonedir) module_hash = module_hash.split()[2] # Build new SRC_URI proto = uris[module].split(':', 1)[0] url = uris[module].replace('%s:' % proto, 'gitsm:', 1) url += ';protocol=%s' % proto url += ";name=%s" % module url += ";bareclone=1;nocheckout=1;nobranch=1" ld = d.createCopy() # Not necessary to set SRC_URI, since we're passing the URI to # Fetch. #ld.setVar('SRC_URI', url) ld.setVar('SRCREV_%s' % module, module_hash) # Workaround for issues with SRCPV/SRCREV_FORMAT errors # error refer to 'multiple' repositories. Only the repository # in the original SRC_URI actually matters... ld.setVar('SRCPV', d.getVar('SRCPV')) ld.setVar('SRCREV_FORMAT', module) newfetch = Fetch([url], ld, cache=False) newfetch.download() local_paths[module] = newfetch.localpath(url) # Correct the submodule references to the local download version... runfetchcmd("%(basecmd)s config submodule.%(module)s.url %(url)s" % {'basecmd': ud.basecmd, 'module': module, 'url' : local_paths[module]}, d, workdir=ud.clonedir) symlink_path = os.path.join(ud.clonedir, 'modules', paths[module]) if not os.path.exists(symlink_path): try: os.makedirs(os.path.dirname(symlink_path), exist_ok=True) except OSError: pass os.symlink(local_paths[module], symlink_path) return True