|
| 1 | +import os |
| 2 | +import re |
| 3 | +import subprocess |
| 4 | +import shutil |
| 5 | + |
| 6 | +DILIGENT_ENGINE_URL = 'https://github.com/DiligentGraphics/DiligentEngine.git' |
| 7 | +SOURCE_IMAGES = 'images' |
| 8 | +SOURCE_TEMPLATE = 'template' |
| 9 | +SOURCE_BUILD = 'DiligentEngine/build/Emscripten/DiligentSamples' |
| 10 | +DESTINATION_DIR = 'BuildArtifacts' |
| 11 | +BUILD_TARGETS = [ |
| 12 | + "Tutorial01_HelloTriangle", |
| 13 | + "Tutorial02_Cube", |
| 14 | + "Tutorial03_Texturing", |
| 15 | + "Tutorial04_Instancing", |
| 16 | + "Tutorial05_TextureArray", |
| 17 | + "Tutorial06_Multithreading", |
| 18 | + "Tutorial09_Quads", |
| 19 | + "Tutorial10_DataStreaming", |
| 20 | + "Tutorial11_ResourceUpdates", |
| 21 | + "Tutorial12_RenderTarget", |
| 22 | + "Tutorial13_ShadowMap", |
| 23 | + "Tutorial14_ComputeShader", |
| 24 | + "Tutorial16_BindlessResources", |
| 25 | + "Tutorial17_MSAA", |
| 26 | + "Tutorial18_Queries", |
| 27 | + "Tutorial19_RenderPasses", |
| 28 | + "Tutorial26_StateCache", |
| 29 | + "Tutorial27_PostProcessing", |
| 30 | + |
| 31 | + "Atmosphere", |
| 32 | + "ImguiDemo", |
| 33 | + "Shadows" |
| 34 | +] |
| 35 | + |
| 36 | +def extract_repoitory_name(repository_url): |
| 37 | + match = re.search(r'/([^/]+?)(\.git)?$', repository_url) |
| 38 | + if match: |
| 39 | + return match.group(1) |
| 40 | + else: |
| 41 | + raise ValueError(f"Invalid repository URL: {repository_url}") |
| 42 | + |
| 43 | +def clone_repository(repository_url): |
| 44 | + try: |
| 45 | + repo_name = extract_repoitory_name(repository_url) |
| 46 | + target_dir = f"./{repo_name}" |
| 47 | + if os.path.exists(target_dir): |
| 48 | + print(f"Repository already cloned in '{target_dir}'. Skipping clone.") |
| 49 | + else: |
| 50 | + command = ["git", "clone", "--recursive", "--depth", "1", repository_url] |
| 51 | + subprocess.run(command, check=True) |
| 52 | + except subprocess.CalledProcessError as e: |
| 53 | + print(f"An error occurred while cloning the repository: {e}") |
| 54 | + except Exception as e: |
| 55 | + print(f"An unexpected error occurred: {e}") |
| 56 | + |
| 57 | +def configure_project(): |
| 58 | + try: |
| 59 | + command = ["emcmake", "cmake", "-S", "./DiligentEngine", "-B", "./DiligentEngine/build/Emscripten", "-DCMAKE_BUILD_TYPE=Release"] |
| 60 | + subprocess.run(command, check=True) |
| 61 | + except subprocess.CalledProcessError as e: |
| 62 | + print(f"An error occurred while configuring the project: {e}") |
| 63 | + except Exception as e: |
| 64 | + print(f"An unexpected error occurred: {e}") |
| 65 | + |
| 66 | +def build_project(): |
| 67 | + try: |
| 68 | + command = ["cmake", "--build", "./DiligentEngine/build/Emscripten"] |
| 69 | + subprocess.run(command, check=True) |
| 70 | + except subprocess.CalledProcessError as e: |
| 71 | + print(f"An error occurred while building the project: {e}") |
| 72 | + except Exception as e: |
| 73 | + print(f"An unexpected error occurred: {e}") |
| 74 | + |
| 75 | +def upload_artefacts(): |
| 76 | + if not os.path.exists(DESTINATION_DIR): |
| 77 | + os.makedirs(DESTINATION_DIR) |
| 78 | + |
| 79 | + shutil.copytree(SOURCE_IMAGES, os.path.join(DESTINATION_DIR, 'images'), dirs_exist_ok=True) |
| 80 | + for item in os.listdir(SOURCE_TEMPLATE): |
| 81 | + source_item = os.path.join(SOURCE_TEMPLATE, item) |
| 82 | + destination_item = os.path.join(DESTINATION_DIR, item) # Corrected the destination path |
| 83 | + |
| 84 | + if os.path.isdir(source_item): |
| 85 | + shutil.copytree(source_item, destination_item, dirs_exist_ok=True) |
| 86 | + else: |
| 87 | + shutil.copy2(source_item, destination_item) |
| 88 | + |
| 89 | + for folder in BUILD_TARGETS: |
| 90 | + source_folder_path_tutorials = os.path.join(SOURCE_BUILD, "Tutorials", folder) |
| 91 | + source_folder_path_samples = os.path.join(SOURCE_BUILD, "Samples", folder) |
| 92 | + destination_folder_path = os.path.join(DESTINATION_DIR, "wasm-modules", folder) |
| 93 | + |
| 94 | + if os.path.exists(source_folder_path_tutorials): |
| 95 | + shutil.copytree(source_folder_path_tutorials, destination_folder_path, dirs_exist_ok=True) |
| 96 | + elif os.path.exists(source_folder_path_samples): |
| 97 | + shutil.copytree(source_folder_path_samples, destination_folder_path, dirs_exist_ok=True) |
| 98 | + else: |
| 99 | + print(f"Folder '{folder}' not found.") |
| 100 | + |
| 101 | +if __name__ == '__main__': |
| 102 | + clone_repository(DILIGENT_ENGINE_URL) |
| 103 | + configure_project() |
| 104 | + build_project() |
| 105 | + upload_artefacts() |
0 commit comments