Skip to content

Commit 98c535a

Browse files
committed
test to guard against cache
1 parent cb3eba0 commit 98c535a

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

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: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
from tools.cmake.common import CMakeTestCase, TESTABLE_CMAKE_FILES
1010

11+
from . import _list_cmake_cache
12+
1113

1214
class TestPreset(CMakeTestCase):
1315

@@ -201,12 +203,11 @@ def test_define_overridable_option_set_override_after_with_cache(self):
201203
# Setting the value after should not affect the cache.
202204
self.assert_cmake_cache("EXECUTORCH_TEST_MESSAGE", "default value", "STRING")
203205

204-
def test_define_overridable_option_cli_override_with_set_override(self):
206+
def test_define_overridable_option_override_existing_cache_with_cli(self):
205207
_cmake_lists_txt = """
206208
cmake_minimum_required(VERSION 3.24)
207209
project(test_preset)
208210
include(${PROJECT_SOURCE_DIR}/preset.cmake)
209-
set(EXECUTORCH_TEST_MESSAGE "set value")
210211
add_subdirectory(example)
211212
"""
212213
_example_cmake_lists_txt = """
@@ -220,9 +221,14 @@ def test_define_overridable_option_cli_override_with_set_override(self):
220221
},
221222
}
222223
)
224+
self.run_cmake()
225+
self.assert_cmake_cache("EXECUTORCH_TEST_MESSAGE", "default value", "STRING")
226+
227+
# Since we cache the get operations, clear it so that it's read again for tests.
228+
_list_cmake_cache.cache_clear()
229+
223230
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")
231+
self.assert_cmake_cache("EXECUTORCH_TEST_MESSAGE", "cli value", "STRING")
226232

227233
def test_set_overridable_option_before(self):
228234
_cmake_lists_txt = """

0 commit comments

Comments
 (0)