Lines Matching +full:key +full:- +full:string

1 # SPDX-License-Identifier: Apache-2.0
9 # It supports basic key-value pairs, like
12 # basic key-object pairs, like
18 # - foo1
19 # - foo2
20 # - foo3
27 # - alpha
28 # - beta
29 # - gamma
35 # - bar: val1
37 # - bar: val2
92 "${CMAKE_CURRENT_FUNCTION}(EXISTS NAME ${ARG_YAML_NAME} <result-var>)."
98 list(POP_FRONT ARG_YAML_UNPARSED_ARGUMENTS out-var)
99 set(${out-var} TRUE PARENT_SCOPE)
101 set(${out-var} ${ARG_YAML_NAME}-NOTFOUND PARENT_SCOPE)
151 execute_process(COMMAND ${PYTHON_EXECUTABLE} -c
168 # yaml_get(<out-var> NAME <name> KEY <key>...)
170 # Get the value of the given key and store the value in <out-var>.
171 # If key represents a list, then the list is returned.
173 # Behavior is undefined if key points to a complex object.
176 # KEY <key>... : Name of key.
177 # <out-var> : Name of output variable.
181 # - Anything will be returned, even json object strings.
182 cmake_parse_arguments(ARG_YAML "" "NAME" "KEY" ${ARGN})
184 zephyr_check_arguments_required_all(${CMAKE_CURRENT_FUNCTION} ARG_YAML NAME KEY)
190 # If key is not found, then type becomes '-NOTFOUND' and value handling is done below.
191 string(JSON type ERROR_VARIABLE error TYPE "${json_content}" ${ARG_YAML_KEY})
193 string(JSON subjson GET "${json_content}" ${ARG_YAML_KEY})
194 string(JSON arraylength LENGTH "${subjson}")
196 math(EXPR arraystop "${arraylength} - 1")
199 string(JSON item GET "${subjson}" ${i})
206 # Searching for a non-existing key should just result in the output value '-NOTFOUND'
207 string(JSON value ERROR_VARIABLE error GET "${json_content}" ${ARG_YAML_KEY})
213 # yaml_length(<out-var> NAME <name> KEY <key>...)
215 # Get the length of the array defined by the given key and store the length in <out-var>.
216 # If key does not define an array, then the length -1 is returned.
219 # KEY <key>... : Name of key defining the list.
220 # <out-var> : Name of output variable.
223 cmake_parse_arguments(ARG_YAML "" "NAME" "KEY" ${ARGN})
225 zephyr_check_arguments_required_all(${CMAKE_CURRENT_FUNCTION} ARG_YAML NAME KEY)
230 string(JSON type ERROR_VARIABLE error TYPE "${json_content}" ${ARG_YAML_KEY})
232 string(JSON subjson GET "${json_content}" ${ARG_YAML_KEY})
233 string(JSON arraylength LENGTH "${subjson}")
235 elseif(type MATCHES ".*-NOTFOUND")
238 message(WARNING "YAML key: ${ARG_YAML_KEY} is not an array.")
239 set(${out_var} -1 PARENT_SCOPE)
244 # yaml_set(NAME <name> KEY <key>... VALUE <value>)
245 # yaml_set(NAME <name> KEY <key>... [APPEND] LIST <value>...)
247 # Set a value or a list of values to given key.
250 # list of values should be appended to the existing list identified with key(s).
253 # KEY <key>... : Name of key.
254 # VALUE <value>: New value for the key.
255 # List <values>: New list of values for the key.
256 # APPEND : Append the list of values to the list of values for the key.
259 cmake_parse_arguments(ARG_YAML "APPEND" "NAME;VALUE" "KEY;LIST" ${ARGN})
261 zephyr_check_arguments_required_all(${CMAKE_CURRENT_FUNCTION} ARG_YAML NAME KEY)
271 # We ignore any errors as we are checking for existence of the key, and
272 # non-existing keys will throw errors but also set type to NOT-FOUND.
273 string(JSON type ERROR_VARIABLE ignore TYPE "${json_content}" ${valid_keys} ${k})
293 string(JSON json_content SET "${json_content}"
300 string(JSON json_content SET "${json_content}" ${ARG_YAML_KEY} "[]")
303 string(JSON subjson GET "${json_content}" ${ARG_YAML_KEY})
304 string(JSON index LENGTH "${subjson}")
306 math(EXPR stop "${index} + ${length} - 1")
310 string(JSON json_content SET "${json_content}" ${ARG_YAML_KEY} ${i} "\"${value}\"")
314 string(JSON json_content SET "${json_content}" ${ARG_YAML_KEY} "\"${ARG_YAML_VALUE}\"")
321 # yaml_remove(NAME <name> KEY <key>...)
323 # Remove the KEY <key>... from the YAML context <name>.
326 # KEY build cmake command
328 # To remove the key 'command' underneath 'cmake' in the toplevel 'build'
331 # KEY <key> : Name of key to remove.
334 cmake_parse_arguments(ARG_YAML "" "NAME" "KEY" ${ARGN})
336 zephyr_check_arguments_required_all(${CMAKE_CURRENT_FUNCTION} ARG_YAML NAME KEY)
340 string(JSON json_content REMOVE "${json_content}" ${ARG_YAML_KEY})
384 math(EXPR level_dec "${level} - 1")
388 string(JSON length LENGTH "${json}")
394 math(EXPR stop "${length} - 1")
396 string(JSON member MEMBER "${json}" ${i})
398 string(JSON type TYPE "${json}" ${member})
399 string(JSON subjson GET "${json}" ${member})
406 string(JSON arraylength LENGTH "${subjson}")
411 math(EXPR arraystop "${arraylength} - 1")
413 string(JSON item GET "${json}" ${member} ${i})
414 set(${yaml} "${${yaml}}${indent_${level}} - ${item}\n")