diff --git a/Makefile b/Makefile index 91df20a1..23885a53 100644 --- a/Makefile +++ b/Makefile @@ -25,18 +25,14 @@ TLOS_PATH := $(GEN_PATH) BASIC_TL_PATH := github.com/vkcom/tl/pkg/basictl TL_BYTE_VERSIONS := ch_proxy.,ab. -SHA256_CHECKSUM := $(shell go run ./cmd/sha256sum ./internal) -ifndef SHA256_CHECKSUM -$(error SHA256_CHECKSUM failed to set, problem with go run cmd/sha256sum internal) -endif .PHONY: build all: build build: - @echo "Building tlgen with sha256 checksum $(SHA256_CHECKSUM)" - @$(GO) build -ldflags "$(COMMON_LDFLAGS) -X 'github.com/vkcom/tl/internal/tlcodegen.buildSHA256Checksum=$(SHA256_CHECKSUM)'" -buildvcs=false -o target/bin/tlgen ./cmd/tlgen + @echo "Building tlgen" + @$(GO) build -ldflags "$(COMMON_LDFLAGS)" -buildvcs=false -o target/bin/tlgen ./cmd/tlgen tlo-bootstrap: build @./target/bin/tlgen \ @@ -84,6 +80,7 @@ goldmaster_nocompile: build --copyrightPath=./COPYRIGHT \ --outdir=./$(GEN_PATH)/goldmaster \ --generateSchemaDocumentation \ + --schemaURL="https://github.com/VKCOM/tl/blob/master/internal/tlcodegen/test/tls/goldmaster.tl" \ --pkgPath=github.com/vkcom/tl/$(GEN_PATH)/goldmaster/tl \ --basicPkgPath=$(BASIC_TL_PATH) \ --generateByteVersions=$(TL_BYTE_VERSIONS) \ @@ -96,6 +93,7 @@ goldmaster_nocompile: build --copyrightPath=./COPYRIGHT \ --outdir=./$(GEN_PATH)/goldmaster_nosplit \ --generateSchemaDocumentation \ + --schemaURL="https://github.com/VKCOM/tl/blob/master/internal/tlcodegen/test/tls/goldmaster.tl" \ --pkgPath=github.com/vkcom/tl/$(GEN_PATH)/goldmaster_nosplit/tl \ --basicPkgPath=$(BASIC_TL_PATH) \ --generateByteVersions=$(TL_BYTE_VERSIONS) \ diff --git a/cmd/sha256sum/sha256sum.go b/cmd/sha256sum/sha256sum.go deleted file mode 100644 index 7b02387a..00000000 --- a/cmd/sha256sum/sha256sum.go +++ /dev/null @@ -1,91 +0,0 @@ -// Copyright 2022 V Kontakte LLC -// -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -package main - -import ( - "crypto/sha256" - "encoding/hex" - "fmt" - "io/fs" - "os" - "path/filepath" - "strings" - - "golang.org/x/exp/slices" -) - -type pair struct { - canonical, common string -} - -// walkDeterministic recursively walks through roots directories -// and returns all regular files with extension fileExt -// -// also copied from projects/vktl/internal/walkdeterministic.go -func walkDeterministic(fileExt string, root ...string) ([]string, error) { - var pairs []pair - for _, r := range root { - err := filepath.Walk(r, func(path string, info fs.FileInfo, err error) error { - if err != nil { - return err - } - if !info.Mode().IsRegular() { - return nil - } - if !strings.HasSuffix(path, fileExt) { - return nil - } - pairs = append(pairs, pair{ - canonical: strings.ReplaceAll(path, string(os.PathSeparator), "/"), - common: path}) - return nil - }) - if err != nil { - return nil, err - } - } - slices.SortFunc(pairs, func(a, b pair) int { - return strings.Compare(a.canonical, b.canonical) - }) - res := make([]string, 0, len(pairs)) - for _, p := range pairs { - res = append(res, p.common) - } - return res, nil -} - -func SHA256All(files []string) (string, error) { - stream := sha256.New() - for _, f := range files { - data, err := os.ReadFile(f) - if err != nil { - return err.Error(), err - } - stream.Write(data) - } - sum := stream.Sum(nil) - return hex.EncodeToString(sum), nil -} - -func main() { - if len(os.Args) < 2 { - _, _ = fmt.Fprintf(os.Stderr, "Usage: sha256sum dir") - os.Exit(1) - } - files, err := walkDeterministic(".go", os.Args[1:]...) - if err != nil { - _, _ = fmt.Fprintf(os.Stderr, "%v", err) - os.Exit(1) - } - sum, err := SHA256All(files) - if err != nil { - _, _ = fmt.Fprintf(os.Stderr, "%v", err) - os.Exit(1) - } - fmt.Printf("%s", sum) - os.Exit(0) -} diff --git a/cmd/tlgen/main2.go b/cmd/tlgen/main2.go index 89175f0a..78107370 100644 --- a/cmd/tlgen/main2.go +++ b/cmd/tlgen/main2.go @@ -60,7 +60,7 @@ func parseFlags(opt *tlcodegen.Gen2Options) { "whether to generate methods to read json in old way") flag.BoolVar(&opt.SchemaDocumentation, "generateSchemaDocumentation", false, "whether to generate .html representation of schema in to tljson.html file") - flag.StringVar(&opt.SchemaURLTemplate, "schemaURLTemplate", "", + flag.StringVar(&opt.SchemaURL, "schemaURL", "", "template for url to current schema if documentation is generated") // C++ diff --git a/internal/tlcodegen/qt_tljson_html.qtpl b/internal/tlcodegen/qt_tljson_html.qtpl index d4d1a968..4763e182 100644 --- a/internal/tlcodegen/qt_tljson_html.qtpl +++ b/internal/tlcodegen/qt_tljson_html.qtpl @@ -1,12 +1,9 @@ {% package tlcodegen %} {% import "fmt" %} -{% import "time" %} {% import "strings" %} -{% import "github.com/vkcom/tl/pkg/build" %} - -{%- func tlJSON(gen *Gen2, buildSHA256Checksum string) -%} +{%- func tlJSON(gen *Gen2, tlgenVersion string) -%} @@ -17,8 +14,9 @@

Schema

diff --git a/internal/tlcodegen/qt_tljson_html.qtpl.go b/internal/tlcodegen/qt_tljson_html.qtpl.go index ad4e8645..9520b06c 100644 --- a/internal/tlcodegen/qt_tljson_html.qtpl.go +++ b/internal/tlcodegen/qt_tljson_html.qtpl.go @@ -5,12 +5,8 @@ package tlcodegen import "fmt" -import "time" - import "strings" -import "github.com/vkcom/tl/pkg/build" - import ( qtio422016 "io" @@ -22,7 +18,7 @@ var ( _ = qt422016.AcquireByteBuffer ) -func streamtlJSON(qw422016 *qt422016.Writer, gen *Gen2, buildSHA256Checksum string) { +func streamtlJSON(qw422016 *qt422016.Writer, gen *Gen2, tlgenVersion string) { qw422016.N().S(` @@ -33,17 +29,14 @@ func streamtlJSON(qw422016 *qt422016.Writer, gen *Gen2, buildSHA256Checksum stri

Schema