From 0977b7a6d376b80124f3853ea585675748ca9b65 Mon Sep 17 00:00:00 2001 From: Mechiel Lukkien Date: Sat, 14 Sep 2024 20:53:21 +0200 Subject: [PATCH] get rid of some more gnulinuxisms to get builds on openbsd going --- Makefile | 66 +++++++++++++++++++------------------- gendoc.sh | 8 ++--- rfc/fetch.sh | 4 +-- tsc.sh | 2 +- unexpand.go | 79 ++++++++++++++++++++++++++++++++++++++++++++++ webmail/msg.js | 4 +-- webmail/text.js | 4 +-- webmail/webmail.js | 4 +-- 8 files changed, 125 insertions(+), 46 deletions(-) create mode 100644 unexpand.go diff --git a/Makefile b/Makefile index 92a4065..44df568 100644 --- a/Makefile +++ b/Makefile @@ -43,7 +43,7 @@ test-upgrade: build # needed for "check" target install-staticcheck: - go install honnef.co/go/tools/cmd/staticcheck@latest + CGO_ENABLED=0 go install honnef.co/go/tools/cmd/staticcheck@latest check: CGO_ENABLED=0 go vet -tags integration @@ -52,25 +52,25 @@ check: CGO_ENABLED=0 go vet -tags errata rfc/errata.go CGO_ENABLED=0 go vet -tags xr rfc/xr.go GOARCH=386 CGO_ENABLED=0 go vet ./... - staticcheck ./... - staticcheck -tags integration - staticcheck -tags website website/website.go - staticcheck -tags link rfc/link.go - staticcheck -tags errata rfc/errata.go - staticcheck -tags xr rfc/xr.go + CGO_ENABLED=0 staticcheck ./... + CGO_ENABLED=0 staticcheck -tags integration + CGO_ENABLED=0 staticcheck -tags website website/website.go + CGO_ENABLED=0 staticcheck -tags link rfc/link.go + CGO_ENABLED=0 staticcheck -tags errata rfc/errata.go + CGO_ENABLED=0 staticcheck -tags xr rfc/xr.go # needed for check-shadow install-shadow: - go install golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow@latest + CGO_ENABLED=0 go install golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow@latest # having "err" shadowed is common, best to not have others check-shadow: - go vet -vettool=$$(which shadow) ./... 2>&1 | grep -v '"err"' - go vet -tags integration -vettool=$$(which shadow) 2>&1 | grep -v '"err"' - go vet -tags website -vettool=$$(which shadow) website/website.go 2>&1 | grep -v '"err"' - go vet -tags link -vettool=$$(which shadow) rfc/link.go 2>&1 | grep -v '"err"' - go vet -tags errata -vettool=$$(which shadow) rfc/errata.go 2>&1 | grep -v '"err"' - go vet -tags xr -vettool=$$(which shadow) rfc/xr.go 2>&1 | grep -v '"err"' + CGO_ENABLED=0 go vet -vettool=$$(which shadow) ./... 2>&1 | grep -v '"err"' + CGO_ENABLED=0 go vet -tags integration -vettool=$$(which shadow) 2>&1 | grep -v '"err"' + CGO_ENABLED=0 go vet -tags website -vettool=$$(which shadow) website/website.go 2>&1 | grep -v '"err"' + CGO_ENABLED=0 go vet -tags link -vettool=$$(which shadow) rfc/link.go 2>&1 | grep -v '"err"' + CGO_ENABLED=0 go vet -tags errata -vettool=$$(which shadow) rfc/errata.go 2>&1 | grep -v '"err"' + CGO_ENABLED=0 go vet -tags xr -vettool=$$(which shadow) rfc/xr.go 2>&1 | grep -v '"err"' fuzz: go test -fuzz FuzzParseSignature -fuzztime 5m ./dkim @@ -125,24 +125,24 @@ install-js0: npm install --ignore-scripts --save-dev --save-exact typescript@5.1.6 webmail/webmail.js: lib.ts webmail/api.ts webmail/lib.ts webmail/webmail.ts - ./tsc.sh $@ $^ + ./tsc.sh $@ lib.ts webmail/api.ts webmail/lib.ts webmail/webmail.ts webmail/msg.js: lib.ts webmail/api.ts webmail/lib.ts webmail/msg.ts - ./tsc.sh $@ $^ + ./tsc.sh $@ lib.ts webmail/api.ts webmail/lib.ts webmail/msg.ts webmail/text.js: lib.ts webmail/api.ts webmail/lib.ts webmail/text.ts - ./tsc.sh $@ $^ + ./tsc.sh $@ lib.ts webmail/api.ts webmail/lib.ts webmail/text.ts webadmin/admin.js: lib.ts webadmin/api.ts webadmin/admin.ts - ./tsc.sh $@ $^ + ./tsc.sh $@ lib.ts webadmin/api.ts webadmin/admin.ts webaccount/account.js: lib.ts webaccount/api.ts webaccount/account.ts - ./tsc.sh $@ $^ + ./tsc.sh $@ lib.ts webaccount/api.ts webaccount/account.ts frontend: node_modules/.bin/tsc webadmin/admin.js webaccount/account.js webmail/webmail.js webmail/msg.js webmail/text.js install-apidiff: - go install golang.org/x/exp/cmd/apidiff@v0.0.0-20231206192017-f3f8817b8deb + CGO_ENABLED=0 go install golang.org/x/exp/cmd/apidiff@v0.0.0-20231206192017-f3f8817b8deb genapidiff: ./apidiff.sh @@ -157,17 +157,17 @@ genwebsite: ./genwebsite.sh buildall: - GOOS=linux GOARCH=arm go build - GOOS=linux GOARCH=arm64 go build - GOOS=linux GOARCH=amd64 go build - GOOS=linux GOARCH=386 go build - GOOS=openbsd GOARCH=amd64 go build - GOOS=freebsd GOARCH=amd64 go build - GOOS=netbsd GOARCH=amd64 go build - GOOS=darwin GOARCH=amd64 go build - GOOS=dragonfly GOARCH=amd64 go build - GOOS=illumos GOARCH=amd64 go build - GOOS=solaris GOARCH=amd64 go build - GOOS=aix GOARCH=ppc64 go build - GOOS=windows GOARCH=amd64 go build + CGO_ENABLED=0 GOOS=linux GOARCH=arm go build + CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build + CGO_ENABLED=0 GOOS=linux GOARCH=386 go build + CGO_ENABLED=0 GOOS=openbsd GOARCH=amd64 go build + CGO_ENABLED=0 GOOS=freebsd GOARCH=amd64 go build + CGO_ENABLED=0 GOOS=netbsd GOARCH=amd64 go build + CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build + CGO_ENABLED=0 GOOS=dragonfly GOARCH=amd64 go build + CGO_ENABLED=0 GOOS=illumos GOARCH=amd64 go build + CGO_ENABLED=0 GOOS=solaris GOARCH=amd64 go build + CGO_ENABLED=0 GOOS=aix GOARCH=ppc64 go build + CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build # no plan9 for now diff --git a/gendoc.sh b/gendoc.sh index 833fe86..0ad44a3 100755 --- a/gendoc.sh +++ b/gendoc.sh @@ -26,7 +26,7 @@ any parameters. Followed by the help and usage information for each command. EOF -./mox 2>&1 | sed -e 's/^usage: */\t/' -e 's/^ */\t/' +./mox 2>&1 | sed -e 's/^usage: */ /' -e 's/^ */ /' echo ./mox helpall 2>&1 @@ -80,14 +80,14 @@ See https://pkg.go.dev/github.com/mjl-/sconf for details. # mox.conf EOF -./mox config describe-static | sed 's/^/\t/' +./mox config describe-static | sed 's/^/ /' cat <$number || rm $number fi done -for name in $(sed -n 's/^\([0-9][0-9]*-eid[0-9][0-9]*\)[ \t].*$/\1/p' index.txt); do +for name in $(sed -n 's/^\([0-9][0-9]*-eid[0-9][0-9]*\)[ ].*$/\1/p' index.txt); do if ! test -f "$name"; then rfc=$(echo $name | cut -f1 -d-) eid=$(echo $name | cut -f2 -d-) diff --git a/tsc.sh b/tsc.sh index 42ea7ab..26d06e9 100755 --- a/tsc.sh +++ b/tsc.sh @@ -8,5 +8,5 @@ set -euo pipefail out=$1 shift ./node_modules/.bin/tsc --noEmitOnError true --pretty false --newLine lf --strict --allowUnreachableCode false --allowUnusedLabels false --noFallthroughCasesInSwitch true --noImplicitReturns true --noUnusedLocals true --noImplicitThis true --noUnusedParameters true --target es2022 --module none --outFile $out.spaces "$@" | sed -E 's/^([^\(]+)\(([0-9]+),([0-9]+)\):/\1:\2:\3: /' -unexpand -t4 <$out.spaces >$out +CGO_ENABLED=0 go run unexpand.go -t 4 <$out.spaces >$out rm $out.spaces diff --git a/unexpand.go b/unexpand.go new file mode 100644 index 0000000..4acf174 --- /dev/null +++ b/unexpand.go @@ -0,0 +1,79 @@ +//go:build tools +// +build tools + +// For unexpand the 4 spaces that the typescript compiler outputs into tabs. +// Not all unexpand commands implement the -t flag (openbsd). +package main + +import ( + "bufio" + "flag" + "fmt" + "io" + "log" + "os" +) + +func xcheckf(err error, format string, args ...any) { + if err != nil { + log.Fatalf("%s: %s", fmt.Sprintf(format, args...), err) + } +} + +func main() { + log.SetFlags(0) + var width int + flag.IntVar(&width, "t", 8, "tab width") + flag.Parse() + flag.Usage = func() { + log.Print("usage: unexpand [-t tabwidth] < input.spaces >output.tabs") + flag.PrintDefaults() + os.Exit(2) + } + if flag.NArg() != 0 { + flag.Usage() + } + if width <= 0 { + flag.Usage() + } + + r := bufio.NewReader(os.Stdin) + w := bufio.NewWriter(os.Stdout) + + nspace := 0 + start := true + + flush := func() { + for ; nspace > 0; nspace-- { + err := w.WriteByte(' ') + xcheckf(err, "write") + } + } + write := func(b byte) { + err := w.WriteByte(b) + xcheckf(err, "write") + } + + for { + b, err := r.ReadByte() + if err == io.EOF { + break + } + xcheckf(err, "read") + + if start && b == ' ' { + nspace++ + if nspace == width { + write('\t') + nspace = 0 + } + } else { + flush() + write(b) + start = b == '\n' + } + } + flush() + err := w.Flush() + xcheckf(err, "flush output") +} diff --git a/webmail/msg.js b/webmail/msg.js index def7253..f0e03e6 100644 --- a/webmail/msg.js +++ b/webmail/msg.js @@ -1051,8 +1051,8 @@ var api; // - To keep the style definitions closer to their use. // - To make it easier to provide both light/regular and dark mode colors. // - To use class names for styling, instead of the the many inline styles. -// Makes it easier to look through a DOM, and easier to change the style of all -// instances of a class. +// Makes it easier to look through a DOM, and easier to change the style of all +// instances of a class. // We keep the default/regular styles and dark-mode styles in separate stylesheets. const cssStyle = dom.style(attr.type('text/css')); document.head.appendChild(cssStyle); diff --git a/webmail/text.js b/webmail/text.js index 2ba1bf1..1576476 100644 --- a/webmail/text.js +++ b/webmail/text.js @@ -1051,8 +1051,8 @@ var api; // - To keep the style definitions closer to their use. // - To make it easier to provide both light/regular and dark mode colors. // - To use class names for styling, instead of the the many inline styles. -// Makes it easier to look through a DOM, and easier to change the style of all -// instances of a class. +// Makes it easier to look through a DOM, and easier to change the style of all +// instances of a class. // We keep the default/regular styles and dark-mode styles in separate stylesheets. const cssStyle = dom.style(attr.type('text/css')); document.head.appendChild(cssStyle); diff --git a/webmail/webmail.js b/webmail/webmail.js index 9e6288c..3fb4229 100644 --- a/webmail/webmail.js +++ b/webmail/webmail.js @@ -1051,8 +1051,8 @@ var api; // - To keep the style definitions closer to their use. // - To make it easier to provide both light/regular and dark mode colors. // - To use class names for styling, instead of the the many inline styles. -// Makes it easier to look through a DOM, and easier to change the style of all -// instances of a class. +// Makes it easier to look through a DOM, and easier to change the style of all +// instances of a class. // We keep the default/regular styles and dark-mode styles in separate stylesheets. const cssStyle = dom.style(attr.type('text/css')); document.head.appendChild(cssStyle);