Преглед на файлове

Updates to pull_and_build_from_git workflow (#131)

* Replace 'git stash' with 'git status' + 'git restore'
* Make --package-root optional and default to {base_path}/temp
* Add target platform alias option to support the same settings for another targeted platform to support additional naming of packages

Signed-off-by: Steve Pham <[email protected]>
Steve Pham преди 2 години
родител
ревизия
656849312e
променени са 1 файла, в които са добавени 39 реда и са изтрити 16 реда
  1. 39 16
      Scripts/extras/pull_and_build_from_git.py

+ 39 - 16
Scripts/extras/pull_and_build_from_git.py

@@ -510,27 +510,44 @@ class BuildInfo(object):
 
         # Sync to the source folder
         if self.src_folder.is_dir():
-            # If the folder exists, see if git stash works or not
-            git_pull_cmd = ['git',
-                            'stash']
-            call_result = subprocess.run(subp_args(git_pull_cmd),
+            print(f"Checking git status of path '{self.src_folder}' ...")
+            git_status_cmd = ['git', 'status', '-s']
+            call_result = subprocess.run(subp_args(git_status_cmd),
                                          shell=True,
                                          capture_output=True,
                                          cwd=str(self.src_folder.resolve()))
+            # If any error, this is not a valid git folder, proceed with cloning
             if call_result.returncode != 0:
+                print(f"Path '{self.src_folder}' is not a valid git folder. Deleting and re-cloning...")
                 # Not a valid git folder, okay to remove and re-clone
                 delete_folder(self.src_folder)
                 self.clone_to_local()
             else:
-                # Do a re-pull
-                git_pull_cmd = ['git',
-                                'pull']
-                call_result = subprocess.run(subp_args(git_pull_cmd),
-                                             shell=True,
-                                             capture_output=True,
-                                             cwd=str(self.src_folder.resolve()))
-                if call_result.returncode != 0:
-                    raise BuildError(f"Error pulling source from GitHub: {call_result.stderr.decode('UTF-8', 'ignore')}")
+                # If this is a valid git folder, check if the patch was applied or if the source was
+                # altered.
+                if len(call_result.stdout.decode('utf-8', 'ignore')):
+                    # If anything changed, then restore the entire source tree
+                    print(f"Path '{self.src_folder}' was modified. Restoring...")
+                    git_restore_cmd = ['git', 'restore', '--recurse-submodules', ':/']
+                    call_result = subprocess.run(subp_args(git_restore_cmd),
+                                                 shell=True,
+                                                 capture_output=False,
+                                                 cwd=str(self.src_folder.resolve()))
+                    if call_result.returncode != 0:
+                        # If we cannot restore through git, then delete the folder and re-clone
+                        print(f"Unable to restore {self.src_folder}. Deleting and re-cloning...")
+                        delete_folder(self.src_folder)
+                        self.clone_to_local()
+
+            # Do a re-pull
+            git_pull_cmd = ['git',
+                            'pull']
+            call_result = subprocess.run(subp_args(git_pull_cmd),
+                                         shell=True,
+                                         capture_output=True,
+                                         cwd=str(self.src_folder.resolve()))
+            if call_result.returncode != 0:
+                raise BuildError(f"Error pulling source from GitHub: {call_result.stderr.decode('UTF-8', 'ignore')}")
         else:
             self.clone_to_local()
 
@@ -1044,6 +1061,9 @@ def prepare_build(platform_name, base_folder, build_folder, package_root_folder,
     try:
         eligible_platforms = build_config["Platforms"][platform.system()]
         target_platform_config = eligible_platforms[platform_name]
+        # Check if the target platform is an alias to another platform from the current eligible_platforms
+        if isinstance(target_platform_config, str) and target_platform_config[0] == '@':
+            target_platform_config = eligible_platforms[target_platform_config[1:]]
     except KeyError as e:
         raise BuildError(f"Invalid build config : {str(e)}")
 
@@ -1118,8 +1138,8 @@ if __name__ == '__main__':
                             help='The platform to build the package for.',
                             required=True)
         parser.add_argument('--package-root',
-                            help="The root path where to install the built packages to.",
-                            required=True)
+                            help="The root path where to install the built packages to. This defaults to the {base_path}/temp. ",
+                            required=False)
         parser.add_argument('--cmake-path',
                             help='Path to where cmake is installed. Defaults to the system installed one.',
                             default='')
@@ -1140,13 +1160,16 @@ if __name__ == '__main__':
 
         parsed_args = parser.parse_args(sys.argv[1:])
 
+        # If package_root is not supplied, default to {base_path}/temp
+        resolved_package_root = parsed_args.package_root or f'{parsed_args.base_path}/temp'
+
         cmake_path = validate_cmake(f"{parsed_args.cmake_path}/cmake" if parsed_args.cmake_path else "cmake")
 
         # Prepare for the build
         build_info = prepare_build(platform_name=parsed_args.platform_name,
                                    base_folder=parsed_args.base_path,
                                    build_folder=parsed_args.build_path,
-                                   package_root_folder=parsed_args.package_root,
+                                   package_root_folder=resolved_package_root,
                                    cmake_command=cmake_path,
                                    build_config_file=parsed_args.build_config_file,
                                    clean=parsed_args.clean,