diff options
author | Oliver Reiche <oliver.reiche@huawei.com> | 2022-12-14 15:48:58 +0100 |
---|---|---|
committer | Oliver Reiche <oliver.reiche@huawei.com> | 2022-12-14 15:48:58 +0100 |
commit | 86144c718100d4b424d95a187c3ed4b9ffb04e8d (patch) | |
tree | dbbb9dd54a3ee49f6a565026a910e514c0ac4359 /rules | |
parent | 886c7b680928276d7f925d30fc206ca27d9a97d1 (diff) | |
parent | b1859c1ba4229812497da501e2843ab20d27682b (diff) | |
download | rules-cc-86144c718100d4b424d95a187c3ed4b9ffb04e8d.tar.gz |
Merge commit 'b1859c1ba4229812497da501e2843ab20d27682b' into rules
Diffstat (limited to 'rules')
-rw-r--r-- | rules/CC/auto/RULES | 186 | ||||
-rw-r--r-- | rules/CC/test/RULES | 20 | ||||
-rw-r--r-- | rules/EXPRESSIONS | 6 | ||||
-rw-r--r-- | rules/data/RULES | 13 |
4 files changed, 212 insertions, 13 deletions
diff --git a/rules/CC/auto/RULES b/rules/CC/auto/RULES index 2429634..ea885cd 100644 --- a/rules/CC/auto/RULES +++ b/rules/CC/auto/RULES @@ -107,6 +107,20 @@ , "symbol to search for and the second value is a list with the header" , "file names to consider for searching." ] + , "size_ctype": + [ "Set a define to size of the specified C type. Must contain a list of" + , "pairs. The first element of each pair is the define name and the" + , "second argument is another pair. This pair's first value is the C" + , "type to check for and the second value is a list with possible sizes" + , "as numbers. If non of the specified sizes matches, the action fails." + ] + , "size_cxxtype": + [ "Set a define to size of the specified C++ type. Must contain a list of" + , "pairs. The first element of each pair is the define name and the" + , "second argument is another pair. This pair's first value is the C++" + , "type to check for and the second value is a list with possible sizes" + , "as numbers. If non of the specified sizes matches, the action fails." + ] } , "string_fields": ["name", "stage", "guard"] , "target_fields": ["hdrs", "deps"] @@ -127,6 +141,8 @@ , "have_cxxtype" , "have_csymbol" , "have_cxxsymbol" + , "size_ctype" + , "size_cxxtype" ] , "imports": { "first": "first_list_entry" @@ -335,6 +351,46 @@ } } ] + , [ "size_check.sh" + , { "type": "BLOB" + , "data": + { "type": "join" + , "separator": "\n" + , "$1": + [ "set -eu" + , "[ $# -ge 4 ]" + , "CC=$1" + , "shift" + , "LANG=$1" + , "shift" + , "DEF=$1" + , "shift" + , "TYPE=$1" + , "shift" + , "INC=\"\"" + , "for HDR in \"\" \"sys/types.h\" \"stdint.h\" \"stddef.h\"; do" + , " if [ -n \"$HDR\" ]; then INC=\"#include \\\"$HDR\\\"\"; fi" + , " for SIZE in \"$@\"; do" + , " SIZE=$(printf %.0f $SIZE)" + , " cat > test.$LANG << EOF" + , "$INC" + , "char __test[(sizeof($TYPE) == $SIZE) ? 1 : -1];" + , "EOF" + , " if $CC @$LANG.flags -c test.$LANG -I ./include 2>/dev/null; then" + , " DEFINE=\"#define $DEF $SIZE\"" + , " if [ -f in/${LANG}sizes.def ]; then" + , " cat in/${LANG}sizes.def > ${LANG}sizes.def" + , " fi" + , " echo \"$DEFINE\n\" >> ${LANG}sizes.def" + , " exit 0" + , " fi" + , " done" + , "done" + , "exit 1" + ] + } + } + ] , [ "guard.def" , { "type": "singleton_map" , "key": "guard.def" @@ -801,6 +857,132 @@ } } ] + , [ "csizes.def" + , { "type": "foldl" + , "range": {"type": "var", "name": "size_ctype", "default": []} + , "start": + { "type": "singleton_map" + , "key": "csizes.def" + , "value": {"type": "BLOB", "data": ""} + } + , "accum_var": "csizes.def" + , "var": "pair" + , "body": + { "type": "let*" + , "bindings": + [ ["list", {"type": "var", "name": "pair"}] + , [ "def" + , { "type": "assert_non_empty" + , "msg": "Define name in 'size_ctype' may not be empty" + , "$1": {"type": "CALL_EXPRESSION", "name": "first"} + } + ] + , ["list", {"type": "CALL_EXPRESSION", "name": "last"}] + , ["type", {"type": "CALL_EXPRESSION", "name": "first"}] + , ["sizes", {"type": "CALL_EXPRESSION", "name": "last"}] + ] + , "body": + { "type": "ACTION" + , "inputs": + { "type": "map_union" + , "$1": + [ { "type": "to_subdir" + , "subdir": "in" + , "$1": {"type": "var", "name": "csizes.def"} + } + , {"type": "env", "vars": ["size_check.sh", "c.flags"]} + , {"type": "var", "name": "includes"} + ] + } + , "cmd": + { "type": "++" + , "$1": + [ [ "sh" + , "./size_check.sh" + , {"type": "var", "name": "CC"} + , "c" + , {"type": "var", "name": "def"} + , {"type": "var", "name": "type"} + ] + , { "type": "foreach" + , "var": "size" + , "range": {"type": "var", "name": "sizes"} + , "body": + { "type": "json_encode" + , "$1": {"type": "var", "name": "size"} + } + } + ] + } + , "env": {"type": "var", "name": "ENV"} + , "outs": ["csizes.def"] + } + } + } + ] + , [ "cxxsizes.def" + , { "type": "foldl" + , "range": {"type": "var", "name": "size_cxxtype", "default": []} + , "start": + { "type": "singleton_map" + , "key": "cxxsizes.def" + , "value": {"type": "BLOB", "data": ""} + } + , "accum_var": "cxxsizes.def" + , "var": "pair" + , "body": + { "type": "let*" + , "bindings": + [ ["list", {"type": "var", "name": "pair"}] + , [ "def" + , { "type": "assert_non_empty" + , "msg": "Define name in 'size_cxxtype' may not be empty" + , "$1": {"type": "CALL_EXPRESSION", "name": "first"} + } + ] + , ["list", {"type": "CALL_EXPRESSION", "name": "last"}] + , ["type", {"type": "CALL_EXPRESSION", "name": "first"}] + , ["sizes", {"type": "CALL_EXPRESSION", "name": "last"}] + ] + , "body": + { "type": "ACTION" + , "inputs": + { "type": "map_union" + , "$1": + [ { "type": "to_subdir" + , "subdir": "in" + , "$1": {"type": "var", "name": "cxxsizes.def"} + } + , {"type": "env", "vars": ["size_check.sh", "cxx.flags"]} + , {"type": "var", "name": "includes"} + ] + } + , "cmd": + { "type": "++" + , "$1": + [ [ "sh" + , "./size_check.sh" + , {"type": "var", "name": "CXX"} + , "cxx" + , {"type": "var", "name": "def"} + , {"type": "var", "name": "type"} + ] + , { "type": "foreach" + , "var": "size" + , "range": {"type": "var", "name": "sizes"} + , "body": + { "type": "json_encode" + , "$1": {"type": "var", "name": "size"} + } + } + ] + } + , "env": {"type": "var", "name": "ENV"} + , "outs": ["cxxsizes.def"] + } + } + } + ] , [ "end.def" , { "type": "singleton_map" , "key": "end.def" @@ -825,6 +1007,8 @@ , {"type": "var", "name": "cxxtypes.def"} , {"type": "var", "name": "csymbols.def"} , {"type": "var", "name": "cxxsymbols.def"} + , {"type": "var", "name": "csizes.def"} + , {"type": "var", "name": "cxxsizes.def"} , {"type": "var", "name": "end.def"} ] } @@ -844,6 +1028,8 @@ , "cxxtypes.def" , "csymbols.def" , "cxxsymbols.def" + , "csizes.def" + , "cxxsizes.def" , "plain.def" , "end.def" , ">" diff --git a/rules/CC/test/RULES b/rules/CC/test/RULES index 4425fd6..3821339 100644 --- a/rules/CC/test/RULES +++ b/rules/CC/test/RULES @@ -96,7 +96,7 @@ ] , "imports": { "artifacts": ["./", "../..", "field_artifacts"] - , "runfiles_list": ["./", "../..", "field_runfiles_list"] + , "runfiles": ["./", "../..", "field_runfiles"] , "compile-deps": ["./", "..", "compile-deps"] , "compile-args-deps": ["./", "..", "compile-args-deps"] , "link-deps": ["./", "..", "link-deps"] @@ -242,15 +242,17 @@ } ] , [ "data" - , { "type": "disjoint_map_union" - , "msg": "Data runfiles may not conflict" - , "$1": - { "type": "let*" - , "bindings": - [ ["fieldname", "data"] - , ["transition", {"type": "var", "name": "deps-transition"}] + , { "type": "let*" + , "bindings": + [ ["fieldname", "data"] + , ["transition", {"type": "var", "name": "deps-transition"}] + ] + , "body": + { "type": "map_union" + , "$1": + [ {"type": "CALL_EXPRESSION", "name": "runfiles"} + , {"type": "CALL_EXPRESSION", "name": "artifacts"} ] - , "body": {"type": "CALL_EXPRESSION", "name": "runfiles_list"} } } ] diff --git a/rules/EXPRESSIONS b/rules/EXPRESSIONS index f40e5a3..b974026 100644 --- a/rules/EXPRESSIONS +++ b/rules/EXPRESSIONS @@ -27,7 +27,8 @@ , "imports": {"artifacts_list": "field_artifacts_list"} , "expression": { "type": "disjoint_map_union" - , "msg": "artifacts must not overlap" + , "msg": + ["artifacts", {"type": "var", "name": "fieldname"}, "must not overlap"] , "$1": {"type": "CALL_EXPRESSION", "name": "artifacts_list"} } } @@ -60,7 +61,8 @@ , "imports": {"runfiles_list": "field_runfiles_list"} , "expression": { "type": "disjoint_map_union" - , "msg": "runfiles must not overlap" + , "msg": + ["runfiles", {"type": "var", "name": "fieldname"}, "must not overlap"] , "$1": {"type": "CALL_EXPRESSION", "name": "runfiles_list"} } } diff --git a/rules/data/RULES b/rules/data/RULES index 99c8e5c..feb1a73 100644 --- a/rules/data/RULES +++ b/rules/data/RULES @@ -19,7 +19,10 @@ , "specied in the field \"deps\" (in their original location)." ] , "runfiles_doc": ["Same as artifacts"] - , "imports": {"runfiles": ["./", "..", "field_runfiles"]} + , "imports": + { "runfiles": ["./", "..", "field_runfiles"] + , "artifacts": ["./", "..", "field_artifacts"] + } , "expression": { "type": "let*" , "bindings": @@ -32,7 +35,13 @@ , [ "srcs" , { "type": "let*" , "bindings": [["fieldname", "srcs"]] - , "body": {"type": "CALL_EXPRESSION", "name": "runfiles"} + , "body": + { "type": "map_union" + , "$1": + [ {"type": "CALL_EXPRESSION", "name": "runfiles"} + , {"type": "CALL_EXPRESSION", "name": "artifacts"} + ] + } } ] , [ "staged" |