You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openserverless.apache.org by ms...@apache.org on 2024/08/05 10:46:51 UTC
(openserverless-cli) 03/06: patching sh for ops
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 0d14d6d7bf7bbb90fc079ed9e153451bc68b8151
Author: Michele Sciabarra <mi...@sciabarra.com>
AuthorDate: Mon Aug 5 12:16:47 2024 +0200
patching sh for ops
---
.gitignore | 23 ++++++++++----------
.gitmodules | 28 ++++++++++++++++++++++++
.goreleaser.yaml | 3 +++
Taskfile.yml | 2 +-
_patches/README.md | 2 +-
_patches/awk | 1 +
_patches/builtin_extra.go | 15 +++++++------
_patches/envsubst | 1 +
_patches/jq | 1 +
_patches/patch-sh.sh | 14 +++++++++---
_patches/patch-task.sh | 2 +-
_patches/sh | 1 +
_patches/task | 1 +
_patches/wsk | 1 +
_patches/wskdeploy | 1 +
go.mod | 2 +-
go.sum | 4 ++--
preflight.go | 5 -----
prereq.go | 55 ++++++++++++++++++++++++++++++-----------------
prereq_test.go | 2 ++
20 files changed, 111 insertions(+), 53 deletions(-)
diff --git a/.gitignore b/.gitignore
index 56b2779..aa81092 100644
--- a/.gitignore
+++ b/.gitignore
@@ -19,26 +19,25 @@
.git-hooks/
.vscode/
.task/
-attic/
-_*
-ops
-!ops/
.latestcheck
.test_fail_then_succeed
-cookie.txt
-actions.zip
-nix/result
.direnv/
+cookie.txt
+attic/
+*.zip
+_*
+7*
+!cmd/ops/
+ops
tests/bats/
tests/test_helper/bats-assert/
tests/test_helper/bats-support/
+tests/prereq/olaris/bin
+tests/coreutils*
+tests/7z*
+!_patch
_patch/task
_patch/gosh
_patch/wsk
_patch/openwhisk-wskdeploy
_patch/openwhisk-cli
-tests/prereq/olaris/bin
-dist/
-tests/coreutils*
-tests/7z*
-7*
diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..bfa876e
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,28 @@
+[submodule "sh"]
+ path = _patches/sh
+ url = https://github.com/sciabarracom/sh
+ branch = openserverless
+[submodule "task"]
+ path = _patches/task
+ url = https://github.com/sciabarracom/task
+ branch = openserverless
+[submodule "wskdeploy"]
+ path = _patches/wskdeploy
+ url = https://github.com/sciabarracom/openwhisk-wskdeploy
+ branch = openserverless
+[submodule "wsk"]
+ path = _patches/wsk
+ url = https://github.com/sciabarracom/openwhisk-cli
+ branch = openserverless
+[submodule "modules/jq"]
+ path = _patches/jq
+ url = https://github.com/nuvolaris/gojq
+ branch = openserverless
+[submodule "modules/awk"]
+ path = _patches/awk
+ url = https://github.com/nuvolaris/goawk
+ branch = openserverless
+[submodule "modules/envsubst"]
+ path = _patches/envsubst
+ url = https://github.com/nuvolaris/envsubst
+ branch = openserverless
diff --git a/.goreleaser.yaml b/.goreleaser.yaml
index e24e977..303a997 100644
--- a/.goreleaser.yaml
+++ b/.goreleaser.yaml
@@ -29,6 +29,9 @@ builds:
goarch:
- amd64
- arm64
+ ignore:
+ - goos: windows
+ goarch: arm64
archives:
- id: default
diff --git a/Taskfile.yml b/Taskfile.yml
index 0d0c57c..55cfc4f 100644
--- a/Taskfile.yml
+++ b/Taskfile.yml
@@ -90,7 +90,7 @@ tasks:
desc: unit test (use F=-v to verbose)
cmds:
- rm -Rf ~/.ops
- - go clean -testcache
+ - go clean -testcache -cache
- go test -count=1 {{.F}} github.com/apache/openserverless-cli
- go test -count=1 {{.F}} github.com/apache/openserverless-cli/config
- go test -count=1 {{.F}} github.com/apache/openserverless-cli/tools
diff --git a/_patches/README.md b/_patches/README.md
index f02d061..db944d7 100644
--- a/_patches/README.md
+++ b/_patches/README.md
@@ -1,4 +1,4 @@
-# Patches:
+# Patches to the tools
- changes to mvdan/sh:
- rename to sciabarracom/sh
diff --git a/_patches/awk b/_patches/awk
new file mode 160000
index 0000000..d0931fd
--- /dev/null
+++ b/_patches/awk
@@ -0,0 +1 @@
+Subproject commit d0931fd55c2c3eadaacbea1ba3684dde951d2159
diff --git a/_patches/builtin_extra.go b/_patches/builtin_extra.go
index c42e0ac..43fa5b8 100644
--- a/_patches/builtin_extra.go
+++ b/_patches/builtin_extra.go
@@ -54,7 +54,7 @@ func isBuiltin(name string) bool {
if isTools(name) {
return true
}
- return IsBuiltin1(name)
+ return isBuiltin_orig(name)
}
func (r *Runner) builtinCode(ctx context.Context, pos syntax.Pos, name string, args []string) int {
@@ -65,19 +65,20 @@ func (r *Runner) builtinCode(ctx context.Context, pos syntax.Pos, name string, a
cmd = append(cmd, name)
}
args = append(cmd, args...)
- fmt.Printf("%v\n", args)
- r.exitShell(ctx, 1)
+ if os.Getenv("TRACE") != "" {
+ fmt.Printf("%v\n", args)
+ }
r.exec(ctx, args)
return r.exit
}
if isTools(name) {
args = append([]string{os.Getenv("OPS_CMD"), "-" + name}, args...)
- fmt.Printf("%v\n", args)
- r.exitShell(ctx, 1)
+ if os.Getenv("TRACE") != "" {
+ fmt.Printf("%v\n", args)
+ }
r.exec(ctx, args)
return r.exit
-
}
- return r.BuiltinCode1(ctx, pos, name, args)
+ return r.builtinCode_orig(ctx, pos, name, args)
}
diff --git a/_patches/envsubst b/_patches/envsubst
new file mode 160000
index 0000000..10ca029
--- /dev/null
+++ b/_patches/envsubst
@@ -0,0 +1 @@
+Subproject commit 10ca029cdb58695b98d525e833ba6dced90b5dcf
diff --git a/_patches/jq b/_patches/jq
new file mode 160000
index 0000000..54b7644
--- /dev/null
+++ b/_patches/jq
@@ -0,0 +1 @@
+Subproject commit 54b764416b6984bf36b79c42d8ccafa1ed1638df
diff --git a/_patches/patch-sh.sh b/_patches/patch-sh.sh
index abc830a..76b6040 100644
--- a/_patches/patch-sh.sh
+++ b/_patches/patch-sh.sh
@@ -21,21 +21,29 @@ cd "$(dirname $0)"
go clean -cache -modcache -testcache
HERE=$PWD
STAG="v3.8.0"
-DTAG="v3.8.2"
+DTAG="v3.8.3"
cd sh
+git reset --hard
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(!) BuiltinCode1(!' -e 's!func isBuiltin!func IsBuiltin1!' interp/builtin.go
+sed -i -e 's!) builtinCode(!) builtinCode_orig(!' -e 's!func isBuiltin!func isBuiltin_orig!' 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
+
+#echo >>go.mod "replace github.com/sciabarracom/sh/v3/interp => ./interp"
+#echo >>go.mod "replace github.com/sciabarracom/sh/v3/syntax => ./syntax"
+#go build ./cmd/gosh
+#
+#exit
+
git commit -m "patching sh for ops" -a
git tag $DTAG
git push -f origin-auth openserverless --tags
VER=$(git rev-parse --short HEAD)
GOBIN=$HERE go install github.com/sciabarracom/sh/v3/cmd/gosh@$VER
-
+OPS_CMD=$(which ops) OPS_TOOLS="jq awk" OPS_COREUTILS="ls cp mv" TRACE=1 ./gosh
diff --git a/_patches/patch-task.sh b/_patches/patch-task.sh
index 5589c1e..ba78c5c 100644
--- a/_patches/patch-task.sh
+++ b/_patches/patch-task.sh
@@ -21,7 +21,7 @@ cd "$(dirname $0)"
HERE=$PWD
SHVER=$(git ls-remote https://github.com/sciabarracom/sh | awk '/refs\/heads\/openserverless/{print $1}')
STAG="v3.38.0"
-DTAG="v3.38.9"
+DTAG="v3.38.10"
cd taskfile
go clean -cache -modcache
git checkout "$STAG" -B openserverless
diff --git a/_patches/sh b/_patches/sh
new file mode 160000
index 0000000..f3da214
--- /dev/null
+++ b/_patches/sh
@@ -0,0 +1 @@
+Subproject commit f3da214dce8792e875c56f647f3d4900100def11
diff --git a/_patches/task b/_patches/task
new file mode 160000
index 0000000..781bf85
--- /dev/null
+++ b/_patches/task
@@ -0,0 +1 @@
+Subproject commit 781bf859e75a764fc76f59f76f830ec8e7d7003d
diff --git a/_patches/wsk b/_patches/wsk
new file mode 160000
index 0000000..39db77e
--- /dev/null
+++ b/_patches/wsk
@@ -0,0 +1 @@
+Subproject commit 39db77e21ff61258d72baa48e4ccbb66005cf44b
diff --git a/_patches/wskdeploy b/_patches/wskdeploy
new file mode 160000
index 0000000..67c642d
--- /dev/null
+++ b/_patches/wskdeploy
@@ -0,0 +1 @@
+Subproject commit 67c642d0ac144727e9cd80efdea1d73cea04dce2
diff --git a/go.mod b/go.mod
index f9561ae..b9f5af0 100644
--- a/go.mod
+++ b/go.mod
@@ -20,7 +20,7 @@ require (
github.com/nuvolaris/jj v0.0.0-20231020143327-10b90948a5d2
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c
github.com/sciabarracom/openwhisk-cli v1.2.1
- github.com/sciabarracom/sh/v3 v3.8.2
+ github.com/sciabarracom/sh/v3 v3.8.3
github.com/sciabarracom/task/v3 v3.38.9
github.com/stretchr/testify v1.9.0
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8
diff --git a/go.sum b/go.sum
index 72a88e3..7c90fc2 100644
--- a/go.sum
+++ b/go.sum
@@ -343,8 +343,8 @@ github.com/sciabarracom/openwhisk-cli v1.2.1 h1:XVEAidwhmoOpvjKkqcIfGzLQwe850K5E
github.com/sciabarracom/openwhisk-cli v1.2.1/go.mod h1:KIF6FPfQ6d2mNSEFP7oiz49iHxjDCeFTnCS7XwHAlUI=
github.com/sciabarracom/openwhisk-wskdeploy v1.2.1 h1:t5hgca9OFEO39t4OqIxcWybYRjyBW7jDhg54eLar29U=
github.com/sciabarracom/openwhisk-wskdeploy v1.2.1/go.mod h1:bWjrIOIAzt8AcPqiJ0mWEecUxXbT4bY4ysMlJO6/q78=
-github.com/sciabarracom/sh/v3 v3.8.2 h1:ZAdlsq2d1UnvdbnOgENhZ/bTqKdwEM89ftX7kokVFnI=
-github.com/sciabarracom/sh/v3 v3.8.2/go.mod h1:CeMVr3PRLhlUrS+VPLTp8dS5/6xNzmmX0h/WVHRR6DA=
+github.com/sciabarracom/sh/v3 v3.8.3 h1:5afHdZzNkW5vgUMP7gHUpBYHezn3BoQsyNgKXKdTpkM=
+github.com/sciabarracom/sh/v3 v3.8.3/go.mod h1:CeMVr3PRLhlUrS+VPLTp8dS5/6xNzmmX0h/WVHRR6DA=
github.com/sciabarracom/task/v3 v3.38.9 h1:LozhBEsGQGYKJCAhOE+0s22IF92DATMNDU/RMzpbSCw=
github.com/sciabarracom/task/v3 v3.38.9/go.mod h1:V88FdSzukQ90H9nzqexBsmBRXpoEpJGsVPMoOnkAsWc=
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
diff --git a/preflight.go b/preflight.go
index 522e757..c4cbacd 100644
--- a/preflight.go
+++ b/preflight.go
@@ -45,11 +45,6 @@ func preflightChecks() error {
preflight.check(checkInstalled("curl"))
preflight.check(checkInstalled("ssh"))
- if getOS() != "windows" {
- preflight.check(checkInstalled("grep"))
- preflight.check(checkInstalled("xz"))
- preflight.check(checkInstalled("gunzip"))
- }
return preflight.err
}
diff --git a/prereq.go b/prereq.go
index 9a80db8..4ccfd3d 100644
--- a/prereq.go
+++ b/prereq.go
@@ -175,53 +175,67 @@ func touchAndClean(dir string, name string, version string) error {
// download a prerequisite
func downloadPrereq(name string, task PrereqTask) error {
+
+ // names and version
+ // xname = executeable name
+ // vname = versioned executable name
version, ok := task.Vars["VERSION"]
if !ok {
+ trace("return because no version for ", name)
return nil
}
+ xname := addExeExt(name)
+ vname := xname + "-" + version
+ // ensure bindir
bindir, err := EnsureBindir()
if err != nil {
return err
}
// check if file and version exists
- vname := name + "-" + version
trace("checking", vname, version)
- if exists(bindir, name) {
- // check if there is an inconsistency in the versions
- if exists(bindir, vname) {
- trace("already downloaded", vname)
+ if exists(bindir, vname) {
+ trace("already downloaded", vname)
+ return nil
+ }
+
+ // checking different versions of the same file
+ oldver, seen := PrereqSeenMap[name]
+ if seen {
+ if oldver == version {
+ trace("same version again", vname)
return nil
}
- oldver, seen := PrereqSeenMap[name]
- if seen {
- if oldver == version {
- trace("same version again", vname)
- return nil
- }
- return fmt.Errorf("WARNING: %s prerequisite found twice with different versions!\nPrevious version: %s, ignoring %s", name, oldver, version)
- }
+ return fmt.Errorf("WARNING: %s prerequisite found twice with different versions!\nPrevious version: %s, ignoring %s", name, oldver, version)
}
+ PrereqSeenMap[name] = version
if taskDryRun {
fmt.Printf("downloading %s %s\n", name, version)
touch(bindir, name)
- touchAndClean(bindir, name, version)
} else {
fmt.Printf("ensuring prerequisite %s %s\n", name, version)
execPrereqTask(bindir, name)
// check if file and version exists
- // fixing the name for windows adding .exe
- name = addExeExt(name)
- if !exists(bindir, name) {
+ if !exists(bindir, xname) {
return fmt.Errorf("failed to download %s version %s", name, version)
}
+ // check if a file is zero length and remove in this case
+ fileInfo, err := os.Stat(joinpath(bindir, xname))
+ if err != nil {
+ return fmt.Errorf("failed to download %s version %s", name, version)
+ }
+ if fileInfo.Size() == 0 {
+ trace("removing the empty file ", xname)
+ err := os.Remove(joinpath(bindir, xname))
+ if err != nil {
+ return fmt.Errorf("cannot remove empty %s ", xname)
+ }
+ }
}
-
- PrereqSeenMap[name] = version
- return touchAndClean(bindir, name, version)
+ return touchAndClean(bindir, xname, version)
}
// ensure prereq are satified looking at the prereq.yml
@@ -237,6 +251,7 @@ func ensurePrereq(root string) error {
trace("ensurePrereq in", root)
prereq, err := loadPrereq(root)
for task := range prereq.Tasks {
+ trace("prereq", task)
err = downloadPrereq(task, prereq.Tasks[task])
if err != nil {
fmt.Printf("error in prereq %s: %v\n", task, err)
diff --git a/prereq_test.go b/prereq_test.go
index bacea9b..62de7f4 100644
--- a/prereq_test.go
+++ b/prereq_test.go
@@ -113,6 +113,8 @@ func Example_ensurePrereq() {
bindir, err := EnsureBindir()
if err == nil {
RemoveAll(bindir)
+ } else {
+ fmt.Printf("ERROR CANNOT REMOVE DIR %v\n", err)
}
dir := joinpath(joinpath(workDir, "tests"), "prereq")
fmt.Println(ensurePrereq(dir))