From 3f15bfd2e47bc98cf409b9f3a1587416c8897b26 Mon Sep 17 00:00:00 2001 From: Evan Simkowitz Date: Thu, 26 Sep 2024 14:36:47 -0700 Subject: [PATCH] Revert "better conditional taskfile running" (#872) Reverts wavetermdev/waveterm#864 There's a typo here that's breaking the Taskfile --- Taskfile.yml | 37 +++++------- cmd/generatego/main-generatego.go | 7 +-- cmd/generatets/main-generatets.go | 95 +++++++++++++++---------------- pkg/tsgen/tsgen.go | 20 ------- 4 files changed, 62 insertions(+), 97 deletions(-) diff --git a/Taskfile.yml b/Taskfile.yml index 80539aa36..2014f91a2 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -59,9 +59,6 @@ tasks: - build:server:linux - build:server:macos - build:server:windows - sources: - - "cmd/server/*.go" - - "pkg/**/*.go" build:server:macos: desc: Build the wavesrv component for macOS (Darwin) platforms (generates artifacts for both arm64 and amd64). @@ -73,9 +70,6 @@ tasks: - task: build:server:internal vars: ARCHS: arm64,amd64 - sources: - - "cmd/server/*.go" - - "pkg/**/*.go" build:server:windows: desc: Build the wavesrv component for Windows platforms (only generates artifacts for the current architecture). @@ -88,9 +82,6 @@ tasks: vars: ARCHS: sh: echo {{if eq "arm" ARCH}}arm64{{else}}{{ARCH}}{{end}} - sources: - - "cmd/server/*.go" - - "pkg/**/*.go" build:server:linux: desc: Build the wavesrv component for Linux platforms (only generates artifacts for the current architecture). @@ -105,9 +96,6 @@ tasks: sh: echo {{if eq "arm" ARCH}}arm64{{else}}{{ARCH}}{{end}} GO_ENV_VARS: sh: echo "{{if eq "amd64" ARCH}}CC=\"zig cc -target x86_64-linux-gnu.2.28\"{{end}}" - sources: - - "cmd/server/*.go" - - "pkg/**/*.go" build:server:internal: requires: @@ -159,11 +147,6 @@ tasks: GOARCH: arm64 deps: - generate - sources: - - "cmd/wsh/**/*.go" - - "pkg/**/*.go" - - go.mod - - go.sum dev:installwsh: desc: quick shortcut to rebuild wsh and install for macos arm64 @@ -191,8 +174,6 @@ tasks: sources: - "cmd/wsh/**/*.go" - "pkg/**/*.go" - - go.mod - - go.sum generates: - dist/bin/wsh-{{.VERSION}}-{{.GOOS}}.{{.NORMALIZEDARCH}}{{.EXT}} cmd: (CGO_ENABLED=0 GOOS={{.GOOS}} GOARCH={{.GOARCH}} go build -ldflags="-s -w -X main.BuildTime=$({{.DATE}} +'%Y%m%d%H%M') -X main.WaveVersion={{.VERSION}}" -o dist/bin/wsh-{{.VERSION}}-{{.GOOS}}.{{.NORMALIZEDARCH}}{{.EXT}} cmd/wsh/main-wsh.go) @@ -208,12 +189,20 @@ tasks: sources: - "cmd/generatego/*.go" - "cmd/generatets/*.go" - - "pkg/**/*.go" - sources-excluce: + - "pkg/service/**/*.go" + - "pkg/waveobj/*.go" + - "pkg/wconfig/**/*.go" + - "pkg/wstore/*.go" + - "pkg/wshrpc/**/*.go" + - "pkg/tsgen/**/*.go" + - "pkg/gogen/**/*.go" + - "pkg/wconfig/**/*.go" + - "pkg/eventbus/eventbus.go" + generates: + - frontend/types/gotypes.d.ts - pkg/wshrpc/wshclient/wshclient.go - - pkg/waveobj/metaconsts.go - - pkg/wconfig/metaconsts.go - # remove the "generates" key since they are conditionally generated (otherwise task will re-run every time) + - frontend/app/store/services.ts + - frontend/app/store/wshserver.ts version: desc: Get the current package version, or bump version if args are present. To pass args to `version.cjs`, add them after `--`. See `version.cjs` for usage definitions for the arguments. diff --git a/cmd/generatego/main-generatego.go b/cmd/generatego/main-generatego.go index 7b8e8b714..9c4a172f8 100644 --- a/cmd/generatego/main-generatego.go +++ b/cmd/generatego/main-generatego.go @@ -10,7 +10,6 @@ import ( "strings" "github.com/wavetermdev/waveterm/pkg/gogen" - "github.com/wavetermdev/waveterm/pkg/tsgen" "github.com/wavetermdev/waveterm/pkg/util/utilfn" "github.com/wavetermdev/waveterm/pkg/waveobj" "github.com/wavetermdev/waveterm/pkg/wconfig" @@ -43,7 +42,7 @@ func GenerateWshClient() { } } buf.WriteString("\n") - err := tsgen.WriteFileIfChanged(WshClientFileName, []byte(buf.String()), true) + err := os.WriteFile(WshClientFileName, []byte(buf.String()), 0644) if err != nil { panic(err) } @@ -55,7 +54,7 @@ func GenerateWaveObjMetaConsts() { gogen.GenerateBoilerplate(&buf, "waveobj", []string{}) gogen.GenerateMetaMapConsts(&buf, "MetaKey_", reflect.TypeOf(waveobj.MetaTSType{})) buf.WriteString("\n") - err := tsgen.WriteFileIfChanged(WaveObjMetaConstsFileName, []byte(buf.String()), true) + err := os.WriteFile(WaveObjMetaConstsFileName, []byte(buf.String()), 0644) if err != nil { panic(err) } @@ -67,7 +66,7 @@ func GenerateSettingsMetaConsts() { gogen.GenerateBoilerplate(&buf, "wconfig", []string{}) gogen.GenerateMetaMapConsts(&buf, "ConfigKey_", reflect.TypeOf(wconfig.SettingsType{})) buf.WriteString("\n") - err := tsgen.WriteFileIfChanged(SettingsMetaConstsFileName, []byte(buf.String()), true) + err := os.WriteFile(SettingsMetaConstsFileName, []byte(buf.String()), 0644) if err != nil { panic(err) } diff --git a/cmd/generatets/main-generatets.go b/cmd/generatets/main-generatets.go index 0968da335..446312adc 100644 --- a/cmd/generatets/main-generatets.go +++ b/cmd/generatets/main-generatets.go @@ -17,11 +17,14 @@ import ( ) func generateTypesFile(tsTypesMap map[reflect.Type]string) error { - var buf strings.Builder - fileName := "frontend/types/gotypes.d.ts" - fmt.Fprintf(os.Stderr, "generating types file to %s\n", fileName) + fd, err := os.Create("frontend/types/gotypes.d.ts") + if err != nil { + return err + } + defer fd.Close() + fmt.Fprintf(os.Stderr, "generating types file to %s\n", fd.Name()) tsgen.GenerateWaveObjTypes(tsTypesMap) - err := tsgen.GenerateServiceTypes(tsTypesMap) + err = tsgen.GenerateServiceTypes(tsTypesMap) if err != nil { fmt.Fprintf(os.Stderr, "Error generating service types: %v\n", err) os.Exit(1) @@ -30,10 +33,10 @@ func generateTypesFile(tsTypesMap map[reflect.Type]string) error { if err != nil { return fmt.Errorf("error generating wsh server types: %w", err) } - fmt.Fprintf(&buf, "// Copyright 2024, Command Line Inc.\n") - fmt.Fprintf(&buf, "// SPDX-License-Identifier: Apache-2.0\n\n") - fmt.Fprintf(&buf, "// generated by cmd/generate/main-generatets.go\n\n") - fmt.Fprintf(&buf, "declare global {\n\n") + fmt.Fprintf(fd, "// Copyright 2024, Command Line Inc.\n") + fmt.Fprintf(fd, "// SPDX-License-Identifier: Apache-2.0\n\n") + fmt.Fprintf(fd, "// generated by cmd/generate/main-generatets.go\n\n") + fmt.Fprintf(fd, "declare global {\n\n") var keys []reflect.Type for key := range tsTypesMap { keys = append(keys, key) @@ -45,68 +48,62 @@ func generateTypesFile(tsTypesMap map[reflect.Type]string) error { }) for _, key := range keys { // don't output generic types - if strings.Contains(key.Name(), "[") { + if strings.Index(key.Name(), "[") != -1 { continue } tsCode := tsTypesMap[key] istr := utilfn.IndentString(" ", tsCode) - fmt.Fprint(&buf, istr) - } - fmt.Fprintf(&buf, "}\n\n") - fmt.Fprintf(&buf, "export {}\n") - err = tsgen.WriteFileIfChanged(fileName, []byte(buf.String()), true) - if err != nil { - return err + fmt.Fprint(fd, istr) } + fmt.Fprintf(fd, "}\n\n") + fmt.Fprintf(fd, "export {}\n") return nil } func generateServicesFile(tsTypesMap map[reflect.Type]string) error { - var buf strings.Builder - fileName := "frontend/app/store/services.ts" - fmt.Fprintf(os.Stderr, "generating services file to %s\n", fileName) - fmt.Fprintf(&buf, "// Copyright 2024, Command Line Inc.\n") - fmt.Fprintf(&buf, "// SPDX-License-Identifier: Apache-2.0\n\n") - fmt.Fprintf(&buf, "// generated by cmd/generate/main-generatets.go\n\n") - fmt.Fprintf(&buf, "import * as WOS from \"./wos\";\n\n") + fd, err := os.Create("frontend/app/store/services.ts") + if err != nil { + return err + } + defer fd.Close() + fmt.Fprintf(os.Stderr, "generating services file to %s\n", fd.Name()) + fmt.Fprintf(fd, "// Copyright 2024, Command Line Inc.\n") + fmt.Fprintf(fd, "// SPDX-License-Identifier: Apache-2.0\n\n") + fmt.Fprintf(fd, "// generated by cmd/generate/main-generatets.go\n\n") + fmt.Fprintf(fd, "import * as WOS from \"./wos\";\n\n") orderedKeys := utilfn.GetOrderedMapKeys(service.ServiceMap) for _, serviceName := range orderedKeys { serviceObj := service.ServiceMap[serviceName] svcStr := tsgen.GenerateServiceClass(serviceName, serviceObj, tsTypesMap) - fmt.Fprint(&buf, svcStr) - fmt.Fprint(&buf, "\n") - } - err := tsgen.WriteFileIfChanged(fileName, []byte(buf.String()), true) - if err != nil { - return err + fmt.Fprint(fd, svcStr) + fmt.Fprint(fd, "\n") } return nil } func generateWshClientApiFile(tsTypeMap map[reflect.Type]string) error { - var buf strings.Builder - fileName := "frontend/app/store/wshclientapi.ts" - declMap := wshrpc.GenerateWshCommandDeclMap() - fmt.Fprintf(os.Stderr, "generating wshclientapi file to %s\n", fileName) - fmt.Fprintf(&buf, "// Copyright 2024, Command Line Inc.\n") - fmt.Fprintf(&buf, "// SPDX-License-Identifier: Apache-2.0\n\n") - fmt.Fprintf(&buf, "// generated by cmd/generate/main-generatets.go\n\n") - fmt.Fprintf(&buf, "import { WshClient } from \"./wshclient\";\n\n") - orderedKeys := utilfn.GetOrderedMapKeys(declMap) - fmt.Fprintf(&buf, "// WshServerCommandToDeclMap\n") - fmt.Fprintf(&buf, "class RpcApiType {\n") - for _, methodDecl := range orderedKeys { - methodDecl := declMap[methodDecl] - methodStr := tsgen.GenerateWshClientApiMethod(methodDecl, tsTypeMap) - fmt.Fprint(&buf, methodStr) - fmt.Fprintf(&buf, "\n") - } - fmt.Fprintf(&buf, "}\n\n") - fmt.Fprintf(&buf, "export const RpcApi = new RpcApiType();\n") - err := tsgen.WriteFileIfChanged(fileName, []byte(buf.String()), true) + fd, err := os.Create("frontend/app/store/wshclientapi.ts") if err != nil { return err } + defer fd.Close() + declMap := wshrpc.GenerateWshCommandDeclMap() + fmt.Fprintf(os.Stderr, "generating wshclientapi file to %s\n", fd.Name()) + fmt.Fprintf(fd, "// Copyright 2024, Command Line Inc.\n") + fmt.Fprintf(fd, "// SPDX-License-Identifier: Apache-2.0\n\n") + fmt.Fprintf(fd, "// generated by cmd/generate/main-generatets.go\n\n") + fmt.Fprintf(fd, "import { WshClient } from \"./wshclient\";\n\n") + orderedKeys := utilfn.GetOrderedMapKeys(declMap) + fmt.Fprintf(fd, "// WshServerCommandToDeclMap\n") + fmt.Fprintf(fd, "class RpcApiType {\n") + for _, methodDecl := range orderedKeys { + methodDecl := declMap[methodDecl] + methodStr := tsgen.GenerateWshClientApiMethod(methodDecl, tsTypeMap) + fmt.Fprint(fd, methodStr) + fmt.Fprintf(fd, "\n") + } + fmt.Fprintf(fd, "}\n\n") + fmt.Fprintf(fd, "export const RpcApi = new RpcApiType();\n") return nil } diff --git a/pkg/tsgen/tsgen.go b/pkg/tsgen/tsgen.go index 86d388a0b..cbde00941 100644 --- a/pkg/tsgen/tsgen.go +++ b/pkg/tsgen/tsgen.go @@ -7,7 +7,6 @@ import ( "bytes" "context" "fmt" - "os" "reflect" "strings" @@ -65,25 +64,6 @@ var updatesRtnRType = reflect.TypeOf(waveobj.UpdatesRtnType{}) var orefRType = reflect.TypeOf((*waveobj.ORef)(nil)).Elem() var wshRpcInterfaceRType = reflect.TypeOf((*wshrpc.WshRpcInterface)(nil)).Elem() -func checkIfFileUpdated(filename string, newContents []byte) bool { - oldContents, err := os.ReadFile(filename) - if err != nil { - return true - } - return !bytes.Equal(oldContents, newContents) -} - -func WriteFileIfChanged(filename string, newContents []byte, verbose bool) error { - shouldWrite := checkIfFileUpdated(filename, newContents) - if !shouldWrite { - if verbose { - fmt.Printf("file %s has not changed (not writing)\n", filename) - } - return nil - } - return os.WriteFile(filename, []byte(newContents), 0644) -} - func generateTSMethodTypes(method reflect.Method, tsTypesMap map[reflect.Type]string, skipFirstArg bool) error { for idx := 0; idx < method.Type.NumIn(); idx++ { if skipFirstArg && idx == 0 {