|
@@ -15,26 +15,36 @@ import os
|
|
|
import pathlib
|
|
|
import subprocess
|
|
|
import shutil
|
|
|
+import sys
|
|
|
import urllib.request
|
|
|
import zipfile
|
|
|
from typing import List
|
|
|
|
|
|
+# O3DE_PACKAGE_NAME is given in the format <PACKAGE_NAME>-<VERSION>-<PLATFORM>
|
|
|
+O3DE_PACKAGE_NAME = os.environ['O3DE_PACKAGE_NAME']
|
|
|
+O3DE_PACKAGE_NAME_PARTS = O3DE_PACKAGE_NAME.split('-')
|
|
|
PACKAGE_NAME: str = "AWSGameLiftServerSDK"
|
|
|
-PACKAGE_VERSION: str = "3.4.2-rev1"
|
|
|
PACKAGE_PLATFORM: str = ""
|
|
|
PACKAGE_URL: str = "https://aws.amazon.com/documentation/gamelift/"
|
|
|
PACKAGE_LICENSE: str = "Apache-2.0"
|
|
|
PACKAGE_LICENSE_FILE: str = "LICENSE_AMAZON_GAMELIFT_SDK.TXT"
|
|
|
|
|
|
-GAMELIFT_SERVER_SDK_RELEASE_VERSION: str = "4.0.2"
|
|
|
-GAMELIFT_SERVER_SDK_DOWNLOAD_URL: str = "https://gamelift-release.s3-us-west-2.amazonaws.com/GameLift_06_03_2021.zip"
|
|
|
+GAMELIFT_SERVER_SDK_RELEASE_VERSION: str = O3DE_PACKAGE_NAME_PARTS[1]
|
|
|
+GAMELIFT_SERVER_SDK_DOWNLOAD_URL: str = "https://gamelift-release.s3-us-west-2.amazonaws.com/GameLift-SDK-Release-5.0.0.zip"
|
|
|
|
|
|
PACKAGE_BASE_PATH: pathlib.Path = pathlib.Path(os.path.dirname(__file__))
|
|
|
PACKAGE_ROOT_PATH: pathlib.Path = PACKAGE_BASE_PATH.parent
|
|
|
+REPO_ROOT_PATH: pathlib.Path = PACKAGE_ROOT_PATH.parent
|
|
|
+GENERAL_SCRIPTS_PATH = REPO_ROOT_PATH / 'Scripts' / 'extras'
|
|
|
PACKAGE_BUILD_TYPES: List[str] = ["Debug", "Release"]
|
|
|
PACKAGE_LIB_TYPES: List[str] = ["Shared", "Static"]
|
|
|
PACKAGE_PLATFORM_OPTIONS: List[str] = ["windows", "linux", "linux-aarch64"]
|
|
|
|
|
|
+# Insert the 3p scripts path so we can use the package downloader to
|
|
|
+# download the openssl dependency
|
|
|
+sys.path.insert(1, str(GENERAL_SCRIPTS_PATH.resolve()))
|
|
|
+from package_downloader import PackageDownloader
|
|
|
+
|
|
|
# Lookup table for the Find{PACKAGE_NAME}.cmake.{platform} source file to copy in case there are shared files across different platforms
|
|
|
FIND_CMAKE_PLATFORM_SUFFIX_BY_PLATFORM = {
|
|
|
'Windows': 'Windows',
|
|
@@ -54,6 +64,25 @@ class WorkingDirectoryInfo(object):
|
|
|
self.build_path = build_path
|
|
|
self.output_path = output_path
|
|
|
self.libs_output_path = libs_output_path
|
|
|
+ self.dependencies_folder_path = (self.root_path / 'dependencies').resolve()
|
|
|
+
|
|
|
+# OpenSSL dependency: (packagename, hash)
|
|
|
+OPENSSL_PACKAGE = ('OpenSSL-1.1.1o-rev1-windows', '52b9d2bc5f3e0c6e405a0f290d1904bf545acc0c73d6a52351247d917c4a06d2')
|
|
|
+def get_dependencies(working_directory: WorkingDirectoryInfo) -> None:
|
|
|
+ # Only windows has an additional dependency on openssl that we need to download from our own packages
|
|
|
+ # The linux builds also rely on openssl, but they use the version on the system
|
|
|
+ if PACKAGE_PLATFORM != 'windows':
|
|
|
+ return
|
|
|
+
|
|
|
+ print("Downloading dependencies...")
|
|
|
+
|
|
|
+ package_name = OPENSSL_PACKAGE[0]
|
|
|
+ package_hash = OPENSSL_PACKAGE[1]
|
|
|
+ if not (working_directory.dependencies_folder_path / package_name).exists():
|
|
|
+ if not PackageDownloader.DownloadAndUnpackPackage(package_name, package_hash, str(working_directory.dependencies_folder_path)):
|
|
|
+ raise Exception("Failed to download OpenSSL dependency!")
|
|
|
+ else:
|
|
|
+ print(f'OpenSSL already in dependencies folder, skipping. Use --clean to refresh')
|
|
|
|
|
|
def subp_args(args) -> str:
|
|
|
arg_string = " ".join([arg for arg in args])
|
|
@@ -89,7 +118,7 @@ def prepare_working_directory() -> WorkingDirectoryInfo:
|
|
|
|
|
|
# source and build directory
|
|
|
source_directory: pathlib.Path = \
|
|
|
- root_directory.joinpath(f"GameLift-SDK-Release-{GAMELIFT_SERVER_SDK_RELEASE_VERSION}/GameLift-Cpp-ServerSDK-{PACKAGE_VERSION.split('-')[0]}")
|
|
|
+ root_directory.joinpath(f"GameLift-SDK-Release-{GAMELIFT_SERVER_SDK_RELEASE_VERSION}/GameLift-Cpp-ServerSDK-{GAMELIFT_SERVER_SDK_RELEASE_VERSION}")
|
|
|
build_directory: pathlib.Path = root_directory.joinpath("build")
|
|
|
build_directory.mkdir(parents=True)
|
|
|
|
|
@@ -112,36 +141,12 @@ def download_gamelift_server_sdk(working_directory: WorkingDirectoryInfo) -> Non
|
|
|
|
|
|
# unzip sdk contents
|
|
|
with zipfile.ZipFile(gamelift_sdk_zip_file, "r") as f:
|
|
|
- f.extractall(working_directory.root_path.resolve())
|
|
|
-
|
|
|
-# apply required patch file to support package build
|
|
|
-def apply_patch_on_sdk_source(working_directory: WorkingDirectoryInfo) -> None:
|
|
|
- patch_file: str = str(PACKAGE_BASE_PATH.joinpath(f"{PACKAGE_NAME}-{PACKAGE_VERSION.split('-')[0]}-{PACKAGE_PLATFORM}.patch").resolve())
|
|
|
- source_folder: str = str(working_directory.source_path.resolve())
|
|
|
- git_result = subprocess.run(subp_args(["git","init"]),
|
|
|
- shell=True,
|
|
|
- capture_output=True,
|
|
|
- cwd=source_folder)
|
|
|
- if git_result.returncode != 0:
|
|
|
- raise Exception(f"Error git init sdk source: {git_result.stderr.decode()}")
|
|
|
- git_result = subprocess.run(subp_args(["git","add","."]),
|
|
|
- shell=True,
|
|
|
- capture_output=True,
|
|
|
- cwd=source_folder)
|
|
|
- if git_result.returncode != 0:
|
|
|
- raise Exception(f"Error git add sdk source: {git_result.stderr.decode()}")
|
|
|
- git_result = subprocess.run(subp_args(["git","commit","-m","temp"]),
|
|
|
- shell=True,
|
|
|
- capture_output=True,
|
|
|
- cwd=source_folder)
|
|
|
- if git_result.returncode != 0:
|
|
|
- raise Exception(f"Error git commit sdk source: {git_result.stderr.decode()}")
|
|
|
- git_result = subprocess.run(subp_args(["git","apply", "--ignore-space-change", "--ignore-whitespace", f"{patch_file}"]),
|
|
|
- shell=True,
|
|
|
- capture_output=True,
|
|
|
- cwd=source_folder)
|
|
|
- if git_result.returncode != 0:
|
|
|
- raise Exception(f"Error git apply patch sdk source: {git_result.stderr.decode()}")
|
|
|
+ unzip_path = working_directory.root_path.resolve()
|
|
|
+ for file in f.namelist():
|
|
|
+ # Ignore the __MACOSX metadata file structure because unzipping
|
|
|
+ # it as well can exceed the max path on windows
|
|
|
+ if not file.startswith('__MACOSX'):
|
|
|
+ f.extract(file, unzip_path)
|
|
|
|
|
|
# get required custom environment for package build
|
|
|
def get_custom_build_env():
|
|
@@ -155,13 +160,14 @@ def get_custom_build_env():
|
|
|
return None
|
|
|
|
|
|
# configure gamelift server sdk project
|
|
|
-def configure_sdk_project(source_folder: str,
|
|
|
+def configure_sdk_project(working_directory: WorkingDirectoryInfo,
|
|
|
build_folder: str,
|
|
|
build_type: str,
|
|
|
lib_type: str) -> None:
|
|
|
+ source_folder: str = working_directory.source_path.resolve()
|
|
|
build_shared: str = "ON" if lib_type == "Shared" else "OFF"
|
|
|
if PACKAGE_PLATFORM == PACKAGE_PLATFORM_OPTIONS[0]:
|
|
|
- generator: str = "-G \"Visual Studio 15 2017\" -A x64"
|
|
|
+ generator: str = "-G \"Visual Studio 17\""
|
|
|
elif PACKAGE_PLATFORM in (PACKAGE_PLATFORM_OPTIONS[1], PACKAGE_PLATFORM_OPTIONS[2]):
|
|
|
generator: str = "-G \"Unix Makefiles\""
|
|
|
else:
|
|
@@ -171,6 +177,14 @@ def configure_sdk_project(source_folder: str,
|
|
|
f"-B {build_folder}",
|
|
|
f"-DBUILD_SHARED_LIBS={build_shared}",
|
|
|
f"-DCMAKE_BUILD_TYPE={build_type}"]
|
|
|
+
|
|
|
+ # On windows add our OpenSSL dependency to the DCMAKE_MODULE_PATH so the
|
|
|
+ # GameLift build can find it
|
|
|
+ if PACKAGE_PLATFORM == 'windows':
|
|
|
+ package_name = OPENSSL_PACKAGE[0]
|
|
|
+ openssl_dependency_path = (working_directory.dependencies_folder_path / package_name).resolve().as_posix()
|
|
|
+ configure_cmd.append(f"-DCMAKE_MODULE_PATH=\"{openssl_dependency_path}\"")
|
|
|
+
|
|
|
configure_result = subprocess.run(subp_args(configure_cmd),
|
|
|
shell=True,
|
|
|
capture_output=True,
|
|
@@ -245,7 +259,7 @@ def build_gamelift_server_sdk(working_directory: WorkingDirectoryInfo,
|
|
|
build_folder: pathlib.Path = working_directory.build_path.joinpath(f"{build_type}_{lib_type}").resolve()
|
|
|
|
|
|
print(f"Generating GameLift Server SDK project with {build_type} {lib_type} configuration...")
|
|
|
- configure_sdk_project(working_directory.source_path.resolve(), build_folder.resolve(), build_type, lib_type)
|
|
|
+ configure_sdk_project(working_directory, build_folder.resolve(), build_type, lib_type)
|
|
|
|
|
|
print(f"Building GameLift Server SDK project with {build_type} {lib_type} configuration...")
|
|
|
build_sdk_project(working_directory.source_path.resolve(), build_folder.resolve(), build_type)
|
|
@@ -256,7 +270,7 @@ def build_gamelift_server_sdk(working_directory: WorkingDirectoryInfo,
|
|
|
# generate required information for package, like name, url, and license
|
|
|
def generate_packageInfo(working_directory: WorkingDirectoryInfo) -> None:
|
|
|
settings={
|
|
|
- 'PackageName': f'{PACKAGE_NAME}-{PACKAGE_VERSION}-{PACKAGE_PLATFORM}',
|
|
|
+ 'PackageName': f'{O3DE_PACKAGE_NAME}',
|
|
|
"URL" : f'{PACKAGE_URL}',
|
|
|
"License" : f'{PACKAGE_LICENSE}',
|
|
|
'LicenseFile': f'{PACKAGE_NAME}/{PACKAGE_LICENSE_FILE}'
|
|
@@ -282,21 +296,21 @@ if __name__ == '__main__':
|
|
|
try:
|
|
|
print("Collecting package build info for GameLift Server SDK...")
|
|
|
collect_package_info()
|
|
|
-
|
|
|
+
|
|
|
print("Prepare working directory...")
|
|
|
working_directory: WorkingDirectoryInfo = prepare_working_directory()
|
|
|
-
|
|
|
+
|
|
|
print(f"Downloading GameLift Server SDK from {GAMELIFT_SERVER_SDK_DOWNLOAD_URL}...")
|
|
|
download_gamelift_server_sdk(working_directory)
|
|
|
-
|
|
|
- print("Initializing and applying patch to GameLift Server SDK source....")
|
|
|
- apply_patch_on_sdk_source(working_directory)
|
|
|
-
|
|
|
+
|
|
|
+ # Retrieve any dependencies (if needed)
|
|
|
+ get_dependencies(working_directory)
|
|
|
+
|
|
|
# build sdk with different configurations
|
|
|
for build_type in PACKAGE_BUILD_TYPES:
|
|
|
for lib_type in PACKAGE_LIB_TYPES:
|
|
|
build_gamelift_server_sdk(working_directory, build_type, lib_type)
|
|
|
-
|
|
|
+
|
|
|
print("Copying include and license files into output directory...")
|
|
|
shutil.copytree(working_directory.source_path.joinpath("gamelift-server-sdk/include").resolve(),
|
|
|
working_directory.libs_output_path.joinpath("include").resolve())
|
|
@@ -304,10 +318,10 @@ if __name__ == '__main__':
|
|
|
str(working_directory.libs_output_path.resolve()))
|
|
|
copy_file_to_destination(str(working_directory.source_path.joinpath("NOTICE_C++_AMAZON_GAMELIFT_SDK.TXT").resolve()),
|
|
|
str(working_directory.libs_output_path.resolve()))
|
|
|
-
|
|
|
+
|
|
|
print("Generating package info into output directory...")
|
|
|
generate_packageInfo(working_directory)
|
|
|
-
|
|
|
+
|
|
|
print("Generating cmake file into output directory...")
|
|
|
generate_cmake_file(working_directory)
|
|
|
exit(0)
|