|
| 1 | +import os |
| 2 | +import subprocess |
| 3 | +import shutil |
| 4 | + |
| 5 | +# Configuration |
| 6 | +SOLUTION_FILE = "iw3xe.sln" |
| 7 | +MSBUILD_PATH = r"C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe" |
| 8 | +BINARY_PATH = r"build\Release\bin\iw3xe.xex" |
| 9 | +STAGING_DIR = r"build\staging" |
| 10 | +RESOURCES_PATH = r"resources\xenia" |
| 11 | +GAME_TITLE_ID = "415607E6" |
| 12 | + |
| 13 | + |
| 14 | +def count_commits(): |
| 15 | + try: |
| 16 | + result = subprocess.run( |
| 17 | + ["git", "rev-list", "--count", "HEAD"], |
| 18 | + capture_output=True, |
| 19 | + text=True, |
| 20 | + check=True, |
| 21 | + ) |
| 22 | + |
| 23 | + # Get the commit count from the command output |
| 24 | + commit_count = result.stdout.strip() |
| 25 | + |
| 26 | + print(f"Total number of commits in the current branch: {commit_count}") |
| 27 | + return commit_count |
| 28 | + except Exception as e: |
| 29 | + print(f"An error occurred: {e}") |
| 30 | + exit(1) |
| 31 | + |
| 32 | + |
| 33 | +# Ensure MSBuild exists |
| 34 | +if not os.path.exists(MSBUILD_PATH): |
| 35 | + print(f"ERROR: MSBuild not found at {MSBUILD_PATH}") |
| 36 | + exit(1) |
| 37 | + |
| 38 | +VERSION_HEADER_PATH = r"src\version.h" |
| 39 | +BUILD_NUMBER = count_commits() |
| 40 | + |
| 41 | +print("Generating version.h with build metadata...") |
| 42 | +with open(VERSION_HEADER_PATH, "w") as version_file: |
| 43 | + version_file.write("// Auto-generated version header\n") |
| 44 | + version_file.write("#pragma once\n\n") |
| 45 | + version_file.write(f"#define BUILD_NUMBER {BUILD_NUMBER}\n") |
| 46 | + |
| 47 | +result = subprocess.run([MSBUILD_PATH, SOLUTION_FILE], stdout=subprocess.DEVNULL) |
| 48 | +if result.returncode != 0: |
| 49 | + print("ERROR: Build failed.") |
| 50 | + exit(result.returncode) |
| 51 | +else: |
| 52 | + print("Build succeeded.") |
| 53 | + |
| 54 | +print("Creating clean staging directory...") |
| 55 | +if os.path.exists(STAGING_DIR): |
| 56 | + shutil.rmtree(STAGING_DIR) |
| 57 | +os.makedirs(STAGING_DIR, exist_ok=True) |
| 58 | + |
| 59 | + |
| 60 | +if os.path.exists(RESOURCES_PATH): |
| 61 | + # Copy the entire xenia directory and its contents to the staging directory |
| 62 | + shutil.copytree(RESOURCES_PATH, os.path.join(STAGING_DIR, "xenia")) |
| 63 | + print("Resources copied successfully") |
| 64 | +else: |
| 65 | + print(f"Resources directory not found at {RESOURCES_PATH}") |
| 66 | + exit(1) |
| 67 | + |
| 68 | +print("Copying binary to staging directory...") |
| 69 | +shutil.copy2( |
| 70 | + BINARY_PATH, |
| 71 | + os.path.join(STAGING_DIR, "xenia", "plugins", GAME_TITLE_ID, "iw3xe.xex"), |
| 72 | +) |
| 73 | + |
| 74 | + |
| 75 | +print("Copying mods/codjumper to staging/raw directory...") |
| 76 | +MODS_PATH = r"mods\codjumper" |
| 77 | +RAW_DIR = os.path.join(STAGING_DIR, "raw") |
| 78 | +if os.path.exists(MODS_PATH): |
| 79 | + os.makedirs(RAW_DIR, exist_ok=True) |
| 80 | + shutil.copytree(MODS_PATH, RAW_DIR, dirs_exist_ok=True) |
| 81 | + print("Mods copied successfully to staging/raw") |
| 82 | +else: |
| 83 | + print(f"Mods directory not found at {MODS_PATH}") |
| 84 | + exit(1) |
| 85 | + |
| 86 | + |
| 87 | +PROJECT_NAME = "iw3xe" |
| 88 | +ZIP_FILE_NAME = f"{PROJECT_NAME}-{BUILD_NUMBER}.zip" |
| 89 | +STAGING_ZIP_PATH = os.path.join("build", ZIP_FILE_NAME) |
| 90 | + |
| 91 | +print("Zipping the staging folder...") |
| 92 | +shutil.make_archive( |
| 93 | + base_name=STAGING_ZIP_PATH.replace(".zip", ""), format="zip", root_dir=STAGING_DIR |
| 94 | +) |
| 95 | +print(f"Staging folder zipped successfully to {STAGING_ZIP_PATH}") |
0 commit comments