diff options
Diffstat (limited to 'rules/shell/RULES')
-rw-r--r-- | rules/shell/RULES | 347 |
1 files changed, 347 insertions, 0 deletions
diff --git a/rules/shell/RULES b/rules/shell/RULES new file mode 100644 index 0000000..7f53a4b --- /dev/null +++ b/rules/shell/RULES @@ -0,0 +1,347 @@ +{ "defaults": + { "doc": + [ "A rule to provide defaults for the usage of the shell" + , "" + , "All targets using invocations of the shell use the target" + , "[\"shel\", \"defaults\"] to determine which shell to use and how to" + , "invoke it. The definition of this default target is probably the only" + , "meaningful use of this rule." + ] + , "target_fields": ["base", "toolchain"] + , "string_fields": ["sh", "PATH", "bin dirs"] + , "field_doc": + { "base": ["Other targets (using the same rule) to inherit values from."] + , "toolchain": + [ "Optional toolchain directory. A collection of artifacts that" + , "form the toolchain, in particular the shell itself, where not taken" + , "from the ambient host environment." + , "Values provided from base are extended." + , "This field is built for the host." + ] + , "sh": + [ "The name of the sh binary; if the the field \"toolchain\" is" + , "not empty, the value is interpreted as relative to the toolchain" + , "directory." + ] + , "PATH": + [ "Paths for looking up system tools." + , "Specifying this field extends values from \"base\"." + ] + , "bin dirs": + [ "Directories of the toolchain that contain additional binaries." + , "Shell-specific rules will add those into PATH." + ] + } + , "config_vars": ["ARCH", "HOST_ARCH", "TARGET_ARCH"] + , "imports": + { "for host": ["transitions", "for host"] + , "artifacts_list": ["", "field_artifacts_list"] + , "base-provides-list": ["CC", "defaults-base-provides-list"] + , "base-provides-++": ["CC", "defaults-base-provides-++"] + , "base-provides": ["CC", "defaults-base-provides"] + } + , "config_transitions": + {"toolchain": [{"type": "CALL_EXPRESSION", "name": "for host"}]} + , "expression": + { "type": "let*" + , "bindings": + [ [ "TOOLCHAIN" + , { "type": "disjoint_map_union" + , "msg": "toolchain artifacts must not overlap" + , "$1": + { "type": "++" + , "$1": + [ { "type": "let*" + , "bindings": + [ ["provider", "TOOLCHAIN"] + , ["default", {"type": "empty_map"}] + ] + , "body": + {"type": "CALL_EXPRESSION", "name": "base-provides-list"} + } + , { "type": "let*" + , "bindings": + [ ["fieldname", "toolchain"] + , [ "transition" + , {"type": "CALL_EXPRESSION", "name": "for host"} + ] + ] + , "body": {"type": "CALL_EXPRESSION", "name": "artifacts_list"} + } + ] + } + } + ] + , [ "sh" + , { "type": "if" + , "cond": {"type": "FIELD", "name": "sh"} + , "then": {"type": "FIELD", "name": "sh"} + , "else": + { "type": "let*" + , "bindings": [["provider", "sh"]] + , "body": {"type": "CALL_EXPRESSION", "name": "base-provides"} + } + } + ] + , [ "NON_SYSTEM_TOOLS" + , { "type": "map_union" + , "$1": + { "type": "++" + , "$1": + [ [ { "type": "let*" + , "bindings": + [ ["provider", "NON_SYSTEM_TOOLS"] + , ["default", {"type": "empty_map"}] + ] + , "body": + {"type": "CALL_EXPRESSION", "name": "base-provides"} + } + ] + , { "type": "if" + , "cond": {"type": "FIELD", "name": "sh"} + , "then": + [ { "type": "singleton_map" + , "key": "sh" + , "value": + { "type": "if" + , "cond": {"type": "FIELD", "name": "toolchain"} + , "then": true + , "else": false + } + } + ] + } + ] + } + } + ] + , [ "PATH" + , { "type": "nub_left" + , "$1": + { "type": "++" + , "$1": + [ {"type": "FIELD", "name": "PATH"} + , { "type": "let*" + , "bindings": [["provider", "PATH"]] + , "body": + {"type": "CALL_EXPRESSION", "name": "base-provides-++"} + } + ] + } + } + ] + , [ "bin dirs" + , { "type": "nub_left" + , "$1": + { "type": "++" + , "$1": + [ {"type": "FIELD", "name": "bin dirs"} + , { "type": "let*" + , "bindings": [["provider", "bin dirs"]] + , "body": + {"type": "CALL_EXPRESSION", "name": "base-provides-++"} + } + ] + } + } + ] + ] + , "body": + { "type": "RESULT" + , "provides": + { "type": "env" + , "vars": ["TOOLCHAIN", "sh", "NON_SYSTEM_TOOLS", "PATH", "bin dirs"] + } + } + } + } +, "cmds": + { "doc": + [ "Execute comands using the shell" + , "" + , "This rule behaves similar to the built-in \"generic\" rule, however" + , "with the difference that the shell toolchain is honored." + ] + , "target_fields": ["deps"] + , "string_fields": ["cmds", "outs", "out_dirs"] + , "implicit": {"defaults": ["defaults"]} + , "field_doc": + { "deps": + [ "Any inputs to the argument." + , "Both, artifacts and rufiles of the dependecies are staged into" + , "the (effective) working directory of the action. Conflicts are" + , "resolved by giving artifacts priority to runfiles, and within" + , "each of those priority to ones brought by the latest dependency." + ] + , "cmds": + [ "The command to be executed." + , "Individual entries are joined by newline characters; the whole" + , "script is then prefixed by commands necessary to set up the" + , "work environment using the shell tool chain." + ] + , "defaults": ["The shell toolchain to use."] + , "outs": ["The expected file outputs"] + , "out_dirs": ["The expected output directories"] + } + , "imports": + { "artifacts_list": ["", "field_artifacts_list"] + , "runfiles_list": ["", "field_runfiles_list"] + , "map_provider": ["", "field_map_provider"] + , "prolog": "prolog" + , "sh": "sh" + , "PATH": "PATH" + } + , "expression": + { "type": "let*" + , "bindings": + [ ["fieldname", "deps"] + , [ "deps" + , { "type": "map_union" + , "$1": + { "type": "++" + , "$1": + [ {"type": "CALL_EXPRESSION", "name": "runfiles_list"} + , {"type": "CALL_EXPRESSION", "name": "artifacts_list"} + ] + } + } + ] + , ["fieldname", "defaults"] + , ["TOOLCHAIN_DIR", "toolchain"] + , [ "toolchain" + , { "type": "to_subdir" + , "subdir": {"type": "var", "name": "TOOLCHAIN_DIR"} + , "$1": + { "type": "let*" + , "bindings": + [["provider", "TOOLCHAIN"], ["default", {"type": "empty_map"}]] + , "body": {"type": "CALL_EXPRESSION", "name": "map_provider"} + } + } + ] + , ["WRKDIR", "work"] + , [ "cmds" + , { "type": "++" + , "$1": + [ {"type": "CALL_EXPRESSION", "name": "prolog"} + , [ { "type": "join_cmd" + , "$1": ["cd", {"type": "var", "name": "WRKDIR"}] + } + ] + , {"type": "FIELD", "name": "cmds"} + ] + } + ] + , ["sh", {"type": "CALL_EXPRESSION", "name": "sh"}] + , [ "cmdfile" + , { "type": "singleton_map" + , "key": "cmd" + , "value": + { "type": "BLOB" + , "data": + { "type": "join" + , "separator": "\n" + , "$1": {"type": "var", "name": "cmds"} + } + } + } + ] + , ["PATH", {"type": "CALL_EXPRESSION", "name": "PATH"}] + , [ "env" + , { "type": "if" + , "cond": {"type": "var", "name": "PATH"} + , "then": + { "type": "singleton_map" + , "key": "PATH" + , "value": + { "type": "join" + , "separator": ":" + , "$1": {"type": "var", "name": "PATH"} + } + } + , "else": {"type": "empty_map"} + } + ] + , [ "outs in WRKDIR" + , { "type": "foreach" + , "range": {"type": "FIELD", "name": "outs"} + , "body": + { "type": "join" + , "$1": + [ {"type": "var", "name": "WRKDIR"} + , "/" + , {"type": "var", "name": "_"} + ] + } + } + ] + , [ "out_dirs in WRKDIR" + , { "type": "foreach" + , "range": {"type": "FIELD", "name": "out_dirs"} + , "body": + { "type": "join" + , "$1": + [ {"type": "var", "name": "WRKDIR"} + , "/" + , {"type": "var", "name": "_"} + ] + } + } + ] + , [ "artifacts" + , { "type": "ACTION" + , "inputs": + { "type": "map_union" + , "$1": + [ {"type": "var", "name": "toolchain"} + , {"type": "var", "name": "cmdfile"} + , { "type": "to_subdir" + , "subdir": {"type": "var", "name": "WRKDIR"} + , "$1": {"type": "var", "name": "deps"} + } + ] + } + , "cmd": [{"type": "var", "name": "sh"}, "cmd"] + , "outs": {"type": "var", "name": "outs in WRKDIR"} + , "out_dirs": {"type": "var", "name": "out_dirs in WRKDIR"} + , "env": {"type": "var", "name": "env"} + } + ] + , [ "staged artifacts" + , { "type": "map_union" + , "$1": + { "type": "foreach" + , "range": + { "type": "++" + , "$1": + [ {"type": "FIELD", "name": "outs"} + , {"type": "FIELD", "name": "out_dirs"} + ] + } + , "body": + { "type": "singleton_map" + , "key": {"type": "var", "name": "_"} + , "value": + { "type": "lookup" + , "map": {"type": "var", "name": "artifacts"} + , "key": + { "type": "join" + , "$1": + [ {"type": "var", "name": "WRKDIR"} + , "/" + , {"type": "var", "name": "_"} + ] + } + } + } + } + } + ] + ] + , "body": + { "type": "RESULT" + , "artifacts": {"type": "var", "name": "staged artifacts"} + } + } + } +} |