From f6f32aa6d88b7bb1691fa80dffa31918b11be432 Mon Sep 17 00:00:00 2001 From: Klaus Aehlig Date: Fri, 5 May 2023 16:28:14 +0200 Subject: ["data", "staged"]: support dropping paths In this way, GLOB constructs can be used more easily. As the dropping happens early, this can also be used to solve staging conflicts, by removing that logical path and later add a consolidated artifact to that path. --- README.md | 1 + rules/data/EXPRESSIONS | 113 +++++++++++++++++++++++++++++++++++++++++++++++++ rules/data/RULES | 39 ++++++++++++++--- 3 files changed, 148 insertions(+), 5 deletions(-) create mode 100644 rules/data/EXPRESSIONS diff --git a/README.md b/README.md index 2e5d427..627c300 100644 --- a/README.md +++ b/README.md @@ -328,6 +328,7 @@ Stage data to a logical subdirectory. | Field | Description | | ----- | ----------- | | `"stage"` | The logical directory to stage the files to. Individual directory components are joined with `"/"`. | +| `"drop"` | List of paths to drop from (each of) the `"srcs"` targets before joining and staging. In this way, GLOB constructs can be used is `"srcs"`. | | `"srcs"` | The files to be staged | | `"deps"` | Targets of with their runfiles should be added as well. Their staging is not changed. | diff --git a/rules/data/EXPRESSIONS b/rules/data/EXPRESSIONS new file mode 100644 index 0000000..929eaf8 --- /dev/null +++ b/rules/data/EXPRESSIONS @@ -0,0 +1,113 @@ +{ "field_artifacts_without": + { "doc": + [ "Query and merge artifacts from target_field's targets," + , "leaving out the specified logical paths." + ] + , "vars": ["fieldname", "transition", "exclude"] + , "vars_doc": + { "fieldname": ["The name of the target_field to query."] + , "transition": ["The optional configuration transition for the targets."] + , "exclude": ["The logical paths to exclude"] + } + , "expression": + { "type": "disjoint_map_union" + , "msg": + [ "artifacts" + , {"type": "var", "name": "fieldname"} + , "must not overlap after dropping paths" + , {"type": "var", "name": "exclude"} + ] + , "$1": + { "type": "foreach" + , "var": "x" + , "range": + {"type": "FIELD", "name": {"type": "var", "name": "fieldname"}} + , "body": + { "type": "map_union" + , "$1": + { "type": "foreach_map" + , "range": + { "type": "DEP_ARTIFACTS" + , "dep": {"type": "var", "name": "x"} + , "transition": + { "type": "var" + , "name": "transition" + , "default": {"type": "empty_map"} + } + } + , "body": + { "type": "if" + , "cond": + { "type": "lookup" + , "key": {"type": "var", "name": "_"} + , "map": {"type": "var", "name": "exclude"} + } + , "then": {"type": "empty_map"} + , "else": + { "type": "singleton_map" + , "key": {"type": "var", "name": "_"} + , "value": {"type": "var", "name": "$_"} + } + } + } + } + } + } + } +, "field_runfiles_without": + { "doc": + [ "Query and merge runfiles from target_field's targets," + , "leaving out the specified logical paths." + ] + , "vars": ["fieldname", "transition", "exclude"] + , "vars_doc": + { "fieldname": ["The name of the target_field to query."] + , "transition": ["The optional configuration transition for the targets."] + , "exclude": ["The logical paths to exclude"] + } + , "expression": + { "type": "disjoint_map_union" + , "msg": + [ "artifacts" + , {"type": "var", "name": "fieldname"} + , "must not overlap after dropping paths" + , {"type": "var", "name": "exclude"} + ] + , "$1": + { "type": "foreach" + , "var": "x" + , "range": + {"type": "FIELD", "name": {"type": "var", "name": "fieldname"}} + , "body": + { "type": "map_union" + , "$1": + { "type": "foreach_map" + , "range": + { "type": "DEP_RUNFILES" + , "dep": {"type": "var", "name": "x"} + , "transition": + { "type": "var" + , "name": "transition" + , "default": {"type": "empty_map"} + } + } + , "body": + { "type": "if" + , "cond": + { "type": "lookup" + , "key": {"type": "var", "name": "_"} + , "map": {"type": "var", "name": "exclude"} + } + , "then": {"type": "empty_map"} + , "else": + { "type": "singleton_map" + , "key": {"type": "var", "name": "_"} + , "value": {"type": "var", "name": "$_"} + } + } + } + } + } + } + } +} diff --git a/rules/data/RULES b/rules/data/RULES index feb1a73..d1f8975 100644 --- a/rules/data/RULES +++ b/rules/data/RULES @@ -1,7 +1,7 @@ { "staged": { "doc": ["Stage data to a logical subdirectory."] , "target_fields": ["srcs", "deps"] - , "string_fields": ["stage"] + , "string_fields": ["stage", "drop"] , "field_doc": { "srcs": ["The files to be staged"] , "stage": @@ -12,9 +12,15 @@ [ "Targets of with their runfiles should be added as well." , "Their staging is not changed." ] + , "drop": + [ "List of paths to drop from (each of) the \"srcs\" targets" + , "before joining and staging. In this way, GLOB constructs can" + , "be used is \"srcs\"." + ] } , "artifacts_doc": - [ "The runfiles of the \"srcs\" targets staged to the directory" + [ "The runfiles and artifacts of the \"srcs\" targets, leaving out" + , "the ones with logical path in \"drop\", staged to the directory" , "specified in \"stage\" together the runfiles of the targets" , "specied in the field \"deps\" (in their original location)." ] @@ -22,6 +28,8 @@ , "imports": { "runfiles": ["./", "..", "field_runfiles"] , "artifacts": ["./", "..", "field_artifacts"] + , "runfiles w/o": "field_artifacts_without" + , "artifacts w/o": "field_artifacts_without" } , "expression": { "type": "let*" @@ -32,15 +40,36 @@ , "$1": {"type": "FIELD", "name": "stage"} } ] + , [ "exclude" + , { "type": "map_union" + , "$1": + { "type": "foreach" + , "range": {"type": "FIELD", "name": "drop"} + , "body": + { "type": "singleton_map" + , "key": {"type": "var", "name": "_"} + , "value": true + } + } + } + ] , [ "srcs" , { "type": "let*" , "bindings": [["fieldname", "srcs"]] , "body": { "type": "map_union" , "$1": - [ {"type": "CALL_EXPRESSION", "name": "runfiles"} - , {"type": "CALL_EXPRESSION", "name": "artifacts"} - ] + { "type": "if" + , "cond": {"type": "var", "name": "exclude"} + , "then": + [ {"type": "CALL_EXPRESSION", "name": "runfiles w/o"} + , {"type": "CALL_EXPRESSION", "name": "artifacts w/o"} + ] + , "else": + [ {"type": "CALL_EXPRESSION", "name": "runfiles"} + , {"type": "CALL_EXPRESSION", "name": "artifacts"} + ] + } } } ] -- cgit v1.2.3