summaryrefslogtreecommitdiff
path: root/rules/patch
diff options
context:
space:
mode:
authorOliver Reiche <oliver.reiche@huawei.com>2022-12-12 11:47:52 +0100
committerOliver Reiche <oliver.reiche@huawei.com>2022-12-12 11:47:52 +0100
commit6e10ee13df0b83511d7fe94bb755ac53f993c0ec (patch)
tree64615ddb751a207ae8da42a620f085795cf1c035 /rules/patch
parent247e09b1ba01deb5649c6a73a7f272e1f72178fe (diff)
parentd44be66f2a916168e0f5a7055e49f12c252b2cd2 (diff)
downloadrules-cc-6e10ee13df0b83511d7fe94bb755ac53f993c0ec.tar.gz
Add 'rules/' from commit 'd44be66f2a916168e0f5a7055e49f12c252b2cd2'
git-subtree-dir: rules git-subtree-mainline: 247e09b1ba01deb5649c6a73a7f272e1f72178fe git-subtree-split: d44be66f2a916168e0f5a7055e49f12c252b2cd2
Diffstat (limited to 'rules/patch')
-rw-r--r--rules/patch/RULES139
1 files changed, 139 insertions, 0 deletions
diff --git a/rules/patch/RULES b/rules/patch/RULES
new file mode 100644
index 0000000..bba83c2
--- /dev/null
+++ b/rules/patch/RULES
@@ -0,0 +1,139 @@
+{ "file":
+ { "doc": ["Replace a file, logically in place, by a patched version"]
+ , "target_fields": ["src", "patch"]
+ , "string_fields": ["patch-part"]
+ , "config_vars": ["PATCH", "ENV"]
+ , "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"]
+ , "runfiles_doc": ["Same as artifacts"]
+ , "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"}
+ }
+ ]
+ , [ "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"]
+ , "env":
+ {"type": "var", "name": "ENV", "default": {"type": "empty_map"}}
+ }
+ , "else": {"type": "var", "name": "patch"}
+ }
+ ]
+ , [ "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"}
+ }
+ }
+ }
+}