diff options
author | Oliver Reiche <oliver.reiche@huawei.com> | 2022-08-04 15:24:42 +0200 |
---|---|---|
committer | Oliver Reiche <oliver.reiche@huawei.com> | 2022-08-04 16:06:54 +0200 |
commit | fe3b10643dd743c56db51b9ef4a090c460668e8d (patch) | |
tree | 9448999e99795521b6154411933a211524c842ba /rules/patch | |
parent | 834e94bbdc0601215d5b9c35652c6b7cf8666b5c (diff) | |
download | justbuild-fe3b10643dd743c56db51b9ef4a090c460668e8d.tar.gz |
rules: Extend patch rule to split parts from patch
Diffstat (limited to 'rules/patch')
-rw-r--r-- | rules/patch/RULES | 68 |
1 files changed, 67 insertions, 1 deletions
diff --git a/rules/patch/RULES b/rules/patch/RULES index 15bc818f..ab5f102f 100644 --- a/rules/patch/RULES +++ b/rules/patch/RULES @@ -1,11 +1,17 @@ { "file": - { "doc": ["Replace a file, logically in pace, by a patched version"] + { "doc": ["Replace a file, logically in place, by a patched version"] , "target_fields": ["src", "patch"] + , "string_fields": ["patch-part"] , "config_vars": ["PATCH"] , "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"] @@ -29,6 +35,66 @@ , "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"] + } + , "else": {"type": "var", "name": "patch"} + } + ] , [ "inputs" , { "type": "map_union" , "$1": |