From 86c4f55b6f578bfae74ab35151c1e4425b7e1fd1 Mon Sep 17 00:00:00 2001 From: Klaus Aehlig Date: Tue, 22 Feb 2022 17:03:21 +0100 Subject: Initial self-hosting commit This is the initial version of our tool that is able to build itself. In can be bootstrapped by ./bin/bootstrap.py Co-authored-by: Oliver Reiche Co-authored-by: Victor Moreno --- CC/EXPRESSIONS | 504 +++++++++++++++++++++++++++++++++++++++++++++ CC/RULES | 538 ++++++++++++++++++++++++++++++++++++++++++++++++ CC/proto/EXPRESSIONS | 301 +++++++++++++++++++++++++++ CC/proto/RULES | 72 +++++++ CC/test/RULES | 265 ++++++++++++++++++++++++ CC/test/test_runner.sh | 36 ++++ EXPRESSIONS | 89 ++++++++ data/RULES | 42 ++++ proto/RULES | 105 ++++++++++ transitions/EXPRESSIONS | 13 ++ 10 files changed, 1965 insertions(+) create mode 100644 CC/EXPRESSIONS create mode 100644 CC/RULES create mode 100644 CC/proto/EXPRESSIONS create mode 100644 CC/proto/RULES create mode 100644 CC/test/RULES create mode 100644 CC/test/test_runner.sh create mode 100644 EXPRESSIONS create mode 100644 data/RULES create mode 100644 proto/RULES create mode 100644 transitions/EXPRESSIONS diff --git a/CC/EXPRESSIONS b/CC/EXPRESSIONS new file mode 100644 index 0000000..f1e6592 --- /dev/null +++ b/CC/EXPRESSIONS @@ -0,0 +1,504 @@ +{ "default-CC": + { "expression": + { "type": "join" + , "$1": + { "type": "++" + , "$1": + { "type": "foreach" + , "var": "x" + , "range": {"type": "FIELD", "name": "defaults"} + , "body": + { "type": "DEP_PROVIDES" + , "provider": "CC" + , "dep": {"type": "var", "name": "x"} + } + } + } + } + } +, "default-CXX": + { "expression": + { "type": "join" + , "$1": + { "type": "++" + , "$1": + { "type": "foreach" + , "var": "x" + , "range": {"type": "FIELD", "name": "defaults"} + , "body": + { "type": "DEP_PROVIDES" + , "provider": "CXX" + , "dep": {"type": "var", "name": "x"} + } + } + } + } + } +, "default-CFLAGS": + { "expression": + { "type": "++" + , "$1": + { "type": "foreach" + , "var": "x" + , "range": {"type": "FIELD", "name": "defaults"} + , "body": + { "type": "DEP_PROVIDES" + , "provider": "CFLAGS" + , "dep": {"type": "var", "name": "x"} + } + } + } + } +, "default-CXXFLAGS": + { "expression": + { "type": "++" + , "$1": + { "type": "foreach" + , "var": "x" + , "range": {"type": "FIELD", "name": "defaults"} + , "body": + { "type": "DEP_PROVIDES" + , "provider": "CXXFLAGS" + , "dep": {"type": "var", "name": "x"} + } + } + } + } +, "default-ENV": + { "expression": + { "type": "foreach" + , "var": "x" + , "range": {"type": "FIELD", "name": "defaults"} + , "body": + { "type": "DEP_PROVIDES" + , "provider": "ENV" + , "dep": {"type": "var", "name": "x"} + } + } + } +, "configure transition": + { "expression": + { "type": "let*" + , "bindings": + [ [ "OS" + , { "type": "assert_non_empty" + , "msg": "Missing field \"os\" for \"configure\"." + , "$1": {"type": "join", "$1": {"type": "FIELD", "name": "os"}} + } + ] + , [ "ARCH" + , { "type": "assert_non_empty" + , "msg": "Missing field \"arch\" for \"configure\"." + , "$1": {"type": "join", "$1": {"type": "FIELD", "name": "arch"}} + } + ] + , ["HOST_ARCH", {"type": "var", "name": "ARCH"}] + , [ "TARGET_ARCH" + , {"type": "join", "$1": {"type": "FIELD", "name": "target_arch"}} + ] + , [ "TARGET_ARCH" + , { "type": "if" + , "cond": {"type": "var", "name": "TARGET_ARCH"} + , "then": {"type": "var", "name": "TARGET_ARCH"} + , "else": {"type": "var", "name": "ARCH"} + } + ] + ] + , "body": + { "type": "map_union" + , "$1": + [ { "type": "singleton_map" + , "key": "OS" + , "value": {"type": "var", "name": "OS"} + } + , { "type": "singleton_map" + , "key": "ARCH" + , "value": {"type": "var", "name": "TARGET_ARCH"} + } + , { "type": "singleton_map" + , "key": "HOST_ARCH" + , "value": {"type": "var", "name": "HOST_ARCH"} + } + , { "type": "singleton_map" + , "key": "TARGET_ARCH" + , "value": {"type": "var", "name": "TARGET_ARCH"} + } + ] + } + } + } +, "compile-deps": + { "expression": + { "type": "disjoint_map_union" + , "$1": + { "type": "++" + , "$1": + [ { "type": "foreach" + , "var": "dep" + , "range": {"type": "FIELD", "name": "deps"} + , "body": + { "type": "DEP_PROVIDES" + , "dep": {"type": "var", "name": "dep"} + , "provider": "compile-deps" + , "default": {"type": "empty_map"} + } + } + , { "type": "foreach" + , "var": "dep" + , "range": {"type": "FIELD", "name": "deps"} + , "body": + {"type": "DEP_RUNFILES", "dep": {"type": "var", "name": "dep"}} + } + , { "type": "foreach" + , "var": "dep" + , "range": {"type": "FIELD", "name": "proto-deps"} + , "body": + { "type": "DEP_PROVIDES" + , "dep": {"type": "var", "name": "dep"} + , "provider": "compile-deps" + , "default": {"type": "empty_map"} + } + } + , { "type": "foreach" + , "var": "dep" + , "range": {"type": "FIELD", "name": "proto-deps"} + , "body": + {"type": "DEP_RUNFILES", "dep": {"type": "var", "name": "dep"}} + } + ] + } + } + } +, "link-deps": + { "expression": + { "type": "disjoint_map_union" + , "$1": + { "type": "++" + , "$1": + [ { "type": "foreach" + , "var": "dep" + , "range": {"type": "FIELD", "name": "deps"} + , "body": + { "type": "DEP_PROVIDES" + , "dep": {"type": "var", "name": "dep"} + , "provider": "link-deps" + , "default": {"type": "empty_map"} + } + } + , { "type": "foreach" + , "var": "dep" + , "range": {"type": "FIELD", "name": "deps"} + , "body": + {"type": "DEP_ARTIFACTS", "dep": {"type": "var", "name": "dep"}} + } + , { "type": "foreach" + , "var": "dep" + , "range": {"type": "FIELD", "name": "proto-deps"} + , "body": + { "type": "DEP_PROVIDES" + , "dep": {"type": "var", "name": "dep"} + , "provider": "link-deps" + , "default": {"type": "empty_map"} + } + } + , { "type": "foreach" + , "var": "dep" + , "range": {"type": "FIELD", "name": "proto-deps"} + , "body": + {"type": "DEP_ARTIFACTS", "dep": {"type": "var", "name": "dep"}} + } + ] + } + } + } +, "objects": + { "vars": ["CXX", "CXXFLAGS", "ENV", "srcs", "compile-deps", "local hdrs"] + , "expression": + { "type": "let*" + , "bindings": + [ [ "include tree" + , { "type": "singleton_map" + , "key": "include" + , "value": + {"type": "TREE", "$1": {"type": "var", "name": "compile-deps"}} + } + ] + , [ "all hdrs" + , { "type": "map_union" + , "$1": + [ {"type": "var", "name": "include tree"} + , { "type": "to_subdir" + , "subdir": "work" + , "$1": {"type": "var", "name": "local hdrs"} + } + ] + } + ] + ] + , "body": + { "type": "map_union" + , "$1": + { "type": "foreach_map" + , "var_key": "src_name" + , "var_val": "src_val" + , "range": {"type": "var", "name": "srcs"} + , "body": + { "type": "let*" + , "bindings": + [ [ "work src_name" + , { "type": "join" + , "separator": "/" + , "$1": ["work", {"type": "var", "name": "src_name"}] + } + ] + , [ "inputs" + , { "type": "map_union" + , "$1": + [ {"type": "var", "name": "all hdrs"} + , { "type": "singleton_map" + , "key": {"type": "var", "name": "work src_name"} + , "value": {"type": "var", "name": "src_val"} + } + ] + } + ] + , [ "out" + , { "type": "change_ending" + , "$1": {"type": "var", "name": "src_name"} + , "ending": ".o" + } + ] + , [ "work out" + , { "type": "join" + , "separator": "/" + , "$1": ["work", {"type": "var", "name": "out"}] + } + ] + , [ "action output" + , { "type": "ACTION" + , "outs": [{"type": "var", "name": "work out"}] + , "inputs": {"type": "var", "name": "inputs"} + , "cmd": + { "type": "++" + , "$1": + [ [{"type": "var", "name": "CXX"}] + , {"type": "var", "name": "CXXFLAGS"} + , ["-I", "work", "-isystem", "include"] + , ["-c", {"type": "var", "name": "work src_name"}] + , ["-o", {"type": "var", "name": "work out"}] + ] + } + } + ] + , [ "staged output artifact" + , { "type": "map_union" + , "$1": + { "type": "foreach_map" + , "range": {"type": "var", "name": "action output"} + , "var_val": "object" + , "body": + { "type": "singleton_map" + , "key": {"type": "var", "name": "out"} + , "value": {"type": "var", "name": "object"} + } + } + } + ] + ] + , "body": {"type": "var", "name": "staged output artifact"} + } + } + } + } + } +, "lib result": + { "vars": + [ "CXX" + , "CXXFLAGS" + , "CC" + , "CFLAGS" + , "ENV" + , "AR" + , "srcs" + , "hdrs" + , "private-hdrs" + , "link external" + , "extra-provides" + ] + , "imports": + { "artifacts": ["./", "..", "field_artifacts"] + , "compile-deps": "compile-deps" + , "link-deps": "link-deps" + , "objects": "objects" + , "default-CC": "default-CC" + , "default-CXX": "default-CXX" + , "default-CFLAGS": "default-CFLAGS" + , "default-CXXFLAGS": "default-CXXFLAGS" + , "default-ENV": "default-ENV" + } + , "expression": + { "type": "let*" + , "bindings": + [ [ "stage" + , { "type": "join" + , "separator": "/" + , "$1": {"type": "FIELD", "name": "stage"} + } + ] + , [ "CXX" + , { "type": "if" + , "cond": {"type": "FIELD", "name": "pure C"} + , "then": + { "type": "var" + , "name": "CC" + , "default": {"type": "CALL_EXPRESSION", "name": "default-CC"} + } + , "else": + { "type": "var" + , "name": "CXX" + , "default": {"type": "CALL_EXPRESSION", "name": "default-CXX"} + } + } + ] + , [ "CXXFLAGS" + , { "type": "if" + , "cond": {"type": "FIELD", "name": "pure C"} + , "then": + { "type": "var" + , "name": "CFLAGS" + , "default": {"type": "CALL_EXPRESSION", "name": "default-CFLAGS"} + } + , "else": + { "type": "var" + , "name": "CXXFLAGS" + , "default": + {"type": "CALL_EXPRESSION", "name": "default-CXXFLAGS"} + } + } + ] + , [ "ENV" + , { "type": "map_union" + , "$1": + { "type": "++" + , "$1": + [ {"type": "CALL_EXPRESSION", "name": "default-ENV"} + , [ { "type": "var" + , "name": "ENV" + , "default": {"type": "empty_map"} + } + ] + ] + } + } + ] + , ["compile-deps", {"type": "CALL_EXPRESSION", "name": "compile-deps"}] + , ["link-deps", {"type": "CALL_EXPRESSION", "name": "link-deps"}] + , [ "local hdrs" + , { "type": "disjoint_map_union" + , "$1": + [ {"type": "var", "name": "hdrs"} + , {"type": "var", "name": "private-hdrs"} + ] + } + ] + , ["objects", {"type": "CALL_EXPRESSION", "name": "objects"}] + , [ "base name" + , {"type": "join", "$1": {"type": "FIELD", "name": "name"}} + ] + , [ "libname" + , { "type": "join" + , "$1": ["lib", {"type": "var", "name": "base name"}, ".a"] + } + ] + , [ "lib" + , { "type": "if" + , "cond": {"type": "var", "name": "objects"} + , "else": {"type": "empty_map"} + , "then": + { "type": "ACTION" + , "outs": [{"type": "var", "name": "libname"}] + , "inputs": {"type": "var", "name": "objects"} + , "cmd": + { "type": "++" + , "$1": + [ [ {"type": "var", "name": "AR", "default": "ar"} + , "cqs" + , {"type": "var", "name": "libname"} + ] + , {"type": "keys", "$1": {"type": "var", "name": "objects"}} + ] + } + } + } + ] + , [ "lib" + , { "type": "to_subdir" + , "subdir": {"type": "var", "name": "stage"} + , "$1": {"type": "var", "name": "lib"} + } + ] + , [ "link-args" + , { "type": "nub_right" + , "$1": + { "type": "++" + , "$1": + [ {"type": "keys", "$1": {"type": "var", "name": "lib"}} + , { "type": "++" + , "$1": + { "type": "foreach" + , "var": "dep" + , "range": {"type": "FIELD", "name": "deps"} + , "body": + { "type": "DEP_PROVIDES" + , "dep": {"type": "var", "name": "dep"} + , "provider": "link-args" + } + } + } + , { "type": "++" + , "$1": + { "type": "foreach" + , "var": "dep" + , "range": {"type": "FIELD", "name": "proto-deps"} + , "body": + { "type": "DEP_PROVIDES" + , "dep": {"type": "var", "name": "dep"} + , "provider": "link-args" + } + } + } + , {"type": "var", "name": "link external", "default": []} + ] + } + } + ] + ] + , "body": + { "type": "RESULT" + , "artifacts": {"type": "var", "name": "lib"} + , "runfiles": {"type": "var", "name": "hdrs"} + , "provides": + { "type": "map_union" + , "$1": + [ { "type": "singleton_map" + , "key": "compile-deps" + , "value": {"type": "var", "name": "compile-deps"} + } + , { "type": "singleton_map" + , "key": "link-deps" + , "value": {"type": "var", "name": "link-deps"} + } + , { "type": "singleton_map" + , "key": "link-args" + , "value": {"type": "var", "name": "link-args"} + } + , { "type": "var" + , "name": "extra-provides" + , "default": {"type": "empty_map"} + } + ] + } + } + } + } +} diff --git a/CC/RULES b/CC/RULES new file mode 100644 index 0000000..93d5afc --- /dev/null +++ b/CC/RULES @@ -0,0 +1,538 @@ +{ "defaults": + { "doc": + [ "A rule to provide defaults." + , "All CC targets take their defaults for CXX, CC, flags, etc from" + , "the target [\"CC\", \"defaults\"]. This is probably the only sensibe" + , "use of this rule. As targets form a different root, the defaults" + , "can be provided without changing this directory." + ] + , "string_fields": ["CC", "CXX", "CFLAGS", "CXXFLAGS", "PATH", "AR"] + , "expression": + { "type": "RESULT" + , "provides": + { "type": "map_union" + , "$1": + [ { "type": "singleton_map" + , "key": "CC" + , "value": {"type": "FIELD", "name": "CC"} + } + , { "type": "singleton_map" + , "key": "CXX" + , "value": {"type": "FIELD", "name": "CXX"} + } + , { "type": "singleton_map" + , "key": "CFLAGS" + , "value": {"type": "FIELD", "name": "CFLAGS"} + } + , { "type": "singleton_map" + , "key": "CXXFLAGS" + , "value": {"type": "FIELD", "name": "CXXFLAGS"} + } + , { "type": "singleton_map" + , "key": "AR" + , "value": {"type": "FIELD", "name": "AR"} + } + , { "type": "singleton_map" + , "key": "ENV" + , "value": + { "type": "singleton_map" + , "key": "PATH" + , "value": + { "type": "join" + , "separator": ":" + , "$1": {"type": "FIELD", "name": "PATH"} + } + } + } + ] + } + } + } +, "configure": + { "doc": + [ "A rule to provide a static platform configuration for a target." + , "The artifacts and runfiles of the specified target will be propagated." + , "The target defined by this rule does not propagate any provides data." + ] + , "config_fields": ["os", "arch", "target_arch"] + , "target_fields": ["target"] + , "field_doc": + { "os": ["The operation system used for building."] + , "arch": ["The architecture used for building."] + , "target_arch": + [ "Non-mandatory target architecture to build for. If omitted, target" + , "architecture is derived from \"arch\"." + ] + , "target": + [ "The target to configure. Multiple targets are supported, but their" + , "artifacts and runfiles should not conflict." + ] + } + , "imports": + { "transition": "configure transition" + , "artifacts": ["./", "..", "field_artifacts"] + , "runfiles": ["./", "..", "field_runfiles"] + } + , "config_transitions": + {"target": [{"type": "CALL_EXPRESSION", "name": "transition"}]} + , "expression": + { "type": "let*" + , "bindings": + [ ["fieldname", "target"] + , ["transition", {"type": "CALL_EXPRESSION", "name": "transition"}] + ] + , "body": + { "type": "RESULT" + , "artifacts": {"type": "CALL_EXPRESSION", "name": "artifacts"} + , "runfiles": {"type": "CALL_EXPRESSION", "name": "runfiles"} + } + } + } +, "header directory": + { "doc": + [ "A directory of header files." + , "" + , "Define a directory of header files that belong together and are staged" + , "in such a way that no other target (used together with this target) will" + , "have to put files in this directory. The typical use case is a library" + , "libfoo that expects all headers to be included as #include \"foo/bar.h\"." + , "In this case, one would define a header direcotry for \"foo\"." + , "" + , "Technically, a tree is created from the given files and staged to the" + , "specified location. Since trees are opaque, the directory name becomes" + , "essentially owned by target. In this way, staging conflicts can be" + , "avoided by detecting them early and not only once a file with the same" + , "name is added to the staging location. Also, as only a tree identifier" + , "has to be passed around, such a directory can be handled more" + , "efficiently by the tool." + ] + , "target_fields": ["hdrs"] + , "string_fields": ["stage", "public stage"] + , "field_doc": + { "hdrs": ["The header files to be put into the header directory."] + , "stage": + [ "The location of the header directory." + , "Path segments are joined with \"/\"." + ] + , "public stage": + [ "If non-empty, no closure for the header directory's stage is created, " + , "so can be combined with other header directories having the same " + , "public staging directory." + ] + } + , "expression": + { "type": "let*" + , "bindings": + [ [ "hdrs" + , { "type": "disjoint_map_union" + , "$1": + { "type": "foreach" + , "var": "x" + , "range": {"type": "FIELD", "name": "hdrs"} + , "body": + {"type": "DEP_RUNFILES", "dep": {"type": "var", "name": "x"}} + } + } + ] + , [ "stage" + , { "type": "join" + , "separator": "/" + , "$1": {"type": "FIELD", "name": "stage"} + } + ] + , [ "dir" + , { "type": "if" + , "cond": {"type": "FIELD", "name": "public stage"} + , "then": + { "type": "to_subdir" + , "subdir": {"type": "var", "name": "stage"} + , "$1": {"type": "var", "name": "hdrs"} + } + , "else": + { "type": "singleton_map" + , "key": {"type": "var", "name": "stage"} + , "value": {"type": "TREE", "$1": {"type": "var", "name": "hdrs"}} + } + } + ] + ] + , "body": + { "type": "RESULT" + , "artifacts": {"type": "var", "name": "dir"} + , "runfiles": {"type": "var", "name": "dir"} + } + } + } +, "library": + { "doc": ["A C++ libaray"] + , "target_fields": ["srcs", "hdrs", "private-hdrs", "deps", "proto"] + , "string_fields": + ["name", "stage", "pure C", "local defines", "link external"] + , "config_vars": ["CXX", "CC", "CXXFLAGS", "CFLAGS", "ENV", "AR"] + , "implicit": {"defaults": ["defaults"]} + , "field_doc": + { "name": + ["The name of the library (without leading \"lib\" or trailing \".a\""] + , "srcs": ["The source files of the library."] + , "hdrs": ["Any public header files of the library."] + , "private-hdrs": + [ "Any header files that only need to be present when compiling the" + , "source files, but are not needed for any consumer of the library" + ] + , "stage": + [ "The logical location of all header and source files, as well as the" + , "resulting library file. Individual directory components are joined" + , "with \"/\"." + ] + , "pure C": + [ "If non-empty, compile as C sources rathter than C++ sources." + , "In particular, CC is used to compile rather than CXX" + ] + , "local defines": + [ "List of defines set for source files local to this target." + , "Each list entry will be prepended by \"-D\"." + ] + , "link external": + ["Additional linker flags for linking external libraries."] + , "deps": ["Any other libraries this library depends upon."] + } + , "config_doc": + { "CXX": ["The name of the C++ compiler to be used."] + , "CC": + ["The name of the C compiler to be used (when compiling pure C code)"] + , "AR": ["The archive tool to used for creating the library"] + , "ENV": ["The environment for any action generated."] + , "CXXFLAGS": + [ "The flags for CXX to be used instead of the default ones." + , "For libraries that should be built in a non-standard way; usually" + , "adapting the default target [\"CC\", \"defaults\"] is the better" + , "choice" + ] + , "CFLAGS": + [ "The flags for CC to be used instead of the default ones." + , "For libraries that should be built in a non-standard way; usually" + , "adapting the default target [\"CC\", \"defaults\"] is the better" + , "choice" + ] + } + , "anonymous": + { "proto-deps": + { "target": "proto" + , "provider": "proto" + , "rule_map": + { "library": ["./", "proto", "library"] + , "service library": ["./", "proto", "service library"] + } + } + } + , "imports": + { "artifacts": ["./", "..", "field_artifacts"] + , "default-CXXFLAGS": "default-CXXFLAGS" + , "default-CFLAGS": "default-CFLAGS" + , "result": "lib result" + } + , "expression": + { "type": "let*" + , "bindings": + [ [ "local defines" + , { "type": "foreach" + , "var": "def" + , "range": {"type": "FIELD", "name": "local defines"} + , "body": + {"type": "join", "$1": ["-D", {"type": "var", "name": "def"}]} + } + ] + , [ "CFLAGS" + , { "type": "++" + , "$1": + [ { "type": "var" + , "name": "CFLAGS" + , "default": + {"type": "CALL_EXPRESSION", "name": "default-CFLAGS"} + } + , {"type": "var", "name": "local defines"} + ] + } + ] + , [ "CXXFLAGS" + , { "type": "++" + , "$1": + [ { "type": "var" + , "name": "CXXFLAGS" + , "default": + {"type": "CALL_EXPRESSION", "name": "default-CXXFLAGS"} + } + , {"type": "var", "name": "local defines"} + ] + } + ] + , [ "stage" + , { "type": "join" + , "separator": "/" + , "$1": {"type": "FIELD", "name": "stage"} + } + ] + , [ "srcs" + , { "type": "to_subdir" + , "subdir": {"type": "var", "name": "stage"} + , "$1": + { "type": "let*" + , "bindings": [["fieldname", "srcs"]] + , "body": {"type": "CALL_EXPRESSION", "name": "artifacts"} + } + } + ] + , [ "hdrs" + , { "type": "to_subdir" + , "subdir": {"type": "var", "name": "stage"} + , "$1": + { "type": "let*" + , "bindings": [["fieldname", "hdrs"]] + , "body": {"type": "CALL_EXPRESSION", "name": "artifacts"} + } + } + ] + , [ "private-hdrs" + , { "type": "to_subdir" + , "subdir": {"type": "var", "name": "stage"} + , "$1": + { "type": "let*" + , "bindings": [["fieldname", "private-hdrs"]] + , "body": {"type": "CALL_EXPRESSION", "name": "artifacts"} + } + } + ] + , ["link external", {"type": "FIELD", "name": "link external"}] + ] + , "body": {"type": "CALL_EXPRESSION", "name": "result"} + } + } +, "binary": + { "doc": ["A binary written in C++"] + , "target_fields": ["srcs", "private-hdrs", "deps", "proto"] + , "string_fields": + ["name", "stage", "pure C", "local defines", "link external"] + , "config_vars": ["CXX", "CC", "CXXFLAGS", "CFLAGS", "ENV"] + , "implicit": {"defaults": ["defaults"]} + , "field_doc": + { "name": ["The name of the binary"] + , "srcs": ["The source files of the library."] + , "private-hdrs": + [ "Any header files that need to be present when compiling the" + , "source files." + ] + , "stage": + [ "The logical location of all header and source files, as well as the" + , "resulting binary file. Individual directory components are joined" + , "with \"/\"." + ] + , "pure C": + [ "If non-empty, compile as C sources rathter than C++ sources." + , "In particular, CC is used to compile rather than CXX" + ] + , "local defines": + [ "List of defines set for source files local to this target." + , "Each list entry will be prepended by \"-D\"." + ] + , "link external": + ["Additional linker flags for linking external libraries."] + , "deps": ["Any other libraries this binary depends upon."] + } + , "config_doc": + { "CXX": ["The name of the C++ compiler to be used."] + , "CC": + ["The name of the C compiler to be used (when compiling pure C code)"] + , "ENV": ["The environment for any action generated."] + , "CXXFLAGS": + [ "The flags for CXX to be used instead of the default ones" + , "taken from the [\"CC\", \"defaults\"] target" + ] + , "CFLAGS": + [ "The flags for CXX to be used instead of the default ones" + , "taken from the [\"CC\", \"defaults\"] target" + ] + } + , "anonymous": + { "proto-deps": + { "target": "proto" + , "provider": "proto" + , "rule_map": + { "library": ["./", "proto", "library"] + , "service library": ["./", "proto", "service library"] + } + } + } + , "imports": + { "artifacts": ["./", "..", "field_artifacts"] + , "compile-deps": "compile-deps" + , "link-deps": "link-deps" + , "objects": "objects" + , "default-CC": "default-CC" + , "default-CXX": "default-CXX" + , "default-CFLAGS": "default-CFLAGS" + , "default-CXXFLAGS": "default-CXXFLAGS" + , "default-ENV": "default-ENV" + } + , "expression": + { "type": "let*" + , "bindings": + [ [ "local defines" + , { "type": "foreach" + , "var": "def" + , "range": {"type": "FIELD", "name": "local defines"} + , "body": + {"type": "join", "$1": ["-D", {"type": "var", "name": "def"}]} + } + ] + , [ "stage" + , { "type": "join" + , "separator": "/" + , "$1": {"type": "FIELD", "name": "stage"} + } + ] + , [ "srcs" + , { "type": "to_subdir" + , "subdir": {"type": "var", "name": "stage"} + , "$1": + { "type": "let*" + , "bindings": [["fieldname", "srcs"]] + , "body": {"type": "CALL_EXPRESSION", "name": "artifacts"} + } + } + ] + , [ "local hdrs" + , { "type": "to_subdir" + , "subdir": {"type": "var", "name": "stage"} + , "$1": + { "type": "let*" + , "bindings": [["fieldname", "private-hdrs"]] + , "body": {"type": "CALL_EXPRESSION", "name": "artifacts"} + } + } + ] + , [ "CXX" + , { "type": "if" + , "cond": {"type": "FIELD", "name": "pure C"} + , "then": + { "type": "var" + , "name": "CC" + , "default": {"type": "CALL_EXPRESSION", "name": "default-CC"} + } + , "else": + { "type": "var" + , "name": "CXX" + , "default": {"type": "CALL_EXPRESSION", "name": "default-CXX"} + } + } + ] + , [ "CXXFLAGS" + , { "type": "if" + , "cond": {"type": "FIELD", "name": "pure C"} + , "then": + { "type": "var" + , "name": "CFLAGS" + , "default": {"type": "CALL_EXPRESSION", "name": "default-CFLAGS"} + } + , "else": + { "type": "var" + , "name": "CXXFLAGS" + , "default": + {"type": "CALL_EXPRESSION", "name": "default-CXXFLAGS"} + } + } + ] + , [ "CXXFLAGS" + , { "type": "++" + , "$1": + [ {"type": "var", "name": "CXXFLAGS"} + , {"type": "var", "name": "local defines"} + ] + } + ] + , [ "ENV" + , { "type": "map_union" + , "$1": + { "type": "++" + , "$1": + [ {"type": "CALL_EXPRESSION", "name": "default-ENV"} + , [ { "type": "var" + , "name": "ENV" + , "default": {"type": "empty_map"} + } + ] + ] + } + } + ] + , ["compile-deps", {"type": "CALL_EXPRESSION", "name": "compile-deps"}] + , ["link-deps", {"type": "CALL_EXPRESSION", "name": "link-deps"}] + , ["objects", {"type": "CALL_EXPRESSION", "name": "objects"}] + , [ "base name" + , {"type": "join", "$1": {"type": "FIELD", "name": "name"}} + ] + , [ "binary name" + , { "type": "if" + , "cond": {"type": "var", "name": "stage"} + , "else": {"type": "var", "name": "base name"} + , "then": + { "type": "join" + , "separator": "/" + , "$1": + [ {"type": "var", "name": "stage"} + , {"type": "var", "name": "base name"} + ] + } + } + ] + , [ "link-args" + , { "type": "nub_right" + , "$1": + { "type": "++" + , "$1": + [ {"type": "keys", "$1": {"type": "var", "name": "objects"}} + , { "type": "++" + , "$1": + { "type": "foreach" + , "var": "dep" + , "range": {"type": "FIELD", "name": "deps"} + , "body": + { "type": "DEP_PROVIDES" + , "dep": {"type": "var", "name": "dep"} + , "provider": "link-args" + } + } + } + , {"type": "FIELD", "name": "link external"} + ] + } + } + ] + , [ "binary" + , { "type": "ACTION" + , "outs": [{"type": "var", "name": "binary name"}] + , "inputs": + { "type": "disjoint_map_union" + , "$1": + [ {"type": "var", "name": "objects"} + , {"type": "var", "name": "link-deps"} + ] + } + , "cmd": + { "type": "++" + , "$1": + [ [ {"type": "var", "name": "CXX"} + , "-o" + , {"type": "var", "name": "binary name"} + ] + , {"type": "var", "name": "link-args"} + ] + } + , "env": {"type": "var", "name": "ENV"} + } + ] + ] + , "body": + {"type": "RESULT", "artifacts": {"type": "var", "name": "binary"}} + } + } +} diff --git a/CC/proto/EXPRESSIONS b/CC/proto/EXPRESSIONS new file mode 100644 index 0000000..a98c51c --- /dev/null +++ b/CC/proto/EXPRESSIONS @@ -0,0 +1,301 @@ +{ "protoc-deps": + { "expression": + { "type": "disjoint_map_union" + , "$1": + { "type": "foreach" + , "var": "dep" + , "range": {"type": "FIELD", "name": "deps"} + , "body": + { "type": "DEP_PROVIDES" + , "dep": {"type": "var", "name": "dep"} + , "provider": "protoc-deps" + , "default": {"type": "empty_map"} + } + } + } + } +, "protoc-compile": + { "vars": ["transition", "service support"] + , "imports": + { "stage": ["", "stage_singleton_field"] + , "result": ["./", "..", "lib result"] + , "field_runfiles": ["", "field_runfiles"] + , "protoc-deps": "protoc-deps" + } + , "expression": + { "type": "let*" + , "bindings": + [ [ "protoc" + , { "type": "let*" + , "bindings": [["fieldname", "protoc"], ["location", "protoc"]] + , "body": {"type": "CALL_EXPRESSION", "name": "stage"} + } + ] + , [ "grpc_cpp_plugin" + , { "type": "if" + , "cond": {"type": "var", "name": "service support"} + , "then": + { "type": "let*" + , "bindings": + [ ["fieldname", "grpc_cpp_plugin"] + , ["location", "grpc_cpp_plugin"] + ] + , "body": {"type": "CALL_EXPRESSION", "name": "stage"} + } + , "else": {"type": "empty_map"} + } + ] + , ["protoc-deps", {"type": "CALL_EXPRESSION", "name": "protoc-deps"}] + , [ "proto deps" + , { "type": "to_subdir" + , "subdir": "work" + , "$1": + { "type": "disjoint_map_union" + , "$1": + { "type": "foreach" + , "var": "x" + , "range": {"type": "FIELD", "name": "well_known_protos"} + , "body": + {"type": "DEP_ARTIFACTS", "dep": {"type": "var", "name": "x"}} + } + } + } + ] + , [ "proto srcs" + , { "type": "disjoint_map_union" + , "msg": "Sources may not conflict" + , "$1": + { "type": "foreach" + , "var": "x" + , "range": {"type": "FIELD", "name": "srcs"} + , "body": + {"type": "DEP_ARTIFACTS", "dep": {"type": "var", "name": "x"}} + } + } + ] + , [ "all proto srcs" + , { "type": "disjoint_map_union" + , "msg": "Conflict with proto files of dependencies" + , "$1": + [ {"type": "var", "name": "protoc-deps"} + , {"type": "var", "name": "proto srcs"} + ] + } + ] + , [ "staged srcs" + , { "type": "to_subdir" + , "subdir": "work" + , "$1": {"type": "var", "name": "proto srcs"} + } + ] + , [ "staged all proto srcs" + , { "type": "to_subdir" + , "subdir": "work" + , "$1": {"type": "var", "name": "all proto srcs"} + } + ] + , [ "outs" + , { "type": "++" + , "$1": + { "type": "foreach" + , "var": "f" + , "range": + {"type": "keys", "$1": {"type": "var", "name": "staged srcs"}} + , "body": + { "type": "++" + , "$1": + [ [ { "type": "change_ending" + , "$1": {"type": "var", "name": "f"} + , "ending": ".pb.h" + } + , { "type": "change_ending" + , "$1": {"type": "var", "name": "f"} + , "ending": ".pb.cc" + } + ] + , { "type": "if" + , "cond": {"type": "var", "name": "service support"} + , "then": + [ { "type": "change_ending" + , "$1": {"type": "var", "name": "f"} + , "ending": ".grpc.pb.h" + } + , { "type": "change_ending" + , "$1": {"type": "var", "name": "f"} + , "ending": ".grpc.pb.cc" + } + ] + , "else": [] + } + ] + } + } + } + ] + , [ "cmd" + , { "type": "++" + , "$1": + [ ["./protoc", "--proto_path=work", "--cpp_out=work"] + , { "type": "if" + , "cond": {"type": "var", "name": "service support"} + , "then": + [ "--grpc_out=work" + , "--plugin=protoc-gen-grpc=./grpc_cpp_plugin" + ] + , "else": [] + } + , {"type": "keys", "$1": {"type": "var", "name": "staged srcs"}} + ] + } + ] + , [ "generated" + , { "type": "ACTION" + , "inputs": + { "type": "map_union" + , "$1": + [ {"type": "var", "name": "staged all proto srcs"} + , {"type": "var", "name": "protoc"} + , {"type": "var", "name": "grpc_cpp_plugin"} + , {"type": "var", "name": "proto deps"} + ] + } + , "outs": {"type": "var", "name": "outs"} + , "cmd": {"type": "var", "name": "cmd"} + } + ] + , [ "srcs" + , { "type": "map_union" + , "$1": + { "type": "foreach" + , "var": "name" + , "range": + {"type": "keys", "$1": {"type": "var", "name": "proto srcs"}} + , "body": + { "type": "map_union" + , "$1": + [ { "type": "singleton_map" + , "key": + { "type": "change_ending" + , "$1": {"type": "var", "name": "name"} + , "ending": ".pb.cc" + } + , "value": + { "type": "lookup" + , "map": {"type": "var", "name": "generated"} + , "key": + { "type": "join" + , "$1": + [ "work/" + , { "type": "change_ending" + , "$1": {"type": "var", "name": "name"} + , "ending": ".pb.cc" + } + ] + } + } + } + , { "type": "if" + , "cond": {"type": "var", "name": "service support"} + , "then": + { "type": "singleton_map" + , "key": + { "type": "change_ending" + , "$1": {"type": "var", "name": "name"} + , "ending": ".grpc.pb.cc" + } + , "value": + { "type": "lookup" + , "map": {"type": "var", "name": "generated"} + , "key": + { "type": "join" + , "$1": + [ "work/" + , { "type": "change_ending" + , "$1": {"type": "var", "name": "name"} + , "ending": ".grpc.pb.cc" + } + ] + } + } + } + , "else": {"type": "empty_map"} + } + ] + } + } + } + ] + , [ "hdrs" + , { "type": "map_union" + , "$1": + { "type": "foreach" + , "var": "name" + , "range": + {"type": "keys", "$1": {"type": "var", "name": "proto srcs"}} + , "body": + { "type": "map_union" + , "$1": + [ { "type": "singleton_map" + , "key": + { "type": "change_ending" + , "$1": {"type": "var", "name": "name"} + , "ending": ".pb.h" + } + , "value": + { "type": "lookup" + , "map": {"type": "var", "name": "generated"} + , "key": + { "type": "join" + , "$1": + [ "work/" + , { "type": "change_ending" + , "$1": {"type": "var", "name": "name"} + , "ending": ".pb.h" + } + ] + } + } + } + , { "type": "if" + , "cond": {"type": "var", "name": "service support"} + , "then": + { "type": "singleton_map" + , "key": + { "type": "change_ending" + , "$1": {"type": "var", "name": "name"} + , "ending": ".grpc.pb.h" + } + , "value": + { "type": "lookup" + , "map": {"type": "var", "name": "generated"} + , "key": + { "type": "join" + , "$1": + [ "work/" + , { "type": "change_ending" + , "$1": {"type": "var", "name": "name"} + , "ending": ".grpc.pb.h" + } + ] + } + } + } + , "else": {"type": "empty_map"} + } + ] + } + } + } + ] + , ["private-hdrs", {"type": "empty_map"}] + , [ "extra-provides" + , { "type": "singleton_map" + , "key": "protoc-deps" + , "value": {"type": "var", "name": "all proto srcs"} + } + ] + ] + , "body": {"type": "CALL_EXPRESSION", "name": "result"} + } + } +} diff --git a/CC/proto/RULES b/CC/proto/RULES new file mode 100644 index 0000000..04082c1 --- /dev/null +++ b/CC/proto/RULES @@ -0,0 +1,72 @@ +{ "library": + { "doc": + [ "A library C++ library, generated from proto files." + , "" + , "This rule usually is used to bind anonymous targets generated from" + , "proto libraries." + ] + , "string_fields": ["name", "stage"] + , "target_fields": ["srcs", "deps"] + , "config_vars": + ["OS", "ARCH", "HOST_ARCH", "CXX", "CC", "CXXFLAGS", "CFLAGS", "ENV", "AR"] + , "implicit": + { "protoc": [["@", "protoc", "", "protoc"]] + , "defaults": [["./", "..", "defaults"]] + , "proto-deps": [["@", "protoc", "", "C++ runtime"]] + , "well_known_protos": [["@", "protoc", "", "well_known_protos"]] + , "pure C": [] + } + , "imports": + { "protoc-compile": "protoc-compile" + , "host transition": ["transitions", "for host"] + } + , "config_transitions": + {"protoc": [{"type": "CALL_EXPRESSION", "name": "host transition"}]} + , "expression": + { "type": "let*" + , "bindings": + [["transition", {"type": "CALL_EXPRESSION", "name": "host transition"}]] + , "body": {"type": "CALL_EXPRESSION", "name": "protoc-compile"} + } + } +, "service library": + { "doc": + [ "A service library C++ library, generated from proto files." + , "" + , "Calls protoc with gRPC plugin to additionally generate gRPC services" + , "from proto libraries." + ] + , "string_fields": ["name", "stage"] + , "target_fields": ["srcs", "deps"] + , "config_vars": + ["OS", "ARCH", "HOST_ARCH", "CXX", "CC", "CXXFLAGS", "CFLAGS", "ENV", "AR"] + , "implicit": + { "protoc": [["@", "protoc", "", "protoc"]] + , "grpc_cpp_plugin": [["@", "grpc", "src/compiler", "grpc_cpp_plugin"]] + , "defaults": [["./", "..", "defaults"]] + , "proto-deps": + [ ["@", "grpc", "", "grpc++_codegen_proto"] + , ["@", "protoc", "", "C++ runtime"] + ] + , "well_known_protos": [["@", "protoc", "", "well_known_protos"]] + , "pure C": [] + } + , "imports": + { "protoc-compile": "protoc-compile" + , "host transition": ["transitions", "for host"] + } + , "config_transitions": + { "protoc": [{"type": "CALL_EXPRESSION", "name": "host transition"}] + , "grpc_cpp_plugin": + [{"type": "CALL_EXPRESSION", "name": "host transition"}] + } + , "expression": + { "type": "let*" + , "bindings": + [ ["service support", true] + , ["transition", {"type": "CALL_EXPRESSION", "name": "host transition"}] + ] + , "body": {"type": "CALL_EXPRESSION", "name": "protoc-compile"} + } + } +} diff --git a/CC/test/RULES b/CC/test/RULES new file mode 100644 index 0000000..de5a485 --- /dev/null +++ b/CC/test/RULES @@ -0,0 +1,265 @@ +{ "test": + { "doc": + [ "A test written in C++" + , "FIXME: the test binary and data must be built for host" + ] + , "tainted": ["test"] + , "target_fields": ["srcs", "private-hdrs", "deps", "data"] + , "string_fields": ["name", "stage"] + , "config_vars": ["CXX", "CC", "CXXFLAGS", "CFLAGS", "ENV"] + , "implicit": + { "defaults": [["./", "..", "defaults"]] + , "proto-deps": [] + , "runner": ["test_runner.sh"] + } + , "field_doc": + { "name": + [ "The name of the test" + , "" + , "Used to name the test binary as well as for staging the test result" + ] + , "srcs": ["The sources of the test binary"] + , "private-hdrs": + [ "Any additional header files that need to be present when compiling" + , "the test binary." + ] + , "stage": + [ "The logical location of all header and source files." + , "Individual directory components are joined with \"/\"." + ] + , "data": ["Any files the test binary needs access to when running"] + } + , "config_doc": + { "CXX": ["The name of the C++ compiler to be used."] + , "ENV": ["The environment for any action generated."] + , "CXXFLAGS": + [ "The flags for CXX to be used instead of the default ones" + , "taken from the [\"CC\", \"defaults\"] target" + ] + } + , "imports": + { "artifacts": ["./", "../..", "field_artifacts"] + , "compile-deps": ["./", "..", "compile-deps"] + , "link-deps": ["./", "..", "link-deps"] + , "objects": ["./", "..", "objects"] + , "default-CXX": ["./", "..", "default-CXX"] + , "default-CXXFLAGS": ["./", "..", "default-CXXFLAGS"] + , "default-ENV": ["./", "..", "default-ENV"] + } + , "expression": + { "type": "let*" + , "bindings": + [ [ "stage" + , { "type": "join" + , "separator": "/" + , "$1": {"type": "FIELD", "name": "stage"} + } + ] + , [ "srcs" + , { "type": "to_subdir" + , "subdir": {"type": "var", "name": "stage"} + , "$1": + { "type": "let*" + , "bindings": [["fieldname", "srcs"]] + , "body": {"type": "CALL_EXPRESSION", "name": "artifacts"} + } + } + ] + , [ "local hdrs" + , { "type": "to_subdir" + , "subdir": {"type": "var", "name": "stage"} + , "$1": + { "type": "let*" + , "bindings": [["fieldname", "private-hdrs"]] + , "body": {"type": "CALL_EXPRESSION", "name": "artifacts"} + } + } + ] + , [ "CXX" + , { "type": "var" + , "name": "CXX" + , "default": {"type": "CALL_EXPRESSION", "name": "default-CXX"} + } + ] + , [ "CXXFLAGS" + , { "type": "var" + , "name": "CXXFLAGS" + , "default": {"type": "CALL_EXPRESSION", "name": "default-CXXFLAGS"} + } + ] + , [ "ENV" + , { "type": "map_union" + , "$1": + { "type": "++" + , "$1": + [ {"type": "CALL_EXPRESSION", "name": "default-ENV"} + , [ { "type": "var" + , "name": "ENV" + , "default": {"type": "empty_map"} + } + ] + ] + } + } + ] + , ["compile-deps", {"type": "CALL_EXPRESSION", "name": "compile-deps"}] + , ["link-deps", {"type": "CALL_EXPRESSION", "name": "link-deps"}] + , ["objects", {"type": "CALL_EXPRESSION", "name": "objects"}] + , [ "base name" + , { "type": "assert_non_empty" + , "msg": "A non-empy name has to be provided" + , "$1": {"type": "join", "$1": {"type": "FIELD", "name": "name"}} + } + ] + , [ "binary name" + , { "type": "if" + , "cond": {"type": "var", "name": "stage"} + , "else": {"type": "var", "name": "base name"} + , "then": + { "type": "join" + , "separator": "/" + , "$1": + [ {"type": "var", "name": "stage"} + , {"type": "var", "name": "base name"} + ] + } + } + ] + , [ "link-args" + , { "type": "nub_right" + , "$1": + { "type": "++" + , "$1": + [ {"type": "keys", "$1": {"type": "var", "name": "objects"}} + , { "type": "++" + , "$1": + { "type": "foreach" + , "var": "dep" + , "range": {"type": "FIELD", "name": "deps"} + , "body": + { "type": "DEP_PROVIDES" + , "dep": {"type": "var", "name": "dep"} + , "provider": "link-args" + } + } + } + ] + } + } + ] + , [ "binary" + , { "type": "ACTION" + , "outs": [{"type": "var", "name": "binary name"}] + , "inputs": + { "type": "disjoint_map_union" + , "$1": + [ {"type": "var", "name": "objects"} + , {"type": "var", "name": "link-deps"} + ] + } + , "cmd": + { "type": "++" + , "$1": + [ [ {"type": "var", "name": "CXX"} + , "-o" + , {"type": "var", "name": "binary name"} + ] + , {"type": "var", "name": "link-args"} + ] + } + , "env": {"type": "var", "name": "ENV"} + } + ] + , [ "staged test binary" + , { "type": "map_union" + , "$1": + { "type": "foreach_map" + , "range": {"type": "var", "name": "binary"} + , "var_val": "binary" + , "body": + { "type": "singleton_map" + , "key": "test" + , "value": {"type": "var", "name": "binary"} + } + } + } + ] + , [ "runner" + , { "type": "map_union" + , "$1": + { "type": "foreach" + , "var": "runner" + , "range": {"type": "FIELD", "name": "runner"} + , "body": + { "type": "map_union" + , "$1": + { "type": "foreach" + , "var": "runner" + , "range": + { "type": "values" + , "$1": + { "type": "DEP_ARTIFACTS" + , "dep": {"type": "var", "name": "runner"} + } + } + , "body": + { "type": "singleton_map" + , "key": "runner.sh" + , "value": {"type": "var", "name": "runner"} + } + } + } + } + } + ] + , [ "data" + , { "type": "disjoint_map_union" + , "msg": "Data runfiles may not conflict" + , "$1": + { "type": "foreach" + , "var": "dep" + , "range": {"type": "FIELD", "name": "data"} + , "body": + {"type": "DEP_RUNFILES", "dep": {"type": "var", "name": "dep"}} + } + } + ] + , [ "test-results" + , { "type": "ACTION" + , "outs": ["result", "stdout", "stderr", "time-start", "time-stop"] + , "inputs": + { "type": "map_union" + , "$1": + [ { "type": "to_subdir" + , "subdir": "work" + , "$1": {"type": "var", "name": "data"} + } + , {"type": "var", "name": "runner"} + , {"type": "var", "name": "staged test binary"} + ] + } + , "cmd": ["sh", "./runner.sh"] + , "may_fail": ["test"] + , "fail_message": + { "type": "join" + , "$1": + ["CC test ", {"type": "var", "name": "binary name"}, " failed"] + } + } + ] + , [ "runfiles" + , { "type": "singleton_map" + , "key": {"type": "var", "name": "base name"} + , "value": + {"type": "TREE", "$1": {"type": "var", "name": "test-results"}} + } + ] + ] + , "body": + { "type": "RESULT" + , "artifacts": {"type": "var", "name": "test-results"} + , "runfiles": {"type": "var", "name": "runfiles"} + } + } + } +} diff --git a/CC/test/test_runner.sh b/CC/test/test_runner.sh new file mode 100644 index 0000000..ed9f48a --- /dev/null +++ b/CC/test/test_runner.sh @@ -0,0 +1,36 @@ +#!/bin/sh + +# ensure all required outputs are present +touch stdout +touch stderr +RESULT=UNKNOWN +echo "${RESULT}" > result +echo UNKNOWN > time-start +echo UNKNOWN > time-stop + +mkdir scratch +export TEST_TMPDIR=$(realpath scratch) +# Change to the working directory; note: the test might not +# have test data, so we have to ensure the presence of the work +# directory. + +mkdir -p work +cd work + +date +%s > ../time-start +# TODO: +# - proper wrapping with timeout +# - test arguments to select specific test cases +if ../test > ../stdout 2> ../stderr +then + RESULT=PASS +else + RESULT=FAIL +fi +date +%s > ../time-stop +echo "${RESULT}" > result + +if [ "${RESULT}" '!=' PASS ] +then + exit 1; +fi diff --git a/EXPRESSIONS b/EXPRESSIONS new file mode 100644 index 0000000..9b35b0a --- /dev/null +++ b/EXPRESSIONS @@ -0,0 +1,89 @@ +{ "field_artifacts": + { "vars": ["fieldname", "transition"] + , "expression": + { "type": "map_union" + , "$1": + { "type": "foreach" + , "var": "x" + , "range": + {"type": "FIELD", "name": {"type": "var", "name": "fieldname"}} + , "body": + { "type": "DEP_ARTIFACTS" + , "dep": {"type": "var", "name": "x"} + , "transition": + { "type": "var" + , "name": "transition" + , "default": {"type": "empty_map"} + } + } + } + } + } +, "field_runfiles": + { "vars": ["fieldname", "transition"] + , "expression": + { "type": "map_union" + , "$1": + { "type": "foreach" + , "var": "x" + , "range": + {"type": "FIELD", "name": {"type": "var", "name": "fieldname"}} + , "body": + { "type": "DEP_RUNFILES" + , "dep": {"type": "var", "name": "x"} + , "transition": + { "type": "var" + , "name": "transition" + , "default": {"type": "empty_map"} + } + } + } + } + } +, "action_env": + { "vars": ["ENV"] + , "expression": + { "type": "map_union" + , "$1": + [ {"type": "singleton_map", "key": "PATH", "value": "/bin:/usr/bin"} + , {"type": "var", "name": "ENV", "default": {"type": "empty_map"}} + ] + } + } +, "stage_singleton_field": + { "vars": ["fieldname", "transition", "location"] + , "expression": + { "type": "disjoint_map_union" + , "$1": + { "type": "foreach" + , "var": "src" + , "range": + {"type": "FIELD", "name": {"type": "var", "name": "fieldname"}} + , "body": + { "type": "disjoint_map_union" + , "$1": + { "type": "foreach" + , "var": "artifact" + , "range": + { "type": "values" + , "$1": + { "type": "DEP_ARTIFACTS" + , "dep": {"type": "var", "name": "src"} + , "transition": + { "type": "var" + , "name": "transition" + , "default": {"type": "empty_map"} + } + } + } + , "body": + { "type": "singleton_map" + , "key": {"type": "var", "name": "location"} + , "value": {"type": "var", "name": "artifact"} + } + } + } + } + } + } +} diff --git a/data/RULES b/data/RULES new file mode 100644 index 0000000..34bc624 --- /dev/null +++ b/data/RULES @@ -0,0 +1,42 @@ +{ "staged": + { "doc": ["Stage data to a logical subdirectory."] + , "target_fields": ["srcs"] + , "string_fields": ["stage"] + , "field_doc": + { "srcs": ["The (run)files to be staged"] + , "stage": + [ "The logical directory to stage the files to." + , "Individual directory components are joined with \"/\"." + ] + } + , "expression": + { "type": "let*" + , "bindings": + [ [ "stage" + , { "type": "join" + , "separator": "/" + , "$1": {"type": "FIELD", "name": "stage"} + } + ] + , [ "srcs" + , { "type": "disjoint_map_union" + , "$1": + { "type": "foreach" + , "var": "x" + , "range": {"type": "FIELD", "name": "srcs"} + , "body": + {"type": "DEP_RUNFILES", "dep": {"type": "var", "name": "x"}} + } + } + ] + , [ "staged" + , { "type": "to_subdir" + , "subdir": {"type": "var", "name": "stage"} + , "$1": {"type": "var", "name": "srcs"} + } + ] + ] + , "body": {"type": "RESULT", "runfiles": {"type": "var", "name": "staged"}} + } + } +} diff --git a/proto/RULES b/proto/RULES new file mode 100644 index 0000000..b6ce000 --- /dev/null +++ b/proto/RULES @@ -0,0 +1,105 @@ +{ "library": + { "target_fields": ["srcs", "deps"] + , "string_fields": ["stage", "name", "service"] + , "expression": + { "type": "let*" + , "bindings": + [ [ "stage" + , { "type": "join" + , "separator": "/" + , "$1": {"type": "FIELD", "name": "stage"} + } + ] + , [ "name" + , { "type": "assert_non_empty" + , "msg": "Have to provide a name, unique in the stage" + , "$1": {"type": "join", "$1": {"type": "FIELD", "name": "name"}} + } + ] + , [ "srcs" + , [ { "type": "VALUE_NODE" + , "$1": + { "type": "RESULT" + , "artifacts": + { "type": "to_subdir" + , "subdir": {"type": "var", "name": "stage"} + , "$1": + { "type": "disjoint_map_union" + , "msg": "Sources have to be conflict free" + , "$1": + { "type": "foreach" + , "var": "x" + , "range": {"type": "FIELD", "name": "srcs"} + , "body": + { "type": "DEP_ARTIFACTS" + , "dep": {"type": "var", "name": "x"} + } + } + } + } + } + } + ] + ] + , [ "deps" + , { "type": "++" + , "$1": + { "type": "foreach" + , "var": "x" + , "range": {"type": "FIELD", "name": "deps"} + , "body": + { "type": "DEP_PROVIDES" + , "dep": {"type": "var", "name": "x"} + , "provider": "proto" + } + } + } + ] + , [ "node" + , { "type": "ABSTRACT_NODE" + , "node_type": + { "type": "if" + , "cond": {"type": "FIELD", "name": "service"} + , "then": "service library" + , "else": "library" + } + , "target_fields": + { "type": "map_union" + , "$1": + [ { "type": "singleton_map" + , "key": "srcs" + , "value": {"type": "var", "name": "srcs"} + } + , { "type": "singleton_map" + , "key": "deps" + , "value": {"type": "var", "name": "deps"} + } + ] + } + , "string_fields": + { "type": "map_union" + , "$1": + [ { "type": "singleton_map" + , "key": "name" + , "value": [{"type": "var", "name": "name"}] + } + , { "type": "singleton_map" + , "key": "stage" + , "value": [{"type": "var", "name": "stage"}] + } + ] + } + } + ] + ] + , "body": + { "type": "RESULT" + , "provides": + { "type": "singleton_map" + , "key": "proto" + , "value": [{"type": "var", "name": "node"}] + } + } + } + } +} diff --git a/transitions/EXPRESSIONS b/transitions/EXPRESSIONS new file mode 100644 index 0000000..8ea7550 --- /dev/null +++ b/transitions/EXPRESSIONS @@ -0,0 +1,13 @@ +{ "for host": + { "vars": ["ARCH", "HOST_ARCH"] + , "expression": + { "type": "singleton_map" + , "key": "TARGET_ARCH" + , "value": + { "type": "var" + , "name": "HOST_ARCH" + , "default": {"type": "var", "name": "ARCH"} + } + } + } +} -- cgit v1.2.3 From 6f1bff70d3757268275fca937ff93d1a6475c3f1 Mon Sep 17 00:00:00 2001 From: Klaus Aehlig Date: Wed, 23 Feb 2022 14:04:41 +0100 Subject: common rule expression: improve error reporting ... by asserting that "stage_singleton_field" return a non-empty map and providing a meaningful message in the "disjoint_map_union" contained in it. --- EXPRESSIONS | 57 +++++++++++++++++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 24 deletions(-) diff --git a/EXPRESSIONS b/EXPRESSIONS index 9b35b0a..d9b8562 100644 --- a/EXPRESSIONS +++ b/EXPRESSIONS @@ -53,33 +53,42 @@ , "stage_singleton_field": { "vars": ["fieldname", "transition", "location"] , "expression": - { "type": "disjoint_map_union" + { "type": "assert_non_empty" + , "msg": + ["No artifact specified in field", {"type": "var", "name": "fieldname"}] , "$1": - { "type": "foreach" - , "var": "src" - , "range": - {"type": "FIELD", "name": {"type": "var", "name": "fieldname"}} - , "body": - { "type": "disjoint_map_union" - , "$1": - { "type": "foreach" - , "var": "artifact" - , "range": - { "type": "values" - , "$1": - { "type": "DEP_ARTIFACTS" - , "dep": {"type": "var", "name": "src"} - , "transition": - { "type": "var" - , "name": "transition" - , "default": {"type": "empty_map"} + { "type": "disjoint_map_union" + , "msg": + [ "Expecting (essentially) a single artifact in field" + , {"type": "var", "name": "fieldname"} + ] + , "$1": + { "type": "foreach" + , "var": "src" + , "range": + {"type": "FIELD", "name": {"type": "var", "name": "fieldname"}} + , "body": + { "type": "disjoint_map_union" + , "$1": + { "type": "foreach" + , "var": "artifact" + , "range": + { "type": "values" + , "$1": + { "type": "DEP_ARTIFACTS" + , "dep": {"type": "var", "name": "src"} + , "transition": + { "type": "var" + , "name": "transition" + , "default": {"type": "empty_map"} + } } } - } - , "body": - { "type": "singleton_map" - , "key": {"type": "var", "name": "location"} - , "value": {"type": "var", "name": "artifact"} + , "body": + { "type": "singleton_map" + , "key": {"type": "var", "name": "location"} + , "value": {"type": "var", "name": "artifact"} + } } } } -- cgit v1.2.3 From 741ef53eab173e10a6e935319ee1af1acdd37273 Mon Sep 17 00:00:00 2001 From: Klaus Aehlig Date: Wed, 23 Feb 2022 15:02:50 +0100 Subject: Add shell/test rule ... allowing to run simple tests given by a shell script. --- shell/test/EXPRESSIONS | 116 ++++++++++++++++++++++++++++++++++++++++++++++ shell/test/RULES | 50 ++++++++++++++++++++ shell/test/test_runner.sh | 44 ++++++++++++++++++ 3 files changed, 210 insertions(+) create mode 100644 shell/test/EXPRESSIONS create mode 100644 shell/test/RULES create mode 100755 shell/test/test_runner.sh diff --git a/shell/test/EXPRESSIONS b/shell/test/EXPRESSIONS new file mode 100644 index 0000000..429cd47 --- /dev/null +++ b/shell/test/EXPRESSIONS @@ -0,0 +1,116 @@ +{ "test-result": + { "vars": ["name", "test.sh"] + , "expression": + { "type": "let*" + , "bindings": + [ [ "runner" + , { "type": "map_union" + , "$1": + { "type": "foreach" + , "var": "runner" + , "range": {"type": "FIELD", "name": "runner"} + , "body": + { "type": "map_union" + , "$1": + { "type": "foreach" + , "var": "runner" + , "range": + { "type": "values" + , "$1": + { "type": "DEP_ARTIFACTS" + , "dep": {"type": "var", "name": "runner"} + } + } + , "body": + { "type": "singleton_map" + , "key": "runner" + , "value": {"type": "var", "name": "runner"} + } + } + } + } + } + ] + , [ "deps" + , { "type": "TREE" + , "$1": + { "type": "disjoint_map_union" + , "msg": "Field 'deps' has to stage in a conflict free way" + , "$1": + { "type": "++" + , "$1": + [ { "type": "foreach" + , "var": "dep" + , "range": {"type": "FIELD", "name": "deps"} + , "body": + { "type": "DEP_RUNFILES" + , "dep": {"type": "var", "name": "dep"} + } + } + , { "type": "foreach" + , "var": "dep" + , "range": {"type": "FIELD", "name": "deps"} + , "body": + { "type": "DEP_ARTIFACTS" + , "dep": {"type": "var", "name": "dep"} + } + } + ] + } + } + } + ] + , [ "test-results" + , { "type": "ACTION" + , "outs": + { "type": "++" + , "$1": + [ ["result", "stdout", "stderr", "time-start", "time-stop"] + , { "type": "foreach" + , "var": "filename" + , "range": {"type": "FIELD", "name": "keep"} + , "body": + { "type": "join" + , "$1": ["work/", {"type": "var", "name": "filename"}] + } + } + ] + } + , "inputs": + { "type": "map_union" + , "$1": + [ { "type": "singleton_map" + , "key": "work" + , "value": {"type": "var", "name": "deps"} + } + , {"type": "var", "name": "runner"} + , {"type": "var", "name": "test.sh"} + ] + } + , "cmd": + { "type": "++" + , "$1": [["./runner"], {"type": "FIELD", "name": "keep"}] + } + , "may_fail": ["test"] + , "fail_message": + { "type": "join" + , "$1": ["shell test ", {"type": "var", "name": "name"}, " failed"] + } + } + ] + , [ "runfiles" + , { "type": "singleton_map" + , "key": {"type": "var", "name": "name"} + , "value": + {"type": "TREE", "$1": {"type": "var", "name": "test-results"}} + } + ] + ] + , "body": + { "type": "RESULT" + , "artifacts": {"type": "var", "name": "test-results"} + , "runfiles": {"type": "var", "name": "runfiles"} + } + } + } +} diff --git a/shell/test/RULES b/shell/test/RULES new file mode 100644 index 0000000..ca5ddbc --- /dev/null +++ b/shell/test/RULES @@ -0,0 +1,50 @@ +{ "script": + { "doc": ["Shell test, given by a test script"] + , "target_fields": ["deps", "test"] + , "string_fields": ["keep", "name"] + , "field_doc": + { "test": ["The shell script for the test, launched with sh"] + , "name": + [ "A name for the test, used in reporting, as well as for staging" + , "the test result tree in the runfiles" + ] + , "keep": + [ "List of names (relativ to the test working directory) of files that" + , "the test might generate that should be kept as part of the output." + , "This might be useful for further analysis of the test" + ] + , "deps": + [ "Any targets that should be staged (with artifacts and runfiles) into" + , "the tests working directory" + ] + } + , "tainted": ["test"] + , "implicit": {"runner": ["test_runner.sh"]} + , "imports": + { "test-result": "test-result" + , "stage": ["./", "../..", "stage_singleton_field"] + } + , "expression": + { "type": "let*" + , "bindings": + [ [ "test.sh" + , { "type": "context" + , "msg": "Expecting 'test' to specify precisely one file containing a shell script" + , "$1": + { "type": "let*" + , "bindings": [["fieldname", "test"], ["location", "test.sh"]] + , "body": {"type": "CALL_EXPRESSION", "name": "stage"} + } + } + ] + , [ "name" + , { "type": "assert_non_empty" + , "msg": "Have to provide a non-empty name for the test (e.g., for result staging)" + , "$1": {"type": "join", "$1": {"type": "FIELD", "name": "name"}} + } + ] + ] + , "body": {"type": "CALL_EXPRESSION", "name": "test-result"} + } + } +} diff --git a/shell/test/test_runner.sh b/shell/test/test_runner.sh new file mode 100755 index 0000000..969b80a --- /dev/null +++ b/shell/test/test_runner.sh @@ -0,0 +1,44 @@ +#!/bin/sh + +# ensure all required outputs are present +touch stdout +touch stderr +RESULT=UNKNOWN +echo "${RESULT}" > result +echo UNKNOWN > time-start +echo UNKNOWN > time-stop + +mkdir scratch +export TEST_TMPDIR=$(realpath scratch) +export TMPDIR="${TEST_TMPDIR}" + +# Change to the working directory; note: while unlikely, the test +# might not have test data, so we have to ensure the presence of +# the work directory. +mkdir -p work +cd work + +date +%s > ../time-start +# TODO: +# - proper wrapping with timeout +if sh ../test.sh > ../stdout 2> ../stderr +then + RESULT=PASS +else + RESULT=FAIL +fi +date +%s > ../time-stop + +# Ensure all the promissed output files in the work directory +# are present, even if the test failed to create them. +for f in "$@" +do + touch "./${f}" +done + +echo "${RESULT}" > ../result + +if [ "${RESULT}" '!=' PASS ] +then + exit 1; +fi -- cgit v1.2.3 From 10600edede9d4faf7ee2384ae25d5fb5c9af09b0 Mon Sep 17 00:00:00 2001 From: Oliver Reiche Date: Thu, 24 Feb 2022 11:27:51 +0100 Subject: rules: Add CC/proto/IDE headers ... to manually request the generation of headers for CC proto bindings. This is useful for IDEs and needed as implicitly generating those bindings via the `proto` field of CC libraries does not expose the produced headers. --- CC/proto/IDE/RULES | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 CC/proto/IDE/RULES diff --git a/CC/proto/IDE/RULES b/CC/proto/IDE/RULES new file mode 100644 index 0000000..558e494 --- /dev/null +++ b/CC/proto/IDE/RULES @@ -0,0 +1,63 @@ +{ "headers": + { "doc": ["Headers of C++ proto binding"] + , "target_fields": ["proto"] + , "string_fields": ["stage"] + , "field_doc": + { "proto": ["The proto source files to create the binding from."] + , "stage": + [ "The logical location of the header files. Individual directory" + , "components are joined with \"/\"." + ] + } + , "anonymous": + { "proto-deps": + { "target": "proto" + , "provider": "proto" + , "rule_map": + { "library": ["./", "..", "library"] + , "service library": ["./", "..", "service library"] + } + } + } + , "imports": {"runfiles": ["./", "../../..", "field_runfiles"]} + , "expression": + { "type": "let*" + , "bindings": + [ [ "stage" + , { "type": "join" + , "separator": "/" + , "$1": {"type": "FIELD", "name": "stage"} + } + ] + ] + , "body": + { "type": "RESULT" + , "artifacts": + { "type": "to_subdir" + , "subdir": {"type": "var", "name": "stage"} + , "$1": + { "type": "map_union" + , "$1": + [ { "type": "let*" + , "bindings": [["fieldname", "proto-deps"]] + , "body": {"type": "CALL_EXPRESSION", "name": "runfiles"} + } + , { "type": "map_union" + , "$1": + { "type": "foreach" + , "var": "x" + , "range": {"type": "FIELD", "name": "proto-deps"} + , "body": + { "type": "DEP_PROVIDES" + , "provider": "compile-deps" + , "dep": {"type": "var", "name": "x"} + } + } + } + ] + } + } + } + } + } +} -- cgit v1.2.3 From e454095520c7b37a56db245b658a121f07b06ce3 Mon Sep 17 00:00:00 2001 From: Oliver Reiche Date: Tue, 1 Mar 2022 12:31:55 +0100 Subject: CC test: Add optional test launcher `CC_TEST_LAUNCHER` --- CC/test/RULES | 15 +++++++++++++-- CC/test/test_runner.sh | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/CC/test/RULES b/CC/test/RULES index de5a485..fa6fdbc 100644 --- a/CC/test/RULES +++ b/CC/test/RULES @@ -6,7 +6,8 @@ , "tainted": ["test"] , "target_fields": ["srcs", "private-hdrs", "deps", "data"] , "string_fields": ["name", "stage"] - , "config_vars": ["CXX", "CC", "CXXFLAGS", "CFLAGS", "ENV"] + , "config_vars": + ["CXX", "CC", "CXXFLAGS", "CFLAGS", "ENV", "CC_TEST_LAUNCHER"] , "implicit": { "defaults": [["./", "..", "defaults"]] , "proto-deps": [] @@ -36,6 +37,10 @@ [ "The flags for CXX to be used instead of the default ones" , "taken from the [\"CC\", \"defaults\"] target" ] + , "CC_TEST_LAUNCHER": + [ "List of strings representing the launcher that is prepend to the" + , "command line for running the test binary." + ] } , "imports": { "artifacts": ["./", "../..", "field_artifacts"] @@ -238,7 +243,13 @@ , {"type": "var", "name": "staged test binary"} ] } - , "cmd": ["sh", "./runner.sh"] + , "cmd": + { "type": "++" + , "$1": + [ ["sh", "./runner.sh"] + , {"type": "var", "name": "CC_TEST_LAUNCHER", "default": []} + ] + } , "may_fail": ["test"] , "fail_message": { "type": "join" diff --git a/CC/test/test_runner.sh b/CC/test/test_runner.sh index ed9f48a..5256867 100644 --- a/CC/test/test_runner.sh +++ b/CC/test/test_runner.sh @@ -21,7 +21,7 @@ date +%s > ../time-start # TODO: # - proper wrapping with timeout # - test arguments to select specific test cases -if ../test > ../stdout 2> ../stderr +if "$@" ../test > ../stdout 2> ../stderr then RESULT=PASS else -- cgit v1.2.3 From d7d7f9d796bc73c8f8cb2dbb6e58039a663f9ef3 Mon Sep 17 00:00:00 2001 From: Klaus Aehlig Date: Wed, 2 Mar 2022 15:12:28 +0100 Subject: Extend shell-test rules to optionally detect flakyness --- shell/test/EXPRESSIONS | 127 ++++++++++++++++++++++++++++++++------------- shell/test/RULES | 108 +++++++++++++++++++++++++++++++++++++- shell/test/test_summary.py | 53 +++++++++++++++++++ 3 files changed, 250 insertions(+), 38 deletions(-) create mode 100755 shell/test/test_summary.py diff --git a/shell/test/EXPRESSIONS b/shell/test/EXPRESSIONS index 429cd47..2b9a62e 100644 --- a/shell/test/EXPRESSIONS +++ b/shell/test/EXPRESSIONS @@ -1,5 +1,5 @@ -{ "test-result": - { "vars": ["name", "test.sh"] +{ "test-action": + { "vars": ["name", "test.sh", "ATTEMPT"] , "expression": { "type": "let*" , "bindings": @@ -60,44 +60,99 @@ } } ] - , [ "test-results" - , { "type": "ACTION" - , "outs": - { "type": "++" - , "$1": - [ ["result", "stdout", "stderr", "time-start", "time-stop"] - , { "type": "foreach" - , "var": "filename" - , "range": {"type": "FIELD", "name": "keep"} - , "body": - { "type": "join" - , "$1": ["work/", {"type": "var", "name": "filename"}] - } - } - ] - } - , "inputs": - { "type": "map_union" - , "$1": - [ { "type": "singleton_map" - , "key": "work" - , "value": {"type": "var", "name": "deps"} - } - , {"type": "var", "name": "runner"} - , {"type": "var", "name": "test.sh"} - ] - } - , "cmd": - { "type": "++" - , "$1": [["./runner"], {"type": "FIELD", "name": "keep"}] + , [ "attempt marker" + , { "type": "if" + , "cond": + { "type": "==" + , "$1": {"type": "var", "name": "ATTEMPT"} + , "$2": null } - , "may_fail": ["test"] - , "fail_message": - { "type": "join" - , "$1": ["shell test ", {"type": "var", "name": "name"}, " failed"] + , "then": {"type": "empty_map"} + , "else": + { "type": "singleton_map" + , "key": "ATTEMPT" + , "value": + {"type": "BLOB", "data": {"type": "var", "name": "ATTEMPT"}} } } ] + , [ "outs" + , { "type": "++" + , "$1": + [ ["result", "stdout", "stderr", "time-start", "time-stop"] + , { "type": "foreach" + , "var": "filename" + , "range": {"type": "FIELD", "name": "keep"} + , "body": + { "type": "join" + , "$1": ["work/", {"type": "var", "name": "filename"}] + } + } + ] + } + ] + , [ "inputs" + , { "type": "map_union" + , "$1": + [ { "type": "singleton_map" + , "key": "work" + , "value": {"type": "var", "name": "deps"} + } + , {"type": "var", "name": "runner"} + , {"type": "var", "name": "test.sh"} + , {"type": "var", "name": "attempt marker"} + ] + } + ] + , [ "cmd" + , { "type": "++" + , "$1": [["./runner"], {"type": "FIELD", "name": "keep"}] + } + ] + ] + , "body": + { "type": "if" + , "cond": + {"type": "==", "$1": {"type": "var", "name": "ATTEMPT"}, "$2": null} + , "then": + { "type": "ACTION" + , "outs": {"type": "var", "name": "outs"} + , "inputs": {"type": "var", "name": "inputs"} + , "cmd": {"type": "var", "name": "cmd"} + , "may_fail": ["test"] + , "fail_message": + { "type": "join" + , "$1": ["shell test ", {"type": "var", "name": "name"}, " failed"] + } + } + , "else": + { "type": "ACTION" + , "outs": {"type": "var", "name": "outs"} + , "inputs": {"type": "var", "name": "inputs"} + , "cmd": {"type": "var", "name": "cmd"} + , "may_fail": ["test"] + , "no_cache": ["test"] + , "fail_message": + { "type": "join" + , "$1": + [ "shell test " + , {"type": "var", "name": "name"} + , " failed (Run " + , {"type": "var", "name": "ATTEMPT"} + , ")" + ] + } + } + } + } + } +, "test-result": + { "vars": ["name", "test.sh"] + , "imports": {"action": "test-action"} + , "expression": + { "type": "let*" + , "bindings": + [ ["test-results", {"type": "CALL_EXPRESSION", "name": "action"}] , [ "runfiles" , { "type": "singleton_map" , "key": {"type": "var", "name": "name"} diff --git a/shell/test/RULES b/shell/test/RULES index ca5ddbc..cf9713a 100644 --- a/shell/test/RULES +++ b/shell/test/RULES @@ -2,6 +2,7 @@ { "doc": ["Shell test, given by a test script"] , "target_fields": ["deps", "test"] , "string_fields": ["keep", "name"] + , "config_vars": ["RUNS_PER_TEST"] , "field_doc": { "test": ["The shell script for the test, launched with sh"] , "name": @@ -18,10 +19,18 @@ , "the tests working directory" ] } + , "config_doc": + { "RUNS_PER_TEST": + [ "The number of times the test should be run in order to detect flakyness." + , "If set, no test action will be taken from cache." + ] + } , "tainted": ["test"] - , "implicit": {"runner": ["test_runner.sh"]} + , "implicit": + {"runner": ["test_runner.sh"], "summarizer": ["test_summary.py"]} , "imports": { "test-result": "test-result" + , "action": "test-action" , "stage": ["./", "../..", "stage_singleton_field"] } , "expression": @@ -44,7 +53,102 @@ } ] ] - , "body": {"type": "CALL_EXPRESSION", "name": "test-result"} + , "body": + { "type": "if" + , "cond": {"type": "var", "name": "RUNS_PER_TEST"} + , "else": {"type": "CALL_EXPRESSION", "name": "test-result"} + , "then": + { "type": "let*" + , "bindings": + [ [ "attempts" + , { "type": "map_union" + , "$1": + { "type": "foreach" + , "var": "ATTEMPT" + , "range": + { "type": "range" + , "$1": {"type": "var", "name": "RUNS_PER_TEST"} + } + , "body": + { "type": "singleton_map" + , "key": {"type": "var", "name": "ATTEMPT"} + , "value": + { "type": "TREE" + , "$1": {"type": "CALL_EXPRESSION", "name": "action"} + } + } + } + } + ] + , [ "summarizer" + , { "type": "map_union" + , "$1": + { "type": "foreach" + , "var": "x" + , "range": {"type": "FIELD", "name": "summarizer"} + , "body": + { "type": "map_union" + , "$1": + { "type": "foreach" + , "var": "x" + , "range": + { "type": "values" + , "$1": + { "type": "DEP_ARTIFACTS" + , "dep": {"type": "var", "name": "x"} + } + } + , "body": + { "type": "singleton_map" + , "key": "summarizer" + , "value": {"type": "var", "name": "x"} + } + } + } + } + } + ] + , [ "summary" + , { "type": "ACTION" + , "inputs": + { "type": "map_union" + , "$1": + [ {"type": "var", "name": "attempts"} + , {"type": "var", "name": "summarizer"} + ] + } + , "outs": + ["stdout", "stderr", "result", "time-start", "time-stop"] + , "cmd": ["./summarizer"] + } + ] + , [ "artifacts" + , { "type": "map_union" + , "$1": + [ {"type": "var", "name": "summary"} + , { "type": "singleton_map" + , "key": "work" + , "value": + {"type": "TREE", "$1": {"type": "var", "name": "attempts"}} + } + ] + } + ] + , [ "runfiles" + , { "type": "singleton_map" + , "key": {"type": "var", "name": "name"} + , "value": + {"type": "TREE", "$1": {"type": "var", "name": "artifacts"}} + } + ] + ] + , "body": + { "type": "RESULT" + , "artifacts": {"type": "var", "name": "artifacts"} + , "runfiles": {"type": "var", "name": "runfiles"} + } + } + } } } } diff --git a/shell/test/test_summary.py b/shell/test/test_summary.py new file mode 100755 index 0000000..cba8d50 --- /dev/null +++ b/shell/test/test_summary.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python3 + +import os +import time + +RESULTS = {} + +time_start = time.time() +time_stop = 0 + +for attempt in os.listdir("."): + if os.path.isdir(attempt): + with open(os.path.join(attempt, "result")) as f: + result = f.read().strip() + RESULTS[result] = RESULTS.get(result, []) + [int(attempt)] + try: + with open(os.path.join(attempt, "time-start")) as f: + time_start = min(time_start, float(f.read().strip())) + except: + pass + try: + with open(os.path.join(attempt, "time-stop")) as f: + time_stop = max(time_start, float(f.read().strip())) + except: + pass + +result = "UNKNOWN" +if set(RESULTS.keys()) <= set(["PASS", "FAIL"]): + if not RESULTS.get("FAIL"): + result = "PASS" + elif not RESULTS.get("PASS"): + result = "FAIL" + else: + result = "FLAKY" +with open("result", "w") as f: + f.write("%s\n" % (result,)) + +with open("time-start", "w") as f: + f.write("%d\n" % (time_start,)) +with open("time-stop", "w") as f: + f.write("%d\n" % (time_stop,)) + +with open("stdout", "w") as f: + f.write("Summary: %s\n\n" % (result,)) + f.write("PASS: %s\n" % (sorted(RESULTS.get("PASS", [])),)) + f.write("FAIL: %s\n" % (sorted(RESULTS.get("FAIL", [])),)) + RESULTS.pop("PASS", None) + RESULTS.pop("FAIL", None) + if RESULTS: + f.write("\nother results: %r\n" % (RESULTS,)) + +with open("stderr", "w") as f: + pass -- cgit v1.2.3 From 3e1a403d5790b09dc0b2cdeac22db188d58ff0cc Mon Sep 17 00:00:00 2001 From: Oliver Reiche Date: Thu, 3 Mar 2022 13:43:44 +0100 Subject: CC rules: Add support for local cflags --- CC/EXPRESSIONS | 9 +++++++++ CC/RULES | 5 ++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CC/EXPRESSIONS b/CC/EXPRESSIONS index f1e6592..1002147 100644 --- a/CC/EXPRESSIONS +++ b/CC/EXPRESSIONS @@ -322,6 +322,7 @@ , "srcs" , "hdrs" , "private-hdrs" + , "local cflags" , "link external" , "extra-provides" ] @@ -376,6 +377,14 @@ } } ] + , [ "CXXFLAGS" + , { "type": "++" + , "$1": + [ {"type": "var", "name": "CXXFLAGS"} + , {"type": "var", "name": "local cflags", "default": []} + ] + } + ] , [ "ENV" , { "type": "map_union" , "$1": diff --git a/CC/RULES b/CC/RULES index 93d5afc..3bbd68c 100644 --- a/CC/RULES +++ b/CC/RULES @@ -167,7 +167,7 @@ { "doc": ["A C++ libaray"] , "target_fields": ["srcs", "hdrs", "private-hdrs", "deps", "proto"] , "string_fields": - ["name", "stage", "pure C", "local defines", "link external"] + ["name", "stage", "pure C", "local defines", "local cflags", "link external"] , "config_vars": ["CXX", "CC", "CXXFLAGS", "CFLAGS", "ENV", "AR"] , "implicit": {"defaults": ["defaults"]} , "field_doc": @@ -192,6 +192,8 @@ [ "List of defines set for source files local to this target." , "Each list entry will be prepended by \"-D\"." ] + , "local cflags": + ["List of compile flags set for source files local to this target."] , "link external": ["Additional linker flags for linking external libraries."] , "deps": ["Any other libraries this library depends upon."] @@ -242,6 +244,7 @@ {"type": "join", "$1": ["-D", {"type": "var", "name": "def"}]} } ] + , ["local cflags", {"type": "FIELD", "name": "local cflags"}] , [ "CFLAGS" , { "type": "++" , "$1": -- cgit v1.2.3 From 3e21b4a4b41e2b93fb992e348059f13ac815f583 Mon Sep 17 00:00:00 2001 From: Oliver Reiche Date: Thu, 3 Mar 2022 13:44:26 +0100 Subject: CC rules: Disable warnings for protobuf --- CC/proto/EXPRESSIONS | 1 + 1 file changed, 1 insertion(+) diff --git a/CC/proto/EXPRESSIONS b/CC/proto/EXPRESSIONS index a98c51c..dd48744 100644 --- a/CC/proto/EXPRESSIONS +++ b/CC/proto/EXPRESSIONS @@ -294,6 +294,7 @@ , "value": {"type": "var", "name": "all proto srcs"} } ] + , ["local cflags", ["-Wno-sign-conversion", "-Wno-unused-function"]] ] , "body": {"type": "CALL_EXPRESSION", "name": "result"} } -- cgit v1.2.3 From adfcea9d9a67dca8627e9c5da9e81b03c1c83857 Mon Sep 17 00:00:00 2001 From: Klaus Aehlig Date: Fri, 4 Mar 2022 15:47:26 +0100 Subject: Add rule ["patch", "file"] ... to patch a single file, logically in place. --- EXPRESSIONS | 50 +++++++++++++++++++++++++++++++++++++++++++++ patch/RULES | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 118 insertions(+) create mode 100644 patch/RULES diff --git a/EXPRESSIONS b/EXPRESSIONS index d9b8562..8c53612 100644 --- a/EXPRESSIONS +++ b/EXPRESSIONS @@ -95,4 +95,54 @@ } } } +, "stage_artifact_to_singleton_field": + { "vars": ["artifact", "fieldname", "transition"] + , "expression": + { "type": "let*" + , "bindings": + [ [ "location" + , { "type": "++" + , "$1": + { "type": "foreach" + , "var": "src" + , "range": + {"type": "FIELD", "name": {"type": "var", "name": "fieldname"}} + , "body": + { "type": "keys" + , "$1": + { "type": "DEP_ARTIFACTS" + , "dep": {"type": "var", "name": "src"} + , "transition": + { "type": "var" + , "name": "transition" + , "default": {"type": "empty_map"} + } + } + } + } + } + ] + , [ "staged_artifact" + , { "type": "foreach_map" + , "range": {"type": "var", "name": "artifact"} + , "var_val": "val" + , "body": + { "type": "foreach" + , "range": {"type": "var", "name": "location"} + , "var": "pos" + , "body": + { "type": "singleton_map" + , "key": {"type": "var", "name": "pos"} + , "value": {"type": "var", "name": "val"} + } + } + } + ] + ] + , "body": + { "type": "disjoint_map_union" + , "$1": {"type": "++", "$1": {"type": "var", "name": "staged_artifact"}} + } + } + } } diff --git a/patch/RULES b/patch/RULES new file mode 100644 index 0000000..87bf575 --- /dev/null +++ b/patch/RULES @@ -0,0 +1,68 @@ +{ "file": + { "doc": ["Replace a file, logically in pace, by a patched version"] + , "target_fields": ["src", "patch"] + , "config_vars": ["PATCH"] + , "field_doc": + { "src": + ["The single source file to patch, typically an explict file reference."] + , "patch": ["The patch to apply."] + } + , "imports": + { "stage_field": ["./", "..", "stage_singleton_field"] + , "stage_artifact": ["./", "..", "stage_artifact_to_singleton_field"] + } + , "expression": + { "type": "let*" + , "bindings": + [ [ "orig" + , { "type": "let*" + , "bindings": [["fieldname", "src"], ["location", "orig"]] + , "body": {"type": "CALL_EXPRESSION", "name": "stage_field"} + } + ] + , [ "patch" + , { "type": "let*" + , "bindings": [["fieldname", "patch"], ["location", "patch"]] + , "body": {"type": "CALL_EXPRESSION", "name": "stage_field"} + } + ] + , [ "inputs" + , { "type": "map_union" + , "$1": + [{"type": "var", "name": "orig"}, {"type": "var", "name": "patch"}] + } + ] + , [ "patched" + , { "type": "ACTION" + , "inputs": {"type": "var", "name": "inputs"} + , "outs": ["patched"] + , "cmd": + [ {"type": "var", "name": "PATCH", "default": "patch"} + , "-s" + , "--read-only=ignore" + , "--follow-symlinks" + , "-o" + , "patched" + , "orig" + , "patch" + ] + } + ] + , [ "result" + , { "type": "let*" + , "bindings": + [ ["artifact", {"type": "var", "name": "patched"}] + , ["fieldname", "src"] + ] + , "body": {"type": "CALL_EXPRESSION", "name": "stage_artifact"} + } + ] + ] + , "body": + { "type": "RESULT" + , "artifacts": {"type": "var", "name": "result"} + , "runfiles": {"type": "var", "name": "result"} + } + } + } +} -- cgit v1.2.3 From f247b8a6fac185e47839074702f87685544c8d90 Mon Sep 17 00:00:00 2001 From: Oliver Reiche Date: Mon, 14 Mar 2022 11:29:28 +0100 Subject: rule CC/test: Introduce TEST_ENV for test runners --- CC/test/RULES | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/CC/test/RULES b/CC/test/RULES index fa6fdbc..fc3ab97 100644 --- a/CC/test/RULES +++ b/CC/test/RULES @@ -7,7 +7,7 @@ , "target_fields": ["srcs", "private-hdrs", "deps", "data"] , "string_fields": ["name", "stage"] , "config_vars": - ["CXX", "CC", "CXXFLAGS", "CFLAGS", "ENV", "CC_TEST_LAUNCHER"] + ["CXX", "CC", "CXXFLAGS", "CFLAGS", "ENV", "TEST_ENV", "CC_TEST_LAUNCHER"] , "implicit": { "defaults": [["./", "..", "defaults"]] , "proto-deps": [] @@ -37,6 +37,7 @@ [ "The flags for CXX to be used instead of the default ones" , "taken from the [\"CC\", \"defaults\"] target" ] + , "TEST_ENV": ["The environment for executing the test runner."] , "CC_TEST_LAUNCHER": [ "List of strings representing the launcher that is prepend to the" , "command line for running the test binary." @@ -250,6 +251,11 @@ , {"type": "var", "name": "CC_TEST_LAUNCHER", "default": []} ] } + , "env": + { "type": "var" + , "name": "TEST_ENV" + , "default": {"type": "empty_map"} + } , "may_fail": ["test"] , "fail_message": { "type": "join" -- cgit v1.2.3 From 72dc96845dab5a0a3b4eb4b45e762b9b2db57f22 Mon Sep 17 00:00:00 2001 From: Oliver Reiche Date: Wed, 16 Mar 2022 10:52:49 +0100 Subject: Format: Apply compact JSON formatting --- CC/RULES | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/CC/RULES b/CC/RULES index 3bbd68c..4267f96 100644 --- a/CC/RULES +++ b/CC/RULES @@ -167,7 +167,13 @@ { "doc": ["A C++ libaray"] , "target_fields": ["srcs", "hdrs", "private-hdrs", "deps", "proto"] , "string_fields": - ["name", "stage", "pure C", "local defines", "local cflags", "link external"] + [ "name" + , "stage" + , "pure C" + , "local defines" + , "local cflags" + , "link external" + ] , "config_vars": ["CXX", "CC", "CXXFLAGS", "CFLAGS", "ENV", "AR"] , "implicit": {"defaults": ["defaults"]} , "field_doc": -- cgit v1.2.3 From 2f0b97725770ca74cd96b04b7b95bd49a9069bfa Mon Sep 17 00:00:00 2001 From: Klaus Aehlig Date: Thu, 17 Mar 2022 09:44:37 +0100 Subject: Add documentation for the "proto" fields in the CC rules --- CC/RULES | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/CC/RULES b/CC/RULES index 4267f96..3cb766c 100644 --- a/CC/RULES +++ b/CC/RULES @@ -203,6 +203,13 @@ , "link external": ["Additional linker flags for linking external libraries."] , "deps": ["Any other libraries this library depends upon."] + , "proto": + [ "Any [\"proto\", \"library\"] this target depends upon directly." + , "The creation of C++ bindings for this proto library as well as of" + , "is dependencies will be taken care of (as anonymous targets, so no" + , "duplicate work will be carried out, even if the same proto library" + , "is used at various places)." + ] } , "config_doc": { "CXX": ["The name of the C++ compiler to be used."] @@ -346,6 +353,13 @@ , "link external": ["Additional linker flags for linking external libraries."] , "deps": ["Any other libraries this binary depends upon."] + , "proto": + [ "Any [\"proto\", \"library\"] this target depends upon directly." + , "The creation of C++ bindings for this proto library as well as of" + , "is dependencies will be taken care of (as anonymous targets, so no" + , "duplicate work will be carried out, even if the same proto library" + , "is used at various places)." + ] } , "config_doc": { "CXX": ["The name of the C++ compiler to be used."] -- cgit v1.2.3 From 413c9c14da147921611a16d568b29751152ed81b Mon Sep 17 00:00:00 2001 From: Oliver Reiche Date: Tue, 22 Mar 2022 12:38:08 +0100 Subject: Create IDE rule for CC targets --- CC/IDE/RULES | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ CC/proto/IDE/RULES | 63 ----------------------------------- 2 files changed, 97 insertions(+), 63 deletions(-) create mode 100644 CC/IDE/RULES delete mode 100644 CC/proto/IDE/RULES diff --git a/CC/IDE/RULES b/CC/IDE/RULES new file mode 100644 index 0000000..31da688 --- /dev/null +++ b/CC/IDE/RULES @@ -0,0 +1,97 @@ +{ "headers": + { "doc": ["Transitive public headers of C++ target"] + , "target_fields": ["proto", "deps"] + , "string_fields": ["stage"] + , "field_doc": + { "proto": ["The proto source files for creating cc bindings."] + , "deps": ["The targets to obtain the headers from."] + , "stage": + [ "The logical location of the header files. Individual directory" + , "components are joined with \"/\"." + ] + } + , "anonymous": + { "proto-deps": + { "target": "proto" + , "provider": "proto" + , "rule_map": + { "library": ["./", "../proto", "library"] + , "service library": ["./", "../proto", "service library"] + } + } + } + , "imports": {"runfiles": ["./", "../..", "field_runfiles"]} + , "expression": + { "type": "let*" + , "bindings": + [ [ "stage" + , { "type": "join" + , "separator": "/" + , "$1": {"type": "FIELD", "name": "stage"} + } + ] + , [ "artifacts" + , { "type": "to_subdir" + , "subdir": {"type": "var", "name": "stage"} + , "$1": + { "type": "map_union" + , "$1": + [ { "type": "let*" + , "bindings": [["fieldname", "proto-deps"]] + , "body": {"type": "CALL_EXPRESSION", "name": "runfiles"} + } + , { "type": "map_union" + , "$1": + { "type": "foreach" + , "var": "x" + , "range": {"type": "FIELD", "name": "proto-deps"} + , "body": + { "type": "DEP_PROVIDES" + , "provider": "compile-deps" + , "dep": {"type": "var", "name": "x"} + , "default": + { "type": "fail" + , "msg": + [ "Expected a library target, but got:" + , {"type": "var", "name": "x"} + ] + } + } + } + } + , { "type": "let*" + , "bindings": [["fieldname", "deps"]] + , "body": {"type": "CALL_EXPRESSION", "name": "runfiles"} + } + , { "type": "map_union" + , "$1": + { "type": "foreach" + , "var": "x" + , "range": {"type": "FIELD", "name": "deps"} + , "body": + { "type": "DEP_PROVIDES" + , "provider": "compile-deps" + , "dep": {"type": "var", "name": "x"} + , "default": + { "type": "fail" + , "msg": + [ "Expected a library target, but got:" + , {"type": "var", "name": "x"} + ] + } + } + } + } + ] + } + } + ] + ] + , "body": + { "type": "RESULT" + , "artifacts": {"type": "var", "name": "artifacts"} + , "runfiles": {"type": "var", "name": "artifacts"} + } + } + } +} diff --git a/CC/proto/IDE/RULES b/CC/proto/IDE/RULES deleted file mode 100644 index 558e494..0000000 --- a/CC/proto/IDE/RULES +++ /dev/null @@ -1,63 +0,0 @@ -{ "headers": - { "doc": ["Headers of C++ proto binding"] - , "target_fields": ["proto"] - , "string_fields": ["stage"] - , "field_doc": - { "proto": ["The proto source files to create the binding from."] - , "stage": - [ "The logical location of the header files. Individual directory" - , "components are joined with \"/\"." - ] - } - , "anonymous": - { "proto-deps": - { "target": "proto" - , "provider": "proto" - , "rule_map": - { "library": ["./", "..", "library"] - , "service library": ["./", "..", "service library"] - } - } - } - , "imports": {"runfiles": ["./", "../../..", "field_runfiles"]} - , "expression": - { "type": "let*" - , "bindings": - [ [ "stage" - , { "type": "join" - , "separator": "/" - , "$1": {"type": "FIELD", "name": "stage"} - } - ] - ] - , "body": - { "type": "RESULT" - , "artifacts": - { "type": "to_subdir" - , "subdir": {"type": "var", "name": "stage"} - , "$1": - { "type": "map_union" - , "$1": - [ { "type": "let*" - , "bindings": [["fieldname", "proto-deps"]] - , "body": {"type": "CALL_EXPRESSION", "name": "runfiles"} - } - , { "type": "map_union" - , "$1": - { "type": "foreach" - , "var": "x" - , "range": {"type": "FIELD", "name": "proto-deps"} - , "body": - { "type": "DEP_PROVIDES" - , "provider": "compile-deps" - , "dep": {"type": "var", "name": "x"} - } - } - } - ] - } - } - } - } - } -} -- cgit v1.2.3 From dd0a24422753a54f8f444c452db269e43242232c Mon Sep 17 00:00:00 2001 From: Klaus Aehlig Date: Wed, 30 Mar 2022 14:00:05 +0200 Subject: rules ["CC", "libray"]: fix doc strings ... to have consistent punctuation. Also make clear, that the configuration does not have to specify "CC", etc, as usually they are taken from the default target. --- CC/RULES | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/CC/RULES b/CC/RULES index 3cb766c..81140cb 100644 --- a/CC/RULES +++ b/CC/RULES @@ -178,12 +178,12 @@ , "implicit": {"defaults": ["defaults"]} , "field_doc": { "name": - ["The name of the library (without leading \"lib\" or trailing \".a\""] + ["The name of the library (without leading \"lib\" or trailing \".a\")."] , "srcs": ["The source files of the library."] , "hdrs": ["Any public header files of the library."] , "private-hdrs": [ "Any header files that only need to be present when compiling the" - , "source files, but are not needed for any consumer of the library" + , "source files, but are not needed for any consumer of the library." ] , "stage": [ "The logical location of all header and source files, as well as the" @@ -192,7 +192,8 @@ ] , "pure C": [ "If non-empty, compile as C sources rathter than C++ sources." - , "In particular, CC is used to compile rather than CXX" + , "In particular, CC is used to compile rather than CXX (or their" + , "respective defaults)." ] , "local defines": [ "List of defines set for source files local to this target." @@ -201,27 +202,37 @@ , "local cflags": ["List of compile flags set for source files local to this target."] , "link external": - ["Additional linker flags for linking external libraries."] + [ "Additional linker flags for linking external libraries (not built" + , "by this tool, typically system libraries)." + ] , "deps": ["Any other libraries this library depends upon."] , "proto": [ "Any [\"proto\", \"library\"] this target depends upon directly." , "The creation of C++ bindings for this proto library as well as of" - , "is dependencies will be taken care of (as anonymous targets, so no" + , "its dependencies will be taken care of (as anonymous targets, so no" , "duplicate work will be carried out, even if the same proto library" , "is used at various places)." ] } , "config_doc": - { "CXX": ["The name of the C++ compiler to be used."] + { "CXX": + [ "The name of the C++ compiler to be used." + , "If None, the respective value from [\"CC\", \"defaults\"] will be taken." + ] , "CC": - ["The name of the C compiler to be used (when compiling pure C code)"] - , "AR": ["The archive tool to used for creating the library"] + [ "The name of the C compiler to be used (when compiling pure C code)." + , "If None, the respective value from [\"CC\", \"defaults\"] will be taken." + ] + , "AR": + [ "The archive tool to used for creating the library" + , "If None, the respective value from [\"CC\", \"defaults\"] will be taken." + ] , "ENV": ["The environment for any action generated."] , "CXXFLAGS": [ "The flags for CXX to be used instead of the default ones." , "For libraries that should be built in a non-standard way; usually" , "adapting the default target [\"CC\", \"defaults\"] is the better" - , "choice" + , "choice." ] , "CFLAGS": [ "The flags for CC to be used instead of the default ones." -- cgit v1.2.3 From 9b38c5822c109e92a3a6c2d9a26582f9e65d3f9b Mon Sep 17 00:00:00 2001 From: Alberto Sartori Date: Thu, 7 Apr 2022 15:02:18 +0200 Subject: fix a typo --- shell/test/RULES | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/test/RULES b/shell/test/RULES index cf9713a..d61f21f 100644 --- a/shell/test/RULES +++ b/shell/test/RULES @@ -10,7 +10,7 @@ , "the test result tree in the runfiles" ] , "keep": - [ "List of names (relativ to the test working directory) of files that" + [ "List of names (relative to the test working directory) of files that" , "the test might generate that should be kept as part of the output." , "This might be useful for further analysis of the test" ] -- cgit v1.2.3 From eaf4587f032549d79400fd4de9aba7c65e6c2fa2 Mon Sep 17 00:00:00 2001 From: Klaus Aehlig Date: Fri, 22 Apr 2022 13:54:03 +0200 Subject: rule ["data", "staged"]: behave more file like ... by presenting the data both, as artifacts and as runfiles in the same way as inputs do. --- data/RULES | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/data/RULES b/data/RULES index 34bc624..17ac2d9 100644 --- a/data/RULES +++ b/data/RULES @@ -3,7 +3,7 @@ , "target_fields": ["srcs"] , "string_fields": ["stage"] , "field_doc": - { "srcs": ["The (run)files to be staged"] + { "srcs": ["The files to be staged"] , "stage": [ "The logical directory to stage the files to." , "Individual directory components are joined with \"/\"." @@ -36,7 +36,11 @@ } ] ] - , "body": {"type": "RESULT", "runfiles": {"type": "var", "name": "staged"}} + , "body": + { "type": "RESULT" + , "artifacts": {"type": "var", "name": "staged"} + , "runfiles": {"type": "var", "name": "staged"} + } } } } -- cgit v1.2.3 From a277ee4162bbe4e56b0cb7206595c4ca8416fc2c Mon Sep 17 00:00:00 2001 From: Klaus Aehlig Date: Fri, 22 Apr 2022 12:53:32 +0200 Subject: rule ["CC", "header directory"]: drop ill-advised "public stage" The idea, as documented, of a header directory is to have a directory, closed as a tree, owned by the respective library and internally handled in an efficient way (as a single tree). If we open up that directory, we just have staged data, and therefore should treat it as such. --- CC/RULES | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/CC/RULES b/CC/RULES index 81140cb..d687bf3 100644 --- a/CC/RULES +++ b/CC/RULES @@ -107,18 +107,13 @@ , "efficiently by the tool." ] , "target_fields": ["hdrs"] - , "string_fields": ["stage", "public stage"] + , "string_fields": ["stage"] , "field_doc": { "hdrs": ["The header files to be put into the header directory."] , "stage": [ "The location of the header directory." , "Path segments are joined with \"/\"." ] - , "public stage": - [ "If non-empty, no closure for the header directory's stage is created, " - , "so can be combined with other header directories having the same " - , "public staging directory." - ] } , "expression": { "type": "let*" @@ -141,18 +136,9 @@ } ] , [ "dir" - , { "type": "if" - , "cond": {"type": "FIELD", "name": "public stage"} - , "then": - { "type": "to_subdir" - , "subdir": {"type": "var", "name": "stage"} - , "$1": {"type": "var", "name": "hdrs"} - } - , "else": - { "type": "singleton_map" - , "key": {"type": "var", "name": "stage"} - , "value": {"type": "TREE", "$1": {"type": "var", "name": "hdrs"}} - } + , { "type": "singleton_map" + , "key": {"type": "var", "name": "stage"} + , "value": {"type": "TREE", "$1": {"type": "var", "name": "hdrs"}} } ] ] -- cgit v1.2.3 From cf6942ed6f8dc22209f8570faa39b3a6231f546f Mon Sep 17 00:00:00 2001 From: Klaus Aehlig Date: Fri, 22 Apr 2022 13:36:56 +0200 Subject: rules: move compiler/flags computation into expressions On the one hand, this keeps the rules files more readable. On the other hand, we can even deduplicate code, as those expressions are used twice. --- CC/EXPRESSIONS | 78 ++++++++++++++++++++++++++++++++-------------------------- CC/RULES | 39 +++-------------------------- 2 files changed, 47 insertions(+), 70 deletions(-) diff --git a/CC/EXPRESSIONS b/CC/EXPRESSIONS index 1002147..48fb4b3 100644 --- a/CC/EXPRESSIONS +++ b/CC/EXPRESSIONS @@ -311,6 +311,45 @@ } } } +, "compiler": + { "vars": ["CC", "CXX"] + , "imports": {"default-CC": "default-CC", "default-CXX": "default-CXX"} + , "expression": + { "type": "if" + , "cond": {"type": "FIELD", "name": "pure C"} + , "then": + { "type": "var" + , "name": "CC" + , "default": {"type": "CALL_EXPRESSION", "name": "default-CC"} + } + , "else": + { "type": "var" + , "name": "CXX" + , "default": {"type": "CALL_EXPRESSION", "name": "default-CXX"} + } + } + } +, "flags": + { "vars": ["CFLAGS", "CXXFLAGS"] + , "imports": + { "default-CFLAGS": "default-CFLAGS" + , "default-CXXFLAGS": "default-CXXFLAGS" + } + , "expression": + { "type": "if" + , "cond": {"type": "FIELD", "name": "pure C"} + , "then": + { "type": "var" + , "name": "CFLAGS" + , "default": {"type": "CALL_EXPRESSION", "name": "default-CFLAGS"} + } + , "else": + { "type": "var" + , "name": "CXXFLAGS" + , "default": {"type": "CALL_EXPRESSION", "name": "default-CXXFLAGS"} + } + } + } , "lib result": { "vars": [ "CXX" @@ -330,11 +369,9 @@ { "artifacts": ["./", "..", "field_artifacts"] , "compile-deps": "compile-deps" , "link-deps": "link-deps" + , "compiler": "compiler" + , "flags": "flags" , "objects": "objects" - , "default-CC": "default-CC" - , "default-CXX": "default-CXX" - , "default-CFLAGS": "default-CFLAGS" - , "default-CXXFLAGS": "default-CXXFLAGS" , "default-ENV": "default-ENV" } , "expression": @@ -346,37 +383,8 @@ , "$1": {"type": "FIELD", "name": "stage"} } ] - , [ "CXX" - , { "type": "if" - , "cond": {"type": "FIELD", "name": "pure C"} - , "then": - { "type": "var" - , "name": "CC" - , "default": {"type": "CALL_EXPRESSION", "name": "default-CC"} - } - , "else": - { "type": "var" - , "name": "CXX" - , "default": {"type": "CALL_EXPRESSION", "name": "default-CXX"} - } - } - ] - , [ "CXXFLAGS" - , { "type": "if" - , "cond": {"type": "FIELD", "name": "pure C"} - , "then": - { "type": "var" - , "name": "CFLAGS" - , "default": {"type": "CALL_EXPRESSION", "name": "default-CFLAGS"} - } - , "else": - { "type": "var" - , "name": "CXXFLAGS" - , "default": - {"type": "CALL_EXPRESSION", "name": "default-CXXFLAGS"} - } - } - ] + , ["CXX", {"type": "CALL_EXPRESSION", "name": "compiler"}] + , ["CXXFLAGS", {"type": "CALL_EXPRESSION", "name": "flags"}] , [ "CXXFLAGS" , { "type": "++" , "$1": diff --git a/CC/RULES b/CC/RULES index d687bf3..01aa634 100644 --- a/CC/RULES +++ b/CC/RULES @@ -387,10 +387,8 @@ , "compile-deps": "compile-deps" , "link-deps": "link-deps" , "objects": "objects" - , "default-CC": "default-CC" - , "default-CXX": "default-CXX" - , "default-CFLAGS": "default-CFLAGS" - , "default-CXXFLAGS": "default-CXXFLAGS" + , "compiler": "compiler" + , "flags": "flags" , "default-ENV": "default-ENV" } , "expression": @@ -430,37 +428,8 @@ } } ] - , [ "CXX" - , { "type": "if" - , "cond": {"type": "FIELD", "name": "pure C"} - , "then": - { "type": "var" - , "name": "CC" - , "default": {"type": "CALL_EXPRESSION", "name": "default-CC"} - } - , "else": - { "type": "var" - , "name": "CXX" - , "default": {"type": "CALL_EXPRESSION", "name": "default-CXX"} - } - } - ] - , [ "CXXFLAGS" - , { "type": "if" - , "cond": {"type": "FIELD", "name": "pure C"} - , "then": - { "type": "var" - , "name": "CFLAGS" - , "default": {"type": "CALL_EXPRESSION", "name": "default-CFLAGS"} - } - , "else": - { "type": "var" - , "name": "CXXFLAGS" - , "default": - {"type": "CALL_EXPRESSION", "name": "default-CXXFLAGS"} - } - } - ] + , ["CXX", {"type": "CALL_EXPRESSION", "name": "compiler"}] + , ["CXXFLAGS", {"type": "CALL_EXPRESSION", "name": "flags"}] , [ "CXXFLAGS" , { "type": "++" , "$1": -- cgit v1.2.3 From d5dfcc32ea3a024203518a3b118af127cfc5c672 Mon Sep 17 00:00:00 2001 From: Klaus Aehlig Date: Tue, 26 Apr 2022 09:34:11 +0200 Subject: Improve documenatation of our internal rules In particular, document the result for the most important rules. --- CC/RULES | 21 +++++++++++++++++++++ CC/test/RULES | 13 +++++++++++++ data/RULES | 5 +++++ patch/RULES | 3 +++ proto/RULES | 30 +++++++++++++++++++++++++++++- shell/test/RULES | 14 ++++++++++++++ 6 files changed, 85 insertions(+), 1 deletion(-) diff --git a/CC/RULES b/CC/RULES index 01aa634..cfe1ae3 100644 --- a/CC/RULES +++ b/CC/RULES @@ -115,6 +115,8 @@ , "Path segments are joined with \"/\"." ] } + , "artifacts_doc": ["The single tree artifact staged to the given location"] + , "runfiles_doc": ["Same as artifacts"] , "expression": { "type": "let*" , "bindings": @@ -227,6 +229,23 @@ , "choice" ] } + , "artifacts_doc": + ["The actual library (libname.a) staged in the specified directory"] + , "runfiles_doc": ["The public headers of this library"] + , "provides_doc": + { "compile-deps": + [ "Map of artifacts specifying any additional files that, besides the runfiles," + , "have to be present in compile actions of targets depending on this library" + ] + , "link-deps": + [ "Map of artifacts specifying any additional files that, besides the artifacts," + , "have to be present in a link actions of targets depending on this library" + ] + , "link-args": + [ "List of strings that have to be added to the command line for linking actions" + , "in targets depending on on this library" + ] + } , "anonymous": { "proto-deps": { "target": "proto" @@ -372,6 +391,8 @@ , "taken from the [\"CC\", \"defaults\"] target" ] } + , "artifacts_doc": ["The final binary, staged to the given directory"] + , "runfiles_doc": ["None"] , "anonymous": { "proto-deps": { "target": "proto" diff --git a/CC/test/RULES b/CC/test/RULES index fc3ab97..50d0dce 100644 --- a/CC/test/RULES +++ b/CC/test/RULES @@ -43,6 +43,19 @@ , "command line for running the test binary." ] } + , "artifacts_doc": + [ "result: the result of this test (\"PASS\" or \"FAIL\"); useful for" + , " generating test reports." + , "stdout/stderr: Any output the invocation of the test binary produced on" + , " the respective file descriptor" + , "time-start/time-stop: The time (decimally coded) in seconds since the" + , " epoch when the test invocation started and ended." + ] + , "runfiles_doc": + [ "A tree consisting of the artifacts staged at the name of the test." + , "As the built-in \"install\" rule only takes the runfiles of its \"deps\"" + , "argument, this gives an easy way of defining test suites." + ] , "imports": { "artifacts": ["./", "../..", "field_artifacts"] , "compile-deps": ["./", "..", "compile-deps"] diff --git a/data/RULES b/data/RULES index 17ac2d9..172fc2f 100644 --- a/data/RULES +++ b/data/RULES @@ -9,6 +9,11 @@ , "Individual directory components are joined with \"/\"." ] } + , "artifacts_doc": + [ "The runfiles of the \"srcs\" targets staged to the directory" + , "specified in \"stage\"." + ] + , "runfiles_doc": ["Same as artifacts"] , "expression": { "type": "let*" , "bindings": diff --git a/patch/RULES b/patch/RULES index 87bf575..15bc818 100644 --- a/patch/RULES +++ b/patch/RULES @@ -7,6 +7,9 @@ ["The single source file to patch, typically an explict file reference."] , "patch": ["The patch to apply."] } + , "artifacts_doc": + ["The patched file, staged to the position the of the original file"] + , "runfiles_doc": ["Same as artifacts"] , "imports": { "stage_field": ["./", "..", "stage_singleton_field"] , "stage_artifact": ["./", "..", "stage_artifact_to_singleton_field"] diff --git a/proto/RULES b/proto/RULES index b6ce000..74182a9 100644 --- a/proto/RULES +++ b/proto/RULES @@ -1,6 +1,34 @@ { "library": - { "target_fields": ["srcs", "deps"] + { "doc": + [ "A proto library as abtract data structure." + , "" + , "Such a libray does not produce any artifacts itself, but it can be" + , "used as a dependency for various language-specific rules." + ] + , "target_fields": ["srcs", "deps"] , "string_fields": ["stage", "name", "service"] + , "field_doc": + { "srcs": ["The proto files for this library"] + , "deps": ["Any other proto library this library depends on"] + , "stage": + [ "The directory to stage the source files to." + , "Directory components are joined by \"/\"." + ] + , "name": ["The name of the (abstract) library."] + , "service": + [ "If non empty, generate a service library (with acces sto \"rpc\"" + , "definitions) instead of a regular one." + ] + } + , "artifacts_doc": ["None"] + , "runfiles_doc": ["None"] + , "provides_doc": + { "proto": + [ "A list containing a single target-graph node with the defintion of" + , "this proto library. The node types generated are \"library\" and" + , "\"service library\"." + ] + } , "expression": { "type": "let*" , "bindings": diff --git a/shell/test/RULES b/shell/test/RULES index d61f21f..74a0b78 100644 --- a/shell/test/RULES +++ b/shell/test/RULES @@ -26,6 +26,20 @@ ] } , "tainted": ["test"] + , "artifacts_doc": + [ "result: the result of this test (\"PASS\" or \"FAIL\"); useful for" + , " generating test reports." + , "stdout/stderr: Any output the invocation of the test binary produced on" + , " the respective file descriptor" + , "work: In this directory, all the files specified to \"keep\" are staged" + , "time-start/time-stop: The time (decimally coded) in seconds since the" + , " epoch when the test invocation started and ended." + ] + , "runfiles_doc": + [ "A tree consisting of the artifacts staged at the name of the test." + , "As the built-in \"install\" rule only takes the runfiles of its \"deps\"" + , "argument, this gives an easy way of defining test suites." + ] , "implicit": {"runner": ["test_runner.sh"], "summarizer": ["test_summary.py"]} , "imports": -- cgit v1.2.3 From 6fa381769ea5ac3505cc202ae442eb7fee35f4ce Mon Sep 17 00:00:00 2001 From: Oliver Reiche Date: Tue, 26 Apr 2022 15:38:19 +0200 Subject: rules: More flexible compile-deps and link-deps ... which can now be parameterized which target_fields to query the dependencies from. --- CC/EXPRESSIONS | 137 ++++++++++++++++++++++++++++++--------------------------- CC/RULES | 1 + CC/test/RULES | 1 + 3 files changed, 73 insertions(+), 66 deletions(-) diff --git a/CC/EXPRESSIONS b/CC/EXPRESSIONS index 48fb4b3..efaf577 100644 --- a/CC/EXPRESSIONS +++ b/CC/EXPRESSIONS @@ -128,86 +128,90 @@ } } , "compile-deps": - { "expression": + { "doc": ["Collect compile dependencies (headers) from given target_fields"] + , "vars": ["deps-fieldnames"] + , "vars_doc": + { "deps-fieldnames": + ["List of target_field names to collect dependencies from."] + } + , "expression": { "type": "disjoint_map_union" , "$1": { "type": "++" , "$1": - [ { "type": "foreach" - , "var": "dep" - , "range": {"type": "FIELD", "name": "deps"} - , "body": - { "type": "DEP_PROVIDES" - , "dep": {"type": "var", "name": "dep"} - , "provider": "compile-deps" - , "default": {"type": "empty_map"} - } - } - , { "type": "foreach" - , "var": "dep" - , "range": {"type": "FIELD", "name": "deps"} - , "body": - {"type": "DEP_RUNFILES", "dep": {"type": "var", "name": "dep"}} - } - , { "type": "foreach" - , "var": "dep" - , "range": {"type": "FIELD", "name": "proto-deps"} - , "body": - { "type": "DEP_PROVIDES" - , "dep": {"type": "var", "name": "dep"} - , "provider": "compile-deps" - , "default": {"type": "empty_map"} - } - } - , { "type": "foreach" - , "var": "dep" - , "range": {"type": "FIELD", "name": "proto-deps"} - , "body": - {"type": "DEP_RUNFILES", "dep": {"type": "var", "name": "dep"}} + { "type": "foreach" + , "var": "fieldname" + , "range": {"type": "var", "name": "deps-fieldnames"} + , "body": + { "type": "++" + , "$1": + [ { "type": "foreach" + , "var": "target" + , "range": + {"type": "FIELD", "name": {"type": "var", "name": "fieldname"}} + , "body": + { "type": "DEP_PROVIDES" + , "dep": {"type": "var", "name": "target"} + , "provider": "compile-deps" + , "default": {"type": "empty_map"} + } + } + , { "type": "foreach" + , "var": "target" + , "range": + {"type": "FIELD", "name": {"type": "var", "name": "fieldname"}} + , "body": + { "type": "DEP_RUNFILES" + , "dep": {"type": "var", "name": "target"} + } + } + ] } - ] + } } } } , "link-deps": - { "expression": + { "doc": ["Collect link dependencies (libraries) from given target_fields"] + , "vars": ["deps-fieldnames"] + , "vars_doc": + { "deps-fieldnames": + ["List of target_field names to collect dependencies from."] + } + , "expression": { "type": "disjoint_map_union" , "$1": { "type": "++" , "$1": - [ { "type": "foreach" - , "var": "dep" - , "range": {"type": "FIELD", "name": "deps"} - , "body": - { "type": "DEP_PROVIDES" - , "dep": {"type": "var", "name": "dep"} - , "provider": "link-deps" - , "default": {"type": "empty_map"} - } - } - , { "type": "foreach" - , "var": "dep" - , "range": {"type": "FIELD", "name": "deps"} - , "body": - {"type": "DEP_ARTIFACTS", "dep": {"type": "var", "name": "dep"}} - } - , { "type": "foreach" - , "var": "dep" - , "range": {"type": "FIELD", "name": "proto-deps"} - , "body": - { "type": "DEP_PROVIDES" - , "dep": {"type": "var", "name": "dep"} - , "provider": "link-deps" - , "default": {"type": "empty_map"} - } - } - , { "type": "foreach" - , "var": "dep" - , "range": {"type": "FIELD", "name": "proto-deps"} - , "body": - {"type": "DEP_ARTIFACTS", "dep": {"type": "var", "name": "dep"}} + { "type": "foreach" + , "var": "fieldname" + , "range": {"type": "var", "name": "deps-fieldnames"} + , "body": + { "type": "++" + , "$1": + [ { "type": "foreach" + , "var": "target" + , "range": + {"type": "FIELD", "name": {"type": "var", "name": "fieldname"}} + , "body": + { "type": "DEP_PROVIDES" + , "dep": {"type": "var", "name": "target"} + , "provider": "link-deps" + , "default": {"type": "empty_map"} + } + } + , { "type": "foreach" + , "var": "target" + , "range": + {"type": "FIELD", "name": {"type": "var", "name": "fieldname"}} + , "body": + { "type": "DEP_ARTIFACTS" + , "dep": {"type": "var", "name": "target"} + } + } + ] } - ] + } } } } @@ -408,6 +412,7 @@ } } ] + , ["deps-fieldnames", ["deps", "proto-deps"]] , ["compile-deps", {"type": "CALL_EXPRESSION", "name": "compile-deps"}] , ["link-deps", {"type": "CALL_EXPRESSION", "name": "link-deps"}] , [ "local hdrs" diff --git a/CC/RULES b/CC/RULES index cfe1ae3..d1925e6 100644 --- a/CC/RULES +++ b/CC/RULES @@ -474,6 +474,7 @@ } } ] + , ["deps-fieldnames", ["deps", "proto-deps"]] , ["compile-deps", {"type": "CALL_EXPRESSION", "name": "compile-deps"}] , ["link-deps", {"type": "CALL_EXPRESSION", "name": "link-deps"}] , ["objects", {"type": "CALL_EXPRESSION", "name": "objects"}] diff --git a/CC/test/RULES b/CC/test/RULES index 50d0dce..af20510 100644 --- a/CC/test/RULES +++ b/CC/test/RULES @@ -121,6 +121,7 @@ } } ] + , ["deps-fieldnames", ["deps", "proto-deps"]] , ["compile-deps", {"type": "CALL_EXPRESSION", "name": "compile-deps"}] , ["link-deps", {"type": "CALL_EXPRESSION", "name": "link-deps"}] , ["objects", {"type": "CALL_EXPRESSION", "name": "objects"}] -- cgit v1.2.3 From 8bbb5274b2779aae44a0c4f76da8df08cf63da84 Mon Sep 17 00:00:00 2001 From: Oliver Reiche Date: Tue, 26 Apr 2022 16:51:01 +0200 Subject: rules: Add field_artifacts_list and field_runfiles_list ... which are more efficient if the caller wants to perform the union manually (because disjointness should be enforced or additional maps should be added to the union, etc.). As a positive side effect, code reuse is slightly increased by consistently calling these newly introduced expressions for obtaining the artifacts/runfiles from all targets of a target field. --- CC/EXPRESSIONS | 22 +++---------- CC/IDE/RULES | 35 ++++++++++---------- CC/RULES | 9 +++--- CC/proto/EXPRESSIONS | 19 +++++------ CC/test/RULES | 9 +++--- EXPRESSIONS | 86 +++++++++++++++++++++++++++++++------------------- data/RULES | 9 +++--- proto/RULES | 10 +++--- shell/test/EXPRESSIONS | 28 +++++++--------- 9 files changed, 110 insertions(+), 117 deletions(-) diff --git a/CC/EXPRESSIONS b/CC/EXPRESSIONS index efaf577..b7b755d 100644 --- a/CC/EXPRESSIONS +++ b/CC/EXPRESSIONS @@ -134,6 +134,7 @@ { "deps-fieldnames": ["List of target_field names to collect dependencies from."] } + , "imports": {"runfiles_list": ["./", "..", "field_runfiles_list"]} , "expression": { "type": "disjoint_map_union" , "$1": @@ -156,15 +157,7 @@ , "default": {"type": "empty_map"} } } - , { "type": "foreach" - , "var": "target" - , "range": - {"type": "FIELD", "name": {"type": "var", "name": "fieldname"}} - , "body": - { "type": "DEP_RUNFILES" - , "dep": {"type": "var", "name": "target"} - } - } + , {"type": "CALL_EXPRESSION", "name": "runfiles_list"} ] } } @@ -178,6 +171,7 @@ { "deps-fieldnames": ["List of target_field names to collect dependencies from."] } + , "imports": {"artifacts_list": ["./", "..", "field_artifacts_list"]} , "expression": { "type": "disjoint_map_union" , "$1": @@ -200,15 +194,7 @@ , "default": {"type": "empty_map"} } } - , { "type": "foreach" - , "var": "target" - , "range": - {"type": "FIELD", "name": {"type": "var", "name": "fieldname"}} - , "body": - { "type": "DEP_ARTIFACTS" - , "dep": {"type": "var", "name": "target"} - } - } + , {"type": "CALL_EXPRESSION", "name": "artifacts_list"} ] } } diff --git a/CC/IDE/RULES b/CC/IDE/RULES index 31da688..dc4b607 100644 --- a/CC/IDE/RULES +++ b/CC/IDE/RULES @@ -20,7 +20,7 @@ } } } - , "imports": {"runfiles": ["./", "../..", "field_runfiles"]} + , "imports": {"runfiles_list": ["./", "../..", "field_runfiles_list"]} , "expression": { "type": "let*" , "bindings": @@ -36,13 +36,14 @@ , "$1": { "type": "map_union" , "$1": - [ { "type": "let*" - , "bindings": [["fieldname", "proto-deps"]] - , "body": {"type": "CALL_EXPRESSION", "name": "runfiles"} - } - , { "type": "map_union" - , "$1": - { "type": "foreach" + { "type": "++" + , "$1": + [ { "type": "let*" + , "bindings": [["fieldname", "proto-deps"]] + , "body": + {"type": "CALL_EXPRESSION", "name": "runfiles_list"} + } + , { "type": "foreach" , "var": "x" , "range": {"type": "FIELD", "name": "proto-deps"} , "body": @@ -58,14 +59,12 @@ } } } - } - , { "type": "let*" - , "bindings": [["fieldname", "deps"]] - , "body": {"type": "CALL_EXPRESSION", "name": "runfiles"} - } - , { "type": "map_union" - , "$1": - { "type": "foreach" + , { "type": "let*" + , "bindings": [["fieldname", "deps"]] + , "body": + {"type": "CALL_EXPRESSION", "name": "runfiles_list"} + } + , { "type": "foreach" , "var": "x" , "range": {"type": "FIELD", "name": "deps"} , "body": @@ -81,8 +80,8 @@ } } } - } - ] + ] + } } } ] diff --git a/CC/RULES b/CC/RULES index d1925e6..0c87721 100644 --- a/CC/RULES +++ b/CC/RULES @@ -117,17 +117,16 @@ } , "artifacts_doc": ["The single tree artifact staged to the given location"] , "runfiles_doc": ["Same as artifacts"] + , "imports": {"runfiles_list": ["./", "..", "field_runfiles_list"]} , "expression": { "type": "let*" , "bindings": [ [ "hdrs" , { "type": "disjoint_map_union" , "$1": - { "type": "foreach" - , "var": "x" - , "range": {"type": "FIELD", "name": "hdrs"} - , "body": - {"type": "DEP_RUNFILES", "dep": {"type": "var", "name": "x"}} + { "type": "let*" + , "bindings": [["fieldname", "hdrs"]] + , "body": {"type": "CALL_EXPRESSION", "name": "runfiles_list"} } } ] diff --git a/CC/proto/EXPRESSIONS b/CC/proto/EXPRESSIONS index dd48744..4b08a2c 100644 --- a/CC/proto/EXPRESSIONS +++ b/CC/proto/EXPRESSIONS @@ -19,7 +19,7 @@ , "imports": { "stage": ["", "stage_singleton_field"] , "result": ["./", "..", "lib result"] - , "field_runfiles": ["", "field_runfiles"] + , "artifacts_list": ["./", "../..", "field_artifacts_list"] , "protoc-deps": "protoc-deps" } , "expression": @@ -52,11 +52,10 @@ , "$1": { "type": "disjoint_map_union" , "$1": - { "type": "foreach" - , "var": "x" - , "range": {"type": "FIELD", "name": "well_known_protos"} - , "body": - {"type": "DEP_ARTIFACTS", "dep": {"type": "var", "name": "x"}} + { "type": "let*" + , "bindings": + [["fieldname", "well_known_protos"], ["transition", null]] + , "body": {"type": "CALL_EXPRESSION", "name": "artifacts_list"} } } } @@ -65,11 +64,9 @@ , { "type": "disjoint_map_union" , "msg": "Sources may not conflict" , "$1": - { "type": "foreach" - , "var": "x" - , "range": {"type": "FIELD", "name": "srcs"} - , "body": - {"type": "DEP_ARTIFACTS", "dep": {"type": "var", "name": "x"}} + { "type": "let*" + , "bindings": [["fieldname", "srcs"], ["transition", null]] + , "body": {"type": "CALL_EXPRESSION", "name": "artifacts_list"} } } ] diff --git a/CC/test/RULES b/CC/test/RULES index af20510..3f8e236 100644 --- a/CC/test/RULES +++ b/CC/test/RULES @@ -58,6 +58,7 @@ ] , "imports": { "artifacts": ["./", "../..", "field_artifacts"] + , "runfiles_list": ["./", "../..", "field_runfiles_list"] , "compile-deps": ["./", "..", "compile-deps"] , "link-deps": ["./", "..", "link-deps"] , "objects": ["./", "..", "objects"] @@ -236,11 +237,9 @@ , { "type": "disjoint_map_union" , "msg": "Data runfiles may not conflict" , "$1": - { "type": "foreach" - , "var": "dep" - , "range": {"type": "FIELD", "name": "data"} - , "body": - {"type": "DEP_RUNFILES", "dep": {"type": "var", "name": "dep"}} + { "type": "let*" + , "bindings": [["fieldname", "data"]] + , "body": {"type": "CALL_EXPRESSION", "name": "runfiles_list"} } } ] diff --git a/EXPRESSIONS b/EXPRESSIONS index 8c53612..3251f92 100644 --- a/EXPRESSIONS +++ b/EXPRESSIONS @@ -1,43 +1,65 @@ -{ "field_artifacts": - { "vars": ["fieldname", "transition"] +{ "field_artifacts_list": + { "doc": ["Query list of artifacts from target_field's targets"] + , "vars": ["fieldname", "transition"] + , "vars_doc": + { "fieldname": "The name of the target_field to query." + , "transition": "The optional configuration transition for the targets." + } + , "expression": + { "type": "foreach" + , "var": "x" + , "range": {"type": "FIELD", "name": {"type": "var", "name": "fieldname"}} + , "body": + { "type": "DEP_ARTIFACTS" + , "dep": {"type": "var", "name": "x"} + , "transition": + {"type": "var", "name": "transition", "default": {"type": "empty_map"}} + } + } + } +, "field_artifacts": + { "doc": ["Query and merge artifacts from target_field's targets"] + , "vars": ["fieldname", "transition"] + , "vars_doc": + { "fieldname": "The name of the target_field to query." + , "transition": "The optional configuration transition for the targets." + } + , "imports": {"artifacts_list": "field_artifacts_list"} , "expression": { "type": "map_union" - , "$1": - { "type": "foreach" - , "var": "x" - , "range": - {"type": "FIELD", "name": {"type": "var", "name": "fieldname"}} - , "body": - { "type": "DEP_ARTIFACTS" - , "dep": {"type": "var", "name": "x"} - , "transition": - { "type": "var" - , "name": "transition" - , "default": {"type": "empty_map"} - } - } + , "$1": {"type": "CALL_EXPRESSION", "name": "artifacts_list"} + } + } +, "field_runfiles_list": + { "doc": ["Query list of runfiles from target_field's targets"] + , "vars": ["fieldname", "transition"] + , "vars_doc": + { "fieldname": "The name of the target_field to query." + , "transition": "The optional configuration transition for the targets." + } + , "expression": + { "type": "foreach" + , "var": "x" + , "range": {"type": "FIELD", "name": {"type": "var", "name": "fieldname"}} + , "body": + { "type": "DEP_RUNFILES" + , "dep": {"type": "var", "name": "x"} + , "transition": + {"type": "var", "name": "transition", "default": {"type": "empty_map"}} } } } , "field_runfiles": - { "vars": ["fieldname", "transition"] + { "doc": ["Query and merge runfiles from target_field's targets"] + , "vars": ["fieldname", "transition"] + , "vars_doc": + { "fieldname": "The name of the target_field to query." + , "transition": "The optional configuration transition for the targets." + } + , "imports": {"runfiles_list": "field_runfiles_list"} , "expression": { "type": "map_union" - , "$1": - { "type": "foreach" - , "var": "x" - , "range": - {"type": "FIELD", "name": {"type": "var", "name": "fieldname"}} - , "body": - { "type": "DEP_RUNFILES" - , "dep": {"type": "var", "name": "x"} - , "transition": - { "type": "var" - , "name": "transition" - , "default": {"type": "empty_map"} - } - } - } + , "$1": {"type": "CALL_EXPRESSION", "name": "runfiles_list"} } } , "action_env": diff --git a/data/RULES b/data/RULES index 172fc2f..4c695e9 100644 --- a/data/RULES +++ b/data/RULES @@ -14,6 +14,7 @@ , "specified in \"stage\"." ] , "runfiles_doc": ["Same as artifacts"] + , "imports": {"runfiles_list": ["./", "..", "field_runfiles_list"]} , "expression": { "type": "let*" , "bindings": @@ -26,11 +27,9 @@ , [ "srcs" , { "type": "disjoint_map_union" , "$1": - { "type": "foreach" - , "var": "x" - , "range": {"type": "FIELD", "name": "srcs"} - , "body": - {"type": "DEP_RUNFILES", "dep": {"type": "var", "name": "x"}} + { "type": "let*" + , "bindings": [["fieldname", "srcs"]] + , "body": {"type": "CALL_EXPRESSION", "name": "runfiles_list"} } } ] diff --git a/proto/RULES b/proto/RULES index 74182a9..5d1b853 100644 --- a/proto/RULES +++ b/proto/RULES @@ -29,6 +29,7 @@ , "\"service library\"." ] } + , "imports": {"artifacts_list": ["./", "..", "field_artifacts_list"]} , "expression": { "type": "let*" , "bindings": @@ -55,13 +56,10 @@ { "type": "disjoint_map_union" , "msg": "Sources have to be conflict free" , "$1": - { "type": "foreach" - , "var": "x" - , "range": {"type": "FIELD", "name": "srcs"} + { "type": "let*" + , "bindings": [["fieldname", "srcs"]] , "body": - { "type": "DEP_ARTIFACTS" - , "dep": {"type": "var", "name": "x"} - } + {"type": "CALL_EXPRESSION", "name": "artifacts_list"} } } } diff --git a/shell/test/EXPRESSIONS b/shell/test/EXPRESSIONS index 2b9a62e..2a99876 100644 --- a/shell/test/EXPRESSIONS +++ b/shell/test/EXPRESSIONS @@ -1,5 +1,9 @@ { "test-action": { "vars": ["name", "test.sh", "ATTEMPT"] + , "imports": + { "artifacts_list": ["./", "../..", "field_artifacts_list"] + , "runfiles_list": ["./", "../..", "field_runfiles_list"] + } , "expression": { "type": "let*" , "bindings": @@ -39,23 +43,13 @@ , "$1": { "type": "++" , "$1": - [ { "type": "foreach" - , "var": "dep" - , "range": {"type": "FIELD", "name": "deps"} - , "body": - { "type": "DEP_RUNFILES" - , "dep": {"type": "var", "name": "dep"} - } - } - , { "type": "foreach" - , "var": "dep" - , "range": {"type": "FIELD", "name": "deps"} - , "body": - { "type": "DEP_ARTIFACTS" - , "dep": {"type": "var", "name": "dep"} - } - } - ] + { "type": "let*" + , "bindings": [["fieldname", "deps"]] + , "body": + [ {"type": "CALL_EXPRESSION", "name": "runfiles_list"} + , {"type": "CALL_EXPRESSION", "name": "artifacts_list"} + ] + } } } } -- cgit v1.2.3 From 6929477049c34c34627c6bba82b35f33c3c84fa0 Mon Sep 17 00:00:00 2001 From: Oliver Reiche Date: Wed, 27 Apr 2022 18:37:21 +0200 Subject: rules: Fix field_artifacts/field_runfiles expressions' docs --- EXPRESSIONS | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/EXPRESSIONS b/EXPRESSIONS index 3251f92..8ead00f 100644 --- a/EXPRESSIONS +++ b/EXPRESSIONS @@ -2,8 +2,8 @@ { "doc": ["Query list of artifacts from target_field's targets"] , "vars": ["fieldname", "transition"] , "vars_doc": - { "fieldname": "The name of the target_field to query." - , "transition": "The optional configuration transition for the targets." + { "fieldname": ["The name of the target_field to query."] + , "transition": ["The optional configuration transition for the targets."] } , "expression": { "type": "foreach" @@ -21,8 +21,8 @@ { "doc": ["Query and merge artifacts from target_field's targets"] , "vars": ["fieldname", "transition"] , "vars_doc": - { "fieldname": "The name of the target_field to query." - , "transition": "The optional configuration transition for the targets." + { "fieldname": ["The name of the target_field to query."] + , "transition": ["The optional configuration transition for the targets."] } , "imports": {"artifacts_list": "field_artifacts_list"} , "expression": @@ -34,8 +34,8 @@ { "doc": ["Query list of runfiles from target_field's targets"] , "vars": ["fieldname", "transition"] , "vars_doc": - { "fieldname": "The name of the target_field to query." - , "transition": "The optional configuration transition for the targets." + { "fieldname": ["The name of the target_field to query."] + , "transition": ["The optional configuration transition for the targets."] } , "expression": { "type": "foreach" @@ -53,8 +53,8 @@ { "doc": ["Query and merge runfiles from target_field's targets"] , "vars": ["fieldname", "transition"] , "vars_doc": - { "fieldname": "The name of the target_field to query." - , "transition": "The optional configuration transition for the targets." + { "fieldname": ["The name of the target_field to query."] + , "transition": ["The optional configuration transition for the targets."] } , "imports": {"runfiles_list": "field_runfiles_list"} , "expression": -- cgit v1.2.3 From 076dd3cdebb6b8662eb1c716261a78b83cb74e0c Mon Sep 17 00:00:00 2001 From: Oliver Reiche Date: Tue, 26 Apr 2022 11:47:35 +0200 Subject: rules: Add "field_map_provider" and "field_list_provider" ... to query and merge map/list entries from the provides map of the given target_fields' targets. --- EXPRESSIONS | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/EXPRESSIONS b/EXPRESSIONS index 8ead00f..e725606 100644 --- a/EXPRESSIONS +++ b/EXPRESSIONS @@ -62,6 +62,59 @@ , "$1": {"type": "CALL_EXPRESSION", "name": "runfiles_list"} } } +, "field_provider_list": + { "doc": ["Query list of providers from targets' provides map"] + , "vars": ["fieldname", "provider", "transition", "default"] + , "vars_doc": + { "fieldname": ["The name of the target_field to query."] + , "provider": ["The name of the map provider in the provides map."] + , "transition": ["The optional configuration transition for the targets."] + , "default": ["The default if the provider was not found (default: [])."] + } + , "expression": + { "type": "foreach" + , "var": "x" + , "range": {"type": "FIELD", "name": {"type": "var", "name": "fieldname"}} + , "body": + { "type": "DEP_PROVIDES" + , "dep": {"type": "var", "name": "x"} + , "provider": {"type": "var", "name": "provider"} + , "transition": + {"type": "var", "name": "transition", "default": {"type": "empty_map"}} + , "default": {"type": "var", "name": "default", "default": []} + } + } + } +, "field_map_provider": + { "doc": ["Query and merge map-providers from targets' provides map"] + , "vars": ["fieldname", "provider", "transition"] + , "vars_doc": + { "fieldname": ["The name of the target_field to query."] + , "provider": ["The name of the map provider in the provides map."] + , "transition": ["The optional configuration transition for the targets."] + } + , "imports": {"provider_list": "field_provider_list"} + , "expression": + { "type": "map_union" + , "$1": + { "type": "let*" + , "bindings": [["default", {"type": "empty_map"}]] + , "body": {"type": "CALL_EXPRESSION", "name": "provider_list"} + } + } + } +, "field_list_provider": + { "doc": ["Query and merge list-providers from targets' provides map"] + , "vars": ["fieldname", "provider", "transition"] + , "vars_doc": + { "fieldname": ["The name of the target_field to query."] + , "provider": ["The name of the list provider in the provides map."] + , "transition": ["The optional configuration transition for the targets."] + } + , "imports": {"provider_list": "field_provider_list"} + , "expression": + {"type": "++", "$1": {"type": "CALL_EXPRESSION", "name": "provider_list"}} + } , "action_env": { "vars": ["ENV"] , "expression": -- cgit v1.2.3 From cd368bef62abce503c6be6f124f1ac53f15cc4e2 Mon Sep 17 00:00:00 2001 From: Oliver Reiche Date: Wed, 27 Apr 2022 18:39:32 +0200 Subject: rules: Honor transition variable in *-deps expressions --- CC/EXPRESSIONS | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CC/EXPRESSIONS b/CC/EXPRESSIONS index b7b755d..23c28d7 100644 --- a/CC/EXPRESSIONS +++ b/CC/EXPRESSIONS @@ -129,10 +129,11 @@ } , "compile-deps": { "doc": ["Collect compile dependencies (headers) from given target_fields"] - , "vars": ["deps-fieldnames"] + , "vars": ["deps-fieldnames", "transition"] , "vars_doc": { "deps-fieldnames": ["List of target_field names to collect dependencies from."] + , "transition": ["The optional configuration transition for the targets."] } , "imports": {"runfiles_list": ["./", "..", "field_runfiles_list"]} , "expression": @@ -166,10 +167,11 @@ } , "link-deps": { "doc": ["Collect link dependencies (libraries) from given target_fields"] - , "vars": ["deps-fieldnames"] + , "vars": ["deps-fieldnames", "transition"] , "vars_doc": { "deps-fieldnames": ["List of target_field names to collect dependencies from."] + , "transition": ["The optional configuration transition for the targets."] } , "imports": {"artifacts_list": ["./", "..", "field_artifacts_list"]} , "expression": -- cgit v1.2.3 From d2fa5912a44a30602e6a4b14cdb99402a4e72a42 Mon Sep 17 00:00:00 2001 From: Oliver Reiche Date: Wed, 27 Apr 2022 13:18:53 +0200 Subject: rules: Add "link-args-deps" expression ... for collecting link-args from dependencies. By consistently using this expression, we fix an issue with C++ binary and test, which both did not collect the linker arguments from their proto-deps. --- CC/EXPRESSIONS | 49 +++++++++++++++++++++++++------------------------ CC/RULES | 14 ++------------ CC/test/RULES | 14 ++------------ 3 files changed, 29 insertions(+), 48 deletions(-) diff --git a/CC/EXPRESSIONS b/CC/EXPRESSIONS index 23c28d7..6fa222b 100644 --- a/CC/EXPRESSIONS +++ b/CC/EXPRESSIONS @@ -203,6 +203,29 @@ } } } +, "link-args-deps": + { "doc": ["Collect linker arguments from given target_fields"] + , "vars": ["deps-fieldnames", "transition"] + , "vars_doc": + { "deps-fieldnames": + ["List of target_field names to collect arguments from."] + , "transition": ["The optional configuration transition for the targets."] + } + , "imports": {"list_provider": ["./", "..", "field_list_provider"]} + , "expression": + { "type": "++" + , "$1": + { "type": "foreach" + , "var": "fieldname" + , "range": {"type": "var", "name": "deps-fieldnames"} + , "body": + { "type": "let*" + , "bindings": [["provider", "link-args"]] + , "body": {"type": "CALL_EXPRESSION", "name": "list_provider"} + } + } + } + } , "objects": { "vars": ["CXX", "CXXFLAGS", "ENV", "srcs", "compile-deps", "local hdrs"] , "expression": @@ -361,6 +384,7 @@ { "artifacts": ["./", "..", "field_artifacts"] , "compile-deps": "compile-deps" , "link-deps": "link-deps" + , "link-args-deps": "link-args-deps" , "compiler": "compiler" , "flags": "flags" , "objects": "objects" @@ -453,30 +477,7 @@ { "type": "++" , "$1": [ {"type": "keys", "$1": {"type": "var", "name": "lib"}} - , { "type": "++" - , "$1": - { "type": "foreach" - , "var": "dep" - , "range": {"type": "FIELD", "name": "deps"} - , "body": - { "type": "DEP_PROVIDES" - , "dep": {"type": "var", "name": "dep"} - , "provider": "link-args" - } - } - } - , { "type": "++" - , "$1": - { "type": "foreach" - , "var": "dep" - , "range": {"type": "FIELD", "name": "proto-deps"} - , "body": - { "type": "DEP_PROVIDES" - , "dep": {"type": "var", "name": "dep"} - , "provider": "link-args" - } - } - } + , {"type": "CALL_EXPRESSION", "name": "link-args-deps"} , {"type": "var", "name": "link external", "default": []} ] } diff --git a/CC/RULES b/CC/RULES index 0c87721..cb13f98 100644 --- a/CC/RULES +++ b/CC/RULES @@ -406,6 +406,7 @@ { "artifacts": ["./", "..", "field_artifacts"] , "compile-deps": "compile-deps" , "link-deps": "link-deps" + , "link-args-deps": "link-args-deps" , "objects": "objects" , "compiler": "compiler" , "flags": "flags" @@ -500,18 +501,7 @@ { "type": "++" , "$1": [ {"type": "keys", "$1": {"type": "var", "name": "objects"}} - , { "type": "++" - , "$1": - { "type": "foreach" - , "var": "dep" - , "range": {"type": "FIELD", "name": "deps"} - , "body": - { "type": "DEP_PROVIDES" - , "dep": {"type": "var", "name": "dep"} - , "provider": "link-args" - } - } - } + , {"type": "CALL_EXPRESSION", "name": "link-args-deps"} , {"type": "FIELD", "name": "link external"} ] } diff --git a/CC/test/RULES b/CC/test/RULES index 3f8e236..93d7706 100644 --- a/CC/test/RULES +++ b/CC/test/RULES @@ -61,6 +61,7 @@ , "runfiles_list": ["./", "../..", "field_runfiles_list"] , "compile-deps": ["./", "..", "compile-deps"] , "link-deps": ["./", "..", "link-deps"] + , "link-args-deps": ["./", "..", "link-args-deps"] , "objects": ["./", "..", "objects"] , "default-CXX": ["./", "..", "default-CXX"] , "default-CXXFLAGS": ["./", "..", "default-CXXFLAGS"] @@ -152,18 +153,7 @@ { "type": "++" , "$1": [ {"type": "keys", "$1": {"type": "var", "name": "objects"}} - , { "type": "++" - , "$1": - { "type": "foreach" - , "var": "dep" - , "range": {"type": "FIELD", "name": "deps"} - , "body": - { "type": "DEP_PROVIDES" - , "dep": {"type": "var", "name": "dep"} - , "provider": "link-args" - } - } - } + , {"type": "CALL_EXPRESSION", "name": "link-args-deps"} ] } } -- cgit v1.2.3 From 124d53937a088813a95317fcd535acc0cf69024a Mon Sep 17 00:00:00 2001 From: Oliver Reiche Date: Wed, 27 Apr 2022 12:52:07 +0200 Subject: rules: Consistently use new provider expressions --- CC/EXPRESSIONS | 140 ++++++++++++++++++++------------------------------- CC/proto/EXPRESSIONS | 19 ++++--- proto/RULES | 19 +++---- 3 files changed, 71 insertions(+), 107 deletions(-) diff --git a/CC/EXPRESSIONS b/CC/EXPRESSIONS index 6fa222b..5025339 100644 --- a/CC/EXPRESSIONS +++ b/CC/EXPRESSIONS @@ -1,79 +1,51 @@ { "default-CC": - { "expression": + { "imports": {"list_provider": ["./", "..", "field_list_provider"]} + , "expression": { "type": "join" , "$1": - { "type": "++" - , "$1": - { "type": "foreach" - , "var": "x" - , "range": {"type": "FIELD", "name": "defaults"} - , "body": - { "type": "DEP_PROVIDES" - , "provider": "CC" - , "dep": {"type": "var", "name": "x"} - } - } + { "type": "let*" + , "bindings": [["fieldname", "defaults"], ["provider", "CC"]] + , "body": {"type": "CALL_EXPRESSION", "name": "list_provider"} } } } , "default-CXX": - { "expression": + { "imports": {"list_provider": ["./", "..", "field_list_provider"]} + , "expression": { "type": "join" , "$1": - { "type": "++" - , "$1": - { "type": "foreach" - , "var": "x" - , "range": {"type": "FIELD", "name": "defaults"} - , "body": - { "type": "DEP_PROVIDES" - , "provider": "CXX" - , "dep": {"type": "var", "name": "x"} - } - } + { "type": "let*" + , "bindings": [["fieldname", "defaults"], ["provider", "CXX"]] + , "body": {"type": "CALL_EXPRESSION", "name": "list_provider"} } } } , "default-CFLAGS": - { "expression": - { "type": "++" - , "$1": - { "type": "foreach" - , "var": "x" - , "range": {"type": "FIELD", "name": "defaults"} - , "body": - { "type": "DEP_PROVIDES" - , "provider": "CFLAGS" - , "dep": {"type": "var", "name": "x"} - } - } + { "imports": {"list_provider": ["./", "..", "field_list_provider"]} + , "expression": + { "type": "let*" + , "bindings": [["fieldname", "defaults"], ["provider", "CFLAGS"]] + , "body": {"type": "CALL_EXPRESSION", "name": "list_provider"} } } , "default-CXXFLAGS": - { "expression": - { "type": "++" - , "$1": - { "type": "foreach" - , "var": "x" - , "range": {"type": "FIELD", "name": "defaults"} - , "body": - { "type": "DEP_PROVIDES" - , "provider": "CXXFLAGS" - , "dep": {"type": "var", "name": "x"} - } - } + { "imports": {"list_provider": ["./", "..", "field_list_provider"]} + , "expression": + { "type": "let*" + , "bindings": [["fieldname", "defaults"], ["provider", "CXXFLAGS"]] + , "body": {"type": "CALL_EXPRESSION", "name": "list_provider"} } } , "default-ENV": - { "expression": - { "type": "foreach" - , "var": "x" - , "range": {"type": "FIELD", "name": "defaults"} - , "body": - { "type": "DEP_PROVIDES" - , "provider": "ENV" - , "dep": {"type": "var", "name": "x"} - } + { "imports": {"provider_list": ["./", "..", "field_provider_list"]} + , "expression": + { "type": "let*" + , "bindings": + [ ["fieldname", "defaults"] + , ["provider", "ENV"] + , ["default", {"type": "empty_map"}] + ] + , "body": {"type": "CALL_EXPRESSION", "name": "provider_list"} } } , "configure transition": @@ -135,7 +107,10 @@ ["List of target_field names to collect dependencies from."] , "transition": ["The optional configuration transition for the targets."] } - , "imports": {"runfiles_list": ["./", "..", "field_runfiles_list"]} + , "imports": + { "runfiles_list": ["./", "..", "field_runfiles_list"] + , "provider_list": ["./", "..", "field_provider_list"] + } , "expression": { "type": "disjoint_map_union" , "$1": @@ -147,19 +122,16 @@ , "body": { "type": "++" , "$1": - [ { "type": "foreach" - , "var": "target" - , "range": - {"type": "FIELD", "name": {"type": "var", "name": "fieldname"}} - , "body": - { "type": "DEP_PROVIDES" - , "dep": {"type": "var", "name": "target"} - , "provider": "compile-deps" - , "default": {"type": "empty_map"} - } - } - , {"type": "CALL_EXPRESSION", "name": "runfiles_list"} - ] + { "type": "let*" + , "bindings": + [ ["provider", "compile-deps"] + , ["default", {"type": "empty_map"}] + ] + , "body": + [ {"type": "CALL_EXPRESSION", "name": "provider_list"} + , {"type": "CALL_EXPRESSION", "name": "runfiles_list"} + ] + } } } } @@ -173,7 +145,10 @@ ["List of target_field names to collect dependencies from."] , "transition": ["The optional configuration transition for the targets."] } - , "imports": {"artifacts_list": ["./", "..", "field_artifacts_list"]} + , "imports": + { "artifacts_list": ["./", "..", "field_artifacts_list"] + , "provider_list": ["./", "..", "field_provider_list"] + } , "expression": { "type": "disjoint_map_union" , "$1": @@ -185,19 +160,14 @@ , "body": { "type": "++" , "$1": - [ { "type": "foreach" - , "var": "target" - , "range": - {"type": "FIELD", "name": {"type": "var", "name": "fieldname"}} - , "body": - { "type": "DEP_PROVIDES" - , "dep": {"type": "var", "name": "target"} - , "provider": "link-deps" - , "default": {"type": "empty_map"} - } - } - , {"type": "CALL_EXPRESSION", "name": "artifacts_list"} - ] + { "type": "let*" + , "bindings": + [["provider", "link-deps"], ["default", {"type": "empty_map"}]] + , "body": + [ {"type": "CALL_EXPRESSION", "name": "provider_list"} + , {"type": "CALL_EXPRESSION", "name": "artifacts_list"} + ] + } } } } diff --git a/CC/proto/EXPRESSIONS b/CC/proto/EXPRESSIONS index 4b08a2c..cb7d8a2 100644 --- a/CC/proto/EXPRESSIONS +++ b/CC/proto/EXPRESSIONS @@ -1,16 +1,15 @@ { "protoc-deps": - { "expression": + { "imports": {"provider_list": ["./", "../..", "field_provider_list"]} + , "expression": { "type": "disjoint_map_union" , "$1": - { "type": "foreach" - , "var": "dep" - , "range": {"type": "FIELD", "name": "deps"} - , "body": - { "type": "DEP_PROVIDES" - , "dep": {"type": "var", "name": "dep"} - , "provider": "protoc-deps" - , "default": {"type": "empty_map"} - } + { "type": "let*" + , "bindings": + [ ["fieldname", "deps"] + , ["provider", "protoc-deps"] + , ["default", {"type": "empty_map"}] + ] + , "body": {"type": "CALL_EXPRESSION", "name": "provider_list"} } } } diff --git a/proto/RULES b/proto/RULES index 5d1b853..9c7c1a2 100644 --- a/proto/RULES +++ b/proto/RULES @@ -29,7 +29,10 @@ , "\"service library\"." ] } - , "imports": {"artifacts_list": ["./", "..", "field_artifacts_list"]} + , "imports": + { "artifacts_list": ["./", "..", "field_artifacts_list"] + , "list_provider": ["./", "..", "field_list_provider"] + } , "expression": { "type": "let*" , "bindings": @@ -68,17 +71,9 @@ ] ] , [ "deps" - , { "type": "++" - , "$1": - { "type": "foreach" - , "var": "x" - , "range": {"type": "FIELD", "name": "deps"} - , "body": - { "type": "DEP_PROVIDES" - , "dep": {"type": "var", "name": "x"} - , "provider": "proto" - } - } + , { "type": "let*" + , "bindings": [["fieldname", "deps"], ["provider", "proto"]] + , "body": {"type": "CALL_EXPRESSION", "name": "list_provider"} } ] , [ "node" -- cgit v1.2.3 From 71e53e4c05201e97717e5fef24c6e5ce5eda980c Mon Sep 17 00:00:00 2001 From: Oliver Reiche Date: Fri, 29 Apr 2022 13:59:30 +0200 Subject: rules: Perform disjoint map union in field_* expressions ... and replace all instances where the field_*_list variant of those expressions is used solely for the purpose of performing the disjoint union manually. --- CC/RULES | 11 ++++------- CC/proto/EXPRESSIONS | 27 +++++++++------------------ EXPRESSIONS | 8 ++++++-- data/RULES | 11 ++++------- 4 files changed, 23 insertions(+), 34 deletions(-) diff --git a/CC/RULES b/CC/RULES index cb13f98..0e9a694 100644 --- a/CC/RULES +++ b/CC/RULES @@ -117,17 +117,14 @@ } , "artifacts_doc": ["The single tree artifact staged to the given location"] , "runfiles_doc": ["Same as artifacts"] - , "imports": {"runfiles_list": ["./", "..", "field_runfiles_list"]} + , "imports": {"runfiles": ["./", "..", "field_runfiles"]} , "expression": { "type": "let*" , "bindings": [ [ "hdrs" - , { "type": "disjoint_map_union" - , "$1": - { "type": "let*" - , "bindings": [["fieldname", "hdrs"]] - , "body": {"type": "CALL_EXPRESSION", "name": "runfiles_list"} - } + , { "type": "let*" + , "bindings": [["fieldname", "hdrs"]] + , "body": {"type": "CALL_EXPRESSION", "name": "runfiles"} } ] , [ "stage" diff --git a/CC/proto/EXPRESSIONS b/CC/proto/EXPRESSIONS index cb7d8a2..4f807fe 100644 --- a/CC/proto/EXPRESSIONS +++ b/CC/proto/EXPRESSIONS @@ -1,16 +1,9 @@ { "protoc-deps": - { "imports": {"provider_list": ["./", "../..", "field_provider_list"]} + { "imports": {"map_provider": ["./", "../..", "field_map_provider"]} , "expression": - { "type": "disjoint_map_union" - , "$1": - { "type": "let*" - , "bindings": - [ ["fieldname", "deps"] - , ["provider", "protoc-deps"] - , ["default", {"type": "empty_map"}] - ] - , "body": {"type": "CALL_EXPRESSION", "name": "provider_list"} - } + { "type": "let*" + , "bindings": [["fieldname", "deps"], ["provider", "protoc-deps"]] + , "body": {"type": "CALL_EXPRESSION", "name": "map_provider"} } } , "protoc-compile": @@ -18,6 +11,7 @@ , "imports": { "stage": ["", "stage_singleton_field"] , "result": ["./", "..", "lib result"] + , "artifacts": ["./", "../..", "field_artifacts"] , "artifacts_list": ["./", "../..", "field_artifacts_list"] , "protoc-deps": "protoc-deps" } @@ -49,13 +43,10 @@ , { "type": "to_subdir" , "subdir": "work" , "$1": - { "type": "disjoint_map_union" - , "$1": - { "type": "let*" - , "bindings": - [["fieldname", "well_known_protos"], ["transition", null]] - , "body": {"type": "CALL_EXPRESSION", "name": "artifacts_list"} - } + { "type": "let*" + , "bindings": + [["fieldname", "well_known_protos"], ["transition", null]] + , "body": {"type": "CALL_EXPRESSION", "name": "artifacts"} } } ] diff --git a/EXPRESSIONS b/EXPRESSIONS index e725606..1c2ff84 100644 --- a/EXPRESSIONS +++ b/EXPRESSIONS @@ -26,7 +26,8 @@ } , "imports": {"artifacts_list": "field_artifacts_list"} , "expression": - { "type": "map_union" + { "type": "disjoint_map_union" + , "msg": "artifacts must not overlap" , "$1": {"type": "CALL_EXPRESSION", "name": "artifacts_list"} } } @@ -59,6 +60,7 @@ , "imports": {"runfiles_list": "field_runfiles_list"} , "expression": { "type": "map_union" + , "msg": "runfiles must not overlap" , "$1": {"type": "CALL_EXPRESSION", "name": "runfiles_list"} } } @@ -95,7 +97,9 @@ } , "imports": {"provider_list": "field_provider_list"} , "expression": - { "type": "map_union" + { "type": "disjoint_map_union" + , "msg": + ["Overlapping entries in provider", {"type": "var", "name": "provider"}] , "$1": { "type": "let*" , "bindings": [["default", {"type": "empty_map"}]] diff --git a/data/RULES b/data/RULES index 4c695e9..df6acce 100644 --- a/data/RULES +++ b/data/RULES @@ -14,7 +14,7 @@ , "specified in \"stage\"." ] , "runfiles_doc": ["Same as artifacts"] - , "imports": {"runfiles_list": ["./", "..", "field_runfiles_list"]} + , "imports": {"runfiles": ["./", "..", "field_runfiles"]} , "expression": { "type": "let*" , "bindings": @@ -25,12 +25,9 @@ } ] , [ "srcs" - , { "type": "disjoint_map_union" - , "$1": - { "type": "let*" - , "bindings": [["fieldname", "srcs"]] - , "body": {"type": "CALL_EXPRESSION", "name": "runfiles_list"} - } + , { "type": "let*" + , "bindings": [["fieldname", "srcs"]] + , "body": {"type": "CALL_EXPRESSION", "name": "runfiles"} } ] , [ "staged" -- cgit v1.2.3 From 326601fdcad8635625e7a706a5426652a4c1de78 Mon Sep 17 00:00:00 2001 From: Klaus Aehlig Date: Mon, 2 May 2022 12:38:00 +0200 Subject: Expression ['', 'field_runfiles']: ensure disjointness ... by using "disjoint_map_union" instead of "map_union" which has a latest-wins semantics and does not have a "msg" arguement. --- EXPRESSIONS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EXPRESSIONS b/EXPRESSIONS index 1c2ff84..f40e5a3 100644 --- a/EXPRESSIONS +++ b/EXPRESSIONS @@ -59,7 +59,7 @@ } , "imports": {"runfiles_list": "field_runfiles_list"} , "expression": - { "type": "map_union" + { "type": "disjoint_map_union" , "msg": "runfiles must not overlap" , "$1": {"type": "CALL_EXPRESSION", "name": "runfiles_list"} } -- cgit v1.2.3 From b49842343371d1b0c99c3abf438a2490e1be372e Mon Sep 17 00:00:00 2001 From: Klaus Aehlig Date: Mon, 2 May 2022 16:58:16 +0200 Subject: rules/CC: for compiler invocation, pass on ENV ... as some compiler need access to the environemnt in order to find their utility programs (like cc1). --- CC/EXPRESSIONS | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CC/EXPRESSIONS b/CC/EXPRESSIONS index 5025339..3c1fa33 100644 --- a/CC/EXPRESSIONS +++ b/CC/EXPRESSIONS @@ -263,6 +263,11 @@ , { "type": "ACTION" , "outs": [{"type": "var", "name": "work out"}] , "inputs": {"type": "var", "name": "inputs"} + , "env": + { "type": "var" + , "name": "ENV" + , "default": {"type": "empty_map"} + } , "cmd": { "type": "++" , "$1": @@ -422,6 +427,8 @@ { "type": "ACTION" , "outs": [{"type": "var", "name": "libname"}] , "inputs": {"type": "var", "name": "objects"} + , "env": + {"type": "var", "name": "ENV", "default": {"type": "empty_map"}} , "cmd": { "type": "++" , "$1": -- cgit v1.2.3 From 7990e2dd1c3cfd99d216afd91b638a0e12156de2 Mon Sep 17 00:00:00 2001 From: Klaus Aehlig Date: Thu, 12 May 2022 14:18:24 +0200 Subject: ["data", "staged"] Allow direct dependencies Add a "deps" field to ["data", "staged"] from which the runfiles also added, without being staged, e.g., another ["data", "staged"] target, possibly with a different stage. This allows convenient collection of files, logically put to different directories. --- data/RULES | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/data/RULES b/data/RULES index df6acce..02f8e11 100644 --- a/data/RULES +++ b/data/RULES @@ -1,6 +1,6 @@ { "staged": { "doc": ["Stage data to a logical subdirectory."] - , "target_fields": ["srcs"] + , "target_fields": ["srcs", "deps"] , "string_fields": ["stage"] , "field_doc": { "srcs": ["The files to be staged"] @@ -8,10 +8,15 @@ [ "The logical directory to stage the files to." , "Individual directory components are joined with \"/\"." ] + , "deps": + [ "Targets of with their runfiles should be added as well." + , "Their staging is not changed." + ] } , "artifacts_doc": [ "The runfiles of the \"srcs\" targets staged to the directory" - , "specified in \"stage\"." + , "specified in \"stage\" together the runfiles of the targets" + , "specied in the field \"deps\" (in their original location)." ] , "runfiles_doc": ["Same as artifacts"] , "imports": {"runfiles": ["./", "..", "field_runfiles"]} @@ -36,11 +41,26 @@ , "$1": {"type": "var", "name": "srcs"} } ] + , [ "dep stage" + , { "type": "let*" + , "bindings": [["fieldname", "deps"]] + , "body": {"type": "CALL_EXPRESSION", "name": "runfiles"} + } + ] + , [ "total" + , { "type": "disjoint_map_union" + , "msg": "Conflict between staged data and dependencies" + , "$1": + [ {"type": "var", "name": "dep stage"} + , {"type": "var", "name": "staged"} + ] + } + ] ] , "body": { "type": "RESULT" - , "artifacts": {"type": "var", "name": "staged"} - , "runfiles": {"type": "var", "name": "staged"} + , "artifacts": {"type": "var", "name": "total"} + , "runfiles": {"type": "var", "name": "total"} } } } -- cgit v1.2.3 From b9d0a59e7832f87431efb377e760773a075a4bfd Mon Sep 17 00:00:00 2001 From: Oliver Reiche Date: Thu, 2 Jun 2022 16:47:11 +0200 Subject: Add rule defaults --- CC/TARGETS | 10 ++++++++++ CC/test/TARGETS | 1 + shell/test/TARGETS | 1 + 3 files changed, 12 insertions(+) create mode 100644 CC/TARGETS create mode 100644 CC/test/TARGETS create mode 100644 shell/test/TARGETS diff --git a/CC/TARGETS b/CC/TARGETS new file mode 100644 index 0000000..2da456b --- /dev/null +++ b/CC/TARGETS @@ -0,0 +1,10 @@ +{ "defaults": + { "type": ["CC", "defaults"] + , "CC": ["cc"] + , "CXX": ["c++"] + , "CFLAGS": [] + , "CXXFLAGS": [] + , "AR": ["ar"] + , "PATH": ["/bin", "/usr/bin"] + } +} diff --git a/CC/test/TARGETS b/CC/test/TARGETS new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/CC/test/TARGETS @@ -0,0 +1 @@ +{} diff --git a/shell/test/TARGETS b/shell/test/TARGETS new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/shell/test/TARGETS @@ -0,0 +1 @@ +{} -- cgit v1.2.3 From 816db9ca82bbcc5c953a5f6449d6768941749888 Mon Sep 17 00:00:00 2001 From: Oliver Reiche Date: Tue, 7 Jun 2022 12:37:22 +0200 Subject: rules: Support TEST_ENV for shell/test script --- shell/test/EXPRESSIONS | 9 +++++++-- shell/test/RULES | 3 ++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/shell/test/EXPRESSIONS b/shell/test/EXPRESSIONS index 2a99876..6d163f3 100644 --- a/shell/test/EXPRESSIONS +++ b/shell/test/EXPRESSIONS @@ -1,5 +1,5 @@ { "test-action": - { "vars": ["name", "test.sh", "ATTEMPT"] + { "vars": ["name", "test.sh", "ATTEMPT", "TEST_ENV"] , "imports": { "artifacts_list": ["./", "../..", "field_artifacts_list"] , "runfiles_list": ["./", "../..", "field_runfiles_list"] @@ -103,6 +103,9 @@ , "$1": [["./runner"], {"type": "FIELD", "name": "keep"}] } ] + , [ "test_env" + , {"type": "var", "name": "TEST_ENV", "default": {"type": "empty_map"}} + ] ] , "body": { "type": "if" @@ -113,6 +116,7 @@ , "outs": {"type": "var", "name": "outs"} , "inputs": {"type": "var", "name": "inputs"} , "cmd": {"type": "var", "name": "cmd"} + , "env": {"type": "var", "name": "test_env"} , "may_fail": ["test"] , "fail_message": { "type": "join" @@ -124,6 +128,7 @@ , "outs": {"type": "var", "name": "outs"} , "inputs": {"type": "var", "name": "inputs"} , "cmd": {"type": "var", "name": "cmd"} + , "env": {"type": "var", "name": "test_env"} , "may_fail": ["test"] , "no_cache": ["test"] , "fail_message": @@ -141,7 +146,7 @@ } } , "test-result": - { "vars": ["name", "test.sh"] + { "vars": ["name", "test.sh", "TEST_ENV"] , "imports": {"action": "test-action"} , "expression": { "type": "let*" diff --git a/shell/test/RULES b/shell/test/RULES index 74a0b78..c4beec4 100644 --- a/shell/test/RULES +++ b/shell/test/RULES @@ -2,7 +2,7 @@ { "doc": ["Shell test, given by a test script"] , "target_fields": ["deps", "test"] , "string_fields": ["keep", "name"] - , "config_vars": ["RUNS_PER_TEST"] + , "config_vars": ["RUNS_PER_TEST", "TEST_ENV"] , "field_doc": { "test": ["The shell script for the test, launched with sh"] , "name": @@ -24,6 +24,7 @@ [ "The number of times the test should be run in order to detect flakyness." , "If set, no test action will be taken from cache." ] + , "TEST_ENV": ["The environment for executing the test runner."] } , "tainted": ["test"] , "artifacts_doc": -- cgit v1.2.3 From c130ef42628648b15824a3ab8514972603cbc3c4 Mon Sep 17 00:00:00 2001 From: Paul Cristian Sarbu Date: Thu, 23 Jun 2022 13:07:09 +0200 Subject: Upd rules doc on writable directories available to test runners --- shell/test/RULES | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/shell/test/RULES b/shell/test/RULES index c4beec4..4242d94 100644 --- a/shell/test/RULES +++ b/shell/test/RULES @@ -4,7 +4,15 @@ , "string_fields": ["keep", "name"] , "config_vars": ["RUNS_PER_TEST", "TEST_ENV"] , "field_doc": - { "test": ["The shell script for the test, launched with sh"] + { "test": + [ "The shell script for the test, launched with sh." + , "" + , "An empty directory is created to store any temporary files needed" + , "by the test, and it is made available in the environment variable" + , "TEST_TMPDIR. The test should not assume write permissions" + , "outside the working directory and the TEST_TMPDIR." + , "For convenience, the environment variable TMPDIR is also set to TEST_TMPDIR." + ] , "name": [ "A name for the test, used in reporting, as well as for staging" , "the test result tree in the runfiles" -- cgit v1.2.3 From 3da82010cea24fb8ed41ff88c5d8df8e086c5aa4 Mon Sep 17 00:00:00 2001 From: Oliver Reiche Date: Thu, 30 Jun 2022 16:42:29 +0200 Subject: Rules: Split library result and library artifact expression --- CC/EXPRESSIONS | 49 +++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 10 deletions(-) diff --git a/CC/EXPRESSIONS b/CC/EXPRESSIONS index 3c1fa33..b551787 100644 --- a/CC/EXPRESSIONS +++ b/CC/EXPRESSIONS @@ -340,7 +340,7 @@ } } } -, "lib result": +, "lib artifact": { "vars": [ "CXX" , "CXXFLAGS" @@ -352,15 +352,10 @@ , "hdrs" , "private-hdrs" , "local cflags" - , "link external" - , "extra-provides" + , "compile-deps" ] , "imports": - { "artifacts": ["./", "..", "field_artifacts"] - , "compile-deps": "compile-deps" - , "link-deps": "link-deps" - , "link-args-deps": "link-args-deps" - , "compiler": "compiler" + { "compiler": "compiler" , "flags": "flags" , "objects": "objects" , "default-ENV": "default-ENV" @@ -400,8 +395,6 @@ } ] , ["deps-fieldnames", ["deps", "proto-deps"]] - , ["compile-deps", {"type": "CALL_EXPRESSION", "name": "compile-deps"}] - , ["link-deps", {"type": "CALL_EXPRESSION", "name": "link-deps"}] , [ "local hdrs" , { "type": "disjoint_map_union" , "$1": @@ -448,6 +441,42 @@ , "$1": {"type": "var", "name": "lib"} } ] + ] + , "body": + { "type": "to_subdir" + , "subdir": {"type": "var", "name": "stage"} + , "$1": {"type": "var", "name": "lib"} + } + } + } +, "lib result": + { "vars": + [ "CXX" + , "CXXFLAGS" + , "CC" + , "CFLAGS" + , "ENV" + , "AR" + , "srcs" + , "hdrs" + , "private-hdrs" + , "local cflags" + , "link external" + , "extra-provides" + ] + , "imports": + { "compile-deps": "compile-deps" + , "link-deps": "link-deps" + , "link-args-deps": "link-args-deps" + , "lib artifact": "lib artifact" + } + , "expression": + { "type": "let*" + , "bindings": + [ ["deps-fieldnames", ["deps", "proto-deps"]] + , ["compile-deps", {"type": "CALL_EXPRESSION", "name": "compile-deps"}] + , ["link-deps", {"type": "CALL_EXPRESSION", "name": "link-deps"}] + , ["lib", {"type": "CALL_EXPRESSION", "name": "lib artifact"}] , [ "link-args" , { "type": "nub_right" , "$1": -- cgit v1.2.3 From d6ade68bc52d56467abdd7aee70c108902f4f0b2 Mon Sep 17 00:00:00 2001 From: Oliver Reiche Date: Thu, 21 Jul 2022 15:07:44 +0200 Subject: Rules: Enforce non-empty library and binary names --- CC/EXPRESSIONS | 18 +++++++++++++++++- CC/RULES | 5 ++++- CC/test/RULES | 2 +- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/CC/EXPRESSIONS b/CC/EXPRESSIONS index b551787..462d219 100644 --- a/CC/EXPRESSIONS +++ b/CC/EXPRESSIONS @@ -405,7 +405,23 @@ ] , ["objects", {"type": "CALL_EXPRESSION", "name": "objects"}] , [ "base name" - , {"type": "join", "$1": {"type": "FIELD", "name": "name"}} + , { "type": "let*" + , "bindings": + [ [ "name" + , {"type": "join", "$1": {"type": "FIELD", "name": "name"}} + ] + ] + , "body": + { "type": "if" + , "cond": {"type": "var", "name": "objects"} + , "then": + { "type": "assert_non_empty" + , "msg": "A name has to be provided for non-header-only libraries" + , "$1": {"type": "var", "name": "name"} + } + , "else": {"type": "var", "name": "name"} + } + } ] , [ "libname" , { "type": "join" diff --git a/CC/RULES b/CC/RULES index 0e9a694..c2c7202 100644 --- a/CC/RULES +++ b/CC/RULES @@ -476,7 +476,10 @@ , ["link-deps", {"type": "CALL_EXPRESSION", "name": "link-deps"}] , ["objects", {"type": "CALL_EXPRESSION", "name": "objects"}] , [ "base name" - , {"type": "join", "$1": {"type": "FIELD", "name": "name"}} + , { "type": "assert_non_empty" + , "msg": "A non-empty name has to be provided for binaries" + , "$1": {"type": "join", "$1": {"type": "FIELD", "name": "name"}} + } ] , [ "binary name" , { "type": "if" diff --git a/CC/test/RULES b/CC/test/RULES index 93d7706..f3175d4 100644 --- a/CC/test/RULES +++ b/CC/test/RULES @@ -129,7 +129,7 @@ , ["objects", {"type": "CALL_EXPRESSION", "name": "objects"}] , [ "base name" , { "type": "assert_non_empty" - , "msg": "A non-empy name has to be provided" + , "msg": "A non-empty name has to be provided" , "$1": {"type": "join", "$1": {"type": "FIELD", "name": "name"}} } ] -- cgit v1.2.3 From 25652f25b59a34012ae7c13bd733b8674a194f8b Mon Sep 17 00:00:00 2001 From: Klaus Aehlig Date: Thu, 14 Jul 2022 17:08:17 +0200 Subject: CC rules: keep dependencies last in linking ... as the external link dependency is still associated with this library. In this way, importing preinstalled libraries can happen in a sound way, even though the actual library is just an external link dependency; still dependencies among external libraries are honored. --- CC/EXPRESSIONS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CC/EXPRESSIONS b/CC/EXPRESSIONS index 462d219..ac57b67 100644 --- a/CC/EXPRESSIONS +++ b/CC/EXPRESSIONS @@ -499,8 +499,8 @@ { "type": "++" , "$1": [ {"type": "keys", "$1": {"type": "var", "name": "lib"}} - , {"type": "CALL_EXPRESSION", "name": "link-args-deps"} , {"type": "var", "name": "link external", "default": []} + , {"type": "CALL_EXPRESSION", "name": "link-args-deps"} ] } } -- cgit v1.2.3 From 0f17e13bc60643d8e6807d6f5a4fffd9bf927b2b Mon Sep 17 00:00:00 2001 From: Oliver Reiche Date: Thu, 4 Aug 2022 15:24:42 +0200 Subject: rules: Extend patch rule to split parts from patch --- patch/RULES | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) diff --git a/patch/RULES b/patch/RULES index 15bc818..ab5f102 100644 --- a/patch/RULES +++ b/patch/RULES @@ -1,11 +1,17 @@ { "file": - { "doc": ["Replace a file, logically in pace, by a patched version"] + { "doc": ["Replace a file, logically in place, by a patched version"] , "target_fields": ["src", "patch"] + , "string_fields": ["patch-part"] , "config_vars": ["PATCH"] , "field_doc": { "src": ["The single source file to patch, typically an explict file reference."] , "patch": ["The patch to apply."] + , "patch-part": + [ "If the patch contains hunks for multiple files, only apply hunks for" + , "the specified file path. Individual directory components are joined" + , "with \"/\". Note that the patch must be provided in unified format." + ] } , "artifacts_doc": ["The patched file, staged to the position the of the original file"] @@ -29,6 +35,66 @@ , "body": {"type": "CALL_EXPRESSION", "name": "stage_field"} } ] + , [ "patch-part" + , { "type": "join" + , "separator": "\\/" + , "$1": {"type": "FIELD", "name": "patch-part"} + } + ] + , [ "splitpatch" + , { "type": "BLOB" + , "data": + { "type": "join" + , "separator": "\n" + , "$1": + [ "set -e" + , { "type": "join" + , "$1": + [ { "type": "join_cmd" + , "$1": + [ "sed" + , "-n" + , { "type": "join" + , "$1": + [ "/^--- " + , {"type": "var", "name": "patch-part"} + , "/," + , "/^[^-+@\\ ]\\|^---\\ /p" + ] + } + ] + } + , " $1 | sed '$d' > patch" + ] + } + ] + } + } + ] + , [ "patch" + , { "type": "if" + , "cond": {"type": "var", "name": "patch-part"} + , "then": + { "type": "ACTION" + , "inputs": + { "type": "map_union" + , "$1": + [ { "type": "to_subdir" + , "subdir": "in" + , "$1": {"type": "var", "name": "patch"} + } + , { "type": "singleton_map" + , "key": "splitpatch" + , "value": {"type": "var", "name": "splitpatch"} + } + ] + } + , "outs": ["patch"] + , "cmd": ["sh", "./splitpatch", "in/patch"] + } + , "else": {"type": "var", "name": "patch"} + } + ] , [ "inputs" , { "type": "map_union" , "$1": -- cgit v1.2.3 From 107c91837e33cfa014991fddf3a784039d9f804d Mon Sep 17 00:00:00 2001 From: Alberto Sartori Date: Thu, 11 Aug 2022 15:24:50 +0200 Subject: rules/CC: fix duplicated staging for library --- CC/EXPRESSIONS | 6 ------ 1 file changed, 6 deletions(-) diff --git a/CC/EXPRESSIONS b/CC/EXPRESSIONS index ac57b67..9e83937 100644 --- a/CC/EXPRESSIONS +++ b/CC/EXPRESSIONS @@ -451,12 +451,6 @@ } } ] - , [ "lib" - , { "type": "to_subdir" - , "subdir": {"type": "var", "name": "stage"} - , "$1": {"type": "var", "name": "lib"} - } - ] ] , "body": { "type": "to_subdir" -- cgit v1.2.3 From 8d810e663ff4995bbceb1f16e1fb02387d76b68f Mon Sep 17 00:00:00 2001 From: Klaus Aehlig Date: Mon, 22 Aug 2022 12:29:58 +0200 Subject: Add a rule to overlay artifact maps ... in a latest-wins fashion. The intended use case is overlaying globs with individual patched files. --- data/RULES | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/data/RULES b/data/RULES index 02f8e11..99c8e5c 100644 --- a/data/RULES +++ b/data/RULES @@ -64,4 +64,37 @@ } } } +, "overlay": + { "doc": + ["Overlay the artifacts of \"deps\" targets in a latest-wins fashion."] + , "target_fields": ["deps"] + , "field_doc": {"deps": ["The targets of which to overlay the artifacts"]} + , "artifacts_doc": + [ "Artifacts of the targets specified in \"deps\". For conflicting" + , "logical paths, the artifact is taken from the latest target (in" + , "the \"deps\" field) that defines that logical path" + ] + , "runfiles_doc": ["Same as artifacts"] + , "expression": + { "type": "let*" + , "bindings": + [ [ "all" + , { "type": "map_union" + , "$1": + { "type": "foreach" + , "var": "dep" + , "range": {"type": "FIELD", "name": "deps"} + , "body": + {"type": "DEP_ARTIFACTS", "dep": {"type": "var", "name": "dep"}} + } + } + ] + ] + , "body": + { "type": "RESULT" + , "artifacts": {"type": "var", "name": "all"} + , "runfiles": {"type": "var", "name": "all"} + } + } + } } -- cgit v1.2.3 From de4f1edc350636e4e2cde14ef1adda8716d394f6 Mon Sep 17 00:00:00 2001 From: Oliver Reiche Date: Fri, 26 Aug 2022 12:05:18 +0200 Subject: Rules: Extend configure rule by 'compiler_family' --- CC/EXPRESSIONS | 17 ++++++++++++++++- CC/RULES | 7 ++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/CC/EXPRESSIONS b/CC/EXPRESSIONS index 9e83937..d04591f 100644 --- a/CC/EXPRESSIONS +++ b/CC/EXPRESSIONS @@ -49,7 +49,8 @@ } } , "configure transition": - { "expression": + { "vars": ["COMPILER_FAMILY"] + , "expression": { "type": "let*" , "bindings": [ [ "OS" @@ -75,6 +76,16 @@ , "else": {"type": "var", "name": "ARCH"} } ] + , [ "FAMILY" + , {"type": "join", "$1": {"type": "FIELD", "name": "compiler_family"}} + ] + , [ "COMPILER_FAMILY" + , { "type": "if" + , "cond": {"type": "var", "name": "FAMILY"} + , "then": {"type": "var", "name": "FAMILY"} + , "else": {"type": "var", "name": "COMPILER_FAMILY"} + } + ] ] , "body": { "type": "map_union" @@ -95,6 +106,10 @@ , "key": "TARGET_ARCH" , "value": {"type": "var", "name": "TARGET_ARCH"} } + , { "type": "singleton_map" + , "key": "COMPILER_FAMILY" + , "value": {"type": "var", "name": "COMPILER_FAMILY"} + } ] } } diff --git a/CC/RULES b/CC/RULES index c2c7202..099a629 100644 --- a/CC/RULES +++ b/CC/RULES @@ -54,8 +54,9 @@ , "The artifacts and runfiles of the specified target will be propagated." , "The target defined by this rule does not propagate any provides data." ] - , "config_fields": ["os", "arch", "target_arch"] + , "config_fields": ["os", "arch", "target_arch", "compiler_family"] , "target_fields": ["target"] + , "config_vars": ["COMPILER_FAMILY"] , "field_doc": { "os": ["The operation system used for building."] , "arch": ["The architecture used for building."] @@ -63,6 +64,10 @@ [ "Non-mandatory target architecture to build for. If omitted, target" , "architecture is derived from \"arch\"." ] + , "compiler_family": + [ "Non-mandatory compiler family used for building. If omitted, compiler" + , "family is taken from variable \"COMPILER_FAMILY\"." + ] , "target": [ "The target to configure. Multiple targets are supported, but their" , "artifacts and runfiles should not conflict." -- cgit v1.2.3 From 3e4e38f6987d7435232b175fd0070608b76b4d50 Mon Sep 17 00:00:00 2001 From: Oliver Reiche Date: Wed, 24 Aug 2022 18:23:37 +0200 Subject: Rules: Implement hierarchical defaults --- CC/EXPRESSIONS | 23 +++++++++ CC/RULES | 134 ++++++++++++++++++++++++++++++++++++++++++--------- CC/proto/EXPRESSIONS | 3 +- 3 files changed, 135 insertions(+), 25 deletions(-) diff --git a/CC/EXPRESSIONS b/CC/EXPRESSIONS index d04591f..7ebc8ad 100644 --- a/CC/EXPRESSIONS +++ b/CC/EXPRESSIONS @@ -48,6 +48,29 @@ , "body": {"type": "CALL_EXPRESSION", "name": "provider_list"} } } +, "defaults-base-provides": + { "doc": ["Query list-provider from 'base' targets (last wins)"] + , "vars": ["provider"] + , "vars_doc": + {"provider": ["The name of the list-provider in the provides map."]} + , "imports": {"provider_list": ["./", "..", "field_provider_list"]} + , "expression": + { "type": "let*" + , "bindings": [["fieldname", "base"]] + , "body": + { "type": "foldl" + , "var": "next" + , "accum_var": "curr" + , "range": {"type": "CALL_EXPRESSION", "name": "provider_list"} + , "body": + { "type": "if" + , "cond": {"type": "var", "name": "next"} + , "then": {"type": "var", "name": "next"} + , "else": {"type": "var", "name": "curr"} + } + } + } + } , "configure transition": { "vars": ["COMPILER_FAMILY"] , "expression": diff --git a/CC/RULES b/CC/RULES index 099a629..d4a85b7 100644 --- a/CC/RULES +++ b/CC/RULES @@ -6,45 +6,131 @@ , "use of this rule. As targets form a different root, the defaults" , "can be provided without changing this directory." ] - , "string_fields": ["CC", "CXX", "CFLAGS", "CXXFLAGS", "PATH", "AR"] + , "target_fields": ["base"] + , "string_fields": + [ "CC" + , "CXX" + , "CFLAGS" + , "CXXFLAGS" + , "ADD_CFLAGS" + , "ADD_CXXFLAGS" + , "PATH" + , "AR" + ] + , "imports": {"base-provides": "defaults-base-provides"} , "expression": - { "type": "RESULT" - , "provides": - { "type": "map_union" - , "$1": - [ { "type": "singleton_map" - , "key": "CC" - , "value": {"type": "FIELD", "name": "CC"} + { "type": "let*" + , "bindings": + [ ["CC", {"type": "FIELD", "name": "CC"}] + , ["CXX", {"type": "FIELD", "name": "CXX"}] + , ["CFLAGS", {"type": "FIELD", "name": "CFLAGS"}] + , ["CXXFLAGS", {"type": "FIELD", "name": "CXXFLAGS"}] + , ["AR", {"type": "FIELD", "name": "AR"}] + , ["PATH", {"type": "FIELD", "name": "PATH"}] + , ["provider", "CC"] + , [ "CC" + , { "type": "if" + , "cond": {"type": "var", "name": "CC"} + , "then": {"type": "var", "name": "CC"} + , "else": {"type": "CALL_EXPRESSION", "name": "base-provides"} } - , { "type": "singleton_map" - , "key": "CXX" - , "value": {"type": "FIELD", "name": "CXX"} + ] + , ["provider", "CXX"] + , [ "CXX" + , { "type": "if" + , "cond": {"type": "var", "name": "CXX"} + , "then": {"type": "var", "name": "CXX"} + , "else": {"type": "CALL_EXPRESSION", "name": "base-provides"} } - , { "type": "singleton_map" - , "key": "CFLAGS" - , "value": {"type": "FIELD", "name": "CFLAGS"} + ] + , ["provider", "CFLAGS"] + , [ "CFLAGS" + , { "type": "if" + , "cond": {"type": "var", "name": "CFLAGS"} + , "then": {"type": "var", "name": "CFLAGS"} + , "else": {"type": "CALL_EXPRESSION", "name": "base-provides"} } - , { "type": "singleton_map" - , "key": "CXXFLAGS" - , "value": {"type": "FIELD", "name": "CXXFLAGS"} + ] + , ["provider", "CXXFLAGS"] + , [ "CXXFLAGS" + , { "type": "if" + , "cond": {"type": "var", "name": "CXXFLAGS"} + , "then": {"type": "var", "name": "CXXFLAGS"} + , "else": {"type": "CALL_EXPRESSION", "name": "base-provides"} } - , { "type": "singleton_map" - , "key": "AR" - , "value": {"type": "FIELD", "name": "AR"} + ] + , ["provider", "AR"] + , [ "AR" + , { "type": "if" + , "cond": {"type": "var", "name": "AR"} + , "then": {"type": "var", "name": "AR"} + , "else": {"type": "CALL_EXPRESSION", "name": "base-provides"} } - , { "type": "singleton_map" - , "key": "ENV" - , "value": + ] + , ["provider", "ENV"] + , [ "ENV" + , { "type": "if" + , "cond": {"type": "var", "name": "PATH"} + , "then": { "type": "singleton_map" , "key": "PATH" , "value": { "type": "join" , "separator": ":" - , "$1": {"type": "FIELD", "name": "PATH"} + , "$1": {"type": "var", "name": "PATH"} } } + , "else": {"type": "CALL_EXPRESSION", "name": "base-provides"} } ] + , [ "CFLAGS" + , { "type": "++" + , "$1": + [ {"type": "var", "name": "CFLAGS"} + , {"type": "FIELD", "name": "ADD_CFLAGS"} + ] + } + ] + , [ "CXXFLAGS" + , { "type": "++" + , "$1": + [ {"type": "var", "name": "CXXFLAGS"} + , {"type": "FIELD", "name": "ADD_CXXFLAGS"} + ] + } + ] + ] + , "body": + { "type": "RESULT" + , "provides": + { "type": "map_union" + , "$1": + [ { "type": "singleton_map" + , "key": "CC" + , "value": {"type": "var", "name": "CC"} + } + , { "type": "singleton_map" + , "key": "CXX" + , "value": {"type": "var", "name": "CXX"} + } + , { "type": "singleton_map" + , "key": "CFLAGS" + , "value": {"type": "var", "name": "CFLAGS"} + } + , { "type": "singleton_map" + , "key": "CXXFLAGS" + , "value": {"type": "var", "name": "CXXFLAGS"} + } + , { "type": "singleton_map" + , "key": "AR" + , "value": {"type": "var", "name": "AR"} + } + , { "type": "singleton_map" + , "key": "ENV" + , "value": {"type": "var", "name": "ENV"} + } + ] + } } } } diff --git a/CC/proto/EXPRESSIONS b/CC/proto/EXPRESSIONS index 4f807fe..ac0018a 100644 --- a/CC/proto/EXPRESSIONS +++ b/CC/proto/EXPRESSIONS @@ -7,7 +7,8 @@ } } , "protoc-compile": - { "vars": ["transition", "service support"] + { "vars": + ["transition", "service support", "CXX", "CXXFLAGS", "ADD_CXXFLAGS"] , "imports": { "stage": ["", "stage_singleton_field"] , "result": ["./", "..", "lib result"] -- cgit v1.2.3 From 7ccfae885273899d42c0ea6059fc6910e72aedbb Mon Sep 17 00:00:00 2001 From: Oliver Reiche Date: Thu, 25 Aug 2022 12:17:26 +0200 Subject: Rules: Implement setting ADD_{C,CXX}FLAGS via variables --- CC/EXPRESSIONS | 28 +++++++++++++++++++++------- CC/RULES | 35 +++++++++++++++++++++++++++++++++-- CC/proto/RULES | 26 ++++++++++++++++++++++++-- CC/test/RULES | 24 +++++++++++++++++++++++- 4 files changed, 101 insertions(+), 12 deletions(-) diff --git a/CC/EXPRESSIONS b/CC/EXPRESSIONS index 7ebc8ad..a1033d9 100644 --- a/CC/EXPRESSIONS +++ b/CC/EXPRESSIONS @@ -358,7 +358,7 @@ } } , "flags": - { "vars": ["CFLAGS", "CXXFLAGS"] + { "vars": ["CFLAGS", "CXXFLAGS", "ADD_CFLAGS", "ADD_CXXFLAGS"] , "imports": { "default-CFLAGS": "default-CFLAGS" , "default-CXXFLAGS": "default-CXXFLAGS" @@ -367,14 +367,24 @@ { "type": "if" , "cond": {"type": "FIELD", "name": "pure C"} , "then": - { "type": "var" - , "name": "CFLAGS" - , "default": {"type": "CALL_EXPRESSION", "name": "default-CFLAGS"} + { "type": "++" + , "$1": + [ { "type": "var" + , "name": "CFLAGS" + , "default": {"type": "CALL_EXPRESSION", "name": "default-CFLAGS"} + } + , {"type": "var", "name": "ADD_CFLAGS", "default": []} + ] } , "else": - { "type": "var" - , "name": "CXXFLAGS" - , "default": {"type": "CALL_EXPRESSION", "name": "default-CXXFLAGS"} + { "type": "++" + , "$1": + [ { "type": "var" + , "name": "CXXFLAGS" + , "default": {"type": "CALL_EXPRESSION", "name": "default-CXXFLAGS"} + } + , {"type": "var", "name": "ADD_CXXFLAGS", "default": []} + ] } } } @@ -382,8 +392,10 @@ { "vars": [ "CXX" , "CXXFLAGS" + , "ADD_CXXFLAGS" , "CC" , "CFLAGS" + , "ADD_CFLAGS" , "ENV" , "AR" , "srcs" @@ -501,8 +513,10 @@ { "vars": [ "CXX" , "CXXFLAGS" + , "ADD_CXXFLAGS" , "CC" , "CFLAGS" + , "ADD_CFLAGS" , "ENV" , "AR" , "srcs" diff --git a/CC/RULES b/CC/RULES index d4a85b7..44bdabc 100644 --- a/CC/RULES +++ b/CC/RULES @@ -249,7 +249,16 @@ , "local cflags" , "link external" ] - , "config_vars": ["CXX", "CC", "CXXFLAGS", "CFLAGS", "ENV", "AR"] + , "config_vars": + [ "CXX" + , "CC" + , "CXXFLAGS" + , "CFLAGS" + , "ADD_CXXFLAGS" + , "ADD_CFLAGS" + , "ENV" + , "AR" + ] , "implicit": {"defaults": ["defaults"]} , "field_doc": { "name": @@ -315,6 +324,18 @@ , "adapting the default target [\"CC\", \"defaults\"] is the better" , "choice" ] + , "ADD_CXXFLAGS": + [ "The flags to add to the default ones for CXX." + , "For libraries that should be built in a non-standard way; usually" + , "adapting the default target [\"CC\", \"defaults\"] is the better" + , "choice." + ] + , "ADD_CFLAGS": + [ "The flags to add to the default ones for CC." + , "For libraries that should be built in a non-standard way; usually" + , "adapting the default target [\"CC\", \"defaults\"] is the better" + , "choice." + ] } , "artifacts_doc": ["The actual library (libname.a) staged in the specified directory"] @@ -431,7 +452,8 @@ , "target_fields": ["srcs", "private-hdrs", "deps", "proto"] , "string_fields": ["name", "stage", "pure C", "local defines", "link external"] - , "config_vars": ["CXX", "CC", "CXXFLAGS", "CFLAGS", "ENV"] + , "config_vars": + ["CXX", "CC", "CXXFLAGS", "CFLAGS", "ADD_CXXFLAGS", "ADD_CFLAGS", "ENV"] , "implicit": {"defaults": ["defaults"]} , "field_doc": { "name": ["The name of the binary"] @@ -477,6 +499,14 @@ [ "The flags for CXX to be used instead of the default ones" , "taken from the [\"CC\", \"defaults\"] target" ] + , "ADD_CXXFLAGS": + [ "The flags to add to the default ones for CXX" + , "taken from the [\"CC\", \"defaults\"] target" + ] + , "ADD_CFLAGS": + [ "The flags to add to the default ones for CC" + , "taken from the [\"CC\", \"defaults\"] target" + ] } , "artifacts_doc": ["The final binary, staged to the given directory"] , "runfiles_doc": ["None"] @@ -615,6 +645,7 @@ , "-o" , {"type": "var", "name": "binary name"} ] + , {"type": "var", "name": "CXXFLAGS"} , {"type": "var", "name": "link-args"} ] } diff --git a/CC/proto/RULES b/CC/proto/RULES index 04082c1..a4579e7 100644 --- a/CC/proto/RULES +++ b/CC/proto/RULES @@ -8,7 +8,18 @@ , "string_fields": ["name", "stage"] , "target_fields": ["srcs", "deps"] , "config_vars": - ["OS", "ARCH", "HOST_ARCH", "CXX", "CC", "CXXFLAGS", "CFLAGS", "ENV", "AR"] + [ "OS" + , "ARCH" + , "HOST_ARCH" + , "CXX" + , "CC" + , "CXXFLAGS" + , "CFLAGS" + , "ADD_CXXFLAGS" + , "ADD_CFLAGS" + , "ENV" + , "AR" + ] , "implicit": { "protoc": [["@", "protoc", "", "protoc"]] , "defaults": [["./", "..", "defaults"]] @@ -39,7 +50,18 @@ , "string_fields": ["name", "stage"] , "target_fields": ["srcs", "deps"] , "config_vars": - ["OS", "ARCH", "HOST_ARCH", "CXX", "CC", "CXXFLAGS", "CFLAGS", "ENV", "AR"] + [ "OS" + , "ARCH" + , "HOST_ARCH" + , "CXX" + , "CC" + , "CXXFLAGS" + , "CFLAGS" + , "ADD_CXXFLAGS" + , "ADD_CFLAGS" + , "ENV" + , "AR" + ] , "implicit": { "protoc": [["@", "protoc", "", "protoc"]] , "grpc_cpp_plugin": [["@", "grpc", "src/compiler", "grpc_cpp_plugin"]] diff --git a/CC/test/RULES b/CC/test/RULES index f3175d4..8082047 100644 --- a/CC/test/RULES +++ b/CC/test/RULES @@ -7,7 +7,16 @@ , "target_fields": ["srcs", "private-hdrs", "deps", "data"] , "string_fields": ["name", "stage"] , "config_vars": - ["CXX", "CC", "CXXFLAGS", "CFLAGS", "ENV", "TEST_ENV", "CC_TEST_LAUNCHER"] + [ "CXX" + , "CC" + , "CXXFLAGS" + , "CFLAGS" + , "ADD_CXXFLAGS" + , "ADD_CFLAGS" + , "ENV" + , "TEST_ENV" + , "CC_TEST_LAUNCHER" + ] , "implicit": { "defaults": [["./", "..", "defaults"]] , "proto-deps": [] @@ -32,11 +41,24 @@ } , "config_doc": { "CXX": ["The name of the C++ compiler to be used."] + , "CC": ["The name of the C compiler to be used."] , "ENV": ["The environment for any action generated."] , "CXXFLAGS": [ "The flags for CXX to be used instead of the default ones" , "taken from the [\"CC\", \"defaults\"] target" ] + , "CFLAGS": + [ "The flags for CC to be used instead of the default ones" + , "taken from the [\"CC\", \"defaults\"] target" + ] + , "ADD_CXXFLAGS": + [ "The flags to add to the default ones for CXX" + , "taken from the [\"CC\", \"defaults\"] target" + ] + , "ADD_CFLAGS": + [ "The flags to add to the default ones for CC" + , "taken from the [\"CC\", \"defaults\"] target" + ] , "TEST_ENV": ["The environment for executing the test runner."] , "CC_TEST_LAUNCHER": [ "List of strings representing the launcher that is prepend to the" -- cgit v1.2.3 From 8e6921348385bfe649ad5dacc6f23f08eddc0f3c Mon Sep 17 00:00:00 2001 From: Oliver Reiche Date: Wed, 14 Sep 2022 15:32:00 +0200 Subject: rules: Fix ar binary not taken from defaults --- CC/EXPRESSIONS | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/CC/EXPRESSIONS b/CC/EXPRESSIONS index a1033d9..2cf5957 100644 --- a/CC/EXPRESSIONS +++ b/CC/EXPRESSIONS @@ -20,6 +20,17 @@ } } } +, "default-AR": + { "imports": {"list_provider": ["./", "..", "field_list_provider"]} + , "expression": + { "type": "join" + , "$1": + { "type": "let*" + , "bindings": [["fieldname", "defaults"], ["provider", "AR"]] + , "body": {"type": "CALL_EXPRESSION", "name": "list_provider"} + } + } + } , "default-CFLAGS": { "imports": {"list_provider": ["./", "..", "field_list_provider"]} , "expression": @@ -408,6 +419,7 @@ { "compiler": "compiler" , "flags": "flags" , "objects": "objects" + , "default-AR": "default-AR" , "default-ENV": "default-ENV" } , "expression": @@ -421,6 +433,7 @@ ] , ["CXX", {"type": "CALL_EXPRESSION", "name": "compiler"}] , ["CXXFLAGS", {"type": "CALL_EXPRESSION", "name": "flags"}] + , ["AR", {"type": "CALL_EXPRESSION", "name": "default-AR"}] , [ "CXXFLAGS" , { "type": "++" , "$1": -- cgit v1.2.3 From 1b8e5c3362673ece4bffe49e0f613eb3b5ec0aeb Mon Sep 17 00:00:00 2001 From: Oliver Reiche Date: Mon, 19 Sep 2022 13:53:38 +0200 Subject: rules: Remove CC/configure rule --- CC/EXPRESSIONS | 66 ---------------------------------------------------------- CC/RULES | 45 --------------------------------------- 2 files changed, 111 deletions(-) diff --git a/CC/EXPRESSIONS b/CC/EXPRESSIONS index 2cf5957..48f40a2 100644 --- a/CC/EXPRESSIONS +++ b/CC/EXPRESSIONS @@ -82,72 +82,6 @@ } } } -, "configure transition": - { "vars": ["COMPILER_FAMILY"] - , "expression": - { "type": "let*" - , "bindings": - [ [ "OS" - , { "type": "assert_non_empty" - , "msg": "Missing field \"os\" for \"configure\"." - , "$1": {"type": "join", "$1": {"type": "FIELD", "name": "os"}} - } - ] - , [ "ARCH" - , { "type": "assert_non_empty" - , "msg": "Missing field \"arch\" for \"configure\"." - , "$1": {"type": "join", "$1": {"type": "FIELD", "name": "arch"}} - } - ] - , ["HOST_ARCH", {"type": "var", "name": "ARCH"}] - , [ "TARGET_ARCH" - , {"type": "join", "$1": {"type": "FIELD", "name": "target_arch"}} - ] - , [ "TARGET_ARCH" - , { "type": "if" - , "cond": {"type": "var", "name": "TARGET_ARCH"} - , "then": {"type": "var", "name": "TARGET_ARCH"} - , "else": {"type": "var", "name": "ARCH"} - } - ] - , [ "FAMILY" - , {"type": "join", "$1": {"type": "FIELD", "name": "compiler_family"}} - ] - , [ "COMPILER_FAMILY" - , { "type": "if" - , "cond": {"type": "var", "name": "FAMILY"} - , "then": {"type": "var", "name": "FAMILY"} - , "else": {"type": "var", "name": "COMPILER_FAMILY"} - } - ] - ] - , "body": - { "type": "map_union" - , "$1": - [ { "type": "singleton_map" - , "key": "OS" - , "value": {"type": "var", "name": "OS"} - } - , { "type": "singleton_map" - , "key": "ARCH" - , "value": {"type": "var", "name": "TARGET_ARCH"} - } - , { "type": "singleton_map" - , "key": "HOST_ARCH" - , "value": {"type": "var", "name": "HOST_ARCH"} - } - , { "type": "singleton_map" - , "key": "TARGET_ARCH" - , "value": {"type": "var", "name": "TARGET_ARCH"} - } - , { "type": "singleton_map" - , "key": "COMPILER_FAMILY" - , "value": {"type": "var", "name": "COMPILER_FAMILY"} - } - ] - } - } - } , "compile-deps": { "doc": ["Collect compile dependencies (headers) from given target_fields"] , "vars": ["deps-fieldnames", "transition"] diff --git a/CC/RULES b/CC/RULES index 44bdabc..6fdab85 100644 --- a/CC/RULES +++ b/CC/RULES @@ -134,51 +134,6 @@ } } } -, "configure": - { "doc": - [ "A rule to provide a static platform configuration for a target." - , "The artifacts and runfiles of the specified target will be propagated." - , "The target defined by this rule does not propagate any provides data." - ] - , "config_fields": ["os", "arch", "target_arch", "compiler_family"] - , "target_fields": ["target"] - , "config_vars": ["COMPILER_FAMILY"] - , "field_doc": - { "os": ["The operation system used for building."] - , "arch": ["The architecture used for building."] - , "target_arch": - [ "Non-mandatory target architecture to build for. If omitted, target" - , "architecture is derived from \"arch\"." - ] - , "compiler_family": - [ "Non-mandatory compiler family used for building. If omitted, compiler" - , "family is taken from variable \"COMPILER_FAMILY\"." - ] - , "target": - [ "The target to configure. Multiple targets are supported, but their" - , "artifacts and runfiles should not conflict." - ] - } - , "imports": - { "transition": "configure transition" - , "artifacts": ["./", "..", "field_artifacts"] - , "runfiles": ["./", "..", "field_runfiles"] - } - , "config_transitions": - {"target": [{"type": "CALL_EXPRESSION", "name": "transition"}]} - , "expression": - { "type": "let*" - , "bindings": - [ ["fieldname", "target"] - , ["transition", {"type": "CALL_EXPRESSION", "name": "transition"}] - ] - , "body": - { "type": "RESULT" - , "artifacts": {"type": "CALL_EXPRESSION", "name": "artifacts"} - , "runfiles": {"type": "CALL_EXPRESSION", "name": "runfiles"} - } - } - } , "header directory": { "doc": [ "A directory of header files." -- cgit v1.2.3 From 6f404766c89fb48c4fc871d2ccb273bc5d5b2e5e Mon Sep 17 00:00:00 2001 From: Oliver Reiche Date: Mon, 19 Sep 2022 14:13:02 +0200 Subject: rules: Use new 'env' expression --- CC/EXPRESSIONS | 13 +----------- CC/RULES | 29 ++------------------------ proto/RULES | 55 +++++++++++++------------------------------------- shell/test/EXPRESSIONS | 6 +----- 4 files changed, 18 insertions(+), 85 deletions(-) diff --git a/CC/EXPRESSIONS b/CC/EXPRESSIONS index 48f40a2..5153b2d 100644 --- a/CC/EXPRESSIONS +++ b/CC/EXPRESSIONS @@ -506,18 +506,7 @@ , "provides": { "type": "map_union" , "$1": - [ { "type": "singleton_map" - , "key": "compile-deps" - , "value": {"type": "var", "name": "compile-deps"} - } - , { "type": "singleton_map" - , "key": "link-deps" - , "value": {"type": "var", "name": "link-deps"} - } - , { "type": "singleton_map" - , "key": "link-args" - , "value": {"type": "var", "name": "link-args"} - } + [ {"type": "env", "vars": ["compile-deps", "link-deps", "link-args"]} , { "type": "var" , "name": "extra-provides" , "default": {"type": "empty_map"} diff --git a/CC/RULES b/CC/RULES index 6fdab85..ac81da2 100644 --- a/CC/RULES +++ b/CC/RULES @@ -103,33 +103,8 @@ , "body": { "type": "RESULT" , "provides": - { "type": "map_union" - , "$1": - [ { "type": "singleton_map" - , "key": "CC" - , "value": {"type": "var", "name": "CC"} - } - , { "type": "singleton_map" - , "key": "CXX" - , "value": {"type": "var", "name": "CXX"} - } - , { "type": "singleton_map" - , "key": "CFLAGS" - , "value": {"type": "var", "name": "CFLAGS"} - } - , { "type": "singleton_map" - , "key": "CXXFLAGS" - , "value": {"type": "var", "name": "CXXFLAGS"} - } - , { "type": "singleton_map" - , "key": "AR" - , "value": {"type": "var", "name": "AR"} - } - , { "type": "singleton_map" - , "key": "ENV" - , "value": {"type": "var", "name": "ENV"} - } - ] + { "type": "env" + , "vars": ["CC", "CXX", "CFLAGS", "CXXFLAGS", "AR", "ENV"] } } } diff --git a/proto/RULES b/proto/RULES index 9c7c1a2..95fb87a 100644 --- a/proto/RULES +++ b/proto/RULES @@ -76,51 +76,24 @@ , "body": {"type": "CALL_EXPRESSION", "name": "list_provider"} } ] - , [ "node" - , { "type": "ABSTRACT_NODE" - , "node_type": - { "type": "if" - , "cond": {"type": "FIELD", "name": "service"} - , "then": "service library" - , "else": "library" - } - , "target_fields": - { "type": "map_union" - , "$1": - [ { "type": "singleton_map" - , "key": "srcs" - , "value": {"type": "var", "name": "srcs"} - } - , { "type": "singleton_map" - , "key": "deps" - , "value": {"type": "var", "name": "deps"} - } - ] - } - , "string_fields": - { "type": "map_union" - , "$1": - [ { "type": "singleton_map" - , "key": "name" - , "value": [{"type": "var", "name": "name"}] - } - , { "type": "singleton_map" - , "key": "stage" - , "value": [{"type": "var", "name": "stage"}] - } - ] + , ["name", [{"type": "var", "name": "name"}]] + , ["stage", [{"type": "var", "name": "stage"}]] + , [ "proto" + , [ { "type": "ABSTRACT_NODE" + , "node_type": + { "type": "if" + , "cond": {"type": "FIELD", "name": "service"} + , "then": "service library" + , "else": "library" + } + , "target_fields": {"type": "env", "vars": ["srcs", "deps"]} + , "string_fields": {"type": "env", "vars": ["name", "stage"]} } - } + ] ] ] , "body": - { "type": "RESULT" - , "provides": - { "type": "singleton_map" - , "key": "proto" - , "value": [{"type": "var", "name": "node"}] - } - } + {"type": "RESULT", "provides": {"type": "env", "vars": ["proto"]}} } } } diff --git a/shell/test/EXPRESSIONS b/shell/test/EXPRESSIONS index 6d163f3..24bf9ec 100644 --- a/shell/test/EXPRESSIONS +++ b/shell/test/EXPRESSIONS @@ -25,11 +25,7 @@ , "dep": {"type": "var", "name": "runner"} } } - , "body": - { "type": "singleton_map" - , "key": "runner" - , "value": {"type": "var", "name": "runner"} - } + , "body": {"type": "env", "vars": ["runner"]} } } } -- cgit v1.2.3 From 874a53375042792720ad426686b25512c29aa6ba Mon Sep 17 00:00:00 2001 From: Oliver Reiche Date: Mon, 19 Sep 2022 18:33:11 +0200 Subject: rules: New rule for config header generation --- CC/auto/EXPRESSIONS | 32 ++ CC/auto/RULES | 874 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 906 insertions(+) create mode 100644 CC/auto/EXPRESSIONS create mode 100644 CC/auto/RULES diff --git a/CC/auto/EXPRESSIONS b/CC/auto/EXPRESSIONS new file mode 100644 index 0000000..ac19f7a --- /dev/null +++ b/CC/auto/EXPRESSIONS @@ -0,0 +1,32 @@ +{ "last_list_entry": + { "vars": ["list"] + , "expression": + { "type": "foldl" + , "range": {"type": "var", "name": "list"} + , "start": null + , "body": {"type": "var", "name": "_"} + } + } +, "first_list_entry": + { "vars": ["list"] + , "imports": {"last": "last_list_entry"} + , "expression": + { "type": "let*" + , "bindings": + [ [ "list" + , { "type": "foldl" + , "range": {"type": "var", "name": "list", "default": []} + , "start": null + , "body": + { "type": "if" + , "cond": {"type": "var", "name": "$1"} + , "then": {"type": "var", "name": "$1"} + , "else": [{"type": "var", "name": "_"}] + } + } + ] + ] + , "body": {"type": "CALL_EXPRESSION", "name": "last"} + } + } +} diff --git a/CC/auto/RULES b/CC/auto/RULES new file mode 100644 index 0000000..3735381 --- /dev/null +++ b/CC/auto/RULES @@ -0,0 +1,874 @@ +{ "config": + { "doc": + [ "Generate a C/C++ config header" + , "" + , "Generate a C/C++ configuration header using defines specified via the" + , "target configuration. In the usual case, a target using this rule is" + , "configured by depending on it from a target that uses the built-in" + , "\"configure\" rule." + ] + , "field_doc": + { "name": ["Name of the header file to generate (incl. file name ext)."] + , "guard": ["The include guard. Multiple segments are joined with \"_\"."] + , "stage": + ["The location of the header. Path segments are joined with \"/\"."] + , "hdrs": + [ "Additional header files to be available in the include path. Useful" + , "for providing additional header files to values given in" + , "\"have_{cfile,cxxfile,ctype,cxxtype,csymbol,cxxsymbol}\"." + ] + , "deps": + [ "Additional public header files from targets to be available in the" + , "include path. Useful for providing additional header files to values" + , "given in \"have_{cfile,cxxfile,ctype,cxxtype,csymbol,cxxsymbol}\"." + ] + } + , "config_doc": + { "CXX": + [ "The name of the C++ compiler to be used by checks. If None, the" + , "respective value from [\"CC\", \"defaults\"] will be taken." + ] + , "CC": + [ "The name of the C compiler to be used by checks. If None, the" + , "respective value from [\"CC\", \"defaults\"] will be taken." + ] + , "CFLAGS": + [ "The flags for CXX to be used instead of the default ones" + , "taken from the [\"CC\", \"defaults\"] target" + ] + , "CXXFLAGS": + [ "The flags for CXX to be used instead of the default ones" + , "taken from the [\"CC\", \"defaults\"] target" + ] + , "ADD_CFLAGS": + [ "The flags to add to the default ones for CC" + , "taken from the [\"CC\", \"defaults\"] target" + ] + , "ADD_CXXFLAGS": + [ "The flags to add to the default ones for CXX" + , "taken from the [\"CC\", \"defaults\"] target" + ] + , "ENV": ["The environment for running file/symbol/type checks."] + , "defines": + [ "Set a define to a specific value unless its value is \"null\". Must" + , "contain a list of pairs. The first element of each pair is the define" + , "name and the second argument is the value to set. Strings must be" + , "properly escaped. Defines generated from this field are added last," + , "so that they can refer to defines from other \"defines*\" and" + , "\"have_*\" values." + ] + , "defines1": + [ "Set a define to \"1\" unless its value is untrue. Must contain a list" + , "of pairs. The first element of each pair is the define name and the" + , "second argument is the value." + ] + , "defines01": + [ "Set a define to \"0\" or \"1\" depending on its value being true." + , "Must contain a list of pairs. The first element of each pair is the" + , "define name and the second argument is the value." + ] + , "have_cfile": + [ "Set a define to \"1\" if the specified C header is in the include" + , "path. Must contain a list of pairs. The first element of each pair is" + , "the define name and the second argument is the C header file name." + ] + , "have_cxxfile": + [ "Set a define to \"1\" if the specified C++ header is in the include" + , "path. Must contain a list of pairs. The first element of each pair is" + , "the define name and the second argument is the C++ header file name." + ] + , "have_ctype": + [ "Set a define to \"1\" if the specified C type is defined. Must" + , "contain a list of pairs. The first element of each pair is the define" + , "name and the second argument is name of the C type. If the specified" + , "C type is not a built-in type, additionally the headers" + , "\"sys/types.h\", \"stdint.h\", and \"stddef.h\" are checked as well." + ] + , "have_cxxtype": + [ "Set a define to \"1\" if the specified C++ type is defined. Must" + , "contain a list of pairs. The first element of each pair is the define" + , "name and the second argument is name of the C++ type. If the specified" + , "C++ type is not a built-in type, additionally the headers" + , "\"sys/types.h\", \"stdint.h\", and \"stddef.h\" are checked as well." + ] + , "have_csymbol": + [ "Set a define to \"1\" if the specified C symbol is defined by one of" + , "the specified headers in the include path. 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" + , "symbol to search for and the second value is a list with the header" + , "file names to consider for searching." + ] + , "have_cxxsymbol": + [ "Set a define to \"1\" if the specified C++ symbol is defined by one of" + , "the specified headers in the include path. 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++" + , "symbol to search for and the second value is a list with the header" + , "file names to consider for searching." + ] + } + , "string_fields": ["name", "stage", "guard"] + , "target_fields": ["hdrs", "deps"] + , "config_vars": + [ "CC" + , "CXX" + , "CFLAGS" + , "CXXFLAGS" + , "ADD_CFLAGS" + , "ADD_CXXFLAGS" + , "ENV" + , "defines" + , "defines1" + , "defines01" + , "have_cfile" + , "have_cxxfile" + , "have_ctype" + , "have_cxxtype" + , "have_csymbol" + , "have_cxxsymbol" + ] + , "imports": + { "first": "first_list_entry" + , "last": "last_list_entry" + , "artifacts": ["./", "../..", "field_artifacts"] + , "compile-deps": ["./", "..", "compile-deps"] + , "default-CC": ["./", "..", "default-CC"] + , "default-CXX": ["./", "..", "default-CXX"] + , "default-CFLAGS": ["./", "..", "default-CFLAGS"] + , "default-CXXFLAGS": ["./", "..", "default-CXXFLAGS"] + , "default-ENV": ["./", "..", "default-ENV"] + } + , "implicit": {"defaults": [["./", "..", "defaults"]]} + , "expression": + { "type": "let*" + , "bindings": + [ ["name", {"type": "join", "$1": {"type": "FIELD", "name": "name"}}] + , [ "stage" + , { "type": "join" + , "separator": "/" + , "$1": {"type": "FIELD", "name": "stage"} + } + ] + , [ "guard" + , { "type": "assert_non_empty" + , "msg": "Config header include guard may not be empty" + , "$1": + { "type": "join" + , "separator": "_" + , "$1": {"type": "FIELD", "name": "guard"} + } + } + ] + , [ "includes" + , { "type": "to_subdir" + , "subdir": "include" + , "$1": + { "type": "disjoint_map_union" + , "msg": "Includes may not overlap" + , "$1": + [ { "type": "let*" + , "bindings": [["fieldname", "hdrs"]] + , "body": {"type": "CALL_EXPRESSION", "name": "artifacts"} + } + , { "type": "let*" + , "bindings": [["deps-fieldnames", ["deps"]]] + , "body": {"type": "CALL_EXPRESSION", "name": "compile-deps"} + } + ] + } + } + ] + , [ "CC" + , { "type": "var" + , "name": "CC" + , "default": {"type": "CALL_EXPRESSION", "name": "default-CC"} + } + ] + , [ "CXX" + , { "type": "var" + , "name": "CXX" + , "default": {"type": "CALL_EXPRESSION", "name": "default-CXX"} + } + ] + , [ "CFLAGS" + , { "type": "++" + , "$1": + [ { "type": "var" + , "name": "CFLAGS" + , "default": + {"type": "CALL_EXPRESSION", "name": "default-CFLAGS"} + } + , {"type": "var", "name": "ADD_CFLAGS", "default": []} + ] + } + ] + , [ "CXXFLAGS" + , { "type": "++" + , "$1": + [ { "type": "var" + , "name": "CXXFLAGS" + , "default": + {"type": "CALL_EXPRESSION", "name": "default-CXXFLAGS"} + } + , {"type": "var", "name": "ADD_CXXFLAGS", "default": []} + ] + } + ] + , [ "ENV" + , { "type": "map_union" + , "$1": + { "type": "++" + , "$1": + [ {"type": "CALL_EXPRESSION", "name": "default-ENV"} + , [ { "type": "var" + , "name": "ENV" + , "default": {"type": "empty_map"} + } + ] + ] + } + } + ] + , [ "c.flags" + , { "type": "BLOB" + , "data": + { "type": "join" + , "separator": "\n" + , "$1": {"type": "var", "name": "CFLAGS"} + } + } + ] + , [ "cxx.flags" + , { "type": "BLOB" + , "data": + { "type": "join" + , "separator": "\n" + , "$1": {"type": "var", "name": "CXXFLAGS"} + } + } + ] + , [ "file_check.sh" + , { "type": "BLOB" + , "data": + { "type": "join" + , "separator": "\n" + , "$1": + [ "set -eu" + , "[ $# -ge 4 ]" + , "CC=$1" + , "LANG=$2" + , "DEF=$3" + , "HDR=$4" + , "DEFINE=\"/* #undef $DEF */\"" + , "echo \"#include \\\"$HDR\\\"\" > test.$LANG" + , "if $CC @$LANG.flags -c test.$LANG -I ./include 2>/dev/null; then DEFINE=\"#define $DEF 1\"; fi" + , "if [ -f in/${LANG}files.def ]; then cat in/${LANG}files.def > ${LANG}files.def; fi" + , "echo \"$DEFINE\n\" >> ${LANG}files.def" + ] + } + } + ] + , [ "type_check.sh" + , { "type": "BLOB" + , "data": + { "type": "join" + , "separator": "\n" + , "$1": + [ "set -eu" + , "[ $# -ge 4 ]" + , "CC=$1" + , "LANG=$2" + , "DEF=$3" + , "TYPE=$4" + , "INC=\"\"" + , "DEFINE=\"/* #undef $DEF */\"" + , "for HDR in \"\" \"sys/types.h\" \"stdint.h\" \"stddef.h\"; do" + , " if [ -n \"$HDR\" ]; then INC=\"#include \\\"$HDR\\\"\"; fi" + , " cat > test.$LANG << EOF" + , "$INC" + , "$TYPE* __test;" + , "EOF" + , " if $CC @$LANG.flags -c test.$LANG -I ./include 2>/dev/null; then" + , " DEFINE=\"#define $DEF 1\"" + , " break" + , " fi" + , "done" + , "if [ -f in/${LANG}types.def ]; then cat in/${LANG}types.def > ${LANG}types.def; fi" + , "echo \"$DEFINE\n\" >> ${LANG}types.def" + ] + } + } + ] + , [ "symbol_check.sh" + , { "type": "BLOB" + , "data": + { "type": "join" + , "separator": "\n" + , "$1": + [ "set -eu" + , "[ $# -ge 4 ]" + , "CC=$1" + , "shift" + , "LANG=$1" + , "shift" + , "DEF=$1" + , "shift" + , "SYMBOL=$1" + , "shift" + , "DEFINE=\"/* #undef $DEF */\"" + , "for INC in \"$@\"; do" + , " cat > test.$LANG << EOF" + , "#include \"$INC\"" + , "#ifndef $SYMBOL" + , "void* __test = &$SYMBOL;" + , "#endif" + , "EOF" + , " if $CC @$LANG.flags -c test.$LANG -I ./include 2>/dev/null; then" + , " DEFINE=\"#define $DEF 1\"" + , " break" + , " fi" + , "done" + , "if [ -f in/${LANG}symbols.def ]; then cat in/${LANG}symbols.def > ${LANG}symbols.def; fi" + , "echo \"$DEFINE\n\" >> ${LANG}symbols.def" + ] + } + } + ] + , [ "guard.def" + , { "type": "singleton_map" + , "key": "guard.def" + , "value": + { "type": "BLOB" + , "data": + { "type": "join" + , "separator": "\n" + , "$1": + [ { "type": "join" + , "separator": " " + , "$1": ["#ifndef", {"type": "var", "name": "guard"}] + } + , { "type": "join" + , "separator": " " + , "$1": ["#define", {"type": "var", "name": "guard"}] + } + , "\n\n" + ] + } + } + } + ] + , [ "plain.def" + , { "type": "singleton_map" + , "key": "plain.def" + , "value": + { "type": "BLOB" + , "data": + { "type": "join" + , "$1": + { "type": "foreach" + , "range": {"type": "var", "name": "defines", "default": []} + , "var": "pair" + , "body": + { "type": "let*" + , "bindings": + [ ["list", {"type": "var", "name": "pair"}] + , [ "def" + , { "type": "assert_non_empty" + , "msg": "Define name in 'defines' may not be empty" + , "$1": {"type": "CALL_EXPRESSION", "name": "first"} + } + ] + , ["val", {"type": "CALL_EXPRESSION", "name": "last"}] + ] + , "body": + { "type": "join" + , "separator": " " + , "$1": + { "type": "case*" + , "expr": {"type": "var", "name": "val"} + , "case": + [ [ null + , [ "/* #undef" + , {"type": "var", "name": "def"} + , "*/\n\n" + ] + ] + ] + , "default": + [ "#define" + , {"type": "var", "name": "def"} + , { "type": "join" + , "$1": [{"type": "var", "name": "val"}, "\n\n"] + } + ] + } + } + } + } + } + } + } + ] + , [ "int1.def" + , { "type": "singleton_map" + , "key": "int1.def" + , "value": + { "type": "BLOB" + , "data": + { "type": "join" + , "$1": + { "type": "foreach" + , "range": {"type": "var", "name": "defines1", "default": []} + , "var": "pair" + , "body": + { "type": "let*" + , "bindings": + [ ["list", {"type": "var", "name": "pair"}] + , [ "def" + , { "type": "assert_non_empty" + , "msg": "Define name in 'defines1' may not be empty" + , "$1": {"type": "CALL_EXPRESSION", "name": "first"} + } + ] + , ["val", {"type": "CALL_EXPRESSION", "name": "last"}] + ] + , "body": + { "type": "join" + , "separator": " " + , "$1": + { "type": "if" + , "cond": {"type": "var", "name": "val"} + , "then": + ["#define", {"type": "var", "name": "def"}, "1\n\n"] + , "else": + ["/* #undef", {"type": "var", "name": "def"}, "*/\n\n"] + } + } + } + } + } + } + } + ] + , [ "int01.def" + , { "type": "singleton_map" + , "key": "int01.def" + , "value": + { "type": "BLOB" + , "data": + { "type": "join" + , "$1": + { "type": "foreach" + , "range": {"type": "var", "name": "defines01", "default": []} + , "var": "pair" + , "body": + { "type": "let*" + , "bindings": + [ ["list", {"type": "var", "name": "pair"}] + , [ "def" + , { "type": "assert_non_empty" + , "msg": "Define name in 'defines01' may not be empty" + , "$1": {"type": "CALL_EXPRESSION", "name": "first"} + } + ] + , ["val", {"type": "CALL_EXPRESSION", "name": "last"}] + ] + , "body": + { "type": "join" + , "separator": " " + , "$1": + [ "#define" + , {"type": "var", "name": "def"} + , { "type": "if" + , "cond": {"type": "var", "name": "val"} + , "then": "1\n\n" + , "else": "0\n\n" + } + ] + } + } + } + } + } + } + ] + , [ "cfiles.def" + , { "type": "foldl" + , "range": {"type": "var", "name": "have_cfile", "default": []} + , "start": + { "type": "singleton_map" + , "key": "cfiles.def" + , "value": {"type": "BLOB", "data": ""} + } + , "accum_var": "cfiles.def" + , "var": "pair" + , "body": + { "type": "let*" + , "bindings": + [ ["list", {"type": "var", "name": "pair"}] + , [ "def" + , { "type": "assert_non_empty" + , "msg": "Define name in 'have_cfile' may not be empty" + , "$1": {"type": "CALL_EXPRESSION", "name": "first"} + } + ] + , ["val", {"type": "CALL_EXPRESSION", "name": "last"}] + ] + , "body": + { "type": "ACTION" + , "inputs": + { "type": "map_union" + , "$1": + [ { "type": "to_subdir" + , "subdir": "in" + , "$1": {"type": "var", "name": "cfiles.def"} + } + , {"type": "env", "vars": ["file_check.sh", "c.flags"]} + , {"type": "var", "name": "includes"} + ] + } + , "cmd": + [ "sh" + , "./file_check.sh" + , {"type": "var", "name": "CC"} + , "c" + , {"type": "var", "name": "def"} + , {"type": "var", "name": "val"} + ] + , "env": {"type": "var", "name": "ENV"} + , "outs": ["cfiles.def"] + } + } + } + ] + , [ "cxxfiles.def" + , { "type": "foldl" + , "range": {"type": "var", "name": "have_cxxfile", "default": []} + , "start": + { "type": "singleton_map" + , "key": "cxxfiles.def" + , "value": {"type": "BLOB", "data": ""} + } + , "accum_var": "cxxfiles.def" + , "var": "pair" + , "body": + { "type": "let*" + , "bindings": + [ ["list", {"type": "var", "name": "pair"}] + , [ "def" + , { "type": "assert_non_empty" + , "msg": "Define name in 'have_cxxfile' may not be empty" + , "$1": {"type": "CALL_EXPRESSION", "name": "first"} + } + ] + , ["val", {"type": "CALL_EXPRESSION", "name": "last"}] + ] + , "body": + { "type": "ACTION" + , "inputs": + { "type": "map_union" + , "$1": + [ { "type": "to_subdir" + , "subdir": "in" + , "$1": {"type": "var", "name": "cxxfiles.def"} + } + , {"type": "env", "vars": ["file_check.sh", "cxx.flags"]} + , {"type": "var", "name": "includes"} + ] + } + , "cmd": + [ "sh" + , "./file_check.sh" + , {"type": "var", "name": "CXX"} + , "cxx" + , {"type": "var", "name": "def"} + , {"type": "var", "name": "val"} + ] + , "env": {"type": "var", "name": "ENV"} + , "outs": ["cxxfiles.def"] + } + } + } + ] + , [ "ctypes.def" + , { "type": "foldl" + , "range": {"type": "var", "name": "have_ctype", "default": []} + , "start": + { "type": "singleton_map" + , "key": "ctypes.def" + , "value": {"type": "BLOB", "data": ""} + } + , "accum_var": "ctypes.def" + , "var": "pair" + , "body": + { "type": "let*" + , "bindings": + [ ["list", {"type": "var", "name": "pair"}] + , [ "def" + , { "type": "assert_non_empty" + , "msg": "Define name in 'have_ctype' may not be empty" + , "$1": {"type": "CALL_EXPRESSION", "name": "first"} + } + ] + , ["type", {"type": "CALL_EXPRESSION", "name": "last"}] + ] + , "body": + { "type": "ACTION" + , "inputs": + { "type": "map_union" + , "$1": + [ { "type": "to_subdir" + , "subdir": "in" + , "$1": {"type": "var", "name": "ctypes.def"} + } + , {"type": "env", "vars": ["type_check.sh", "c.flags"]} + , {"type": "var", "name": "includes"} + ] + } + , "cmd": + [ "sh" + , "./type_check.sh" + , {"type": "var", "name": "CC"} + , "c" + , {"type": "var", "name": "def"} + , {"type": "var", "name": "type"} + ] + , "env": {"type": "var", "name": "ENV"} + , "outs": ["ctypes.def"] + } + } + } + ] + , [ "cxxtypes.def" + , { "type": "foldl" + , "range": {"type": "var", "name": "have_cxxtype", "default": []} + , "start": + { "type": "singleton_map" + , "key": "cxxtypes.def" + , "value": {"type": "BLOB", "data": ""} + } + , "accum_var": "cxxtypes.def" + , "var": "pair" + , "body": + { "type": "let*" + , "bindings": + [ ["list", {"type": "var", "name": "pair"}] + , [ "def" + , { "type": "assert_non_empty" + , "msg": "Define name in 'have_cxxtype' may not be empty" + , "$1": {"type": "CALL_EXPRESSION", "name": "first"} + } + ] + , ["type", {"type": "CALL_EXPRESSION", "name": "last"}] + ] + , "body": + { "type": "ACTION" + , "inputs": + { "type": "map_union" + , "$1": + [ { "type": "to_subdir" + , "subdir": "in" + , "$1": {"type": "var", "name": "cxxtypes.def"} + } + , {"type": "env", "vars": ["type_check.sh", "cxx.flags"]} + , {"type": "var", "name": "includes"} + ] + } + , "cmd": + [ "sh" + , "./type_check.sh" + , {"type": "var", "name": "CXX"} + , "cxx" + , {"type": "var", "name": "def"} + , {"type": "var", "name": "type"} + ] + , "env": {"type": "var", "name": "ENV"} + , "outs": ["cxxtypes.def"] + } + } + } + ] + , [ "csymbols.def" + , { "type": "foldl" + , "range": {"type": "var", "name": "have_csymbol", "default": []} + , "start": + { "type": "singleton_map" + , "key": "csymbols.def" + , "value": {"type": "BLOB", "data": ""} + } + , "accum_var": "csymbols.def" + , "var": "pair" + , "body": + { "type": "let*" + , "bindings": + [ ["list", {"type": "var", "name": "pair"}] + , [ "def" + , { "type": "assert_non_empty" + , "msg": "Define name in 'have_csymbol' may not be empty" + , "$1": {"type": "CALL_EXPRESSION", "name": "first"} + } + ] + , ["list", {"type": "CALL_EXPRESSION", "name": "last"}] + , ["sym", {"type": "CALL_EXPRESSION", "name": "first"}] + , ["hdrs", {"type": "CALL_EXPRESSION", "name": "last"}] + ] + , "body": + { "type": "ACTION" + , "inputs": + { "type": "map_union" + , "$1": + [ { "type": "to_subdir" + , "subdir": "in" + , "$1": {"type": "var", "name": "csymbols.def"} + } + , {"type": "env", "vars": ["symbol_check.sh", "c.flags"]} + , {"type": "var", "name": "includes"} + ] + } + , "cmd": + { "type": "++" + , "$1": + [ [ "sh" + , "./symbol_check.sh" + , {"type": "var", "name": "CC"} + , "c" + , {"type": "var", "name": "def"} + , {"type": "var", "name": "sym"} + ] + , {"type": "var", "name": "hdrs"} + ] + } + , "env": {"type": "var", "name": "ENV"} + , "outs": ["csymbols.def"] + } + } + } + ] + , [ "cxxsymbols.def" + , { "type": "foldl" + , "range": {"type": "var", "name": "have_cxxsymbol", "default": []} + , "start": + { "type": "singleton_map" + , "key": "cxxsymbols.def" + , "value": {"type": "BLOB", "data": ""} + } + , "accum_var": "cxxsymbols.def" + , "var": "pair" + , "body": + { "type": "let*" + , "bindings": + [ ["list", {"type": "var", "name": "pair"}] + , [ "def" + , { "type": "assert_non_empty" + , "msg": "Define name in 'have_cxxsymbol' may not be empty" + , "$1": {"type": "CALL_EXPRESSION", "name": "first"} + } + ] + , ["list", {"type": "CALL_EXPRESSION", "name": "last"}] + , ["sym", {"type": "CALL_EXPRESSION", "name": "first"}] + , ["hdrs", {"type": "CALL_EXPRESSION", "name": "last"}] + ] + , "body": + { "type": "ACTION" + , "inputs": + { "type": "map_union" + , "$1": + [ { "type": "to_subdir" + , "subdir": "in" + , "$1": {"type": "var", "name": "cxxsymbols.def"} + } + , {"type": "env", "vars": ["symbol_check.sh", "cxx.flags"]} + , {"type": "var", "name": "includes"} + ] + } + , "cmd": + { "type": "++" + , "$1": + [ [ "sh" + , "./symbol_check.sh" + , {"type": "var", "name": "CXX"} + , "cxx" + , {"type": "var", "name": "def"} + , {"type": "var", "name": "sym"} + ] + , {"type": "var", "name": "hdrs"} + ] + } + , "env": {"type": "var", "name": "ENV"} + , "outs": ["cxxsymbols.def"] + } + } + } + ] + , [ "end.def" + , { "type": "singleton_map" + , "key": "end.def" + , "value": {"type": "BLOB", "data": "\n#endif\n"} + } + ] + , [ "outname" + , {"type": "join", "$1": ["out/", {"type": "var", "name": "name"}]} + ] + , [ "outfile" + , { "type": "ACTION" + , "inputs": + { "type": "map_union" + , "$1": + [ {"type": "var", "name": "guard.def"} + , {"type": "var", "name": "plain.def"} + , {"type": "var", "name": "int1.def"} + , {"type": "var", "name": "int01.def"} + , {"type": "var", "name": "cfiles.def"} + , {"type": "var", "name": "cxxfiles.def"} + , {"type": "var", "name": "ctypes.def"} + , {"type": "var", "name": "cxxtypes.def"} + , {"type": "var", "name": "csymbols.def"} + , {"type": "var", "name": "cxxsymbols.def"} + , {"type": "var", "name": "end.def"} + ] + } + , "cmd": + [ "sh" + , "-c" + , { "type": "join" + , "separator": " " + , "$1": + [ "cat" + , "guard.def" + , "int1.def" + , "int01.def" + , "cfiles.def" + , "cxxfiles.def" + , "ctypes.def" + , "cxxtypes.def" + , "csymbols.def" + , "cxxsymbols.def" + , "plain.def" + , "end.def" + , ">" + , { "type": "join_cmd" + , "$1": [{"type": "var", "name": "outname"}] + } + ] + } + ] + , "outs": [{"type": "var", "name": "outname"}] + } + ] + , [ "outfile" + , { "type": "to_subdir" + , "subdir": {"type": "var", "name": "stage"} + , "flat": true + , "$1": {"type": "var", "name": "outfile"} + } + ] + ] + , "body": + { "type": "RESULT" + , "artifacts": {"type": "var", "name": "outfile"} + , "runfiles": {"type": "var", "name": "outfile"} + } + } + } +} -- cgit v1.2.3 From 2a7102b66d534e9ae3cafbe7f2fdd3c3f5d979c0 Mon Sep 17 00:00:00 2001 From: Klaus Aehlig Date: Wed, 12 Oct 2022 12:08:59 +0200 Subject: Add copyright and license notice to all source and header files Signed-off-by: Goetz Brasche --- CC/test/test_runner.sh | 14 ++++++++++++++ shell/test/test_runner.sh | 14 ++++++++++++++ shell/test/test_summary.py | 14 ++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/CC/test/test_runner.sh b/CC/test/test_runner.sh index 5256867..716eaa9 100644 --- a/CC/test/test_runner.sh +++ b/CC/test/test_runner.sh @@ -1,4 +1,18 @@ #!/bin/sh +# Copyright 2022 Huawei Cloud Computing Technology Co., Ltd. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + # ensure all required outputs are present touch stdout diff --git a/shell/test/test_runner.sh b/shell/test/test_runner.sh index 969b80a..a99d5b7 100755 --- a/shell/test/test_runner.sh +++ b/shell/test/test_runner.sh @@ -1,4 +1,18 @@ #!/bin/sh +# Copyright 2022 Huawei Cloud Computing Technology Co., Ltd. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + # ensure all required outputs are present touch stdout diff --git a/shell/test/test_summary.py b/shell/test/test_summary.py index cba8d50..0b5e656 100755 --- a/shell/test/test_summary.py +++ b/shell/test/test_summary.py @@ -1,4 +1,18 @@ #!/usr/bin/env python3 +# Copyright 2022 Huawei Cloud Computing Technology Co., Ltd. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + import os import time -- cgit v1.2.3 From d46702ca599954864737a49b20cac20632bc37ba Mon Sep 17 00:00:00 2001 From: Oliver Reiche Date: Wed, 26 Oct 2022 17:09:25 +0200 Subject: rules: Honor ENV variable for protobuf compilation --- CC/proto/EXPRESSIONS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CC/proto/EXPRESSIONS b/CC/proto/EXPRESSIONS index ac0018a..9e3a962 100644 --- a/CC/proto/EXPRESSIONS +++ b/CC/proto/EXPRESSIONS @@ -8,7 +8,7 @@ } , "protoc-compile": { "vars": - ["transition", "service support", "CXX", "CXXFLAGS", "ADD_CXXFLAGS"] + ["transition", "service support", "CXX", "CXXFLAGS", "ADD_CXXFLAGS", "ENV"] , "imports": { "stage": ["", "stage_singleton_field"] , "result": ["./", "..", "lib result"] -- cgit v1.2.3 From f24419a7cb95a38a4fe66b8c86b7cc059ebb8975 Mon Sep 17 00:00:00 2001 From: Christian Lütke Stetzkamp Date: Thu, 27 Oct 2022 12:47:37 +0200 Subject: rules: Honor ENV for patch separation --- patch/RULES | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/patch/RULES b/patch/RULES index ab5f102..bba83c2 100644 --- a/patch/RULES +++ b/patch/RULES @@ -2,7 +2,7 @@ { "doc": ["Replace a file, logically in place, by a patched version"] , "target_fields": ["src", "patch"] , "string_fields": ["patch-part"] - , "config_vars": ["PATCH"] + , "config_vars": ["PATCH", "ENV"] , "field_doc": { "src": ["The single source file to patch, typically an explict file reference."] @@ -91,6 +91,8 @@ } , "outs": ["patch"] , "cmd": ["sh", "./splitpatch", "in/patch"] + , "env": + {"type": "var", "name": "ENV", "default": {"type": "empty_map"}} } , "else": {"type": "var", "name": "patch"} } -- cgit v1.2.3 From fab3d562121e80290004c37a262dc5c0515652ed Mon Sep 17 00:00:00 2001 From: Christian Lütke Stetzkamp Date: Thu, 27 Oct 2022 12:48:47 +0200 Subject: rules: Honor ENV for finding cat --- CC/auto/RULES | 1 + 1 file changed, 1 insertion(+) diff --git a/CC/auto/RULES b/CC/auto/RULES index 3735381..ab1e689 100644 --- a/CC/auto/RULES +++ b/CC/auto/RULES @@ -854,6 +854,7 @@ } ] , "outs": [{"type": "var", "name": "outname"}] + , "env": {"type": "var", "name": "ENV"} } ] , [ "outfile" -- cgit v1.2.3 From 6b54d45ca06de445d36ad3ae10446073f652264f Mon Sep 17 00:00:00 2001 From: Klaus Aehlig Date: Mon, 31 Oct 2022 12:35:46 +0100 Subject: CC/test test_runner.sh: correctly report the reuslt The test runner is supposed to report the reult in a file called 'result' in the top-level action directory. However, before starting the actual test, it changes the working directory to the subdir 'work' where the input of the test action is located. Therefore, when reporting the result, the correct file name is '../result'. Fix this. --- CC/test/test_runner.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CC/test/test_runner.sh b/CC/test/test_runner.sh index 716eaa9..84b9072 100644 --- a/CC/test/test_runner.sh +++ b/CC/test/test_runner.sh @@ -42,7 +42,7 @@ else RESULT=FAIL fi date +%s > ../time-stop -echo "${RESULT}" > result +echo "${RESULT}" > ../result if [ "${RESULT}" '!=' PASS ] then -- cgit v1.2.3 From fd849467c6360a9c19c656b701eff0cd30357893 Mon Sep 17 00:00:00 2001 From: Alberto Sartori Date: Wed, 2 Nov 2022 16:39:59 +0100 Subject: rules: don't always use the default archiver --- CC/EXPRESSIONS | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/CC/EXPRESSIONS b/CC/EXPRESSIONS index 5153b2d..77dcd9a 100644 --- a/CC/EXPRESSIONS +++ b/CC/EXPRESSIONS @@ -367,7 +367,12 @@ ] , ["CXX", {"type": "CALL_EXPRESSION", "name": "compiler"}] , ["CXXFLAGS", {"type": "CALL_EXPRESSION", "name": "flags"}] - , ["AR", {"type": "CALL_EXPRESSION", "name": "default-AR"}] + , [ "AR" + , { "type": "var" + , "name": "AR" + , "default": {"type": "CALL_EXPRESSION", "name": "default-AR"} + } + ] , [ "CXXFLAGS" , { "type": "++" , "$1": -- cgit v1.2.3 From c7414470a5f4a56712e7e91b74bf839d813c9f5c Mon Sep 17 00:00:00 2001 From: Alberto Sartori Date: Wed, 2 Nov 2022 16:43:48 +0100 Subject: proto: honor configured archiver --- CC/proto/EXPRESSIONS | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/CC/proto/EXPRESSIONS b/CC/proto/EXPRESSIONS index 9e3a962..b2b3ea0 100644 --- a/CC/proto/EXPRESSIONS +++ b/CC/proto/EXPRESSIONS @@ -8,7 +8,14 @@ } , "protoc-compile": { "vars": - ["transition", "service support", "CXX", "CXXFLAGS", "ADD_CXXFLAGS", "ENV"] + [ "transition" + , "service support" + , "CXX" + , "CXXFLAGS" + , "ADD_CXXFLAGS" + , "ENV" + , "AR" + ] , "imports": { "stage": ["", "stage_singleton_field"] , "result": ["./", "..", "lib result"] -- cgit v1.2.3 From 52467f17b7b99b044267617c33f142f66ef5d0d7 Mon Sep 17 00:00:00 2001 From: Klaus Aehlig Date: Wed, 16 Nov 2022 16:59:12 +0100 Subject: rules/CC/EXPRESSIONS: drop unused local define --- CC/EXPRESSIONS | 1 - 1 file changed, 1 deletion(-) diff --git a/CC/EXPRESSIONS b/CC/EXPRESSIONS index 77dcd9a..fdef17f 100644 --- a/CC/EXPRESSIONS +++ b/CC/EXPRESSIONS @@ -396,7 +396,6 @@ } } ] - , ["deps-fieldnames", ["deps", "proto-deps"]] , [ "local hdrs" , { "type": "disjoint_map_union" , "$1": -- cgit v1.2.3 From 5c517c8cf9a28942394a29d95a31a1cde412b26d Mon Sep 17 00:00:00 2001 From: Klaus Aehlig Date: Wed, 16 Nov 2022 17:04:26 +0100 Subject: support the concept of private deps i.e., libraries that are used only in the implementation without use in the public header files. In this way, the set of headers exposed to dependencies can be reduced leading potentially to better incrementality. --- CC/EXPRESSIONS | 4 +++- CC/RULES | 7 ++++++- CC/proto/RULES | 2 ++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CC/EXPRESSIONS b/CC/EXPRESSIONS index fdef17f..7871ace 100644 --- a/CC/EXPRESSIONS +++ b/CC/EXPRESSIONS @@ -486,7 +486,7 @@ , "expression": { "type": "let*" , "bindings": - [ ["deps-fieldnames", ["deps", "proto-deps"]] + [ ["deps-fieldnames", ["deps", "private-deps", "proto-deps"]] , ["compile-deps", {"type": "CALL_EXPRESSION", "name": "compile-deps"}] , ["link-deps", {"type": "CALL_EXPRESSION", "name": "link-deps"}] , ["lib", {"type": "CALL_EXPRESSION", "name": "lib artifact"}] @@ -502,6 +502,8 @@ } } ] + , ["deps-fieldnames", ["deps", "proto-deps"]] + , ["compile-deps", {"type": "CALL_EXPRESSION", "name": "compile-deps"}] ] , "body": { "type": "RESULT" diff --git a/CC/RULES b/CC/RULES index ac81da2..ab01a50 100644 --- a/CC/RULES +++ b/CC/RULES @@ -170,7 +170,8 @@ } , "library": { "doc": ["A C++ libaray"] - , "target_fields": ["srcs", "hdrs", "private-hdrs", "deps", "proto"] + , "target_fields": + ["srcs", "hdrs", "private-hdrs", "deps", "private-deps", "proto"] , "string_fields": [ "name" , "stage" @@ -220,6 +221,10 @@ , "by this tool, typically system libraries)." ] , "deps": ["Any other libraries this library depends upon."] + , "private-deps": + [ "Any other libraries this library depends upon but does not include" + , "in its public headers." + ] , "proto": [ "Any [\"proto\", \"library\"] this target depends upon directly." , "The creation of C++ bindings for this proto library as well as of" diff --git a/CC/proto/RULES b/CC/proto/RULES index a4579e7..d53ab35 100644 --- a/CC/proto/RULES +++ b/CC/proto/RULES @@ -26,6 +26,7 @@ , "proto-deps": [["@", "protoc", "", "C++ runtime"]] , "well_known_protos": [["@", "protoc", "", "well_known_protos"]] , "pure C": [] + , "private-deps": [] } , "imports": { "protoc-compile": "protoc-compile" @@ -72,6 +73,7 @@ ] , "well_known_protos": [["@", "protoc", "", "well_known_protos"]] , "pure C": [] + , "private-deps": [] } , "imports": { "protoc-compile": "protoc-compile" -- cgit v1.2.3 From 18d2c74493d270d896a81e8593acdbee8b295408 Mon Sep 17 00:00:00 2001 From: Oliver Reiche Date: Thu, 8 Dec 2022 12:53:55 +0100 Subject: rules: Fix missing cflags for linking test binary ... which is required for cross-compilation, e.g., clang's `-target` option. --- CC/test/RULES | 1 + 1 file changed, 1 insertion(+) diff --git a/CC/test/RULES b/CC/test/RULES index 8082047..0d7a9ba 100644 --- a/CC/test/RULES +++ b/CC/test/RULES @@ -197,6 +197,7 @@ , "-o" , {"type": "var", "name": "binary name"} ] + , {"type": "var", "name": "CXXFLAGS"} , {"type": "var", "name": "link-args"} ] } -- cgit v1.2.3 From 00103df6ff5d06c85d6c42f1b9d1f56f2325ad3a Mon Sep 17 00:00:00 2001 From: Oliver Reiche Date: Mon, 28 Nov 2022 15:41:36 +0100 Subject: rules: Drop the ["CC", "header directory"] ... in favor of the "tree" built-in rule. --- CC/RULES | 59 ----------------------------------------------------------- 1 file changed, 59 deletions(-) diff --git a/CC/RULES b/CC/RULES index ab01a50..9e599e1 100644 --- a/CC/RULES +++ b/CC/RULES @@ -109,65 +109,6 @@ } } } -, "header directory": - { "doc": - [ "A directory of header files." - , "" - , "Define a directory of header files that belong together and are staged" - , "in such a way that no other target (used together with this target) will" - , "have to put files in this directory. The typical use case is a library" - , "libfoo that expects all headers to be included as #include \"foo/bar.h\"." - , "In this case, one would define a header direcotry for \"foo\"." - , "" - , "Technically, a tree is created from the given files and staged to the" - , "specified location. Since trees are opaque, the directory name becomes" - , "essentially owned by target. In this way, staging conflicts can be" - , "avoided by detecting them early and not only once a file with the same" - , "name is added to the staging location. Also, as only a tree identifier" - , "has to be passed around, such a directory can be handled more" - , "efficiently by the tool." - ] - , "target_fields": ["hdrs"] - , "string_fields": ["stage"] - , "field_doc": - { "hdrs": ["The header files to be put into the header directory."] - , "stage": - [ "The location of the header directory." - , "Path segments are joined with \"/\"." - ] - } - , "artifacts_doc": ["The single tree artifact staged to the given location"] - , "runfiles_doc": ["Same as artifacts"] - , "imports": {"runfiles": ["./", "..", "field_runfiles"]} - , "expression": - { "type": "let*" - , "bindings": - [ [ "hdrs" - , { "type": "let*" - , "bindings": [["fieldname", "hdrs"]] - , "body": {"type": "CALL_EXPRESSION", "name": "runfiles"} - } - ] - , [ "stage" - , { "type": "join" - , "separator": "/" - , "$1": {"type": "FIELD", "name": "stage"} - } - ] - , [ "dir" - , { "type": "singleton_map" - , "key": {"type": "var", "name": "stage"} - , "value": {"type": "TREE", "$1": {"type": "var", "name": "hdrs"}} - } - ] - ] - , "body": - { "type": "RESULT" - , "artifacts": {"type": "var", "name": "dir"} - , "runfiles": {"type": "var", "name": "dir"} - } - } - } , "library": { "doc": ["A C++ libaray"] , "target_fields": -- cgit v1.2.3 From d0fd0957b485cb28e22557f3fab11075cd5a6b8b Mon Sep 17 00:00:00 2001 From: Oliver Reiche Date: Fri, 2 Dec 2022 15:33:03 +0100 Subject: rules: Refactoring and minor improvements Compared to the previous commit, the action graphs for just and its unit tests are unchanged. - Git hash of action graph for ["",""]: c6e75f17abd7ffaab6ff9bb725ad67ec0bf6c973 - Git hash of action graph for ["test/buildtool","TESTS"]: 8063dfb3dd7daa9ae01d95c177e14946f785c57e Refactor: - "local cflags" to "private-cflags" - "local defines" to "private-defines" - "link externals" to "private-ldflags" - "deps" to "private-deps" for (test) binaries - "proto" to "private-proto" for binaries Improvements: - consistent variable declaration order: OS, ARCH, HOST_ARCH, TARGET_ARCH, CC, CXX, CFLAGS, CXXFLAGS, ADD_CFLAGS, ADD_CXXFLAGS, AR, ENV, PATH - use fields close to their definition (in RULES) - use common expression for binaries and test binaries - split expression "flags" and "compiler" ... to separate ones for CC and CXX. - rename "transition" to "deps-transition" ... to avoid conflicts with other transitions. - support "defaults-transition" for CC expressions Implement: - "cflags" for libraries - "private-cflags" for (test) binaries - "private-defines" for test binaries - "private-ldflags" for test binaries - (public) "defines" for libraries --- CC/EXPRESSIONS | 527 ++++++++++++++++++++++++++++++++++++++----------- CC/RULES | 275 ++++++++++---------------- CC/auto/RULES | 8 +- CC/proto/EXPRESSIONS | 31 ++- CC/proto/RULES | 57 +++--- CC/test/RULES | 181 +++++++---------- shell/test/EXPRESSIONS | 29 ++- shell/test/RULES | 3 + 8 files changed, 662 insertions(+), 449 deletions(-) diff --git a/CC/EXPRESSIONS b/CC/EXPRESSIONS index 7871ace..81ac1fd 100644 --- a/CC/EXPRESSIONS +++ b/CC/EXPRESSIONS @@ -1,59 +1,98 @@ { "default-CC": - { "imports": {"list_provider": ["./", "..", "field_list_provider"]} + { "vars": ["defaults-transition"] + , "imports": {"list_provider": ["./", "..", "field_list_provider"]} , "expression": { "type": "join" , "$1": { "type": "let*" - , "bindings": [["fieldname", "defaults"], ["provider", "CC"]] + , "bindings": + [ ["fieldname", "defaults"] + , ["provider", "CC"] + , [ "transition" + , {"type": "var", "name": "defaults-transition", "default": null} + ] + ] , "body": {"type": "CALL_EXPRESSION", "name": "list_provider"} } } } , "default-CXX": - { "imports": {"list_provider": ["./", "..", "field_list_provider"]} + { "vars": ["defaults-transition"] + , "imports": {"list_provider": ["./", "..", "field_list_provider"]} , "expression": { "type": "join" , "$1": { "type": "let*" - , "bindings": [["fieldname", "defaults"], ["provider", "CXX"]] + , "bindings": + [ ["fieldname", "defaults"] + , ["provider", "CXX"] + , [ "transition" + , {"type": "var", "name": "defaults-transition", "default": null} + ] + ] , "body": {"type": "CALL_EXPRESSION", "name": "list_provider"} } } } , "default-AR": - { "imports": {"list_provider": ["./", "..", "field_list_provider"]} + { "vars": ["defaults-transition"] + , "imports": {"list_provider": ["./", "..", "field_list_provider"]} , "expression": { "type": "join" , "$1": { "type": "let*" - , "bindings": [["fieldname", "defaults"], ["provider", "AR"]] + , "bindings": + [ ["fieldname", "defaults"] + , ["provider", "AR"] + , [ "transition" + , {"type": "var", "name": "defaults-transition", "default": null} + ] + ] , "body": {"type": "CALL_EXPRESSION", "name": "list_provider"} } } } , "default-CFLAGS": - { "imports": {"list_provider": ["./", "..", "field_list_provider"]} + { "vars": ["defaults-transition"] + , "imports": {"list_provider": ["./", "..", "field_list_provider"]} , "expression": { "type": "let*" - , "bindings": [["fieldname", "defaults"], ["provider", "CFLAGS"]] + , "bindings": + [ ["fieldname", "defaults"] + , ["provider", "CFLAGS"] + , [ "transition" + , {"type": "var", "name": "defaults-transition", "default": null} + ] + ] , "body": {"type": "CALL_EXPRESSION", "name": "list_provider"} } } , "default-CXXFLAGS": - { "imports": {"list_provider": ["./", "..", "field_list_provider"]} + { "vars": ["defaults-transition"] + , "imports": {"list_provider": ["./", "..", "field_list_provider"]} , "expression": { "type": "let*" - , "bindings": [["fieldname", "defaults"], ["provider", "CXXFLAGS"]] + , "bindings": + [ ["fieldname", "defaults"] + , ["provider", "CXXFLAGS"] + , [ "transition" + , {"type": "var", "name": "defaults-transition", "default": null} + ] + ] , "body": {"type": "CALL_EXPRESSION", "name": "list_provider"} } } , "default-ENV": - { "imports": {"provider_list": ["./", "..", "field_provider_list"]} + { "vars": ["defaults-transition"] + , "imports": {"provider_list": ["./", "..", "field_provider_list"]} , "expression": { "type": "let*" , "bindings": [ ["fieldname", "defaults"] , ["provider", "ENV"] + , [ "transition" + , {"type": "var", "name": "defaults-transition", "default": null} + ] , ["default", {"type": "empty_map"}] ] , "body": {"type": "CALL_EXPRESSION", "name": "provider_list"} @@ -84,11 +123,12 @@ } , "compile-deps": { "doc": ["Collect compile dependencies (headers) from given target_fields"] - , "vars": ["deps-fieldnames", "transition"] + , "vars": ["deps-fieldnames", "deps-transition"] , "vars_doc": { "deps-fieldnames": ["List of target_field names to collect dependencies from."] - , "transition": ["The optional configuration transition for the targets."] + , "deps-transition": + ["The optional configuration transition for the targets."] } , "imports": { "runfiles_list": ["./", "..", "field_runfiles_list"] @@ -108,6 +148,7 @@ { "type": "let*" , "bindings": [ ["provider", "compile-deps"] + , ["transition", {"type": "var", "name": "deps-transition"}] , ["default", {"type": "empty_map"}] ] , "body": @@ -120,13 +161,41 @@ } } } +, "compile-args-deps": + { "doc": ["Collect compile arguments from given target_fields"] + , "vars": ["deps-fieldnames", "deps-transition"] + , "vars_doc": + { "deps-fieldnames": + ["List of target_field names to collect arguments from."] + , "deps-transition": + ["The optional configuration transition for the targets."] + } + , "imports": {"list_provider": ["./", "..", "field_list_provider"]} + , "expression": + { "type": "++" + , "$1": + { "type": "foreach" + , "var": "fieldname" + , "range": {"type": "var", "name": "deps-fieldnames"} + , "body": + { "type": "let*" + , "bindings": + [ ["provider", "compile-args"] + , ["transition", {"type": "var", "name": "deps-transition"}] + ] + , "body": {"type": "CALL_EXPRESSION", "name": "list_provider"} + } + } + } + } , "link-deps": { "doc": ["Collect link dependencies (libraries) from given target_fields"] - , "vars": ["deps-fieldnames", "transition"] + , "vars": ["deps-fieldnames", "deps-transition"] , "vars_doc": { "deps-fieldnames": ["List of target_field names to collect dependencies from."] - , "transition": ["The optional configuration transition for the targets."] + , "deps-transition": + ["The optional configuration transition for the targets."] } , "imports": { "artifacts_list": ["./", "..", "field_artifacts_list"] @@ -145,7 +214,10 @@ , "$1": { "type": "let*" , "bindings": - [["provider", "link-deps"], ["default", {"type": "empty_map"}]] + [ ["provider", "link-deps"] + , ["default", {"type": "empty_map"}] + , ["transition", {"type": "var", "name": "deps-transition"}] + ] , "body": [ {"type": "CALL_EXPRESSION", "name": "provider_list"} , {"type": "CALL_EXPRESSION", "name": "artifacts_list"} @@ -158,11 +230,12 @@ } , "link-args-deps": { "doc": ["Collect linker arguments from given target_fields"] - , "vars": ["deps-fieldnames", "transition"] + , "vars": ["deps-fieldnames", "deps-transition"] , "vars_doc": { "deps-fieldnames": ["List of target_field names to collect arguments from."] - , "transition": ["The optional configuration transition for the targets."] + , "deps-transition": + ["The optional configuration transition for the targets."] } , "imports": {"list_provider": ["./", "..", "field_list_provider"]} , "expression": @@ -173,14 +246,25 @@ , "range": {"type": "var", "name": "deps-fieldnames"} , "body": { "type": "let*" - , "bindings": [["provider", "link-args"]] + , "bindings": + [ ["provider", "link-args"] + , ["transition", {"type": "var", "name": "deps-transition"}] + ] , "body": {"type": "CALL_EXPRESSION", "name": "list_provider"} } } } } , "objects": - { "vars": ["CXX", "CXXFLAGS", "ENV", "srcs", "compile-deps", "local hdrs"] + { "vars": + [ "COMPILER" + , "COMPILE_FLAGS" + , "ENV" + , "srcs" + , "hdrs" + , "private-hdrs" + , "compile-deps" + ] , "expression": { "type": "let*" , "bindings": @@ -197,7 +281,13 @@ [ {"type": "var", "name": "include tree"} , { "type": "to_subdir" , "subdir": "work" - , "$1": {"type": "var", "name": "local hdrs"} + , "$1": + { "type": "disjoint_map_union" + , "$1": + [ {"type": "var", "name": "hdrs"} + , {"type": "var", "name": "private-hdrs"} + ] + } } ] } @@ -254,8 +344,8 @@ , "cmd": { "type": "++" , "$1": - [ [{"type": "var", "name": "CXX"}] - , {"type": "var", "name": "CXXFLAGS"} + [ [{"type": "var", "name": "COMPILER"}] + , {"type": "var", "name": "COMPILE_FLAGS"} , ["-I", "work", "-isystem", "include"] , ["-c", {"type": "var", "name": "work src_name"}] , ["-o", {"type": "var", "name": "work out"}] @@ -284,70 +374,98 @@ } } } +, "compiler-cc": + { "vars": ["CC", "defaults-transition"] + , "imports": {"default-CC": "default-CC"} + , "expression": + { "type": "var" + , "name": "CC" + , "default": {"type": "CALL_EXPRESSION", "name": "default-CC"} + } + } +, "compiler-cxx": + { "vars": ["CXX", "defaults-transition"] + , "imports": {"default-CXX": "default-CXX"} + , "expression": + { "type": "var" + , "name": "CXX" + , "default": {"type": "CALL_EXPRESSION", "name": "default-CXX"} + } + } , "compiler": - { "vars": ["CC", "CXX"] - , "imports": {"default-CC": "default-CC", "default-CXX": "default-CXX"} + { "vars": ["CC", "CXX", "pure C", "defaults-transition"] + , "imports": {"compiler-cc": "compiler-cc", "compiler-cxx": "compiler-cxx"} , "expression": { "type": "if" - , "cond": {"type": "FIELD", "name": "pure C"} - , "then": - { "type": "var" - , "name": "CC" - , "default": {"type": "CALL_EXPRESSION", "name": "default-CC"} - } - , "else": - { "type": "var" - , "name": "CXX" - , "default": {"type": "CALL_EXPRESSION", "name": "default-CXX"} - } + , "cond": {"type": "var", "name": "pure C"} + , "then": {"type": "CALL_EXPRESSION", "name": "compiler-cc"} + , "else": {"type": "CALL_EXPRESSION", "name": "compiler-cxx"} } } -, "flags": - { "vars": ["CFLAGS", "CXXFLAGS", "ADD_CFLAGS", "ADD_CXXFLAGS"] - , "imports": - { "default-CFLAGS": "default-CFLAGS" - , "default-CXXFLAGS": "default-CXXFLAGS" +, "flags-cc": + { "vars": ["CFLAGS", "ADD_CFLAGS", "defaults-transition"] + , "imports": {"default-CFLAGS": "default-CFLAGS"} + , "expression": + { "type": "++" + , "$1": + [ { "type": "var" + , "name": "CFLAGS" + , "default": {"type": "CALL_EXPRESSION", "name": "default-CFLAGS"} + } + , {"type": "var", "name": "ADD_CFLAGS", "default": []} + ] } + } +, "flags-cxx": + { "vars": ["CXXFLAGS", "ADD_CXXFLAGS", "defaults-transition"] + , "imports": {"default-CXXFLAGS": "default-CXXFLAGS"} , "expression": - { "type": "if" - , "cond": {"type": "FIELD", "name": "pure C"} - , "then": - { "type": "++" - , "$1": - [ { "type": "var" - , "name": "CFLAGS" - , "default": {"type": "CALL_EXPRESSION", "name": "default-CFLAGS"} - } - , {"type": "var", "name": "ADD_CFLAGS", "default": []} - ] - } - , "else": - { "type": "++" - , "$1": - [ { "type": "var" - , "name": "CXXFLAGS" - , "default": {"type": "CALL_EXPRESSION", "name": "default-CXXFLAGS"} - } - , {"type": "var", "name": "ADD_CXXFLAGS", "default": []} - ] - } + { "type": "++" + , "$1": + [ { "type": "var" + , "name": "CXXFLAGS" + , "default": {"type": "CALL_EXPRESSION", "name": "default-CXXFLAGS"} + } + , {"type": "var", "name": "ADD_CXXFLAGS", "default": []} + ] } } -, "lib artifact": +, "flags": { "vars": - [ "CXX" + [ "CFLAGS" , "CXXFLAGS" + , "ADD_CFLAGS" , "ADD_CXXFLAGS" - , "CC" + , "pure C" + , "defaults-transition" + ] + , "imports": {"flags-cc": "flags-cc", "flags-cxx": "flags-cxx"} + , "expression": + { "type": "if" + , "cond": {"type": "var", "name": "pure C"} + , "then": {"type": "CALL_EXPRESSION", "name": "flags-cc"} + , "else": {"type": "CALL_EXPRESSION", "name": "flags-cxx"} + } + } +, "lib artifact": + { "vars": + [ "CC" + , "CXX" , "CFLAGS" + , "CXXFLAGS" , "ADD_CFLAGS" - , "ENV" + , "ADD_CXXFLAGS" , "AR" + , "ENV" + , "name" + , "pure C" , "srcs" , "hdrs" , "private-hdrs" - , "local cflags" + , "stage" , "compile-deps" + , "compile-args" + , "defaults-transition" ] , "imports": { "compiler": "compiler" @@ -359,28 +477,21 @@ , "expression": { "type": "let*" , "bindings": - [ [ "stage" - , { "type": "join" - , "separator": "/" - , "$1": {"type": "FIELD", "name": "stage"} + [ ["COMPILER", {"type": "CALL_EXPRESSION", "name": "compiler"}] + , [ "COMPILE_FLAGS" + , { "type": "++" + , "$1": + [ {"type": "CALL_EXPRESSION", "name": "flags"} + , {"type": "var", "name": "compile-args"} + ] } ] - , ["CXX", {"type": "CALL_EXPRESSION", "name": "compiler"}] - , ["CXXFLAGS", {"type": "CALL_EXPRESSION", "name": "flags"}] , [ "AR" , { "type": "var" , "name": "AR" , "default": {"type": "CALL_EXPRESSION", "name": "default-AR"} } ] - , [ "CXXFLAGS" - , { "type": "++" - , "$1": - [ {"type": "var", "name": "CXXFLAGS"} - , {"type": "var", "name": "local cflags", "default": []} - ] - } - ] , [ "ENV" , { "type": "map_union" , "$1": @@ -396,32 +507,16 @@ } } ] - , [ "local hdrs" - , { "type": "disjoint_map_union" - , "$1": - [ {"type": "var", "name": "hdrs"} - , {"type": "var", "name": "private-hdrs"} - ] - } - ] , ["objects", {"type": "CALL_EXPRESSION", "name": "objects"}] , [ "base name" - , { "type": "let*" - , "bindings": - [ [ "name" - , {"type": "join", "$1": {"type": "FIELD", "name": "name"}} - ] - ] - , "body": - { "type": "if" - , "cond": {"type": "var", "name": "objects"} - , "then": - { "type": "assert_non_empty" - , "msg": "A name has to be provided for non-header-only libraries" - , "$1": {"type": "var", "name": "name"} - } - , "else": {"type": "var", "name": "name"} + , { "type": "if" + , "cond": {"type": "var", "name": "objects"} + , "then": + { "type": "assert_non_empty" + , "msg": "A name has to be provided for non-header-only libraries" + , "$1": {"type": "var", "name": "name"} } + , "else": {"type": "var", "name": "name"} } ] , [ "libname" @@ -462,23 +557,30 @@ } , "lib result": { "vars": - [ "CXX" - , "CXXFLAGS" - , "ADD_CXXFLAGS" - , "CC" + [ "CC" + , "CXX" , "CFLAGS" + , "CXXFLAGS" , "ADD_CFLAGS" - , "ENV" + , "ADD_CXXFLAGS" , "AR" + , "ENV" + , "name" + , "pure C" , "srcs" , "hdrs" , "private-hdrs" - , "local cflags" - , "link external" + , "cflags" + , "private-cflags" + , "private-ldflags" + , "stage" , "extra-provides" + , "public-fieldnames" + , "private-fieldnames" ] , "imports": { "compile-deps": "compile-deps" + , "compile-args-deps": "compile-args-deps" , "link-deps": "link-deps" , "link-args-deps": "link-args-deps" , "lib artifact": "lib artifact" @@ -486,8 +588,20 @@ , "expression": { "type": "let*" , "bindings": - [ ["deps-fieldnames", ["deps", "private-deps", "proto-deps"]] + [ ["deps-fieldnames", {"type": "var", "name": "private-fieldnames"}] , ["compile-deps", {"type": "CALL_EXPRESSION", "name": "compile-deps"}] + , [ "compile-args" + , { "type": "nub_right" + , "$1": + { "type": "++" + , "$1": + [ {"type": "var", "name": "cflags"} + , {"type": "var", "name": "private-cflags"} + , {"type": "CALL_EXPRESSION", "name": "compile-args-deps"} + ] + } + } + ] , ["link-deps", {"type": "CALL_EXPRESSION", "name": "link-deps"}] , ["lib", {"type": "CALL_EXPRESSION", "name": "lib artifact"}] , [ "link-args" @@ -496,14 +610,25 @@ { "type": "++" , "$1": [ {"type": "keys", "$1": {"type": "var", "name": "lib"}} - , {"type": "var", "name": "link external", "default": []} + , {"type": "var", "name": "private-ldflags", "default": []} , {"type": "CALL_EXPRESSION", "name": "link-args-deps"} ] } } ] - , ["deps-fieldnames", ["deps", "proto-deps"]] + , ["deps-fieldnames", {"type": "var", "name": "public-fieldnames"}] , ["compile-deps", {"type": "CALL_EXPRESSION", "name": "compile-deps"}] + , [ "compile-args" + , { "type": "nub_right" + , "$1": + { "type": "++" + , "$1": + [ {"type": "var", "name": "cflags"} + , {"type": "CALL_EXPRESSION", "name": "compile-args-deps"} + ] + } + } + ] ] , "body": { "type": "RESULT" @@ -512,7 +637,10 @@ , "provides": { "type": "map_union" , "$1": - [ {"type": "env", "vars": ["compile-deps", "link-deps", "link-args"]} + [ { "type": "env" + , "vars": + ["compile-deps", "compile-args", "link-deps", "link-args"] + } , { "type": "var" , "name": "extra-provides" , "default": {"type": "empty_map"} @@ -522,4 +650,171 @@ } } } +, "bin artifact": + { "doc": ["Produces the binary artifact."] + , "vars": + [ "CC" + , "CXX" + , "CFLAGS" + , "CXXFLAGS" + , "ADD_CFLAGS" + , "ADD_CXXFLAGS" + , "ENV" + , "name" + , "pure C" + , "srcs" + , "private-hdrs" + , "stage" + , "compile-deps" + , "compile-args" + , "link-deps" + , "link-args" + , "defaults-transition" + ] + , "imports": + { "compiler": "compiler" + , "flags": "flags" + , "objects": "objects" + , "default-ENV": "default-ENV" + } + , "expression": + { "type": "let*" + , "bindings": + [ ["COMPILER", {"type": "CALL_EXPRESSION", "name": "compiler"}] + , [ "COMPILE_FLAGS" + , { "type": "++" + , "$1": + [ {"type": "CALL_EXPRESSION", "name": "flags"} + , {"type": "var", "name": "compile-args"} + ] + } + ] + , [ "ENV" + , { "type": "map_union" + , "$1": + { "type": "++" + , "$1": + [ {"type": "CALL_EXPRESSION", "name": "default-ENV"} + , [ { "type": "var" + , "name": "ENV" + , "default": {"type": "empty_map"} + } + ] + ] + } + } + ] + , ["hdrs", {"type": "empty_map"}] + , ["objects", {"type": "CALL_EXPRESSION", "name": "objects"}] + , [ "link-args" + , { "type": "nub_right" + , "$1": + { "type": "++" + , "$1": + [ {"type": "keys", "$1": {"type": "var", "name": "objects"}} + , {"type": "var", "name": "link-args"} + ] + } + } + ] + , [ "binpath" + , { "type": "if" + , "cond": {"type": "var", "name": "stage"} + , "then": + { "type": "join" + , "separator": "/" + , "$1": + [ {"type": "var", "name": "stage"} + , {"type": "var", "name": "name"} + ] + } + , "else": {"type": "var", "name": "name"} + } + ] + , [ "binary" + , { "type": "ACTION" + , "outs": [{"type": "var", "name": "binpath"}] + , "inputs": + { "type": "disjoint_map_union" + , "$1": + [ {"type": "var", "name": "objects"} + , {"type": "var", "name": "link-deps"} + ] + } + , "cmd": + { "type": "++" + , "$1": + [ [ {"type": "var", "name": "COMPILER"} + , "-o" + , {"type": "var", "name": "binpath"} + ] + , {"type": "var", "name": "COMPILE_FLAGS"} + , {"type": "var", "name": "link-args"} + ] + } + , "env": {"type": "var", "name": "ENV"} + } + ] + ] + , "body": {"type": "var", "name": "binary"} + } + } +, "bin result": + { "doc": ["Produces the binary target result."] + , "vars": + [ "CC" + , "CXX" + , "CFLAGS" + , "CXXFLAGS" + , "ADD_CFLAGS" + , "ADD_CXXFLAGS" + , "ENV" + , "name" + , "pure C" + , "srcs" + , "private-hdrs" + , "private-cflags" + , "private-ldflags" + , "stage" + , "private-fieldnames" + ] + , "imports": + { "compile-deps": "compile-deps" + , "compile-args-deps": "compile-args-deps" + , "link-deps": "link-deps" + , "link-args-deps": "link-args-deps" + , "binary": "bin artifact" + } + , "expression": + { "type": "let*" + , "bindings": + [ ["deps-fieldnames", {"type": "var", "name": "private-fieldnames"}] + , ["compile-deps", {"type": "CALL_EXPRESSION", "name": "compile-deps"}] + , [ "compile-args" + , { "type": "++" + , "$1": + [ {"type": "CALL_EXPRESSION", "name": "compile-args-deps"} + , {"type": "var", "name": "private-cflags"} + ] + } + ] + , ["link-deps", {"type": "CALL_EXPRESSION", "name": "link-deps"}] + , [ "link-args" + , { "type": "nub_right" + , "$1": + { "type": "++" + , "$1": + [ {"type": "CALL_EXPRESSION", "name": "link-args-deps"} + , {"type": "var", "name": "private-ldflags"} + ] + } + } + ] + ] + , "body": + { "type": "RESULT" + , "artifacts": {"type": "CALL_EXPRESSION", "name": "binary"} + } + } + } } diff --git a/CC/RULES b/CC/RULES index 9e599e1..9b041dd 100644 --- a/CC/RULES +++ b/CC/RULES @@ -1,7 +1,7 @@ { "defaults": { "doc": [ "A rule to provide defaults." - , "All CC targets take their defaults for CXX, CC, flags, etc from" + , "All CC targets take their defaults for CC, CXX, flags, etc from" , "the target [\"CC\", \"defaults\"]. This is probably the only sensibe" , "use of this rule. As targets form a different root, the defaults" , "can be provided without changing this directory." @@ -14,8 +14,8 @@ , "CXXFLAGS" , "ADD_CFLAGS" , "ADD_CXXFLAGS" - , "PATH" , "AR" + , "PATH" ] , "imports": {"base-provides": "defaults-base-provides"} , "expression": @@ -110,26 +110,28 @@ } } , "library": - { "doc": ["A C++ libaray"] + { "doc": ["A C++ library"] , "target_fields": ["srcs", "hdrs", "private-hdrs", "deps", "private-deps", "proto"] , "string_fields": [ "name" , "stage" , "pure C" - , "local defines" - , "local cflags" - , "link external" + , "defines" + , "private-defines" + , "cflags" + , "private-cflags" + , "private-ldflags" ] , "config_vars": - [ "CXX" - , "CC" - , "CXXFLAGS" + [ "CC" + , "CXX" , "CFLAGS" - , "ADD_CXXFLAGS" + , "CXXFLAGS" , "ADD_CFLAGS" - , "ENV" + , "ADD_CXXFLAGS" , "AR" + , "ENV" ] , "implicit": {"defaults": ["defaults"]} , "field_doc": @@ -151,13 +153,19 @@ , "In particular, CC is used to compile rather than CXX (or their" , "respective defaults)." ] - , "local defines": + , "defines": + [ "List of defines set for this target and its consumers." + , "Each list entry will be prepended by \"-D\"." + ] + , "private-defines": [ "List of defines set for source files local to this target." , "Each list entry will be prepended by \"-D\"." ] - , "local cflags": + , "cflags": + ["List of compile flags set for this target and its consumers."] + , "private-cflags": ["List of compile flags set for source files local to this target."] - , "link external": + , "private-ldflags": [ "Additional linker flags for linking external libraries (not built" , "by this tool, typically system libraries)." ] @@ -175,30 +183,31 @@ ] } , "config_doc": - { "CXX": - [ "The name of the C++ compiler to be used." - , "If None, the respective value from [\"CC\", \"defaults\"] will be taken." - ] - , "CC": + { "CC": [ "The name of the C compiler to be used (when compiling pure C code)." , "If None, the respective value from [\"CC\", \"defaults\"] will be taken." ] - , "AR": - [ "The archive tool to used for creating the library" + , "CXX": + [ "The name of the C++ compiler to be used." , "If None, the respective value from [\"CC\", \"defaults\"] will be taken." ] - , "ENV": ["The environment for any action generated."] + , "CFLAGS": + [ "The flags for CC to be used instead of the default ones." + , "For libraries that should be built in a non-standard way; usually" + , "adapting the default target [\"CC\", \"defaults\"] is the better" + , "choice." + ] , "CXXFLAGS": [ "The flags for CXX to be used instead of the default ones." , "For libraries that should be built in a non-standard way; usually" , "adapting the default target [\"CC\", \"defaults\"] is the better" , "choice." ] - , "CFLAGS": - [ "The flags for CC to be used instead of the default ones." + , "ADD_CFLAGS": + [ "The flags to add to the default ones for CC." , "For libraries that should be built in a non-standard way; usually" , "adapting the default target [\"CC\", \"defaults\"] is the better" - , "choice" + , "choice." ] , "ADD_CXXFLAGS": [ "The flags to add to the default ones for CXX." @@ -206,12 +215,11 @@ , "adapting the default target [\"CC\", \"defaults\"] is the better" , "choice." ] - , "ADD_CFLAGS": - [ "The flags to add to the default ones for CC." - , "For libraries that should be built in a non-standard way; usually" - , "adapting the default target [\"CC\", \"defaults\"] is the better" - , "choice." + , "AR": + [ "The archive tool to used for creating the library" + , "If None, the respective value from [\"CC\", \"defaults\"] will be taken." ] + , "ENV": ["The environment for any action generated."] } , "artifacts_doc": ["The actual library (libname.a) staged in the specified directory"] @@ -241,44 +249,35 @@ } } , "imports": - { "artifacts": ["./", "..", "field_artifacts"] - , "default-CXXFLAGS": "default-CXXFLAGS" - , "default-CFLAGS": "default-CFLAGS" - , "result": "lib result" - } + {"artifacts": ["./", "..", "field_artifacts"], "result": "lib result"} , "expression": { "type": "let*" , "bindings": - [ [ "local defines" - , { "type": "foreach" - , "var": "def" - , "range": {"type": "FIELD", "name": "local defines"} - , "body": - {"type": "join", "$1": ["-D", {"type": "var", "name": "def"}]} - } - ] - , ["local cflags", {"type": "FIELD", "name": "local cflags"}] - , [ "CFLAGS" + [ ["name", {"type": "join", "$1": {"type": "FIELD", "name": "name"}}] + , ["pure C", {"type": "FIELD", "name": "pure C"}] + , [ "cflags" , { "type": "++" , "$1": - [ { "type": "var" - , "name": "CFLAGS" - , "default": - {"type": "CALL_EXPRESSION", "name": "default-CFLAGS"} + [ {"type": "FIELD", "name": "cflags"} + , { "type": "foreach" + , "var": "def" + , "range": {"type": "FIELD", "name": "defines"} + , "body": + {"type": "join", "$1": ["-D", {"type": "var", "name": "def"}]} } - , {"type": "var", "name": "local defines"} ] } ] - , [ "CXXFLAGS" + , [ "private-cflags" , { "type": "++" , "$1": - [ { "type": "var" - , "name": "CXXFLAGS" - , "default": - {"type": "CALL_EXPRESSION", "name": "default-CXXFLAGS"} + [ { "type": "foreach" + , "var": "def" + , "range": {"type": "FIELD", "name": "private-defines"} + , "body": + {"type": "join", "$1": ["-D", {"type": "var", "name": "def"}]} } - , {"type": "var", "name": "local defines"} + , {"type": "FIELD", "name": "private-cflags"} ] } ] @@ -318,18 +317,26 @@ } } ] - , ["link external", {"type": "FIELD", "name": "link external"}] + , ["private-ldflags", {"type": "FIELD", "name": "private-ldflags"}] + , ["public-fieldnames", ["deps", "proto-deps"]] + , ["private-fieldnames", ["deps", "private-deps", "proto-deps"]] ] , "body": {"type": "CALL_EXPRESSION", "name": "result"} } } , "binary": { "doc": ["A binary written in C++"] - , "target_fields": ["srcs", "private-hdrs", "deps", "proto"] + , "target_fields": ["srcs", "private-hdrs", "private-deps", "private-proto"] , "string_fields": - ["name", "stage", "pure C", "local defines", "link external"] + [ "name" + , "stage" + , "pure C" + , "private-defines" + , "private-cflags" + , "private-ldflags" + ] , "config_vars": - ["CXX", "CC", "CXXFLAGS", "CFLAGS", "ADD_CXXFLAGS", "ADD_CFLAGS", "ENV"] + ["CC", "CXX", "CFLAGS", "CXXFLAGS", "ADD_CFLAGS", "ADD_CXXFLAGS", "ENV"] , "implicit": {"defaults": ["defaults"]} , "field_doc": { "name": ["The name of the binary"] @@ -347,14 +354,16 @@ [ "If non-empty, compile as C sources rathter than C++ sources." , "In particular, CC is used to compile rather than CXX" ] - , "local defines": + , "private-defines": [ "List of defines set for source files local to this target." , "Each list entry will be prepended by \"-D\"." ] - , "link external": + , "private-cflags": + ["List of compile flags set for source files local to this target."] + , "private-ldflags": ["Additional linker flags for linking external libraries."] - , "deps": ["Any other libraries this binary depends upon."] - , "proto": + , "private-deps": ["Any other libraries this binary depends upon."] + , "private-proto": [ "Any [\"proto\", \"library\"] this target depends upon directly." , "The creation of C++ bindings for this proto library as well as of" , "is dependencies will be taken care of (as anonymous targets, so no" @@ -363,32 +372,32 @@ ] } , "config_doc": - { "CXX": ["The name of the C++ compiler to be used."] - , "CC": + { "CC": ["The name of the C compiler to be used (when compiling pure C code)"] - , "ENV": ["The environment for any action generated."] - , "CXXFLAGS": - [ "The flags for CXX to be used instead of the default ones" - , "taken from the [\"CC\", \"defaults\"] target" - ] + , "CXX": ["The name of the C++ compiler to be used."] , "CFLAGS": [ "The flags for CXX to be used instead of the default ones" , "taken from the [\"CC\", \"defaults\"] target" ] - , "ADD_CXXFLAGS": - [ "The flags to add to the default ones for CXX" + , "CXXFLAGS": + [ "The flags for CXX to be used instead of the default ones" , "taken from the [\"CC\", \"defaults\"] target" ] , "ADD_CFLAGS": [ "The flags to add to the default ones for CC" , "taken from the [\"CC\", \"defaults\"] target" ] + , "ADD_CXXFLAGS": + [ "The flags to add to the default ones for CXX" + , "taken from the [\"CC\", \"defaults\"] target" + ] + , "ENV": ["The environment for any action generated."] } , "artifacts_doc": ["The final binary, staged to the given directory"] , "runfiles_doc": ["None"] , "anonymous": - { "proto-deps": - { "target": "proto" + { "private-proto-deps": + { "target": "private-proto" , "provider": "proto" , "rule_map": { "library": ["./", "proto", "library"] @@ -397,26 +406,17 @@ } } , "imports": - { "artifacts": ["./", "..", "field_artifacts"] - , "compile-deps": "compile-deps" - , "link-deps": "link-deps" - , "link-args-deps": "link-args-deps" - , "objects": "objects" - , "compiler": "compiler" - , "flags": "flags" - , "default-ENV": "default-ENV" - } + {"artifacts": ["./", "..", "field_artifacts"], "bin result": "bin result"} , "expression": { "type": "let*" , "bindings": - [ [ "local defines" - , { "type": "foreach" - , "var": "def" - , "range": {"type": "FIELD", "name": "local defines"} - , "body": - {"type": "join", "$1": ["-D", {"type": "var", "name": "def"}]} + [ [ "name" + , { "type": "assert_non_empty" + , "msg": "A non-empty name has to be provided for binaries" + , "$1": {"type": "join", "$1": {"type": "FIELD", "name": "name"}} } ] + , ["pure C", {"type": "FIELD", "name": "pure C"}] , [ "stage" , { "type": "join" , "separator": "/" @@ -433,7 +433,7 @@ } } ] - , [ "local hdrs" + , [ "private-hdrs" , { "type": "to_subdir" , "subdir": {"type": "var", "name": "stage"} , "$1": @@ -443,94 +443,23 @@ } } ] - , ["CXX", {"type": "CALL_EXPRESSION", "name": "compiler"}] - , ["CXXFLAGS", {"type": "CALL_EXPRESSION", "name": "flags"}] - , [ "CXXFLAGS" + , [ "private-cflags" , { "type": "++" , "$1": - [ {"type": "var", "name": "CXXFLAGS"} - , {"type": "var", "name": "local defines"} + [ { "type": "foreach" + , "var": "def" + , "range": {"type": "FIELD", "name": "private-defines"} + , "body": + {"type": "join", "$1": ["-D", {"type": "var", "name": "def"}]} + } + , {"type": "FIELD", "name": "private-cflags"} ] } ] - , [ "ENV" - , { "type": "map_union" - , "$1": - { "type": "++" - , "$1": - [ {"type": "CALL_EXPRESSION", "name": "default-ENV"} - , [ { "type": "var" - , "name": "ENV" - , "default": {"type": "empty_map"} - } - ] - ] - } - } - ] - , ["deps-fieldnames", ["deps", "proto-deps"]] - , ["compile-deps", {"type": "CALL_EXPRESSION", "name": "compile-deps"}] - , ["link-deps", {"type": "CALL_EXPRESSION", "name": "link-deps"}] - , ["objects", {"type": "CALL_EXPRESSION", "name": "objects"}] - , [ "base name" - , { "type": "assert_non_empty" - , "msg": "A non-empty name has to be provided for binaries" - , "$1": {"type": "join", "$1": {"type": "FIELD", "name": "name"}} - } - ] - , [ "binary name" - , { "type": "if" - , "cond": {"type": "var", "name": "stage"} - , "else": {"type": "var", "name": "base name"} - , "then": - { "type": "join" - , "separator": "/" - , "$1": - [ {"type": "var", "name": "stage"} - , {"type": "var", "name": "base name"} - ] - } - } - ] - , [ "link-args" - , { "type": "nub_right" - , "$1": - { "type": "++" - , "$1": - [ {"type": "keys", "$1": {"type": "var", "name": "objects"}} - , {"type": "CALL_EXPRESSION", "name": "link-args-deps"} - , {"type": "FIELD", "name": "link external"} - ] - } - } - ] - , [ "binary" - , { "type": "ACTION" - , "outs": [{"type": "var", "name": "binary name"}] - , "inputs": - { "type": "disjoint_map_union" - , "$1": - [ {"type": "var", "name": "objects"} - , {"type": "var", "name": "link-deps"} - ] - } - , "cmd": - { "type": "++" - , "$1": - [ [ {"type": "var", "name": "CXX"} - , "-o" - , {"type": "var", "name": "binary name"} - ] - , {"type": "var", "name": "CXXFLAGS"} - , {"type": "var", "name": "link-args"} - ] - } - , "env": {"type": "var", "name": "ENV"} - } - ] + , ["private-ldflags", {"type": "FIELD", "name": "private-ldflags"}] + , ["private-fieldnames", ["private-deps", "private-proto-deps"]] ] - , "body": - {"type": "RESULT", "artifacts": {"type": "var", "name": "binary"}} + , "body": {"type": "CALL_EXPRESSION", "name": "bin result"} } } } diff --git a/CC/auto/RULES b/CC/auto/RULES index ab1e689..2429634 100644 --- a/CC/auto/RULES +++ b/CC/auto/RULES @@ -24,12 +24,12 @@ ] } , "config_doc": - { "CXX": - [ "The name of the C++ compiler to be used by checks. If None, the" + { "CC": + [ "The name of the C compiler to be used by checks. If None, the" , "respective value from [\"CC\", \"defaults\"] will be taken." ] - , "CC": - [ "The name of the C compiler to be used by checks. If None, the" + , "CXX": + [ "The name of the C++ compiler to be used by checks. If None, the" , "respective value from [\"CC\", \"defaults\"] will be taken." ] , "CFLAGS": diff --git a/CC/proto/EXPRESSIONS b/CC/proto/EXPRESSIONS index b2b3ea0..1ab17a5 100644 --- a/CC/proto/EXPRESSIONS +++ b/CC/proto/EXPRESSIONS @@ -8,13 +8,17 @@ } , "protoc-compile": { "vars": - [ "transition" - , "service support" - , "CXX" + [ "CXX" , "CXXFLAGS" , "ADD_CXXFLAGS" - , "ENV" , "AR" + , "ENV" + , "name" + , "stage" + , "service support" + , "deps-transition" + , "public-fieldnames" + , "private-fieldnames" ] , "imports": { "stage": ["", "stage_singleton_field"] @@ -26,9 +30,14 @@ , "expression": { "type": "let*" , "bindings": - [ [ "protoc" + [ ["pure C", false] + , [ "protoc" , { "type": "let*" - , "bindings": [["fieldname", "protoc"], ["location", "protoc"]] + , "bindings": + [ ["fieldname", "protoc"] + , ["transition", {"type": "var", "name": "deps-transition"}] + , ["location", "protoc"] + ] , "body": {"type": "CALL_EXPRESSION", "name": "stage"} } ] @@ -39,6 +48,7 @@ { "type": "let*" , "bindings": [ ["fieldname", "grpc_cpp_plugin"] + , ["transition", {"type": "var", "name": "deps-transition"}] , ["location", "grpc_cpp_plugin"] ] , "body": {"type": "CALL_EXPRESSION", "name": "stage"} @@ -52,8 +62,7 @@ , "subdir": "work" , "$1": { "type": "let*" - , "bindings": - [["fieldname", "well_known_protos"], ["transition", null]] + , "bindings": [["fieldname", "well_known_protos"]] , "body": {"type": "CALL_EXPRESSION", "name": "artifacts"} } } @@ -63,7 +72,7 @@ , "msg": "Sources may not conflict" , "$1": { "type": "let*" - , "bindings": [["fieldname", "srcs"], ["transition", null]] + , "bindings": [["fieldname", "srcs"]] , "body": {"type": "CALL_EXPRESSION", "name": "artifacts_list"} } } @@ -289,7 +298,9 @@ , "value": {"type": "var", "name": "all proto srcs"} } ] - , ["local cflags", ["-Wno-sign-conversion", "-Wno-unused-function"]] + , ["cflags", []] + , ["private-cflags", ["-Wno-sign-conversion", "-Wno-unused-function"]] + , ["private-ldflags", []] ] , "body": {"type": "CALL_EXPRESSION", "name": "result"} } diff --git a/CC/proto/RULES b/CC/proto/RULES index d53ab35..d1cfc4e 100644 --- a/CC/proto/RULES +++ b/CC/proto/RULES @@ -8,25 +8,12 @@ , "string_fields": ["name", "stage"] , "target_fields": ["srcs", "deps"] , "config_vars": - [ "OS" - , "ARCH" - , "HOST_ARCH" - , "CXX" - , "CC" - , "CXXFLAGS" - , "CFLAGS" - , "ADD_CXXFLAGS" - , "ADD_CFLAGS" - , "ENV" - , "AR" - ] + ["OS", "ARCH", "HOST_ARCH", "CXX", "CFLAGS", "ADD_CFLAGS", "AR", "ENV"] , "implicit": { "protoc": [["@", "protoc", "", "protoc"]] , "defaults": [["./", "..", "defaults"]] , "proto-deps": [["@", "protoc", "", "C++ runtime"]] , "well_known_protos": [["@", "protoc", "", "well_known_protos"]] - , "pure C": [] - , "private-deps": [] } , "imports": { "protoc-compile": "protoc-compile" @@ -37,7 +24,19 @@ , "expression": { "type": "let*" , "bindings": - [["transition", {"type": "CALL_EXPRESSION", "name": "host transition"}]] + [ ["name", {"type": "join", "$1": {"type": "FIELD", "name": "name"}}] + , [ "stage" + , { "type": "join" + , "separator": "/" + , "$1": {"type": "FIELD", "name": "stage"} + } + ] + , [ "deps-transition" + , {"type": "CALL_EXPRESSION", "name": "host transition"} + ] + , ["public-fieldnames", ["deps", "proto-deps"]] + , ["private-fieldnames", ["deps", "proto-deps"]] + ] , "body": {"type": "CALL_EXPRESSION", "name": "protoc-compile"} } } @@ -51,18 +50,7 @@ , "string_fields": ["name", "stage"] , "target_fields": ["srcs", "deps"] , "config_vars": - [ "OS" - , "ARCH" - , "HOST_ARCH" - , "CXX" - , "CC" - , "CXXFLAGS" - , "CFLAGS" - , "ADD_CXXFLAGS" - , "ADD_CFLAGS" - , "ENV" - , "AR" - ] + ["OS", "ARCH", "HOST_ARCH", "CXX", "CXXFLAGS", "ADD_CXXFLAGS", "AR", "ENV"] , "implicit": { "protoc": [["@", "protoc", "", "protoc"]] , "grpc_cpp_plugin": [["@", "grpc", "src/compiler", "grpc_cpp_plugin"]] @@ -72,8 +60,6 @@ , ["@", "protoc", "", "C++ runtime"] ] , "well_known_protos": [["@", "protoc", "", "well_known_protos"]] - , "pure C": [] - , "private-deps": [] } , "imports": { "protoc-compile": "protoc-compile" @@ -88,7 +74,18 @@ { "type": "let*" , "bindings": [ ["service support", true] - , ["transition", {"type": "CALL_EXPRESSION", "name": "host transition"}] + , ["name", {"type": "join", "$1": {"type": "FIELD", "name": "name"}}] + , [ "stage" + , { "type": "join" + , "separator": "/" + , "$1": {"type": "FIELD", "name": "stage"} + } + ] + , [ "deps-transition" + , {"type": "CALL_EXPRESSION", "name": "host transition"} + ] + , ["public-fieldnames", ["deps", "proto-deps"]] + , ["private-fieldnames", ["deps", "proto-deps"]] ] , "body": {"type": "CALL_EXPRESSION", "name": "protoc-compile"} } diff --git a/CC/test/RULES b/CC/test/RULES index 0d7a9ba..b42b6c4 100644 --- a/CC/test/RULES +++ b/CC/test/RULES @@ -4,24 +4,28 @@ , "FIXME: the test binary and data must be built for host" ] , "tainted": ["test"] - , "target_fields": ["srcs", "private-hdrs", "deps", "data"] - , "string_fields": ["name", "stage"] + , "target_fields": ["srcs", "private-hdrs", "private-deps", "data"] + , "string_fields": + [ "name" + , "stage" + , "pure C" + , "private-defines" + , "private-cflags" + , "private-ldflags" + ] , "config_vars": - [ "CXX" - , "CC" - , "CXXFLAGS" + [ "CC" + , "CXX" , "CFLAGS" - , "ADD_CXXFLAGS" + , "CXXFLAGS" , "ADD_CFLAGS" + , "ADD_CXXFLAGS" , "ENV" , "TEST_ENV" , "CC_TEST_LAUNCHER" ] , "implicit": - { "defaults": [["./", "..", "defaults"]] - , "proto-deps": [] - , "runner": ["test_runner.sh"] - } + {"defaults": [["./", "..", "defaults"]], "runner": ["test_runner.sh"]} , "field_doc": { "name": [ "The name of the test" @@ -33,6 +37,16 @@ [ "Any additional header files that need to be present when compiling" , "the test binary." ] + , "private-defines": + [ "List of defines set for source files local to this target." + , "Each list entry will be prepended by \"-D\"." + ] + , "private-cflags": + ["List of compile flags set for source files local to this target."] + , "private-ldflags": + [ "Additional linker flags for linking external libraries (not built" + , "by this tool, typically system libraries)." + ] , "stage": [ "The logical location of all header and source files." , "Individual directory components are joined with \"/\"." @@ -40,25 +54,25 @@ , "data": ["Any files the test binary needs access to when running"] } , "config_doc": - { "CXX": ["The name of the C++ compiler to be used."] - , "CC": ["The name of the C compiler to be used."] - , "ENV": ["The environment for any action generated."] - , "CXXFLAGS": - [ "The flags for CXX to be used instead of the default ones" - , "taken from the [\"CC\", \"defaults\"] target" - ] + { "CC": ["The name of the C compiler to be used."] + , "CXX": ["The name of the C++ compiler to be used."] , "CFLAGS": [ "The flags for CC to be used instead of the default ones" , "taken from the [\"CC\", \"defaults\"] target" ] - , "ADD_CXXFLAGS": - [ "The flags to add to the default ones for CXX" + , "CXXFLAGS": + [ "The flags for CXX to be used instead of the default ones" , "taken from the [\"CC\", \"defaults\"] target" ] , "ADD_CFLAGS": [ "The flags to add to the default ones for CC" , "taken from the [\"CC\", \"defaults\"] target" ] + , "ADD_CXXFLAGS": + [ "The flags to add to the default ones for CXX" + , "taken from the [\"CC\", \"defaults\"] target" + ] + , "ENV": ["The environment for any action generated."] , "TEST_ENV": ["The environment for executing the test runner."] , "CC_TEST_LAUNCHER": [ "List of strings representing the launcher that is prepend to the" @@ -75,24 +89,30 @@ ] , "runfiles_doc": [ "A tree consisting of the artifacts staged at the name of the test." - , "As the built-in \"install\" rule only takes the runfiles of its \"deps\"" - , "argument, this gives an easy way of defining test suites." + , "As the built-in \"install\" rule only takes the runfiles of its" + , "\"private-deps\" argument, this gives an easy way of defining test" + , "suites." ] , "imports": { "artifacts": ["./", "../..", "field_artifacts"] , "runfiles_list": ["./", "../..", "field_runfiles_list"] , "compile-deps": ["./", "..", "compile-deps"] + , "compile-args-deps": ["./", "..", "compile-args-deps"] , "link-deps": ["./", "..", "link-deps"] , "link-args-deps": ["./", "..", "link-args-deps"] - , "objects": ["./", "..", "objects"] - , "default-CXX": ["./", "..", "default-CXX"] - , "default-CXXFLAGS": ["./", "..", "default-CXXFLAGS"] - , "default-ENV": ["./", "..", "default-ENV"] + , "binary": ["./", "..", "bin artifact"] } , "expression": { "type": "let*" , "bindings": - [ [ "stage" + [ [ "name" + , { "type": "assert_non_empty" + , "msg": "A non-empty name has to be provided for binaries" + , "$1": {"type": "join", "$1": {"type": "FIELD", "name": "name"}} + } + ] + , ["pure C", {"type": "FIELD", "name": "pure C"}] + , [ "stage" , { "type": "join" , "separator": "/" , "$1": {"type": "FIELD", "name": "stage"} @@ -108,7 +128,7 @@ } } ] - , [ "local hdrs" + , [ "private-hdrs" , { "type": "to_subdir" , "subdir": {"type": "var", "name": "stage"} , "$1": @@ -118,92 +138,32 @@ } } ] - , [ "CXX" - , { "type": "var" - , "name": "CXX" - , "default": {"type": "CALL_EXPRESSION", "name": "default-CXX"} - } - ] - , [ "CXXFLAGS" - , { "type": "var" - , "name": "CXXFLAGS" - , "default": {"type": "CALL_EXPRESSION", "name": "default-CXXFLAGS"} - } - ] - , [ "ENV" - , { "type": "map_union" + , ["deps-fieldnames", ["private-deps"]] + , ["compile-deps", {"type": "CALL_EXPRESSION", "name": "compile-deps"}] + , [ "compile-args" + , { "type": "++" , "$1": - { "type": "++" - , "$1": - [ {"type": "CALL_EXPRESSION", "name": "default-ENV"} - , [ { "type": "var" - , "name": "ENV" - , "default": {"type": "empty_map"} - } - ] - ] - } + [ { "type": "foreach" + , "var": "def" + , "range": {"type": "FIELD", "name": "private-defines"} + , "body": + {"type": "join", "$1": ["-D", {"type": "var", "name": "def"}]} + } + , {"type": "FIELD", "name": "private-cflags"} + , {"type": "CALL_EXPRESSION", "name": "compile-args-deps"} + ] } ] - , ["deps-fieldnames", ["deps", "proto-deps"]] - , ["compile-deps", {"type": "CALL_EXPRESSION", "name": "compile-deps"}] , ["link-deps", {"type": "CALL_EXPRESSION", "name": "link-deps"}] - , ["objects", {"type": "CALL_EXPRESSION", "name": "objects"}] - , [ "base name" - , { "type": "assert_non_empty" - , "msg": "A non-empty name has to be provided" - , "$1": {"type": "join", "$1": {"type": "FIELD", "name": "name"}} - } - ] - , [ "binary name" - , { "type": "if" - , "cond": {"type": "var", "name": "stage"} - , "else": {"type": "var", "name": "base name"} - , "then": - { "type": "join" - , "separator": "/" - , "$1": - [ {"type": "var", "name": "stage"} - , {"type": "var", "name": "base name"} - ] - } - } - ] , [ "link-args" - , { "type": "nub_right" + , { "type": "++" , "$1": - { "type": "++" - , "$1": - [ {"type": "keys", "$1": {"type": "var", "name": "objects"}} - , {"type": "CALL_EXPRESSION", "name": "link-args-deps"} - ] - } - } - ] - , [ "binary" - , { "type": "ACTION" - , "outs": [{"type": "var", "name": "binary name"}] - , "inputs": - { "type": "disjoint_map_union" - , "$1": - [ {"type": "var", "name": "objects"} - , {"type": "var", "name": "link-deps"} - ] - } - , "cmd": - { "type": "++" - , "$1": - [ [ {"type": "var", "name": "CXX"} - , "-o" - , {"type": "var", "name": "binary name"} - ] - , {"type": "var", "name": "CXXFLAGS"} - , {"type": "var", "name": "link-args"} - ] - } - , "env": {"type": "var", "name": "ENV"} + [ {"type": "CALL_EXPRESSION", "name": "link-args-deps"} + , {"type": "FIELD", "name": "private-ldflags"} + ] } ] + , ["binary", {"type": "CALL_EXPRESSION", "name": "binary"}] , [ "staged test binary" , { "type": "map_union" , "$1": @@ -256,6 +216,13 @@ } } ] + , [ "test-name" + , { "type": "join" + , "separator": "/" + , "$1": + [{"type": "var", "name": "stage"}, {"type": "var", "name": "name"}] + } + ] , [ "test-results" , { "type": "ACTION" , "outs": ["result", "stdout", "stderr", "time-start", "time-stop"] @@ -286,13 +253,13 @@ , "fail_message": { "type": "join" , "$1": - ["CC test ", {"type": "var", "name": "binary name"}, " failed"] + ["CC test ", {"type": "var", "name": "test-name"}, " failed"] } } ] , [ "runfiles" , { "type": "singleton_map" - , "key": {"type": "var", "name": "base name"} + , "key": {"type": "var", "name": "name"} , "value": {"type": "TREE", "$1": {"type": "var", "name": "test-results"}} } diff --git a/shell/test/EXPRESSIONS b/shell/test/EXPRESSIONS index 24bf9ec..444de92 100644 --- a/shell/test/EXPRESSIONS +++ b/shell/test/EXPRESSIONS @@ -1,5 +1,13 @@ { "test-action": - { "vars": ["name", "test.sh", "ATTEMPT", "TEST_ENV"] + { "vars": + [ "TEST_ENV" + , "ATTEMPT" + , "name" + , "test.sh" + , "keep" + , "runner" + , "deps-fieldname" + ] , "imports": { "artifacts_list": ["./", "../..", "field_artifacts_list"] , "runfiles_list": ["./", "../..", "field_runfiles_list"] @@ -12,7 +20,7 @@ , "$1": { "type": "foreach" , "var": "runner" - , "range": {"type": "FIELD", "name": "runner"} + , "range": {"type": "var", "name": "runner"} , "body": { "type": "map_union" , "$1": @@ -35,12 +43,17 @@ , { "type": "TREE" , "$1": { "type": "disjoint_map_union" - , "msg": "Field 'deps' has to stage in a conflict free way" + , "msg": + [ "Field" + , {"type": "var", "name": "deps-fieldname"} + , "has to stage in a conflict free way" + ] , "$1": { "type": "++" , "$1": { "type": "let*" - , "bindings": [["fieldname", "deps"]] + , "bindings": + [["fieldname", {"type": "var", "name": "deps-fieldname"}]] , "body": [ {"type": "CALL_EXPRESSION", "name": "runfiles_list"} , {"type": "CALL_EXPRESSION", "name": "artifacts_list"} @@ -72,7 +85,7 @@ [ ["result", "stdout", "stderr", "time-start", "time-stop"] , { "type": "foreach" , "var": "filename" - , "range": {"type": "FIELD", "name": "keep"} + , "range": {"type": "var", "name": "keep"} , "body": { "type": "join" , "$1": ["work/", {"type": "var", "name": "filename"}] @@ -95,9 +108,7 @@ } ] , [ "cmd" - , { "type": "++" - , "$1": [["./runner"], {"type": "FIELD", "name": "keep"}] - } + , {"type": "++", "$1": [["./runner"], {"type": "var", "name": "keep"}]} ] , [ "test_env" , {"type": "var", "name": "TEST_ENV", "default": {"type": "empty_map"}} @@ -142,7 +153,7 @@ } } , "test-result": - { "vars": ["name", "test.sh", "TEST_ENV"] + { "vars": ["TEST_ENV", "name", "test.sh", "keep", "runner", "deps-fieldname"] , "imports": {"action": "test-action"} , "expression": { "type": "let*" diff --git a/shell/test/RULES b/shell/test/RULES index 4242d94..990e8d9 100644 --- a/shell/test/RULES +++ b/shell/test/RULES @@ -75,6 +75,9 @@ , "$1": {"type": "join", "$1": {"type": "FIELD", "name": "name"}} } ] + , ["keep", {"type": "FIELD", "name": "keep"}] + , ["runner", {"type": "FIELD", "name": "runner"}] + , ["deps-fieldname", "deps"] ] , "body": { "type": "if" -- cgit v1.2.3 From 164bc8a638e50a69466dae5f1b0e0355daa5f20c Mon Sep 17 00:00:00 2001 From: Oliver Reiche Date: Wed, 7 Dec 2022 14:50:53 +0100 Subject: rules: Add argument support for test binaries --- CC/test/RULES | 41 +++++++++++++++++++++++------- CC/test/test_runner.py | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++ CC/test/test_runner.sh | 50 ------------------------------------ 3 files changed, 101 insertions(+), 59 deletions(-) create mode 100755 CC/test/test_runner.py delete mode 100644 CC/test/test_runner.sh diff --git a/CC/test/RULES b/CC/test/RULES index b42b6c4..44cf1c4 100644 --- a/CC/test/RULES +++ b/CC/test/RULES @@ -7,6 +7,7 @@ , "target_fields": ["srcs", "private-hdrs", "private-deps", "data"] , "string_fields": [ "name" + , "args" , "stage" , "pure C" , "private-defines" @@ -25,13 +26,14 @@ , "CC_TEST_LAUNCHER" ] , "implicit": - {"defaults": [["./", "..", "defaults"]], "runner": ["test_runner.sh"]} + {"defaults": [["./", "..", "defaults"]], "runner": ["test_runner.py"]} , "field_doc": { "name": [ "The name of the test" , "" , "Used to name the test binary as well as for staging the test result" ] + , "args": ["Command line arguments for the test binary"] , "srcs": ["The sources of the test binary"] , "private-hdrs": [ "Any additional header files that need to be present when compiling" @@ -198,7 +200,7 @@ } , "body": { "type": "singleton_map" - , "key": "runner.sh" + , "key": "runner" , "value": {"type": "var", "name": "runner"} } } @@ -206,6 +208,31 @@ } } ] + , [ "test-args" + , { "type": "singleton_map" + , "key": "test-args.json" + , "value": + { "type": "BLOB" + , "data": + { "type": "json_encode" + , "$1": {"type": "FIELD", "name": "args", "default": []} + } + } + } + ] + , [ "test-launcher" + , { "type": "singleton_map" + , "key": "test-launcher.json" + , "value": + { "type": "BLOB" + , "data": + { "type": "json_encode" + , "$1": + {"type": "var", "name": "CC_TEST_LAUNCHER", "default": []} + } + } + } + ] , [ "data" , { "type": "disjoint_map_union" , "msg": "Data runfiles may not conflict" @@ -234,16 +261,12 @@ , "$1": {"type": "var", "name": "data"} } , {"type": "var", "name": "runner"} + , {"type": "var", "name": "test-args"} + , {"type": "var", "name": "test-launcher"} , {"type": "var", "name": "staged test binary"} ] } - , "cmd": - { "type": "++" - , "$1": - [ ["sh", "./runner.sh"] - , {"type": "var", "name": "CC_TEST_LAUNCHER", "default": []} - ] - } + , "cmd": ["./runner"] , "env": { "type": "var" , "name": "TEST_ENV" diff --git a/CC/test/test_runner.py b/CC/test/test_runner.py new file mode 100755 index 0000000..0647621 --- /dev/null +++ b/CC/test/test_runner.py @@ -0,0 +1,69 @@ +#!/usr/bin/env python3 +# Copyright 2022 Huawei Cloud Computing Technology Co., Ltd. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import json +import os +import subprocess +import time + +time_start = time.time() +time_stop = 0 +result = "UNKNOWN" +stderr = "" +stdout = "" + + +def dump_results(): + with open("result", "w") as f: + f.write("%s\n" % (result, )) + with open("time-start", "w") as f: + f.write("%d\n" % (time_start, )) + with open("time-stop", "w") as f: + f.write("%d\n" % (time_stop, )) + with open("stdout", "w") as f: + f.write("%s\n" % (stdout, )) + with open("stderr", "w") as f: + f.write("%s\n" % (stderr, )) + + +dump_results() + +TEMP_DIR = os.path.realpath("scratch") +os.makedirs(TEMP_DIR, exist_ok=True) + +WORK_DIR = os.path.realpath("work") +os.makedirs(WORK_DIR, exist_ok=True) + +ENV = dict(os.environ, TEST_TMPDIR=TEMP_DIR) + +with open('test-launcher.json') as f: + test_launcher = json.load(f) + +with open('test-args.json') as f: + test_args = json.load(f) + +ret = subprocess.run(test_launcher + ["../test"] + test_args, + cwd=WORK_DIR, + env=ENV, + capture_output=True) + +time_stop = time.time() +result = "PASS" if ret.returncode == 0 else "FAIL" +stdout = ret.stdout.decode("utf-8") +stderr = ret.stderr.decode("utf-8") + +dump_results() + +if result != "PASS": exit(1) diff --git a/CC/test/test_runner.sh b/CC/test/test_runner.sh deleted file mode 100644 index 84b9072..0000000 --- a/CC/test/test_runner.sh +++ /dev/null @@ -1,50 +0,0 @@ -#!/bin/sh -# Copyright 2022 Huawei Cloud Computing Technology Co., Ltd. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -# ensure all required outputs are present -touch stdout -touch stderr -RESULT=UNKNOWN -echo "${RESULT}" > result -echo UNKNOWN > time-start -echo UNKNOWN > time-stop - -mkdir scratch -export TEST_TMPDIR=$(realpath scratch) -# Change to the working directory; note: the test might not -# have test data, so we have to ensure the presence of the work -# directory. - -mkdir -p work -cd work - -date +%s > ../time-start -# TODO: -# - proper wrapping with timeout -# - test arguments to select specific test cases -if "$@" ../test > ../stdout 2> ../stderr -then - RESULT=PASS -else - RESULT=FAIL -fi -date +%s > ../time-stop -echo "${RESULT}" > ../result - -if [ "${RESULT}" '!=' PASS ] -then - exit 1; -fi -- cgit v1.2.3 From 9d5af26d047744cba54d6597ad59d23aca4e1369 Mon Sep 17 00:00:00 2001 From: Oliver Reiche Date: Tue, 6 Dec 2022 16:51:56 +0100 Subject: rules: Add cross-compile support for tests --- CC/test/RULES | 23 +++++++++++++++++------ shell/test/EXPRESSIONS | 15 +++++++++++++-- shell/test/RULES | 6 ++++++ 3 files changed, 36 insertions(+), 8 deletions(-) diff --git a/CC/test/RULES b/CC/test/RULES index 44cf1c4..4425fd6 100644 --- a/CC/test/RULES +++ b/CC/test/RULES @@ -1,8 +1,5 @@ { "test": - { "doc": - [ "A test written in C++" - , "FIXME: the test binary and data must be built for host" - ] + { "doc": ["A test written in C++"] , "tainted": ["test"] , "target_fields": ["srcs", "private-hdrs", "private-deps", "data"] , "string_fields": @@ -15,7 +12,9 @@ , "private-ldflags" ] , "config_vars": - [ "CC" + [ "ARCH" + , "HOST_ARCH" + , "CC" , "CXX" , "CFLAGS" , "CXXFLAGS" @@ -103,6 +102,12 @@ , "link-deps": ["./", "..", "link-deps"] , "link-args-deps": ["./", "..", "link-args-deps"] , "binary": ["./", "..", "bin artifact"] + , "host transition": ["transitions", "for host"] + } + , "config_transitions": + { "defaults": [{"type": "CALL_EXPRESSION", "name": "host transition"}] + , "private-deps": [{"type": "CALL_EXPRESSION", "name": "host transition"}] + , "data": [{"type": "CALL_EXPRESSION", "name": "host transition"}] } , "expression": { "type": "let*" @@ -140,6 +145,9 @@ } } ] + , ["host-trans", {"type": "CALL_EXPRESSION", "name": "host transition"}] + , ["defaults-transition", {"type": "var", "name": "host-trans"}] + , ["deps-transition", {"type": "var", "name": "host-trans"}] , ["deps-fieldnames", ["private-deps"]] , ["compile-deps", {"type": "CALL_EXPRESSION", "name": "compile-deps"}] , [ "compile-args" @@ -238,7 +246,10 @@ , "msg": "Data runfiles may not conflict" , "$1": { "type": "let*" - , "bindings": [["fieldname", "data"]] + , "bindings": + [ ["fieldname", "data"] + , ["transition", {"type": "var", "name": "deps-transition"}] + ] , "body": {"type": "CALL_EXPRESSION", "name": "runfiles_list"} } } diff --git a/shell/test/EXPRESSIONS b/shell/test/EXPRESSIONS index 444de92..d9b1fbc 100644 --- a/shell/test/EXPRESSIONS +++ b/shell/test/EXPRESSIONS @@ -7,6 +7,7 @@ , "keep" , "runner" , "deps-fieldname" + , "deps-transition" ] , "imports": { "artifacts_list": ["./", "../..", "field_artifacts_list"] @@ -53,7 +54,9 @@ , "$1": { "type": "let*" , "bindings": - [["fieldname", {"type": "var", "name": "deps-fieldname"}]] + [ ["fieldname", {"type": "var", "name": "deps-fieldname"}] + , ["transition", {"type": "var", "name": "deps-transition"}] + ] , "body": [ {"type": "CALL_EXPRESSION", "name": "runfiles_list"} , {"type": "CALL_EXPRESSION", "name": "artifacts_list"} @@ -153,7 +156,15 @@ } } , "test-result": - { "vars": ["TEST_ENV", "name", "test.sh", "keep", "runner", "deps-fieldname"] + { "vars": + [ "TEST_ENV" + , "name" + , "test.sh" + , "keep" + , "runner" + , "deps-fieldname" + , "deps-transition" + ] , "imports": {"action": "test-action"} , "expression": { "type": "let*" diff --git a/shell/test/RULES b/shell/test/RULES index 990e8d9..92c0ccc 100644 --- a/shell/test/RULES +++ b/shell/test/RULES @@ -55,7 +55,10 @@ { "test-result": "test-result" , "action": "test-action" , "stage": ["./", "../..", "stage_singleton_field"] + , "host transition": ["transitions", "for host"] } + , "config_transitions": + {"deps": [{"type": "CALL_EXPRESSION", "name": "host transition"}]} , "expression": { "type": "let*" , "bindings": @@ -78,6 +81,9 @@ , ["keep", {"type": "FIELD", "name": "keep"}] , ["runner", {"type": "FIELD", "name": "runner"}] , ["deps-fieldname", "deps"] + , [ "deps-transition" + , {"type": "CALL_EXPRESSION", "name": "host transition"} + ] ] , "body": { "type": "if" -- cgit v1.2.3 From c529dcdf4f03c8d9531ea4640c4f9e3777d6ae51 Mon Sep 17 00:00:00 2001 From: Oliver Reiche Date: Wed, 7 Dec 2022 17:44:49 +0100 Subject: rules: Create library in stage directory --- CC/EXPRESSIONS | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/CC/EXPRESSIONS b/CC/EXPRESSIONS index 81ac1fd..f719c48 100644 --- a/CC/EXPRESSIONS +++ b/CC/EXPRESSIONS @@ -524,13 +524,27 @@ , "$1": ["lib", {"type": "var", "name": "base name"}, ".a"] } ] + , [ "libpath" + , { "type": "if" + , "cond": {"type": "var", "name": "stage"} + , "then": + { "type": "join" + , "separator": "/" + , "$1": + [ {"type": "var", "name": "stage"} + , {"type": "var", "name": "libname"} + ] + } + , "else": {"type": "var", "name": "libname"} + } + ] , [ "lib" , { "type": "if" , "cond": {"type": "var", "name": "objects"} , "else": {"type": "empty_map"} , "then": { "type": "ACTION" - , "outs": [{"type": "var", "name": "libname"}] + , "outs": [{"type": "var", "name": "libpath"}] , "inputs": {"type": "var", "name": "objects"} , "env": {"type": "var", "name": "ENV", "default": {"type": "empty_map"}} @@ -539,7 +553,7 @@ , "$1": [ [ {"type": "var", "name": "AR", "default": "ar"} , "cqs" - , {"type": "var", "name": "libname"} + , {"type": "var", "name": "libpath"} ] , {"type": "keys", "$1": {"type": "var", "name": "objects"}} ] @@ -548,11 +562,7 @@ } ] ] - , "body": - { "type": "to_subdir" - , "subdir": {"type": "var", "name": "stage"} - , "$1": {"type": "var", "name": "lib"} - } + , "body": {"type": "var", "name": "lib"} } } , "lib result": -- cgit v1.2.3 From 3a3a0d668bbe146ca3a264f119b5e551311ff9e2 Mon Sep 17 00:00:00 2001 From: Oliver Reiche Date: Wed, 7 Dec 2022 17:45:55 +0100 Subject: rules: ldflags have precedence over transitive link args --- CC/EXPRESSIONS | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CC/EXPRESSIONS b/CC/EXPRESSIONS index f719c48..7beac0a 100644 --- a/CC/EXPRESSIONS +++ b/CC/EXPRESSIONS @@ -814,8 +814,8 @@ , "$1": { "type": "++" , "$1": - [ {"type": "CALL_EXPRESSION", "name": "link-args-deps"} - , {"type": "var", "name": "private-ldflags"} + [ {"type": "var", "name": "private-ldflags"} + , {"type": "CALL_EXPRESSION", "name": "link-args-deps"} ] } } -- cgit v1.2.3 From a0b2b5d0891e2212333e091c43dc5a6f5578ed4b Mon Sep 17 00:00:00 2001 From: Oliver Reiche Date: Wed, 7 Dec 2022 17:46:38 +0100 Subject: rules: cflags have precedence over defines --- CC/RULES | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CC/RULES b/CC/RULES index 9b041dd..3bfd200 100644 --- a/CC/RULES +++ b/CC/RULES @@ -271,13 +271,13 @@ , [ "private-cflags" , { "type": "++" , "$1": - [ { "type": "foreach" + [ {"type": "FIELD", "name": "private-cflags"} + , { "type": "foreach" , "var": "def" , "range": {"type": "FIELD", "name": "private-defines"} , "body": {"type": "join", "$1": ["-D", {"type": "var", "name": "def"}]} } - , {"type": "FIELD", "name": "private-cflags"} ] } ] -- cgit v1.2.3 From d44be66f2a916168e0f5a7055e49f12c252b2cd2 Mon Sep 17 00:00:00 2001 From: Oliver Reiche Date: Mon, 12 Dec 2022 11:00:29 +0100 Subject: rules: Fix missing arch vars for shell tests --- shell/test/RULES | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/test/RULES b/shell/test/RULES index 92c0ccc..98bf27c 100644 --- a/shell/test/RULES +++ b/shell/test/RULES @@ -2,7 +2,7 @@ { "doc": ["Shell test, given by a test script"] , "target_fields": ["deps", "test"] , "string_fields": ["keep", "name"] - , "config_vars": ["RUNS_PER_TEST", "TEST_ENV"] + , "config_vars": ["ARCH", "HOST_ARCH", "RUNS_PER_TEST", "TEST_ENV"] , "field_doc": { "test": [ "The shell script for the test, launched with sh." -- cgit v1.2.3