From 7a25a17fae641fef241d3fecf80d6ea6cdd8fb5d Mon Sep 17 00:00:00 2001 From: phistere Date: Thu, 20 May 2021 09:13:01 -0500 Subject: [PATCH] Fixes a few issues when using an engine name different from the default --- .../Template/EngineFinder.cmake | 5 ++- cmake/install/engine.json.in | 2 +- scripts/o3de/o3de/engine_template.py | 43 +++++++++++++++++-- 3 files changed, 43 insertions(+), 7 deletions(-) diff --git a/Templates/DefaultProject/Template/EngineFinder.cmake b/Templates/DefaultProject/Template/EngineFinder.cmake index 7dfddf2c5f..a7dbf671fd 100644 --- a/Templates/DefaultProject/Template/EngineFinder.cmake +++ b/Templates/DefaultProject/Template/EngineFinder.cmake @@ -20,13 +20,14 @@ if(json_error) message(FATAL_ERROR "Unable to read key 'engine' from 'project.json', error: ${json_error}") endif() -# Read the list of paths from ~.o3de/o3de_manifest.json -if($ENV{USERPROFILE} AND EXISTS $ENV{USERPROFILE}) +if(DEFINED ENV{USERPROFILE} AND EXISTS $ENV{USERPROFILE}) set(manifest_path $ENV{USERPROFILE}/.o3de/o3de_manifest.json) # Windows else() set(manifest_path $ENV{HOME}/.o3de/o3de_manifest.json) # Unix endif() +# Read the ~/.o3de/o3de_manifest.json file and look through the 'engines_path' object. +# Find a key that matches LY_ENGINE_NAME_TO_USE and use that as the engine path. if(EXISTS ${manifest_path}) file(READ ${manifest_path} manifest_json) diff --git a/cmake/install/engine.json.in b/cmake/install/engine.json.in index 04ee6348d3..4a8579d864 100644 --- a/cmake/install/engine.json.in +++ b/cmake/install/engine.json.in @@ -1,6 +1,6 @@ { "engine_name": "@LY_VERSION_ENGINE_NAME@", - "restricted": "@LY_VERSION_ENGINE_NAME@", + "restricted": "o3de", "FileVersion": 1, "O3DEVersion": "@LY_VERSION_STRING@", "O3DECopyrightYear": @LY_VERSION_COPYRIGHT_YEAR@, diff --git a/scripts/o3de/o3de/engine_template.py b/scripts/o3de/o3de/engine_template.py index 23acab33d4..ad7ec55e1f 100755 --- a/scripts/o3de/o3de/engine_template.py +++ b/scripts/o3de/o3de/engine_template.py @@ -1652,10 +1652,45 @@ def create_project(project_path: str, d.write('# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n') d.write('# {END_LICENSE}\n') - # copy the o3de_manifest.cmake into the project root - engine_path = registration.get_this_engine_path() - o3de_manifest_cmake = f'{engine_path}/cmake/o3de_manifest.cmake' - shutil.copy(o3de_manifest_cmake, project_path) + # set the "engine" element of the project.json + engine_json = f'{registration.get_this_engine_path()}/engine.json' + if not registration.valid_o3de_engine_json(engine_json): + logger.error(f"Engine json {engine_json} is not valid.") + return 1 + + with open(engine_json) as s: + try: + engine_json_data = json.load(s) + except Exception as e: + logger.error(f"Failed to read engine json {engine_json}: {str(e)}") + return 1 + + try: + engine_name = engine_json_data['engine_name'] + except Exception as e: + logger.error(f"Engine json {engine_json} engine_name not found.") + return 1 + + project_json = f"{project_path}/project.json".replace('//', '/') + if not registration.valid_o3de_project_json(project_json): + logger.error(f'Project json {project_json} is not valid.') + return 1 + + with open(project_json, 'r') as s: + try: + project_json_data = json.load(s) + except Exception as e: + logger.error(f'Failed to load project json {project_json}.') + return 1 + + project_json_data.update({"engine": engine_name}) + os.unlink(project_json) + with open(project_json, 'w') as s: + try: + s.write(json.dumps(project_json_data, indent=4)) + except Exception as e: + logger.error(f'Failed to write project json {project_json}.') + return 1 return 0