|
| 1 | +# Filename: Tools/CI/scripts/prepare_build_scripts.py |
| 2 | + |
| 3 | +import os |
| 4 | +import shutil |
| 5 | +import sys |
| 6 | + |
| 7 | +def main(): |
| 8 | + """ |
| 9 | + Cleans and prepares the 'Assets/Scripts/Editor' directory for build automation scripts. |
| 10 | + It deletes the directory if it exists, recreates it, and copies in the necessary |
| 11 | + assembly definition and C# script files. |
| 12 | + """ |
| 13 | + # --- 1. Argument Validation --- |
| 14 | + if len(sys.argv) < 2: |
| 15 | + print("Error: Missing required argument.") |
| 16 | + print("Usage: python prepare_build_scripts.py <path_to_project_root>") |
| 17 | + sys.exit(1) |
| 18 | + |
| 19 | + project_root = sys.argv[1] |
| 20 | + |
| 21 | + # --- 2. Define File Paths --- |
| 22 | + # The target directory inside the Unity project |
| 23 | + target_dir = os.path.join(project_root, 'Assets', 'Scripts', 'Editor') |
| 24 | + |
| 25 | + # The source files for build automation |
| 26 | + source_asmdef = 'Tools/CI/scripts/BuildAutomation/Unity.ProjectBuild.Editor.asmdef' |
| 27 | + source_script = 'Tools/CI/scripts/BuildAutomation/BuilderScripts.cs' |
| 28 | + |
| 29 | + print(f"Preparing build scripts for project at: {project_root}") |
| 30 | + print(f"Target editor script directory: {target_dir}") |
| 31 | + |
| 32 | + # --- 3. Clean and Recreate Directory --- |
| 33 | + try: |
| 34 | + if os.path.exists(target_dir): |
| 35 | + print(f"Directory '{target_dir}' exists. Removing it.") |
| 36 | + shutil.rmtree(target_dir) |
| 37 | + |
| 38 | + print(f"Creating directory: {target_dir}") |
| 39 | + os.makedirs(target_dir) |
| 40 | + |
| 41 | + except OSError as e: |
| 42 | + print(f"Error managing directory: {e}") |
| 43 | + sys.exit(1) |
| 44 | + |
| 45 | + # --- 4. Copy Build Automation Files --- |
| 46 | + try: |
| 47 | + print(f"Copying '{source_asmdef}' to '{target_dir}'") |
| 48 | + shutil.copy(source_asmdef, target_dir) |
| 49 | + |
| 50 | + print(f"Copying '{source_script}' to '{target_dir}'") |
| 51 | + shutil.copy(source_script, target_dir) |
| 52 | + |
| 53 | + except IOError as e: |
| 54 | + print(f"Error copying files: {e}") |
| 55 | + sys.exit(1) |
| 56 | + |
| 57 | + print("\nSuccessfully prepared build automation scripts.") |
| 58 | + |
| 59 | +if __name__ == "__main__": |
| 60 | + main() |
| 61 | + |
0 commit comments