Skip to content
This repository was archived by the owner on Sep 3, 2024. It is now read-only.

Commit 38be2fa

Browse files
author
William McLendon
committed
TRILFRAME-120-A: Minor cleanup pass
1 parent db04d15 commit 38be2fa

File tree

4 files changed

+53
-12
lines changed

4 files changed

+53
-12
lines changed

SetProgramOptions.wpr

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,7 @@ proj.launch-config = {loc('../../coding/pyExampleLib/configparser/configparser-e
9090
'ustom',
9191
(u'',
9292
'launch-5Gyw4cvA0PytPLLy'))}
93-
proj.main-file = loc('examples/example-01.py')
93+
proj.main-file = loc('exec-example-SetProgramOptions.py')
9494
testing.auto-test-file-specs = (('regex',
95-
'setprogramoptions\\\\unittests\\\\test_.*'\
96-
'\\.py'),)
95+
'unittests\\\\test_.*\\.py'),)
9796
testing.test-framework = {None: ':internal pytest'}

src/setprogramoptions/SetProgramOptionsCMake.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,12 +222,13 @@ def _program_option_handler_opt_set_cmake_var_bash(self, params: list, value: st
222222
params = params[1 : 4]
223223
param_opts = self._helper_opt_set_cmake_var_parse_parameters(params)
224224

225-
# PARENT_SCOPE (i.e., type-1 non-cached operations) should not be
225+
# Type-1 (non-cached / PARENT_SCOPE / non-typed) entries should not be
226226
# written to the set of Bash parameters.
227227
if param_opts['VARIANT'] == 1:
228228
msg = f"bash generator - `{varname}={value}` skipped because"
229229
msg += f" it is a non-cached (type-1) operation."
230-
msg += f" To generate a bash arg for this consider adding FORCE or a TYPE."
230+
msg += f" To generate a bash arg for this consider adding FORCE or a TYPE"
231+
msg += f" and remove PARENT_SCOPE if it exists."
231232
self.exception_control_event("WARNING", ValueError, message=msg)
232233
return None
233234

@@ -246,7 +247,6 @@ def _program_option_handler_opt_set_cmake_var_bash(self, params: list, value: st
246247

247248
# If the type is provided then include the `:<typename>` argument.
248249
# Note: CMake defaults to STRING if not provided.
249-
#if param_opts['VARIANT'] == 2 and param_opts['TYPE'] is not None: # DEADCODE: this can't be false now
250250
params.append(":" + param_opts['TYPE'])
251251

252252
# Save variable to the cache of 'known'/'set' cmake variables
@@ -376,12 +376,15 @@ def _helper_opt_set_cmake_var_parse_parameters(self, params: list):
376376
"""
377377
default_cache_var_type = "STRING"
378378

379-
output = {'FORCE': False, 'PARENT_SCOPE': False, 'TYPE': None}
379+
output = {'FORCE': False, 'PARENT_SCOPE': False, 'TYPE': None, 'VARIANT': None}
380380

381381
for option in params[: 4]:
382382
if option == "FORCE":
383383
output['FORCE'] = True
384384
# If FORCE is found but we have no TYPE yet, set to the default.
385+
# TODO: Should we be setting the default to STRING here when FORCE
386+
# is provided with no explicit type? Future CMake versions might
387+
# someday change the default which would possibly break this?
385388
if output['TYPE'] is None:
386389
output['TYPE'] = default_cache_var_type
387390
elif option == "PARENT_SCOPE":
@@ -395,6 +398,7 @@ def _helper_opt_set_cmake_var_parse_parameters(self, params: list):
395398
if output['FORCE'] and output['PARENT_SCOPE']:
396399
msg = "ERROR: CMake does not allow `FORCE` and `PARENT_SCOPE` to both be used."
397400
self.exception_control_event("CATASTROPHIC", ValueError, message=msg)
401+
398402
# Case 2: PARENT_SCOPE and CACHE will cause a CMake warning
399403
# and the value will include the cache entries as a list:
400404
# `set(FOO "VAL" CACHE STRING "docstring" PARENT_SCOPE)`

src/setprogramoptions/unittests/files_ini/config_test_setprogramoptions.ini

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,23 @@ opt-set-cmake-var CMAKE_VAR_E FORCE BOOL : ON
6565
opt-set-cmake-var CMAKE_VAR_F BOOL PARENT_SCOPE : ON
6666
opt-set-cmake-var CMAKE_VAR_G PARENT_SCOPE BOOL : ON
6767

68+
6869
[TEST_CMAKE_CACHE_PARAM_TEST_02]
6970
# Validate what happens if there's a bad param.
7071
# Note: FORCE option will make this a CACHE var of type STRING
7172
opt-set-cmake-var CMAKE_VAR_A FORCE FOOBAR: ON
7273

7374

75+
# This section is to be used to ensure that PARENT_SCOPE
76+
# will force a type-1 (non-cache) var.
77+
# The entries with PARENT_SCOPE enabled should not appear
78+
# in generated BASH output.
79+
[TEST_CMAKE_PARENT_SCOPE_NOT_BASH]
80+
opt-set-cmake-var FOO_VAR_A PARENT_SCOPE : FOO_VAL A
81+
opt-set-cmake-var FOO_VAR_B STRING PARENT_SCOPE : FOO_VAL B
82+
83+
84+
7485
#
7586
# Sample Test Configurations
7687
#

src/setprogramoptions/unittests/test_SetProgramOptionsCMake.py

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -426,11 +426,10 @@ def test_SetProgramOptionsCMake_param_order_01(self):
426426

427427
print("-----[ TEST BEGIN ]----------------------------------------")
428428
option_list_bash_expect = [
429-
'-DCMAKE_VAR_A:STRING="ON"', #'-DCMAKE_VAR_B=ON',
429+
'-DCMAKE_VAR_A:STRING="ON"',
430430
'-DCMAKE_VAR_C:BOOL=ON',
431431
'-DCMAKE_VAR_D:BOOL=ON',
432-
'-DCMAKE_VAR_E:BOOL=ON', #'-DCMAKE_VAR_F=ON;CACHE;BOOL;',
433-
#'-DCMAKE_VAR_G=ON;CACHE;BOOL;'
432+
'-DCMAKE_VAR_E:BOOL=ON',
434433
]
435434

436435
option_list_bash_actual = parser.gen_option_list(section, generator="bash")
@@ -474,7 +473,36 @@ def test_SetProgramOptionsCMake_param_order_02(self):
474473
print("-----[ TEST END ]------------------------------------------")
475474

476475
print("OK")
477-
return
476+
return 0
477+
478+
def test_SetProgramOptionsCMake_bash_generator_ignores_PARENT_SCOPE(self):
479+
"""
480+
Verify that the bash generator will not add a ``-D`` entry for a
481+
``opt-set-cmake-var`` that has the ``PARENT_SCOPE`` flag since that
482+
will always force CMake to create a type-1 (non-cache) var assignment.
483+
"""
484+
parser = self._create_standard_parser()
485+
486+
section = "TEST_CMAKE_PARENT_SCOPE_NOT_BASH"
487+
print("Section : {}".format(section))
488+
489+
print("-----[ TEST BEGIN ]----------------------------------------")
490+
option_list_bash_expect = []
491+
option_list_bash_actual = parser.gen_option_list(section, generator="bash")
492+
self.assertListEqual(option_list_bash_expect, option_list_bash_actual)
493+
print("-----[ TEST END ]------------------------------------------")
494+
495+
print("-----[ TEST BEGIN ]----------------------------------------")
496+
option_list_cmake_fragment_expect = [
497+
'set(FOO_VAR_A "FOO_VAL A" PARENT_SCOPE)',
498+
'set(FOO_VAR_B "FOO_VAL B" CACHE STRING "from .ini configuration" PARENT_SCOPE)'
499+
]
500+
option_list_cmake_fragment_actual = parser.gen_option_list(section, generator="cmake_fragment")
501+
self.assertListEqual(option_list_cmake_fragment_expect, option_list_cmake_fragment_actual)
502+
print("-----[ TEST END ]------------------------------------------")
503+
504+
print("OK")
505+
return 0
478506

479507
def test_SetProgramOptionsCMake_fail_on_FORCE_and_PARENT_SCOPE(self):
480508
"""
@@ -646,4 +674,3 @@ def _execute_parser(self, parser, section):
646674

647675

648676

649-
# TEST_CMAKE_CACHE_PARAM_TEST_02

0 commit comments

Comments
 (0)