[edk2-devel] [edk2-staging/EdkRepo] [PATCH] EdkRepo: Fix sync -u when the initial combo is not present in the new manifest

Ashley E Desimone posted 1 patch 4 years ago
Failed in applying to current master (apply log)
edkrepo/commands/sync_command.py | 37 ++++++++++++++++++++++++++++---------
edkrepo/common/humble.py         |  3 ++-
2 files changed, 30 insertions(+), 10 deletions(-)
[edk2-devel] [edk2-staging/EdkRepo] [PATCH] EdkRepo: Fix sync -u when the initial combo is not present in the new manifest
Posted by Ashley E Desimone 4 years ago
Allow the sync command to update the local manifest when the
combos in the initial manifest are no longer present if a
combo with compatible repo_sources is available. If this case
is encountered change the current checked out combo to be the
default combination from the new manifest file.

Signed-off-by: Ashley E Desimone <ashley.e.desimone@intel.com>
Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
Cc: Puja Pandya <puja.pandya@intel.com>
Cc: Erik Bjorge <erik.c.bjorge@intel.com>
Cc: Bret Barkelew <Bret.Barkelew@microsoft.com>
Cc: Prince Agyeman <prince.agyeman@intel.com>
---
 edkrepo/commands/sync_command.py | 37 ++++++++++++++++++++++++++++---------
 edkrepo/common/humble.py         |  3 ++-
 2 files changed, 30 insertions(+), 10 deletions(-)

diff --git a/edkrepo/commands/sync_command.py b/edkrepo/commands/sync_command.py
index eac8727..af83cd2 100644
--- a/edkrepo/commands/sync_command.py
+++ b/edkrepo/commands/sync_command.py
@@ -29,7 +29,7 @@ from edkrepo.common.humble import SYNC_MANIFEST_DIFF_WARNING, SYNC_MANIFEST_UPDA
 from edkrepo.common.humble import SPARSE_RESET, SPARSE_CHECKOUT, SYNC_REPO_CHANGE, SYNCING, FETCHING, UPDATING_MANIFEST
 from edkrepo.common.humble import NO_SYNC_DETACHED_HEAD, SYNC_COMMITS_ON_MASTER, SYNC_ERROR
 from edkrepo.common.humble import MIRROR_BEHIND_PRIMARY_REPO, SYNC_NEEDS_REBASE, INCLUDED_FILE_NAME
-from edkrepo.common.humble import SYNC_BRANCH_CHANGE_ON_LOCAL
+from edkrepo.common.humble import SYNC_BRANCH_CHANGE_ON_LOCAL, SYNC_INCOMPATIBLE_COMBO
 from edkrepo.common.humble import SYNC_REBASE_CALC_FAIL
 from edkrepo.common.pathfix import get_actual_path
 from edkrepo.common.common_repo_functions import pull_latest_manifest_repo, clone_repos, sparse_checkout_enabled
@@ -104,8 +104,15 @@ class SyncCommand(EdkrepoCommand):
         if args.update_local_manifest: #NOTE: hyphens in arg name replaced with underscores due to argparse
             self.__update_local_manifest(args, config, initial_manifest, workspace_path)
         manifest = get_workspace_manifest()
+        if args.update_local_manifest:
+            try:
+                repo_sources_to_sync = manifest.get_repo_sources(current_combo)
+            except ValueError:
+                # The manifest file was updated and the initial combo is no longer present so use the default combo
+                current_combo = manifest.general_config.default_combo
+                repo_sources_to_sync = manifest.get_repo_sources(current_combo)
         manifest.write_current_combo(current_combo)
-        repo_sources_to_sync = manifest.get_repo_sources(current_combo)
+
         sync_error = False
         # Calculate the hooks which need to be updated, added or removed for the sync
         if args.update_local_manifest:
@@ -211,9 +218,26 @@ class SyncCommand(EdkrepoCommand):
         ci_index_xml_rel_path = os.path.normpath(ci_index_xml.get_project_xml(initial_manifest.project_info.codename))
         global_manifest_path = os.path.join(global_manifest_directory, ci_index_xml_rel_path)
         new_manifest_to_check = ManifestXml(global_manifest_path)
+
+        # Does the current combo exist in the new manifest? If not check to see if you can use the repo sources from
+        # the default combo
+        initial_combos = combinations_in_manifest(initial_manifest)
+        new_combos = combinations_in_manifest(new_manifest_to_check)
+        if (current_combo not in new_combos) or (set(new_combos) != set(initial_combos)):
+            if initial_manifest.get_repo_sources(current_combo) == new_manifest_to_check.get_repo_sources(new_manifest_to_check.general_config.default_combo):
+                new_sources_for_current_combo = new_manifest_to_check.get_repo_sources(new_manifest_to_check.general_config.default_combo)
+                new_sources = new_sources_for_current_combo
+            else:
+                # Since asymetric combinations are not supported error out with an IMCOMPATIBLE_COMBO warning
+                print(SYNC_COMBO_CHANGE.format(current_combo, initial_manifest.project_info.codename))
+                raise EdkrepoManifestChangedException(SYNC_INCOMPATIBLE_COMBO)
+        else:
+            new_sources_for_current_combo = new_manifest_to_check.get_repo_sources(current_combo)
+            new_sources = new_manifest_to_check.get_repo_sources(current_combo)
+
         remove_included_config(initial_manifest.remotes, initial_manifest.submodule_alternate_remotes, local_manifest_dir)
         write_included_config(new_manifest_to_check.remotes, new_manifest_to_check.submodule_alternate_remotes, local_manifest_dir)
-        new_sources_for_current_combo = new_manifest_to_check.get_repo_sources(current_combo)
+
         self.__check_submodule_config(workspace_path, new_manifest_to_check, new_sources_for_current_combo)
         new_manifest_remotes = {name:url for name, url in new_manifest_to_check.remotes}
         #check for changes to remote urls
@@ -221,12 +245,7 @@ class SyncCommand(EdkrepoCommand):
             if remote_name in new_manifest_remotes.keys():
                 if initial_manifest_remotes[remote_name] != new_manifest_remotes[remote_name]:
                     raise EdkrepoManifestChangedException(SYNC_URL_CHANGE.format(remote_name))
-        #check to see if the currently checked out combo exists in the new manifest.
-        new_combos = combinations_in_manifest(new_manifest_to_check)
-        if current_combo not in new_combos:
-            raise EdkrepoManifestChangedException(SYNC_COMBO_CHANGE.format(current_combo,
-                                                                           initial_manifest.project_info.codename))
-        new_sources = new_manifest_to_check.get_repo_sources(current_combo)
+
         # Check that the repo sources lists are the same. If they are not the same and the override flag is not set, throw an exception.
         if not args.override and set(initial_sources) != set(new_sources):
             raise EdkrepoManifestChangedException(SYNC_REPO_CHANGE.format(initial_manifest.project_info.codename))
diff --git a/edkrepo/common/humble.py b/edkrepo/common/humble.py
index 5326e88..64b9519 100644
--- a/edkrepo/common/humble.py
+++ b/edkrepo/common/humble.py
@@ -49,7 +49,7 @@ SYNC_COMMITS_ON_MASTER = 'Commits were found on {0} branch.\n  (use the "--overr
 SYNC_ERROR = '\nError: Some repositories were not updated.'
 SYNC_MANIFEST_NOT_FOUND = 'A manifest for project, {0}, was not found.\nTo complete this operation please rerun the command with the --override flag\n' + SYNC_EXIT
 SYNC_URL_CHANGE = 'The URL for the remote, {0} has changed.\n' + SYNC_EXIT
-SYNC_COMBO_CHANGE = 'The current checked out combination, {0}, does not exist in the latest manifest for project, {1}\n' + SYNC_EXIT
+SYNC_COMBO_CHANGE = 'The current checked out combination, {0}, does not exist in the latest manifest for project, {1}\n' 
 SYNC_REPO_CHANGE = 'The latest manifest for project, {0}, requires a change in currently cloned repositories.\nTo complete this operation please rerun the command with the --override flag\n' + SYNC_EXIT
 SYNC_SOURCE_MOVE_WARNING = '{}{}WARNING:{}{} {{}} being moved to {{}}'.format(Style.BRIGHT, Fore.RED, Style.RESET_ALL, Fore.RED)
 SYNC_REMOVE_WARNING = '{}{}WARNING:{}{} The following repos no longer exist in the new manifest and can no \nlonger be used for submitting code. Please manually delete the following \ndirectories after saving any work you have in them:'.format(Style.BRIGHT, Fore.RED, Style.RESET_ALL, Fore.RED)
@@ -58,6 +58,7 @@ SYNC_NEEDS_REBASE = BRANCH_BEHIND + '\n' + '  (use "git rebase {target_remote}/{
 SYNC_UPDATE_FIX = 'To checkout the new SHA/tag/branch run edkrepo checkout on the current combo.\n'
 SYNC_BRANCH_CHANGE_ON_LOCAL = 'The SHA, tag or branch defined in the current combo has changed from {} to {} for the {} repo.\n The current workspace is not on the SHA/tag/branch defined in the initial combo. Unable to checkout new SHA/tag/branch.\n' + SYNC_UPDATE_FIX
 SYNC_REBASE_CALC_FAIL = 'Unable to calculate if a rebase is required for the current branch'
+SYNC_INCOMPATIBLE_COMBO = 'No compatible combinations found in the latest manifest file. Cloning a new workspace is recommended. ' + SYNC_EXIT
 
 #informational messages for sync_command.py
 SYNCING = 'Syncing {0} to latest {1} branch ...'
-- 
2.16.2.windows.1


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#57140): https://edk2.groups.io/g/devel/message/57140
Mute This Topic: https://groups.io/mt/72904946/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-

Re: [edk2-devel] [edk2-staging/EdkRepo] [PATCH] EdkRepo: Fix sync -u when the initial combo is not present in the new manifest
Posted by Nate DeSimone 4 years ago
Reviewed-by: Nate DeSimone <nathaniel.l.desimone@intel.com>

-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Ashley E Desimone
Sent: Thursday, April 9, 2020 12:19 PM
To: devel@edk2.groups.io
Cc: Desimone, Nathaniel L <nathaniel.l.desimone@intel.com>; Pandya, Puja <puja.pandya@intel.com>; Bjorge, Erik C <erik.c.bjorge@intel.com>; Bret Barkelew <Bret.Barkelew@microsoft.com>; Agyeman, Prince <prince.agyeman@intel.com>
Subject: [edk2-devel] [edk2-staging/EdkRepo] [PATCH] EdkRepo: Fix sync -u when the initial combo is not present in the new manifest

Allow the sync command to update the local manifest when the combos in the initial manifest are no longer present if a combo with compatible repo_sources is available. If this case is encountered change the current checked out combo to be the default combination from the new manifest file.

Signed-off-by: Ashley E Desimone <ashley.e.desimone@intel.com>
Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
Cc: Puja Pandya <puja.pandya@intel.com>
Cc: Erik Bjorge <erik.c.bjorge@intel.com>
Cc: Bret Barkelew <Bret.Barkelew@microsoft.com>
Cc: Prince Agyeman <prince.agyeman@intel.com>
---
 edkrepo/commands/sync_command.py | 37 ++++++++++++++++++++++++++++---------
 edkrepo/common/humble.py         |  3 ++-
 2 files changed, 30 insertions(+), 10 deletions(-)

diff --git a/edkrepo/commands/sync_command.py b/edkrepo/commands/sync_command.py
index eac8727..af83cd2 100644
--- a/edkrepo/commands/sync_command.py
+++ b/edkrepo/commands/sync_command.py
@@ -29,7 +29,7 @@ from edkrepo.common.humble import SYNC_MANIFEST_DIFF_WARNING, SYNC_MANIFEST_UPDA  from edkrepo.common.humble import SPARSE_RESET, SPARSE_CHECKOUT, SYNC_REPO_CHANGE, SYNCING, FETCHING, UPDATING_MANIFEST  from edkrepo.common.humble import NO_SYNC_DETACHED_HEAD, SYNC_COMMITS_ON_MASTER, SYNC_ERROR  from edkrepo.common.humble import MIRROR_BEHIND_PRIMARY_REPO, SYNC_NEEDS_REBASE, INCLUDED_FILE_NAME -from edkrepo.common.humble import SYNC_BRANCH_CHANGE_ON_LOCAL
+from edkrepo.common.humble import SYNC_BRANCH_CHANGE_ON_LOCAL, 
+SYNC_INCOMPATIBLE_COMBO
 from edkrepo.common.humble import SYNC_REBASE_CALC_FAIL  from edkrepo.common.pathfix import get_actual_path  from edkrepo.common.common_repo_functions import pull_latest_manifest_repo, clone_repos, sparse_checkout_enabled @@ -104,8 +104,15 @@ class SyncCommand(EdkrepoCommand):
         if args.update_local_manifest: #NOTE: hyphens in arg name replaced with underscores due to argparse
             self.__update_local_manifest(args, config, initial_manifest, workspace_path)
         manifest = get_workspace_manifest()
+        if args.update_local_manifest:
+            try:
+                repo_sources_to_sync = manifest.get_repo_sources(current_combo)
+            except ValueError:
+                # The manifest file was updated and the initial combo is no longer present so use the default combo
+                current_combo = manifest.general_config.default_combo
+                repo_sources_to_sync = 
+ manifest.get_repo_sources(current_combo)
         manifest.write_current_combo(current_combo)
-        repo_sources_to_sync = manifest.get_repo_sources(current_combo)
+
         sync_error = False
         # Calculate the hooks which need to be updated, added or removed for the sync
         if args.update_local_manifest:
@@ -211,9 +218,26 @@ class SyncCommand(EdkrepoCommand):
         ci_index_xml_rel_path = os.path.normpath(ci_index_xml.get_project_xml(initial_manifest.project_info.codename))
         global_manifest_path = os.path.join(global_manifest_directory, ci_index_xml_rel_path)
         new_manifest_to_check = ManifestXml(global_manifest_path)
+
+        # Does the current combo exist in the new manifest? If not check to see if you can use the repo sources from
+        # the default combo
+        initial_combos = combinations_in_manifest(initial_manifest)
+        new_combos = combinations_in_manifest(new_manifest_to_check)
+        if (current_combo not in new_combos) or (set(new_combos) != set(initial_combos)):
+            if initial_manifest.get_repo_sources(current_combo) == new_manifest_to_check.get_repo_sources(new_manifest_to_check.general_config.default_combo):
+                new_sources_for_current_combo = new_manifest_to_check.get_repo_sources(new_manifest_to_check.general_config.default_combo)
+                new_sources = new_sources_for_current_combo
+            else:
+                # Since asymetric combinations are not supported error out with an IMCOMPATIBLE_COMBO warning
+                print(SYNC_COMBO_CHANGE.format(current_combo, initial_manifest.project_info.codename))
+                raise EdkrepoManifestChangedException(SYNC_INCOMPATIBLE_COMBO)
+        else:
+            new_sources_for_current_combo = new_manifest_to_check.get_repo_sources(current_combo)
+            new_sources = 
+ new_manifest_to_check.get_repo_sources(current_combo)
+
         remove_included_config(initial_manifest.remotes, initial_manifest.submodule_alternate_remotes, local_manifest_dir)
         write_included_config(new_manifest_to_check.remotes, new_manifest_to_check.submodule_alternate_remotes, local_manifest_dir)
-        new_sources_for_current_combo = new_manifest_to_check.get_repo_sources(current_combo)
+
         self.__check_submodule_config(workspace_path, new_manifest_to_check, new_sources_for_current_combo)
         new_manifest_remotes = {name:url for name, url in new_manifest_to_check.remotes}
         #check for changes to remote urls @@ -221,12 +245,7 @@ class SyncCommand(EdkrepoCommand):
             if remote_name in new_manifest_remotes.keys():
                 if initial_manifest_remotes[remote_name] != new_manifest_remotes[remote_name]:
                     raise EdkrepoManifestChangedException(SYNC_URL_CHANGE.format(remote_name))
-        #check to see if the currently checked out combo exists in the new manifest.
-        new_combos = combinations_in_manifest(new_manifest_to_check)
-        if current_combo not in new_combos:
-            raise EdkrepoManifestChangedException(SYNC_COMBO_CHANGE.format(current_combo,
-                                                                           initial_manifest.project_info.codename))
-        new_sources = new_manifest_to_check.get_repo_sources(current_combo)
+
         # Check that the repo sources lists are the same. If they are not the same and the override flag is not set, throw an exception.
         if not args.override and set(initial_sources) != set(new_sources):
             raise EdkrepoManifestChangedException(SYNC_REPO_CHANGE.format(initial_manifest.project_info.codename))
diff --git a/edkrepo/common/humble.py b/edkrepo/common/humble.py index 5326e88..64b9519 100644
--- a/edkrepo/common/humble.py
+++ b/edkrepo/common/humble.py
@@ -49,7 +49,7 @@ SYNC_COMMITS_ON_MASTER = 'Commits were found on {0} branch.\n  (use the "--overr  SYNC_ERROR = '\nError: Some repositories were not updated.'
 SYNC_MANIFEST_NOT_FOUND = 'A manifest for project, {0}, was not found.\nTo complete this operation please rerun the command with the --override flag\n' + SYNC_EXIT  SYNC_URL_CHANGE = 'The URL for the remote, {0} has changed.\n' + SYNC_EXIT -SYNC_COMBO_CHANGE = 'The current checked out combination, {0}, does not exist in the latest manifest for project, {1}\n' + SYNC_EXIT
+SYNC_COMBO_CHANGE = 'The current checked out combination, {0}, does not exist in the latest manifest for project, {1}\n' 
 SYNC_REPO_CHANGE = 'The latest manifest for project, {0}, requires a change in currently cloned repositories.\nTo complete this operation please rerun the command with the --override flag\n' + SYNC_EXIT  SYNC_SOURCE_MOVE_WARNING = '{}{}WARNING:{}{} {{}} being moved to {{}}'.format(Style.BRIGHT, Fore.RED, Style.RESET_ALL, Fore.RED)  SYNC_REMOVE_WARNING = '{}{}WARNING:{}{} The following repos no longer exist in the new manifest and can no \nlonger be used for submitting code. Please manually delete the following \ndirectories after saving any work you have in them:'.format(Style.BRIGHT, Fore.RED, Style.RESET_ALL, Fore.RED) @@ -58,6 +58,7 @@ SYNC_NEEDS_REBASE = BRANCH_BEHIND + '\n' + '  (use "git rebase {target_remote}/{  SYNC_UPDATE_FIX = 'To checkout the new SHA/tag/branch run edkrepo checkout on the current combo.\n'
 SYNC_BRANCH_CHANGE_ON_LOCAL = 'The SHA, tag or branch defined in the current combo has changed from {} to {} for the {} repo.\n The current workspace is not on the SHA/tag/branch defined in the initial combo. Unable to checkout new SHA/tag/branch.\n' + SYNC_UPDATE_FIX  SYNC_REBASE_CALC_FAIL = 'Unable to calculate if a rebase is required for the current branch'
+SYNC_INCOMPATIBLE_COMBO = 'No compatible combinations found in the 
+latest manifest file. Cloning a new workspace is recommended. ' + 
+SYNC_EXIT
 
 #informational messages for sync_command.py  SYNCING = 'Syncing {0} to latest {1} branch ...'
--
2.16.2.windows.1





-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#57215): https://edk2.groups.io/g/devel/message/57215
Mute This Topic: https://groups.io/mt/72904946/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-