Updated the enable gem and disable gem API (#54)
* Updated the enable gem and disable gem API Renamed remove_gem_project.py -> disable_gem.py Renamed add_gem_project.py -> enable_gem.py Renamed the "add-gem-to-project" command -> "enable-gem" Renamed the "remove-gem-from-project" command -> "disable-gem" Fixed the parsing of the enabled gems from the enabled_gems.cmake file * Adding newline to the end of the CMakeLists.txtmain
parent
f9b2517ea3
commit
394ac7ab6a
@ -1,259 +0,0 @@
|
|||||||
#
|
|
||||||
# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
|
||||||
# its licensors.
|
|
||||||
#
|
|
||||||
# For complete copyright and license terms please see the LICENSE at the root of this
|
|
||||||
# distribution (the "License"). All use of this software is governed by the License,
|
|
||||||
# or, if provided, by the license below or the license accompanying this file. Do not
|
|
||||||
# remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
#
|
|
||||||
|
|
||||||
import os
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
from o3de import add_gem_project
|
|
||||||
|
|
||||||
TEST_WITHOUT_NO_GEM_CONTENT = """
|
|
||||||
# {BEGIN_LICENSE}
|
|
||||||
# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
|
||||||
# its licensors.
|
|
||||||
#
|
|
||||||
# For complete copyright and license terms please see the LICENSE at the root of this
|
|
||||||
# distribution (the "License"). All use of this software is governed by the License,
|
|
||||||
# or, if provided, by the license below or the license accompanying this file. Do not
|
|
||||||
# remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
# {END_LICENSE}
|
|
||||||
|
|
||||||
set(GEM_DEPENDENCIES
|
|
||||||
)
|
|
||||||
"""
|
|
||||||
|
|
||||||
TEST_WITHOUT_ONLY_GEM_CONTENT = """
|
|
||||||
# {BEGIN_LICENSE}
|
|
||||||
# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
|
||||||
# its licensors.
|
|
||||||
#
|
|
||||||
# For complete copyright and license terms please see the LICENSE at the root of this
|
|
||||||
# distribution (the "License"). All use of this software is governed by the License,
|
|
||||||
# or, if provided, by the license below or the license accompanying this file. Do not
|
|
||||||
# remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
# {END_LICENSE}
|
|
||||||
|
|
||||||
set(GEM_DEPENDENCIES
|
|
||||||
Gem::TestGem
|
|
||||||
)
|
|
||||||
"""
|
|
||||||
|
|
||||||
TEST_WITHOUT_ADDED_GEM_CONTENT = """
|
|
||||||
# {BEGIN_LICENSE}
|
|
||||||
# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
|
||||||
# its licensors.
|
|
||||||
#
|
|
||||||
# For complete copyright and license terms please see the LICENSE at the root of this
|
|
||||||
# distribution (the "License"). All use of this software is governed by the License,
|
|
||||||
# or, if provided, by the license below or the license accompanying this file. Do not
|
|
||||||
# remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
# {END_LICENSE}
|
|
||||||
|
|
||||||
set(GEM_DEPENDENCIES
|
|
||||||
Gem::ExistingGem
|
|
||||||
)
|
|
||||||
"""
|
|
||||||
|
|
||||||
TEST_WITH_ADDED_GEM_CONTENT = """
|
|
||||||
# {BEGIN_LICENSE}
|
|
||||||
# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
|
||||||
# its licensors.
|
|
||||||
#
|
|
||||||
# For complete copyright and license terms please see the LICENSE at the root of this
|
|
||||||
# distribution (the "License"). All use of this software is governed by the License,
|
|
||||||
# or, if provided, by the license below or the license accompanying this file. Do not
|
|
||||||
# remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
# {END_LICENSE}
|
|
||||||
|
|
||||||
set(GEM_DEPENDENCIES
|
|
||||||
Gem::TestGem
|
|
||||||
Gem::ExistingGem
|
|
||||||
)
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
|
||||||
"contents, gem, expected_result, runtime_present, expect_failure", [
|
|
||||||
pytest.param(TEST_WITHOUT_ADDED_GEM_CONTENT, "TestGem", TEST_WITH_ADDED_GEM_CONTENT, True, False),
|
|
||||||
pytest.param(TEST_WITHOUT_ADDED_GEM_CONTENT, "TestGem", TEST_WITH_ADDED_GEM_CONTENT, False, True),
|
|
||||||
pytest.param(TEST_WITHOUT_ADDED_GEM_CONTENT, "/TestGem", TEST_WITH_ADDED_GEM_CONTENT, True, True),
|
|
||||||
pytest.param(TEST_WITHOUT_NO_GEM_CONTENT, "TestGem", TEST_WITHOUT_ONLY_GEM_CONTENT, True, False),
|
|
||||||
]
|
|
||||||
)
|
|
||||||
def test_add_gem_dependency(tmpdir, contents, gem, expected_result, runtime_present, expect_failure):
|
|
||||||
dev_root = str(tmpdir.join('dev').realpath()).replace('\\', '/')
|
|
||||||
os.makedirs(dev_root, exist_ok=True)
|
|
||||||
|
|
||||||
dev_project_gem_code = f'{dev_root}/TestProject/Gem/Code'
|
|
||||||
os.makedirs(dev_project_gem_code, exist_ok=True)
|
|
||||||
|
|
||||||
runtime_dependencies_cmake_file = f'{dev_project_gem_code}/runtime_dependencies.cmake'
|
|
||||||
if runtime_present:
|
|
||||||
if os.path.isfile(runtime_dependencies_cmake_file):
|
|
||||||
os.unlink(runtime_dependencies_cmake_file)
|
|
||||||
with open(runtime_dependencies_cmake_file, 'a') as s:
|
|
||||||
s.write(contents)
|
|
||||||
|
|
||||||
result = add_gem_project.add_gem_dependency(runtime_dependencies_cmake_file, gem)
|
|
||||||
|
|
||||||
if expect_failure:
|
|
||||||
assert result != 0
|
|
||||||
else:
|
|
||||||
assert result == 0
|
|
||||||
with open(runtime_dependencies_cmake_file, 'r') as s:
|
|
||||||
s_data = s.read()
|
|
||||||
assert s_data == expected_result
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
|
||||||
"contents, gem, expected_result, runtime_present, expect_failure", [
|
|
||||||
pytest.param(TEST_WITH_ADDED_GEM_CONTENT, "TestGem", TEST_WITHOUT_ADDED_GEM_CONTENT, True, False),
|
|
||||||
pytest.param(TEST_WITH_ADDED_GEM_CONTENT, "TestGem", TEST_WITHOUT_ADDED_GEM_CONTENT, False, True),
|
|
||||||
pytest.param(TEST_WITHOUT_ADDED_GEM_CONTENT, "TestGem", TEST_WITHOUT_ADDED_GEM_CONTENT, True, True)
|
|
||||||
]
|
|
||||||
)
|
|
||||||
def test_remove_gem_dependency(tmpdir, contents, gem, expected_result, runtime_present, expect_failure):
|
|
||||||
dev_root = str(tmpdir.join('dev').realpath()).replace('\\', '/')
|
|
||||||
os.makedirs(dev_root, exist_ok=True)
|
|
||||||
|
|
||||||
dev_project_gem_code = f'{dev_root}/TestProject/Gem/Code'
|
|
||||||
os.makedirs(dev_project_gem_code, exist_ok=True)
|
|
||||||
|
|
||||||
runtime_dependencies_cmake_file = f'{dev_project_gem_code}/runtime_dependencies.cmake'
|
|
||||||
if runtime_present:
|
|
||||||
if os.path.isfile(runtime_dependencies_cmake_file):
|
|
||||||
os.unlink(runtime_dependencies_cmake_file)
|
|
||||||
with open(runtime_dependencies_cmake_file, 'a') as s:
|
|
||||||
s.write(contents)
|
|
||||||
|
|
||||||
result = add_remove_gem.remove_gem_dependency(runtime_dependencies_cmake_file, gem)
|
|
||||||
|
|
||||||
if expect_failure:
|
|
||||||
assert result != 0
|
|
||||||
else:
|
|
||||||
assert result == 0
|
|
||||||
with open(runtime_dependencies_cmake_file, 'r') as s:
|
|
||||||
s_data = s.read()
|
|
||||||
assert s_data == expected_result
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("add,"
|
|
||||||
" contents, gem, project, expected_result,"
|
|
||||||
" runtime_present, tool_present,"
|
|
||||||
" ask_for_runtime, ask_for_tool,"
|
|
||||||
" expect_failure", [
|
|
||||||
pytest.param(True,
|
|
||||||
TEST_WITHOUT_ADDED_GEM_CONTENT, "TestGem", "TestProject",
|
|
||||||
TEST_WITH_ADDED_GEM_CONTENT,
|
|
||||||
True, True,
|
|
||||||
True, True,
|
|
||||||
False),
|
|
||||||
pytest.param(True,
|
|
||||||
TEST_WITHOUT_ADDED_GEM_CONTENT, "TestGem", "TestProject",
|
|
||||||
TEST_WITH_ADDED_GEM_CONTENT,
|
|
||||||
True, False,
|
|
||||||
True, True,
|
|
||||||
True),
|
|
||||||
pytest.param(True,
|
|
||||||
TEST_WITHOUT_ADDED_GEM_CONTENT, "TestGem", "TestProject",
|
|
||||||
TEST_WITH_ADDED_GEM_CONTENT,
|
|
||||||
False, True,
|
|
||||||
True, True,
|
|
||||||
True),
|
|
||||||
pytest.param(True,
|
|
||||||
TEST_WITHOUT_ADDED_GEM_CONTENT, "TestGem", "TestProject",
|
|
||||||
TEST_WITH_ADDED_GEM_CONTENT,
|
|
||||||
False, False,
|
|
||||||
True, True,
|
|
||||||
True),
|
|
||||||
|
|
||||||
pytest.param(False,
|
|
||||||
TEST_WITH_ADDED_GEM_CONTENT, "TestGem", "TestProject",
|
|
||||||
TEST_WITHOUT_ADDED_GEM_CONTENT,
|
|
||||||
True, True,
|
|
||||||
True, True,
|
|
||||||
False),
|
|
||||||
pytest.param(False,
|
|
||||||
TEST_WITH_ADDED_GEM_CONTENT, "TestGem", "TestProject",
|
|
||||||
TEST_WITHOUT_ADDED_GEM_CONTENT,
|
|
||||||
True, False,
|
|
||||||
True, True,
|
|
||||||
True),
|
|
||||||
pytest.param(False,
|
|
||||||
TEST_WITH_ADDED_GEM_CONTENT, "TestGem", "TestProject",
|
|
||||||
TEST_WITHOUT_ADDED_GEM_CONTENT,
|
|
||||||
False, True,
|
|
||||||
True, True,
|
|
||||||
True),
|
|
||||||
pytest.param(False,
|
|
||||||
TEST_WITH_ADDED_GEM_CONTENT, "TestGem", "TestProject",
|
|
||||||
TEST_WITHOUT_ADDED_GEM_CONTENT,
|
|
||||||
False, False,
|
|
||||||
True, True,
|
|
||||||
True)
|
|
||||||
]
|
|
||||||
)
|
|
||||||
def test_add_remove_gem(tmpdir,
|
|
||||||
add,
|
|
||||||
contents, gem, project,
|
|
||||||
expected_result,
|
|
||||||
runtime_present, tool_present,
|
|
||||||
ask_for_runtime, ask_for_tool,
|
|
||||||
expect_failure):
|
|
||||||
dev_root = str(tmpdir.join('dev').realpath()).replace('\\', '/')
|
|
||||||
os.makedirs(dev_root, exist_ok=True)
|
|
||||||
|
|
||||||
dev_project_gem_code = f'{dev_root}/TestProject/Gem/Code'
|
|
||||||
os.makedirs(dev_project_gem_code, exist_ok=True)
|
|
||||||
|
|
||||||
runtime_dependencies_cmake_file = f'{dev_project_gem_code}/runtime_dependencies.cmake'
|
|
||||||
if runtime_present:
|
|
||||||
if os.path.isfile(runtime_dependencies_cmake_file):
|
|
||||||
os.unlink(runtime_dependencies_cmake_file)
|
|
||||||
with open(runtime_dependencies_cmake_file, 'a') as s:
|
|
||||||
s.write(contents)
|
|
||||||
|
|
||||||
tool_dependencies_cmake_file = f'{dev_project_gem_code}/tool_dependencies.cmake'
|
|
||||||
os.makedirs(dev_project_gem_code, exist_ok=True)
|
|
||||||
|
|
||||||
if tool_present:
|
|
||||||
if os.path.isfile(tool_dependencies_cmake_file):
|
|
||||||
os.unlink(tool_dependencies_cmake_file)
|
|
||||||
with open(tool_dependencies_cmake_file, 'w') as s:
|
|
||||||
s.write(contents)
|
|
||||||
|
|
||||||
project_folder = f'{dev_root}/TestProject'
|
|
||||||
os.makedirs(project_folder, exist_ok=True)
|
|
||||||
|
|
||||||
gems_folder = f'{dev_root}/Gems'
|
|
||||||
os.makedirs(gems_folder, exist_ok=True)
|
|
||||||
|
|
||||||
gem_folder = f'{gems_folder}/{gem}'
|
|
||||||
os.makedirs(gem_folder, exist_ok=True)
|
|
||||||
|
|
||||||
result = add_remove_gem.add_remove_gem(add, dev_root, gem, project, ask_for_runtime, ask_for_tool)
|
|
||||||
|
|
||||||
if expect_failure:
|
|
||||||
assert result != 0
|
|
||||||
else:
|
|
||||||
assert result == 0
|
|
||||||
if runtime_present:
|
|
||||||
with open(runtime_dependencies_cmake_file, 'r') as s:
|
|
||||||
s_data = s.read()
|
|
||||||
assert s_data == expected_result
|
|
||||||
if tool_present:
|
|
||||||
with open(tool_dependencies_cmake_file, 'r') as s:
|
|
||||||
s_data = s.read()
|
|
||||||
assert s_data == expected_result
|
|
||||||
|
|
||||||
@ -0,0 +1,69 @@
|
|||||||
|
#
|
||||||
|
# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
|
||||||
|
# its licensors.
|
||||||
|
#
|
||||||
|
# For complete copyright and license terms please see the LICENSE at the root of this
|
||||||
|
# distribution (the "License"). All use of this software is governed by the License,
|
||||||
|
# or, if provided, by the license below or the license accompanying this file. Do not
|
||||||
|
# remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
#
|
||||||
|
|
||||||
|
import io
|
||||||
|
import json
|
||||||
|
import logging
|
||||||
|
import pytest
|
||||||
|
import pathlib
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
from o3de import cmake
|
||||||
|
|
||||||
|
|
||||||
|
class TestGetEnabledGems:
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"enable_gems_cmake_data, expected_set", [
|
||||||
|
pytest.param("""
|
||||||
|
# Comment
|
||||||
|
set(ENABLED_GEMS foo bar baz)
|
||||||
|
""", set(['foo', 'bar', 'baz'])),
|
||||||
|
pytest.param("""
|
||||||
|
# Comment
|
||||||
|
set(ENABLED_GEMS
|
||||||
|
foo
|
||||||
|
bar
|
||||||
|
baz
|
||||||
|
)
|
||||||
|
""", set(['foo', 'bar', 'baz'])),
|
||||||
|
pytest.param("""
|
||||||
|
# Comment
|
||||||
|
set(ENABLED_GEMS
|
||||||
|
foo
|
||||||
|
bar
|
||||||
|
baz)
|
||||||
|
""", set(['foo', 'bar', 'baz'])),
|
||||||
|
pytest.param("""
|
||||||
|
# Comment
|
||||||
|
set(ENABLED_GEMS
|
||||||
|
foo bar
|
||||||
|
baz)
|
||||||
|
""", set(['foo', 'bar', 'baz'])),
|
||||||
|
pytest.param("""
|
||||||
|
# Comment
|
||||||
|
set(RANDOM_VARIABLE TestGame, TestProject Test Engine)
|
||||||
|
set(ENABLED_GEMS HelloWorld IceCream
|
||||||
|
foo
|
||||||
|
baz bar
|
||||||
|
baz baz baz baz baz morebaz lessbaz
|
||||||
|
)
|
||||||
|
Random Text
|
||||||
|
""", set(['HelloWorld', 'IceCream', 'foo', 'bar', 'baz', 'morebaz', 'lessbaz'])),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
def test_get_enabled_gems(self, enable_gems_cmake_data, expected_set):
|
||||||
|
enabled_gems_set = set()
|
||||||
|
with patch('pathlib.Path.resolve', return_value=pathlib.Path('enabled_gems.cmake')) as pathlib_is_resolve_mock,\
|
||||||
|
patch('pathlib.Path.is_file', return_value=True) as pathlib_is_file_mock,\
|
||||||
|
patch('pathlib.Path.open', return_value=io.StringIO(enable_gems_cmake_data)) as pathlib_open_mock:
|
||||||
|
enabled_gems_set = cmake.get_enabled_gems(pathlib.Path('enabled_gems.cmake'))
|
||||||
|
|
||||||
|
assert enabled_gems_set == expected_set
|
||||||
Loading…
Reference in New Issue