public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Bjorge, Erik C" <erik.c.bjorge@intel.com>
To: devel@edk2.groups.io
Cc: Ashley E Desimone <ashley.e.desimone@intel.com>,
	Nate DeSimone <nathaniel.l.desimone@intel.com>,
	Puja Pandya <puja.pandya@intel.com>,
	Bret Barkelew <Bret.Barkelew@microsoft.com>,
	Prince Agyeman <prince.agyeman@intel.com>
Subject: [edk2-staging/EdkRepo] [PATCH v1] EdkRepo: Adding manifest support for submodule init
Date: Tue, 12 May 2020 11:04:00 -0700	[thread overview]
Message-ID: <643f03028f1dd1cfc8b51dcbb024b851b9414900.1589306304.git.erik.c.bjorge@intel.com> (raw)

Enabling support for selective submodule initialization in the manifest
file.  This will allow for more control over the submodules that are
initialized.  If this section is not present the existing functionality
will be used.

Signed-off-by: Erik Bjorge <erik.c.bjorge@intel.com>
Cc: Ashley E Desimone <ashley.e.desimone@intel.com>
Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
Cc: Puja Pandya <puja.pandya@intel.com>
Cc: Bret Barkelew <Bret.Barkelew@microsoft.com>
Cc: Prince Agyeman <prince.agyeman@intel.com>
---
 edkrepo_manifest_parser/edk_manifest.py | 78 +++++++++++++++++++++++++
 1 file changed, 78 insertions(+)

diff --git a/edkrepo_manifest_parser/edk_manifest.py b/edkrepo_manifest_parser/edk_manifest.py
index 1e2b111..45be2fe 100644
--- a/edkrepo_manifest_parser/edk_manifest.py
+++ b/edkrepo_manifest_parser/edk_manifest.py
@@ -37,6 +37,7 @@ FolderToFolderMappingFolder = namedtuple('FolderToFolderMappingFolder', ['projec
 FolderToFolderMappingFolderExclude = namedtuple('FolderToFolderMappingFolderExclude', ['path'])
 
 SubmoduleAlternateRemote = namedtuple('SubmoduleAlternateRemote', ['remote_name', 'original_url', 'alternate_url'])
+SubmoduleInitPath = namedtuple('SubmoduleInitPath', ['remote_name', 'combo', 'recursive', 'path'])
 
 REQUIRED_ATTRIB_ERROR_MSG = "Required attribute malformed in <{}>: {}"
 NO_ASSOCIATED_REMOTE = 'There are no remotes associated with the ClientGitHook entry:\nsource:{} destination:{}' \
@@ -138,6 +139,7 @@ class ManifestXml(BaseXmlHelper):
         self._commit_templates = {}           # dict of commit message templates with the remote name as the key
         self._folder_to_folder_mappings = []  # List of FolderToFolderMapping objects
         self._submodule_alternate_remotes = []
+        self._submodule_init_list = []
 
         #
         # Append include XML's to the Manifest etree before parsing
@@ -191,6 +193,13 @@ class ManifestXml(BaseXmlHelper):
             for element in subroot.iter(tag='SubmoduleAlternateRemote'):
                 self._submodule_alternate_remotes.append(_SubmoduleAlternateRemote(element, self._remotes))
 
+        #
+        # Determine submodule initialization paths
+        #
+        for subroot in self._tree.iter(tag='SelectiveSubmoduleInitList'):
+            for element in subroot.iter(tag='Submodule'):
+                self._submodule_init_list.append(_SubmoduleInitEntry(element))
+
         #
         # parse <CombinationList> tags
         # requires RemoteList to be parsed first
@@ -386,6 +395,22 @@ class ManifestXml(BaseXmlHelper):
                 alternates.append(alternate.tuple)
         return alternates
 
+    def get_submodule_init_paths(self, remote_name=None, combo=None):
+        submodule_list = []
+        if remote_name is None and combo is None:
+            submodule_list = self._tuple_list(self._submodule_init_list)
+        elif remote_name is not None and combo is None:
+            submodule_list = self._tuple_list(
+                [x for x in self._submodule_init_list if x.remote_name == remote_name])
+        elif remote_name is None and combo is not None:
+            submodule_list = self._tuple_list(
+                [x for x in self._submodule_init_list if x.combo == combo or x.combo is None])
+        else:
+            submodule_list = self._tuple_list(
+                [x for x in self._submodule_init_list
+                 if x.remote_name == remote_name and (x.combo == combo or x.combo is None)])
+        return submodule_list
+
     def write_current_combo(self, combo_name, filename=None):
         #
         # Updates the CurrentClonedCombo tag of _tree attribute and writes the entire tree out to the
@@ -460,6 +485,10 @@ class ManifestXml(BaseXmlHelper):
         if self._tree.find('SubmoduleAlternateRemotes'):
             submodule_alt_url_root = ET.SubElement(pin_root, 'SubmoduleAlternateRemotes')
 
+        selective_submodules_root = None
+        if self._tree.find('SelectiveSubmoduleInitList'):
+            selective_submodules_root = ET.SubElement(pin_root, 'SelectiveSubmoduleInitList')
+
         remote_root = ET.SubElement(pin_root, 'RemoteList')
         source_root = ET.SubElement(pin_root, 'Combination')
         source_root.attrib['name'] = self._combinations[combo_name].name
@@ -487,6 +516,13 @@ class ManifestXml(BaseXmlHelper):
                     if alt_url_element.attrib['remote'] == src_tuple.remote_name:
                         submodule_alt_url_root.append(alt_url_element)
 
+            for subroot_selective_subs in self._tree.iter('SelectiveSubmoduleInitList'):
+                for selective_sub in subroot_selective_subs.iter('Submodule'):
+                    if selective_sub.attrib['remote'] == src_tuple.remote_name:
+                        if 'combo' in selective_sub.attrib and selective_sub.attrib['combo'] != combo_name:
+                            continue
+                        selective_submodules_root.append(selective_sub)
+
             sparse = 'true' if src_tuple.sparse else 'false'
             sub = 'true' if src_tuple.enable_submodule else 'false'
             # Write the source element based on what value branch or commit is available.
@@ -535,6 +571,10 @@ class ManifestXml(BaseXmlHelper):
             submodule_alt_url_root.text = '\n    '
             submodule_alt_url_root.tail = '\n\n  '
             list(submodule_alt_url_root)[-1].tail = '\n  '
+        if selective_submodules_root:
+            selective_submodules_root.text = '\n    '
+            selective_submodules_root.tail = '\n\n  '
+            list(selective_submodules_root)[-1].tail = '\n  '
         remote_root.text = '\n    '
         remote_root.tail = '\n\n  '
         list(remote_root)[-1].tail = '\n  '
@@ -882,6 +922,27 @@ class _SubmoduleAlternateRemote():
         return SubmoduleAlternateRemote(self.remote_name, self.originalUrl, self.altUrl)
 
 
+class _SubmoduleInitEntry():
+    def __init__(self, element):
+        try:
+            self.remote_name = element.attrib['remote']
+            self.path = element.text
+        except KeyError as k:
+            raise KeyError(REQUIRED_ATTRIB_ERROR_MSG.format(k, element.tag))
+        try:
+            self.combo = element.attrib['combo']
+        except Exception:
+            self.combo = None
+        try:
+            self.recursive = element.attrib['recursive'].lower() == 'true'
+        except Exception:
+            self.recursive = False
+
+    @property
+    def tuple(self):
+        return SubmoduleInitPath(self.remote_name, self.combo, self.recursive, self.path)
+
+
 #
 # Optional entry point for debug and validation of the CiIndexXml & ManifestXml classes
 #
@@ -956,6 +1017,23 @@ def main():
                 for alt in alts:
                     print(alt)
 
+        print('\nGet Submodule Init Objects')
+        print('\nAll:')
+        for entry in test_manifest.get_submodule_init_paths():
+            print('+ {}'.format(entry))
+        print('\nPer Remote:')
+        for remote in test_manifest.remotes:
+            for entry in test_manifest.get_submodule_init_paths(remote.name):
+                print('+ {}'.format(entry))
+        print('\nCurrent Combo:')
+        current_combo = test_manifest.general_config.current_combo
+        for entry in test_manifest.get_submodule_init_paths(combo=current_combo):
+            print('+ {}'.format(entry))
+        print('\nCurrent Combo Per Remote:')
+        for remote in test_manifest.remotes:
+            for entry in test_manifest.get_submodule_init_paths(remote.name, current_combo):
+                print('+ {}'.format(entry))
+
         if not test_manifest.is_pin_file():
             print('\nSparse settings:')
             print(test_manifest.sparse_settings)
-- 
2.21.0.windows.1


             reply	other threads:[~2020-05-12 18:04 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-12 18:04 Bjorge, Erik C [this message]
2020-05-12 21:18 ` [edk2-staging/EdkRepo] [PATCH v1] EdkRepo: Adding manifest support for submodule init Ashley E Desimone
2020-05-12 21:36 ` Ashley E Desimone

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=643f03028f1dd1cfc8b51dcbb024b851b9414900.1589306304.git.erik.c.bjorge@intel.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox