This is an automated email from the ASF dual-hosted git repository.

msciabarra pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/openserverless-cli.git

commit 55857892f4d65c4f5f5c4999b87847977abc4119
Author: Michele Sciabarra <[email protected]>
AuthorDate: Thu Jul 18 10:50:37 2024 +0200

    patches for task and sh repetable...
---
 cli.code-workspace       |  25 ++++++++++++++++++++
 patches/README.md        |  17 ++++++++++++++
 patches/builtin_extra.go |  60 +++++++++++++++++++++++++++++++++++++++++++++++
 patches/gosh             | Bin 0 -> 3998109 bytes
 patches/opsfile.yml      |   0
 patches/patch-sh.sh      |  28 ++++++++++++++++++++++
 patches/patch-task.sh    |  32 +++++++++++++++++++++++++
 tools/sh                 |   2 +-
 tools/task               |   2 +-
 9 files changed, 164 insertions(+), 2 deletions(-)

diff --git a/cli.code-workspace b/cli.code-workspace
new file mode 100644
index 0000000..2f80524
--- /dev/null
+++ b/cli.code-workspace
@@ -0,0 +1,25 @@
+{
+  "folders": [
+    {
+      "name": "ops",
+      "path": "."
+    },
+    {
+      "name": "task",
+      "path": "tools/task"
+    },
+    {
+      "name": "sh",
+      "path": "tools/sh"
+    }
+  ],
+  "settings": {
+    "workbench.colorCustomizations": {
+      "activityBar.background": "#28075d",
+      "titleBar.activeBackground": "#28075d",
+      "titleBar.activeForeground": "#28075d",
+      "statusBar.background": "#28075d"
+    },
+    "go.goroot": 
"/nix/store/nnh57s7m672k6snkanhz1kb18skwjpbg-go-1.21.11/share/go"
+  }
+}
diff --git a/patches/README.md b/patches/README.md
new file mode 100644
index 0000000..a792728
--- /dev/null
+++ b/patches/README.md
@@ -0,0 +1,17 @@
+
+This is the procedure we followed to build the patched versions of:
+
+ github.com/go-task/task -> github.com/sciabarracom/task
+ mvdan.cc/sh -> github.com/sciabarracom/sh
+ 
+1. fork mvdan.cc/sh in github.com/sciabarracom/sh
+   fork github.com/go-task/task in github.com/sciabarracom/task
+
+2. checkout v3.8.0 for sh and v3.38.0 for task as openserverless branch and 
set openserverless as the default branch
+
+4. git submodule update --init, then add orig-auth to both with an 
authentication token so you can push it
+
+5. bash patch-sh.sh
+   bash patch-task.sk
+
+to patch and push
diff --git a/patches/builtin_extra.go b/patches/builtin_extra.go
new file mode 100644
index 0000000..aefa1e2
--- /dev/null
+++ b/patches/builtin_extra.go
@@ -0,0 +1,60 @@
+// Copyright (c) 2024, Michele Sciabarra  <[email protected]>
+// See LICENSE for licensing information
+
+package interp
+
+import (
+       "context"
+       "fmt"
+
+       "github.com/sciabarracom/sh/v3/syntax"
+)
+
+func isCoreutil(name string) bool {
+       switch name {
+       case
+               "arch", "b2sum", "b3sum", "base32", "base64", "basename", 
"basenc", "cat", "chgrp", "chmod", "chown", "chroot",
+               "cksum", "comm", "cp", "csplit", "cut", "date", "dd", "df", 
"dir", "dircolors", "dirname", "du", "echo", "env", "expand",
+               "expr", "factor", "false", "fmt", "fold", "groups", "hashsum", 
"head", "hostid", "hostname", "id", "install", "join",
+               "kill", "link", "ln", "logname", "ls", "md5sum", "mkdir", 
"mkfifo", "mknod", "mktemp", "more", "mv", "nice", "nl",
+               "nohup", "nproc", "numfmt", "od", "paste", "pathchk", "pinky", 
"pr", "printenv", "printf", "ptx", "pwd", "readlink",
+               "realpath", "rm", "rmdir", "seq", "sha1sum", "sha224sum", 
"sha256sum", "sha3-224sum", "sha3-256sum", "sha3-384sum",
+               "sha3-512sum", "sha384sum", "sha3sum", "sha512sum", 
"shake128sum", "shake256sum", "shred", "shuf", "sleep", "sort",
+               "split", "stat", "stdbuf", "sum", "sync", "tac", "tail", "tee", 
"test", "timeout", "touch", "tr", "true", "truncate",
+               "tsort", "tty", "uname", "unexpand", "uniq", "unlink", 
"uptime", "users", "vdir", "wc", "who", "whoami", "yes",
+               "coreutils":
+               return true
+       }
+       return false
+
+}
+
+func isBuiltin(name string) bool {
+
+       if isCoreutil(name) {
+               return true
+       }
+       return _isBuiltin(name)
+}
+
+func (r *Runner) builtinCode(ctx context.Context, pos syntax.Pos, name string, 
args []string) int {
+
+       if isCoreutil(name) {
+
+               cmd := []string{"coreutils"}
+               if name != "coreutils" {
+                       cmd = append(cmd, name)
+               }
+               args = append(cmd, args...)
+               fmt.Printf("%v\n", args)
+               // TODO: Consider unix.Exec, i.e. actually replacing
+               // the process. It's in theory what a shell should do,
+               // but in practice it would kill the entire Go process
+               // and it's not available on Windows.
+               r.exitShell(ctx, 1)
+               r.exec(ctx, args)
+               return r.exit
+       }
+
+       return _builtinCode(ctx, pos, name, args)
+}
diff --git a/patches/gosh b/patches/gosh
new file mode 100755
index 0000000..feea20d
Binary files /dev/null and b/patches/gosh differ
diff --git a/patches/opsfile.yml b/patches/opsfile.yml
new file mode 100644
index 0000000..e69de29
diff --git a/patches/patch-sh.sh b/patches/patch-sh.sh
new file mode 100644
index 0000000..ea1b1b6
--- /dev/null
+++ b/patches/patch-sh.sh
@@ -0,0 +1,28 @@
+#!/bin/sh
+cd "$(dirname $0)"
+# any suggestion how to avoid this rename and use just replaces in go.mod is 
welcome
+go clean -cache -modcache -testcache
+HERE=$PWD
+STAG="v3.8.0"
+DTAG="$STAG-openserverless"
+cd ../tools/sh
+git checkout "$STAG" -B openserverless
+cp $HERE/builtin_extra.go interp/builtin_extra.go
+git add interp/builtin_extra.go
+sed  -i -e 's!) builtinCode(!) _builtinCode(!' -e 's!func isBuiltin!func 
_isBuiltin!' interp/builtin.go
+find . \( -name \*.go -o -name go.mod \) | while read file 
+do echo $file 
+   sed -i 's!mvdan.cc/sh!github.com/sciabarracom/sh!' $file 
+done
+go clean -modcache -cache -testcache -fuzzcache
+go mod tidy
+git commit -m "patching sh for ops" -a
+git push origin-auth openserverless -f
+git tag -d $DTAG
+git tag $DTAG
+git push origin-auth --delete $DTAG
+git push origin-auth $DTAG
+GOBIN=$HERE go install github.com/sciabarracom/sh/v3/cmd/gosh@$DTAG
+
+#echo now push it git push origin-auth openserverless
+
diff --git a/patches/patch-task.sh b/patches/patch-task.sh
new file mode 100644
index 0000000..efee39a
--- /dev/null
+++ b/patches/patch-task.sh
@@ -0,0 +1,32 @@
+#!/bin/sh
+cd "$(dirname $0)"
+# any suggestion how to avoid this rename and use just replaces in go.mod is 
welcome
+HERE=$PWD
+STAG="v3.38.0"
+DTAG="$STAG-openserverless"
+cd ../tools/task
+git checkout "$TAG" -B openserverless
+mkdir -p cmd/taskmain
+cat cmd/task/task.go \
+| sed -e 's/package main/package taskmain/' \
+| sed -e 's/func main() {/func Task(_args []string) { os.Args = _args/' \
+| tee cmd/taskmain/task.go
+cp $HERE/task.go cmd/taskmain/task.go
+git add cmd/taskmain/task.go
+find . \( -name \*.go -o -name go.mod \) | while read file 
+do echo $file 
+   sed -i "s!go-task/task!sciabarracom/task!" $file
+   sed -i 's!mvdan.sh/cc!sciabarracom/sh!' $file
+   sed -i 's!"Taskfile.!"opsfile.!' $file
+   sed -i 's!task: !ops: !' $file
+done
+go clean -modcache -cache -testcache -fuzzcache
+go mod tidy
+git commit -m "patching sh for ops" -a
+git push origin-auth openserverless -f
+git tag -d $DTAG
+git tag $DTAG
+git push origin-auth --delete $DTAG
+git push origin-auth $DTAG
+GOBIN=$HERE go install github.com/sciabarracom/task/v3/cmd/task@$DTAG
+
diff --git a/tools/sh b/tools/sh
index 84baa08..cff5f78 160000
--- a/tools/sh
+++ b/tools/sh
@@ -1 +1 @@
-Subproject commit 84baa08f139fb171b86ff7f25b834d4a3ef19c6f
+Subproject commit cff5f78351fc572179e787b98a733aad73453f8d
diff --git a/tools/task b/tools/task
index 88b0950..8a3c8cc 160000
--- a/tools/task
+++ b/tools/task
@@ -1 +1 @@
-Subproject commit 88b095020e14defcce4645e72f503eb5d880f78d
+Subproject commit 8a3c8cc57237a90790c28c1b2f3dec46bd689beb

Reply via email to