Skip to content

Commit 98823c6

Browse files
committed
test to guard against cache
1 parent cb3eba0 commit 98823c6

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

tools/cmake/common/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ class _CacheValue:
7474

7575

7676
# Get the key/value pair listed in a CMakeCache.txt file.
77-
@cache
7877
def _list_cmake_cache(cache_path: str) -> Dict[str, _CacheValue]:
7978
result = {}
8079
with open(cache_path, "r") as cache_file:

tools/cmake/common/preset.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ macro(define_overridable_option NAME DESCRIPTION VALUE_TYPE DEFAULT_VALUE)
7676
message(FATAL_ERROR "Invalid option (${NAME}) value type '${VALUE_TYPE}', must be either STRING or BOOL")
7777
endif()
7878

79-
if(DEFINED ${NAME})
79+
if(DEFINED ${NAME} AND NOT DEFINED CACHE{${NAME}})
8080
set(${NAME} ${${NAME}} CACHE ${VALUE_TYPE} ${DESCRIPTION} FORCE)
8181
else()
8282
set(${NAME} ${DEFAULT_VALUE} CACHE ${VALUE_TYPE} ${DESCRIPTION})

tools/cmake/common/preset_test.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,11 @@ def test_define_overridable_option_set_override_after_with_cache(self):
201201
# Setting the value after should not affect the cache.
202202
self.assert_cmake_cache("EXECUTORCH_TEST_MESSAGE", "default value", "STRING")
203203

204-
def test_define_overridable_option_cli_override_with_set_override(self):
204+
def test_define_overridable_option_override_existing_cache(self):
205205
_cmake_lists_txt = """
206206
cmake_minimum_required(VERSION 3.24)
207207
project(test_preset)
208208
include(${PROJECT_SOURCE_DIR}/preset.cmake)
209-
set(EXECUTORCH_TEST_MESSAGE "set value")
210209
add_subdirectory(example)
211210
"""
212211
_example_cmake_lists_txt = """
@@ -220,9 +219,11 @@ def test_define_overridable_option_cli_override_with_set_override(self):
220219
},
221220
}
222221
)
222+
self.run_cmake()
223+
self.assert_cmake_cache("EXECUTORCH_TEST_MESSAGE", "default value", "STRING")
224+
223225
self.run_cmake(cmake_args=["-DEXECUTORCH_TEST_MESSAGE='cli value'"])
224-
# If an option is set through cmake, it should NOT be overridable from the CLI.
225-
self.assert_cmake_cache("EXECUTORCH_TEST_MESSAGE", "set value", "STRING")
226+
self.assert_cmake_cache("EXECUTORCH_TEST_MESSAGE", "cli value", "STRING")
226227

227228
def test_set_overridable_option_before(self):
228229
_cmake_lists_txt = """

0 commit comments

Comments
 (0)