summaryrefslogtreecommitdiff
path: root/patch
diff options
context:
space:
mode:
authorKlaus Aehlig <klaus.aehlig@huawei.com>2022-03-04 15:47:26 +0100
committerKlaus Aehlig <klaus.aehlig@huawei.com>2022-03-04 20:07:46 +0100
commitadfcea9d9a67dca8627e9c5da9e81b03c1c83857 (patch)
tree5f8be5c08ce041d1cb2bbfc6fffd3ffff3d64ca3 /patch
parent3e21b4a4b41e2b93fb992e348059f13ac815f583 (diff)
downloadrules-cc-adfcea9d9a67dca8627e9c5da9e81b03c1c83857.tar.gz
Add rule ["patch", "file"]
... to patch a single file, logically in place.
Diffstat (limited to 'patch')
-rw-r--r--patch/RULES68
1 files changed, 68 insertions, 0 deletions
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"}
+ }
+ }
+ }
+}