Revert "cmake: support array of maps in yaml module"
This reverts commit f24f5288f3
.
as it's part of a series of commits causing issues on Windows
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
This commit is contained in:
parent
652e183037
commit
6fddb19463
3 changed files with 15 additions and 129 deletions
|
@ -4,7 +4,7 @@
|
|||
|
||||
# CMake YAML module for handling of YAML files.
|
||||
#
|
||||
# This module offers basic support for simple files.
|
||||
# This module offers basic support for simple yaml files.
|
||||
#
|
||||
# It supports basic key-value pairs, like
|
||||
# foo: bar
|
||||
|
@ -19,13 +19,6 @@
|
|||
# - foo2
|
||||
# - foo3
|
||||
#
|
||||
# Support for list of maps, like:
|
||||
# foo:
|
||||
# - bar: val1
|
||||
# baz: val1
|
||||
# - bar: val2
|
||||
# baz: val2
|
||||
#
|
||||
# All of above can be combined, for example like:
|
||||
# foo:
|
||||
# bar: baz
|
||||
|
@ -35,6 +28,14 @@
|
|||
# - beta
|
||||
# - gamma
|
||||
# fred: thud
|
||||
#
|
||||
# Support for list of objects are currently experimental and not guranteed to work.
|
||||
# For example:
|
||||
# foo:
|
||||
# - bar: val1
|
||||
# baz: val1
|
||||
# - bar: val2
|
||||
# baz: val2
|
||||
|
||||
include_guard(GLOBAL)
|
||||
|
||||
|
@ -242,7 +243,6 @@ endfunction()
|
|||
# Usage:
|
||||
# yaml_set(NAME <name> KEY <key>... VALUE <value>)
|
||||
# yaml_set(NAME <name> KEY <key>... [APPEND] LIST <value>...)
|
||||
# yaml_set(NAME <name> KEY <key>... [APPEND] LIST MAP <map1> MAP <map2> MAP ...)
|
||||
#
|
||||
# Set a value or a list of values to given key.
|
||||
#
|
||||
|
@ -254,9 +254,6 @@ endfunction()
|
|||
# VALUE <value>: New value for the key.
|
||||
# List <values>: New list of values for the key.
|
||||
# APPEND : Append the list of values to the list of values for the key.
|
||||
# MAP <map> : Map, with key-value pairs where key-value is separated by ':', and pairs separated by ',',
|
||||
# format: "<key1>: <value1>, <key2>: <value2>, ..."
|
||||
# MAP can be given multiple times to separate maps when adding them to a list.
|
||||
#
|
||||
function(yaml_set)
|
||||
cmake_parse_arguments(ARG_YAML "APPEND" "NAME;VALUE" "KEY;LIST" ${ARGN})
|
||||
|
@ -306,33 +303,13 @@ function(yaml_set)
|
|||
string(JSON subjson GET "${json_content}" ${ARG_YAML_KEY})
|
||||
string(JSON index LENGTH "${subjson}")
|
||||
list(LENGTH ARG_YAML_LIST length)
|
||||
math(EXPR stop "${index} + ${length} - 1")
|
||||
if(NOT length EQUAL 0)
|
||||
list(GET ARG_YAML_LIST 0 entry_0)
|
||||
if(entry_0 STREQUAL MAP)
|
||||
math(EXPR length "${length} / 2")
|
||||
math(EXPR stop "${index} + ${length} - 1")
|
||||
foreach(i RANGE ${index} ${stop})
|
||||
list(POP_FRONT ARG_YAML_LIST argument)
|
||||
if(NOT argument STREQUAL MAP)
|
||||
message(FATAL_ERROR "")
|
||||
message(FATAL_ERROR "${function}(${argument} ) is not valid at this position.\n"
|
||||
"Syntax is 'LIST MAP \"key1: value1.1, ...\" MAP \"key1: value1.2, ...\""
|
||||
)
|
||||
endif()
|
||||
list(POP_FRONT ARG_YAML_LIST map_value)
|
||||
string(REGEX REPLACE "[ ]*(:|,)[ ]*" "\"\\1\"" qouted_map_value "\"${map_value}\"")
|
||||
message("foo: ${map_value}")
|
||||
message("bar: ${qouted_map_value}")
|
||||
string(JSON json_content SET "${json_content}" ${ARG_YAML_KEY} ${i} "{${qouted_map_value}}")
|
||||
endforeach()
|
||||
else()
|
||||
math(EXPR stop "${index} + ${length} - 1")
|
||||
foreach(i RANGE ${index} ${stop})
|
||||
list(POP_FRONT ARG_YAML_LIST value)
|
||||
string(JSON json_content SET "${json_content}" ${ARG_YAML_KEY} ${i} "\"${value}\"")
|
||||
endforeach()
|
||||
endif()
|
||||
endif()
|
||||
else()
|
||||
string(JSON json_content SET "${json_content}" ${ARG_YAML_KEY} "\"${ARG_YAML_VALUE}\"")
|
||||
endif()
|
||||
|
@ -434,18 +411,7 @@ function(to_yaml json level yaml)
|
|||
math(EXPR arraystop "${arraylength} - 1")
|
||||
foreach(i RANGE 0 ${arraystop})
|
||||
string(JSON item GET "${json}" ${member} ${i})
|
||||
# Check the length of item. Only OBJECT and ARRAY may have length, so a length at this
|
||||
# level means `to_yaml()` should be called recursively.
|
||||
string(JSON length ERROR_VARIABLE ignore LENGTH "${item}")
|
||||
if(length)
|
||||
set(non_indent_yaml)
|
||||
to_yaml("${item}" 0 non_indent_yaml)
|
||||
string(REGEX REPLACE "\n$" "" non_indent_yaml "${non_indent_yaml}")
|
||||
string(REPLACE "\n" "\n${indent_${level}} " indent_yaml "${non_indent_yaml}")
|
||||
set(${yaml} "${${yaml}}${indent_${level}} - ${indent_yaml}\n")
|
||||
else()
|
||||
set(${yaml} "${${yaml}}${indent_${level}} - ${item}\n")
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
||||
else()
|
||||
|
|
|
@ -99,25 +99,6 @@ function(test_reading_int)
|
|||
)
|
||||
endfunction()
|
||||
|
||||
function(test_reading_map_list_entry)
|
||||
set(expected_length 2)
|
||||
set(expected_name "MapEntry1")
|
||||
set(expected_int 5)
|
||||
yaml_length(actual_length NAME yaml-test KEY cmake test map-list)
|
||||
yaml_get(actual_name NAME yaml-test KEY cmake test map-list 0 map-entry-name)
|
||||
yaml_get(actual_int NAME yaml-test KEY cmake test map-list 0 map-entry-int)
|
||||
|
||||
test_assert(TEST ${expected_length} EQUAL ${actual_length}
|
||||
COMMENT "yaml key value does not match expectation."
|
||||
)
|
||||
test_assert(TEST ${expected_name} STREQUAL ${actual_name}
|
||||
COMMENT "yaml key value does not match expectation."
|
||||
)
|
||||
test_assert(TEST ${expected_int} EQUAL ${actual_int}
|
||||
COMMENT "yaml key value does not match expectation."
|
||||
)
|
||||
endfunction()
|
||||
|
||||
function(test_reading_not_found)
|
||||
set(expected cmake-missing-NOTFOUND)
|
||||
yaml_get(actual NAME yaml-test KEY cmake missing test key)
|
||||
|
@ -145,15 +126,6 @@ function(test_reading_not_array)
|
|||
)
|
||||
endfunction()
|
||||
|
||||
function(test_reading_not_found_map_list_entry)
|
||||
set(expected cmake-test-map-list-3-NOTFOUND)
|
||||
yaml_get(actual NAME yaml-test KEY cmake test map-list 3 map-entry-name)
|
||||
|
||||
test_assert(TEST ${expected} STREQUAL ${actual}
|
||||
COMMENT "Expected -NOTFOUND, but something was found."
|
||||
)
|
||||
endfunction()
|
||||
|
||||
function(test_save_new_file)
|
||||
yaml_save(NAME yaml-test FILE ${CMAKE_BINARY_DIR}/${CMAKE_CURRENT_FUNCTION}_test_save.yaml)
|
||||
|
||||
|
@ -288,50 +260,6 @@ function(test_setting_list_int)
|
|||
endforeach()
|
||||
endfunction()
|
||||
|
||||
function(test_setting_map_list_entry)
|
||||
yaml_create(FILE ${CMAKE_BINARY_DIR}/${CMAKE_CURRENT_FUNCTION}_test_create.yaml
|
||||
NAME ${CMAKE_CURRENT_FUNCTION}_yaml-create
|
||||
)
|
||||
|
||||
set(new_entry_name_0 MapEntryNew1)
|
||||
set(new_entry_int_0 42)
|
||||
set(new_entry_name_1 MapEntryNew2)
|
||||
set(new_entry_int_1 24)
|
||||
set(new_entry_name_2 MapEntryNew3)
|
||||
set(new_entry_int_2 4224)
|
||||
yaml_set(actual NAME ${CMAKE_CURRENT_FUNCTION}_yaml-create
|
||||
KEY cmake test set map-list LIST
|
||||
MAP "map-entry-name: ${new_entry_name_0}, map-entry-int: ${new_entry_int_0}"
|
||||
MAP "map-entry-name: ${new_entry_name_1}, map-entry-int: ${new_entry_int_1}"
|
||||
MAP "map-entry-name: ${new_entry_name_2}, map-entry-int: ${new_entry_int_2}"
|
||||
)
|
||||
|
||||
yaml_save(NAME ${CMAKE_CURRENT_FUNCTION}_yaml-create)
|
||||
|
||||
# Read-back the yaml and verify the values.
|
||||
yaml_load(FILE ${CMAKE_BINARY_DIR}/${CMAKE_CURRENT_FUNCTION}_test_create.yaml
|
||||
NAME ${CMAKE_CURRENT_FUNCTION}_readback
|
||||
)
|
||||
|
||||
yaml_length(readback NAME ${CMAKE_CURRENT_FUNCTION}_readback KEY cmake test set map-list)
|
||||
|
||||
test_assert(TEST 3 EQUAL ${readback}
|
||||
COMMENT "readback yaml list length does not match original."
|
||||
)
|
||||
|
||||
foreach(index 0 1 2)
|
||||
yaml_get(readback_name NAME ${CMAKE_CURRENT_FUNCTION}_readback KEY cmake test set map-list ${index} map-entry-name)
|
||||
yaml_get(readback_int NAME ${CMAKE_CURRENT_FUNCTION}_readback KEY cmake test set map-list ${index} map-entry-int)
|
||||
|
||||
test_assert(TEST "${readback_name}" STREQUAL "${new_entry_name_${index}}"
|
||||
COMMENT "list values mismatch."
|
||||
)
|
||||
test_assert(TEST "${readback_int}" EQUAL "${new_entry_int_${index}}"
|
||||
COMMENT "list values mismatch."
|
||||
)
|
||||
endforeach()
|
||||
endfunction()
|
||||
|
||||
function(test_setting_empty_value)
|
||||
yaml_create(FILE ${CMAKE_BINARY_DIR}/${CMAKE_CURRENT_FUNCTION}_test_create.yaml
|
||||
NAME ${CMAKE_CURRENT_FUNCTION}_yaml-create
|
||||
|
@ -456,11 +384,9 @@ test_reading_string()
|
|||
test_reading_int()
|
||||
test_reading_list_strings()
|
||||
test_reading_list_int()
|
||||
test_reading_map_list_entry()
|
||||
test_reading_not_found()
|
||||
test_reading_not_found_array()
|
||||
test_reading_not_array()
|
||||
test_reading_not_found_map_list_entry()
|
||||
|
||||
test_save_new_file()
|
||||
|
||||
|
@ -468,7 +394,6 @@ test_setting_int()
|
|||
test_setting_string()
|
||||
test_setting_list_strings()
|
||||
test_setting_list_int()
|
||||
test_setting_map_list_entry()
|
||||
|
||||
test_setting_empty_value()
|
||||
test_setting_empty_list()
|
||||
|
|
|
@ -11,8 +11,3 @@ cmake:
|
|||
- "list"
|
||||
- "of"
|
||||
- "strings"
|
||||
map-list:
|
||||
- map-entry-name: "MapEntry1"
|
||||
map-entry-int: 5
|
||||
- map-entry-name: "MapEntry2"
|
||||
map-entry-int: 4
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue