summaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
Diffstat (limited to 'shell')
-rw-r--r--shell/EXPRESSIONS69
-rw-r--r--shell/RULES189
-rw-r--r--shell/test/EXPRESSIONS86
-rw-r--r--shell/test/RULES23
-rwxr-xr-xshell/test/runner1
5 files changed, 365 insertions, 3 deletions
diff --git a/shell/EXPRESSIONS b/shell/EXPRESSIONS
index 722e897..34a5c92 100644
--- a/shell/EXPRESSIONS
+++ b/shell/EXPRESSIONS
@@ -99,4 +99,73 @@
, "body": {"type": "CALL_EXPRESSION", "name": "list_provider"}
}
}
+, "prolog":
+ { "vars": ["fieldname", "TOOLCHAIN_DIR"]
+ , "imports": {"list_provider": ["./", "..", "field_list_provider"]}
+ , "expression":
+ { "type": "let*"
+ , "bindings":
+ [ ["provider", "bin dirs"]
+ , ["bin dirs", {"type": "CALL_EXPRESSION", "name": "list_provider"}]
+ , [ "relative paths"
+ , { "type": "foreach"
+ , "range": {"type": "var", "name": "bin dirs"}
+ , "body":
+ { "type": "join"
+ , "separator": "/"
+ , "$1":
+ [ "."
+ , { "type": "var"
+ , "name": "TOOLCHAIN_DIR"
+ , "default": "toolchain"
+ }
+ , {"type": "var", "name": "_"}
+ ]
+ }
+ }
+ ]
+ , [ "pwd paths"
+ , { "type": "foreach"
+ , "range": {"type": "var", "name": "bin dirs"}
+ , "body":
+ { "type": "join"
+ , "separator": "/"
+ , "$1":
+ [ "$(pwd)"
+ , { "type": "var"
+ , "name": "TOOLCHAIN_DIR"
+ , "default": "toolchain"
+ }
+ , {"type": "var", "name": "_"}
+ ]
+ }
+ }
+ ]
+ ]
+ , "body":
+ [ "__PATH=$PATH"
+ , { "type": "join"
+ , "$1":
+ [ "export PATH="
+ , { "type": "join"
+ , "separator": ":"
+ , "$1": {"type": "var", "name": "relative paths"}
+ }
+ , "${PATH:+:}${PATH}"
+ ]
+ }
+ , { "type": "join"
+ , "$1":
+ [ "export PATH="
+ , { "type": "join"
+ , "separator": ":"
+ , "$1": {"type": "var", "name": "pwd paths"}
+ }
+ , "${__PATH:+:}${__PATH}"
+ ]
+ }
+ , "unset __PATH"
+ ]
+ }
+ }
}
diff --git a/shell/RULES b/shell/RULES
index b9e91bb..7f53a4b 100644
--- a/shell/RULES
+++ b/shell/RULES
@@ -155,4 +155,193 @@
}
}
}
+, "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"}
+ }
+ }
+ }
}
diff --git a/shell/test/EXPRESSIONS b/shell/test/EXPRESSIONS
index c4e0a3c..9791911 100644
--- a/shell/test/EXPRESSIONS
+++ b/shell/test/EXPRESSIONS
@@ -15,11 +15,13 @@
, "imports":
{ "artifacts_list": ["./", "../..", "field_artifacts_list"]
, "runfiles_list": ["./", "../..", "field_runfiles_list"]
+ , "map_provider": ["./", "../..", "field_map_provider"]
, "default-TOOLCHAIN": ["./", "../../CC", "default-TOOLCHAIN"]
, "default-NON_SYSTEM_TOOLS":
["./", "../../CC", "default-NON_SYSTEM_TOOLS"]
, "default-PATH": ["./", "../../CC", "default-PATH"]
, "default-sh": ["./", "..", "default-sh"]
+ , "sh prolog": ["shell", "prolog"]
}
, "expression":
{ "type": "let*"
@@ -59,6 +61,20 @@
, [ "NON_SYSTEM_TOOLS"
, {"type": "CALL_EXPRESSION", "name": "default-NON_SYSTEM_TOOLS"}
]
+ , [ "sh from outside"
+ , { "type": "if"
+ , "cond":
+ { "type": "lookup"
+ , "key": "sh"
+ , "map": {"type": "var", "name": "NON_SYSTEM_TOOLS"}
+ }
+ , "then":
+ { "type": "join"
+ , "$1": ["./toolchain/", {"type": "var", "name": "sh"}]
+ }
+ , "else": {"type": "var", "name": "sh"}
+ }
+ ]
, [ "sh from workdir"
, { "type": "if"
, "cond":
@@ -73,6 +89,36 @@
, "else": {"type": "var", "name": "sh"}
}
]
+ , [ "with-env"
+ , { "type": "singleton_map"
+ , "key": "with-env"
+ , "value":
+ { "type": "BLOB"
+ , "data":
+ { "type": "join"
+ , "separator": "\n"
+ , "$1":
+ { "type": "++"
+ , "$1":
+ [ { "type": "let*"
+ , "bindings": [["fieldname", "defaults"]]
+ , "body": {"type": "CALL_EXPRESSION", "name": "sh prolog"}
+ }
+ , [ ""
+ , { "type": "join_cmd"
+ , "$1":
+ { "type": "++"
+ , "$1": [["./runner"], {"type": "var", "name": "keep"}]
+ }
+ }
+ , ""
+ ]
+ ]
+ }
+ }
+ }
+ }
+ ]
, [ "invocation cmd"
, [{"type": "var", "name": "sh from workdir"}, "../test.sh"]
]
@@ -154,6 +200,19 @@
}
}
]
+ , [ "run-libs"
+ , { "type": "TREE"
+ , "$1":
+ { "type": "let*"
+ , "bindings":
+ [ ["fieldname", {"type": "var", "name": "deps-fieldname"}]
+ , ["provider", "run-libs"]
+ , ["transition", {"type": "var", "name": "deps-transition"}]
+ ]
+ , "body": {"type": "CALL_EXPRESSION", "name": "map_provider"}
+ }
+ }
+ ]
, [ "attempt marker"
, { "type": "if"
, "cond":
@@ -202,7 +261,12 @@
, "key": "work"
, "value": {"type": "var", "name": "deps"}
}
+ , { "type": "singleton_map"
+ , "key": "libs"
+ , "value": {"type": "var", "name": "run-libs"}
+ }
, {"type": "var", "name": "toolchain"}
+ , {"type": "var", "name": "with-env"}
, {"type": "var", "name": "runner"}
, {"type": "var", "name": "invocation"}
, {"type": "var", "name": "test.sh"}
@@ -210,8 +274,26 @@
]
}
]
- , [ "cmd"
- , {"type": "++", "$1": [["./runner"], {"type": "var", "name": "keep"}]}
+ , ["cmd", [{"type": "var", "name": "sh from outside"}, "with-env"]]
+ , [ "test_env"
+ , { "type": "map_union"
+ , "$1":
+ [ { "type": "if"
+ , "cond":
+ { "type": "=="
+ , "$1": {"type": "var", "name": "ATTEMPT"}
+ , "$2": null
+ }
+ , "then": {"type": "empty_map"}
+ , "else":
+ { "type": "singleton_map"
+ , "key": "TEST_RUN_NUMBER"
+ , "value": {"type": "var", "name": "ATTEMPT"}
+ }
+ }
+ , {"type": "var", "name": "test_env"}
+ ]
+ }
]
]
, "body":
diff --git a/shell/test/RULES b/shell/test/RULES
index 3d49db2..bab1d8b 100644
--- a/shell/test/RULES
+++ b/shell/test/RULES
@@ -50,6 +50,10 @@
, "outside the working directory and the TEST_TMPDIR."
, "For convenience, the environment variable TMPDIR is also set to TEST_TMPDIR."
, ""
+ , "If the configuration variable RUNS_PER_TEST is set, the environment"
+ , "variable TEST_RUN_NUMBER will also be set to the number of the attempt,"
+ , "counting from 0."
+ , ""
, "This running of the test is carried out by the implicit dependency"
, "on the target \"runner\". By setting this target in the target layer"
, "of this rues repository (instead of letting it default to the"
@@ -97,7 +101,7 @@
, "default to the respective file) the layout of the summary can be"
, "changed globally."
]
- , "TEST_ENV": ["The environment for executing the test runner."]
+ , "TEST_ENV": ["Additional environment for executing the test runner."]
, "TIMEOUT_SCALE":
["Factor on how to scale the timeout for this test. Defaults to 1.0."]
, "TARGET_ARCH":
@@ -146,6 +150,7 @@
, "stage": ["./", "../..", "stage_singleton_field"]
, "host transition": ["transitions", "maybe for host"]
, "target properties": ["transitions", "target properties"]
+ , "default-PATH": ["./", "../../CC", "default-PATH"]
, "field_list": ["", "field_list_provider"]
}
, "config_transitions":
@@ -276,6 +281,12 @@
}
}
]
+ , [ "summary PATH"
+ , { "type": "join"
+ , "separator": ":"
+ , "$1": {"type": "CALL_EXPRESSION", "name": "default-PATH"}
+ }
+ ]
, [ "summary"
, { "type": "ACTION"
, "inputs":
@@ -293,6 +304,16 @@
, "name": "TEST_SUMMARY_EXECUTION_PROPERTIES"
, "default": {"type": "empty_map"}
}
+ , "env":
+ { "type": "if"
+ , "cond": {"type": "var", "name": "summary PATH"}
+ , "then":
+ { "type": "singleton_map"
+ , "key": "PATH"
+ , "value": {"type": "var", "name": "summary PATH"}
+ }
+ , "else": {"type": "empty_map"}
+ }
}
]
, [ "attempts"
diff --git a/shell/test/runner b/shell/test/runner
index 624610b..f2f5766 100755
--- a/shell/test/runner
+++ b/shell/test/runner
@@ -26,6 +26,7 @@ pwd > pwd
mkdir scratch
export TEST_TMPDIR=$(realpath scratch)
export TMPDIR="${TEST_TMPDIR}"
+export LD_LIBRARY_PATH=$(realpath ./libs):$LD_LIBRARY_PATH
# Change to the working directory; note: while unlikely, the test
# might not have test data, so we have to ensure the presence of