Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Schema commit, timestamp, tweaks to marker file #36

Merged
merged 3 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ tlo-bootstrap: build
--copyrightPath=./COPYRIGHT \
--pkgPath=github.com/vkcom/tl/internal/tlast/gentlo/tl \
--basicPkgPath=github.com/vkcom/tl/pkg/basictl \
--generateRPCCode=false \
--outdir=./internal/tlast/gentlo \
./internal/tlast/tls.tl

Expand All @@ -53,7 +52,6 @@ gen_check: build
--basicPkgPath=$(BASIC_TL_PATH) \
--generateByteVersions=$(TL_BYTE_VERSIONS) \
--generateLegacyJsonRead=false \
--generateRPCCode=false \
./$(TLS_PATH)/schema.tl

.PHONY: gen
Expand All @@ -74,33 +72,34 @@ goldmaster_nocompile: build
--generateByteVersions=cases_bytes. \
--generateRandomCode \
--generateLegacyJsonRead=false \
--generateRPCCode=false \
./$(TLS_PATH)/cases.tl
@./target/bin/tlgen --language=go --split-internal -v \
--copyrightPath=./COPYRIGHT \
--outdir=./$(GEN_PATH)/goldmaster \
--generateSchemaDocumentation \
--schemaURL="https://github.com/VKCOM/tl/blob/master/internal/tlcodegen/test/tls/goldmaster.tl" \
--schemaCommit=abcdefgh \
--schemaTimestamp=301822800 \
--pkgPath=github.com/vkcom/tl/$(GEN_PATH)/goldmaster/tl \
--basicPkgPath=$(BASIC_TL_PATH) \
--generateByteVersions=$(TL_BYTE_VERSIONS) \
--generateRandomCode \
--generateLegacyJsonRead=false \
--generateRPCCode=false \
--canonicalFormPath=./$(TLS_PATH)/goldmaster_canonical.tl \
./$(TLS_PATH)/goldmaster.tl ./$(TLS_PATH)/goldmaster2.tl ./$(TLS_PATH)/goldmaster3.tl
@./target/bin/tlgen --language=go -v \
--copyrightPath=./COPYRIGHT \
--outdir=./$(GEN_PATH)/goldmaster_nosplit \
--generateSchemaDocumentation \
--schemaURL="https://github.com/VKCOM/tl/blob/master/internal/tlcodegen/test/tls/goldmaster.tl" \
--schemaCommit=abcdefgh \
--schemaTimestamp=301822800 \
--pkgPath=github.com/vkcom/tl/$(GEN_PATH)/goldmaster_nosplit/tl \
--basicPkgPath=$(BASIC_TL_PATH) \
--generateByteVersions=$(TL_BYTE_VERSIONS) \
--tloPath=./$(TLOS_PATH)/goldmaster.tlo \
--generateRandomCode \
--generateLegacyJsonRead=false \
--generateRPCCode=false \
--canonicalFormPath=./$(TLS_PATH)/goldmaster_canonical.tl \
./$(TLS_PATH)/goldmaster.tl ./$(TLS_PATH)/goldmaster2.tl ./$(TLS_PATH)/goldmaster3.tl

Expand All @@ -116,7 +115,6 @@ gen_tlo: build # do not set --basicPkgPath, or you'll have hard time updating ba
@./target/bin/tlgen --language=go \
--copyrightPath=./COPYRIGHT \
--pkgPath=github.com/vkcom/tl/internal/tlast/gentlo/tl \
--generateRPCCode=false \
--outdir=./internal/tlast/gentlo \
./internal/tlast/tls.tl

Expand All @@ -138,7 +136,6 @@ qtpl:
cpp: build
@./target/bin/tlgen -language=cpp -v \
--outdir=./$(GEN_PATH)/cpp \
--generateRPCCode=false \
--basicPkgPath=$(BASIC_TL_PATH) \
./$(TLS_PATH)/cpp.tl
g++ -o $(GEN_PATH)/test_cpp $(GEN_PATH)/test_cpp.cpp $(GEN_PATH)/cpp/all.cpp -std=c++17 -O3 -Wno-noexcept-type -g -Wall -Wextra -Werror=return-type -Wno-unused-parameter
9 changes: 1 addition & 8 deletions cmd/tlgen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,13 @@
package main

import (
"fmt"
"log"
"runtime/debug"

"github.com/vkcom/tl/internal/tlcodegen"
)

func main() {
bi, ok := debug.ReadBuildInfo()
if !ok {
log.Printf("Failed to read build info")
return
}
fmt.Printf("tlgen version: %+v\n", bi.Main.Version)
log.Printf("tlgen version: %s", tlcodegen.TLGenVersion())

log.SetFlags(0)

Expand Down
27 changes: 16 additions & 11 deletions cmd/tlgen/main2.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ func parseFlags(opt *tlcodegen.Gen2Options) {
flag.BoolVar(&opt.SchemaDocumentation, "generateSchemaDocumentation", false,
"whether to generate .html representation of schema in to tljson.html file")
flag.StringVar(&opt.SchemaURL, "schemaURL", "",
"template for url to current schema if documentation is generated")
"url of schema (for documentation)")
flag.UintVar(&opt.SchemaTimestamp, "schemaTimestamp", 0,
"timestamp of schema (for documentation, TLO version)")
flag.StringVar(&opt.SchemaCommit, "schemaCommit", "",
"commit of schema (for documentation)")

// C++
flag.StringVar(&opt.RootCPPNamespace, "cpp-namespace", "",
Expand All @@ -80,34 +84,35 @@ func parseFlags(opt *tlcodegen.Gen2Options) {
}

func run(opt tlcodegen.Gen2Options) {
var commit, version = tlcodegen.TLGenBuildInfo()
log.Printf("tlgen version: %s, commit: %s", version, commit)
if err := runMain(&opt); err != nil {
var parseError *tlast.ParseError
if errors.As(err, &parseError) {
parseError.ConsolePrint(opt.ErrorWriter, err, false)
} else {
log.Println(err.Error())
}
log.Printf("TL Generation Failed")
os.Exit(1)
} else {
if opt.Language == "" {
log.Printf("TL Linter Success")
log.Printf("TL Linter Failed")
} else {
log.Printf("TL Generation Success")
log.Printf("TL Generation Failed")
}
os.Exit(1)
return
}
if opt.Language == "" {
log.Printf("TL Linter Success")
} else {
log.Printf("TL Generation Success")
}
}

func runMain(opt *tlcodegen.Gen2Options) error {
var ast tlast.TL
var fullAst tlast.TL
var args []string
if opt.ErrorWriter == nil {
opt.ErrorWriter = os.Stdout
}
args = append(args, flag.Args()...)
args := flag.Args()
if len(args) == 0 {
return fmt.Errorf("specify 1 or more input TL schema filenames after flags")
}
Expand Down Expand Up @@ -143,7 +148,7 @@ func runMain(opt *tlcodegen.Gen2Options) error {
if opt.Verbose {
log.Print("generating tlo file")
}
s, err := fullAst.GenerateTLO()
s, err := fullAst.GenerateTLO(uint32(opt.SchemaTimestamp))
if err != nil {
return fmt.Errorf("error on generating tlo: %w", err)
}
Expand Down
22 changes: 7 additions & 15 deletions internal/tlast/tlgen_tlo.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (ps *paramScope) find(f func(e param) bool) (param, bool) {
return param{}, false
}

func (tl TL) GenerateTLO() (tls.SchemaV4, error) {
func (tl TL) GenerateTLO(version uint32) (tls.SchemaV4, error) {
allCombinators := make(map[string]*Combinator, len(tl))
for i, comb := range tl {
allCombinators[comb.Construct.Name.String()] = tl[i]
Expand Down Expand Up @@ -291,9 +291,13 @@ func (tl TL) GenerateTLO() (tls.SchemaV4, error) {
v4B, _ := functions[j].AsV4()
return v4A.Id < v4B.Id
})
date := version
if version == 0 {
date = uint32(time.Now().Unix())
}
return tls.SchemaV4{
Version: 0, // always 0
Date: int32(time.Now().Unix()),
Version: int32(version), // TODO - must be changed to # in tl definition
Date: int32(date), // TODO - must be changed to # in tl definition
TypesNum: uint32(len(types)),
Types: types,
ConstructorNum: uint32(len(constructors)),
Expand All @@ -303,18 +307,6 @@ func (tl TL) GenerateTLO() (tls.SchemaV4, error) {
}, nil
}

func (tl TL) GenerateTLOBytes() ([]byte, error) {
s, err := tl.GenerateTLO()
if err != nil {
return nil, err
}
res, err := s.WriteBoxed(nil)
if err != nil {
return nil, fmt.Errorf("can't write TLO boxed: %w", err)
}
return res, nil
}

func typeRefToTypeExpr(mc paramScope, allCombinators map[string]*Combinator, tlsTypes map[string]*tls.Type, t *TypeRef, bare bool) tls.TypeExpr {
if typeExpr, ok := builtinTypeExprUnions[t.Type.String()]; ok {
return typeExpr
Expand Down
9 changes: 8 additions & 1 deletion internal/tlcodegen/qt_tljson_html.qtpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{% package tlcodegen %}

{% import "fmt" %}
{% import "time" %}
{% import "strings" %}

{%- func tlJSON(gen *Gen2, tlgenVersion string) -%}
Expand All @@ -16,7 +17,13 @@
<ul>
<li>tlgen version: {%s tlgenVersion %}</li>
{%- if gen.options.SchemaURL != "" -%}
<li><abbr>TL</abbr> <a href="{%s gen.options.SchemaURL %}">schema</a></li>
<li><abbr>TL</abbr> schema <a href="{%s gen.options.SchemaURL %}">url</a></li>
{%- endif -%}
{%- if gen.options.SchemaCommit != "" -%}
<li><abbr>TL</abbr> schema commit: {%s gen.options.SchemaCommit %}</li>
{%- endif -%}
{%- if gen.options.SchemaTimestamp != 0 -%}
<li><abbr>TL</abbr> schema version: {%v gen.options.SchemaTimestamp %} ({%v time.Unix(int64(gen.options.SchemaTimestamp),0).UTC() %})</li>
{%- endif -%}
<li><abbr>TL</abbr> ⟷ <abbr>JSON</abbr> mapping rules: <a href="https://github.com/VKCOM/tl/blob/master/TLJSON.md">TLJSON.md</a></li>
</ul>
Expand Down
20 changes: 18 additions & 2 deletions internal/tlcodegen/qt_tljson_html.qtpl.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion internal/tlcodegen/test/gen/cases/tlgen2_version.txt
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
tlgen2 version (devel)
tlgen version: (devel)
schema url:
schema commit:
schema version: 0 (1970-01-01 00:00:00 +0000 UTC)
5 changes: 4 additions & 1 deletion internal/tlcodegen/test/gen/goldmaster/tlgen2_version.txt
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
tlgen2 version (devel)
tlgen version: (devel)
schema url: https://github.com/VKCOM/tl/blob/master/internal/tlcodegen/test/tls/goldmaster.tl
schema commit: abcdefgh
schema version: 301822800 (1979-07-26 07:40:00 +0000 UTC)
4 changes: 3 additions & 1 deletion internal/tlcodegen/test/gen/goldmaster/tljson.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
<h1>Schema</h1>
<ul>
<li>tlgen version: (devel)</li>
<li><abbr>TL</abbr> <a href="https://github.com/VKCOM/tl/blob/master/internal/tlcodegen/test/tls/goldmaster.tl">schema</a></li>
<li><abbr>TL</abbr> schema <a href="https://github.com/VKCOM/tl/blob/master/internal/tlcodegen/test/tls/goldmaster.tl">url</a></li>
<li><abbr>TL</abbr> schema commit: abcdefgh</li>
<li><abbr>TL</abbr> schema version: 301822800 (1979-07-26 07:40:00 +0000 UTC)</li>
<li><abbr>TL</abbr> ⟷ <abbr>JSON</abbr> mapping rules: <a href="https://github.com/VKCOM/tl/blob/master/TLJSON.md">TLJSON.md</a></li>
</ul>
<h1>Functions</h1>
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
tlgen2 version (devel)
tlgen version: (devel)
schema url: https://github.com/VKCOM/tl/blob/master/internal/tlcodegen/test/tls/goldmaster.tl
schema commit: abcdefgh
schema version: 301822800 (1979-07-26 07:40:00 +0000 UTC)
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
<h1>Schema</h1>
<ul>
<li>tlgen version: (devel)</li>
<li><abbr>TL</abbr> <a href="https://github.com/VKCOM/tl/blob/master/internal/tlcodegen/test/tls/goldmaster.tl">schema</a></li>
<li><abbr>TL</abbr> schema <a href="https://github.com/VKCOM/tl/blob/master/internal/tlcodegen/test/tls/goldmaster.tl">url</a></li>
<li><abbr>TL</abbr> schema commit: abcdefgh</li>
<li><abbr>TL</abbr> schema version: 301822800 (1979-07-26 07:40:00 +0000 UTC)</li>
<li><abbr>TL</abbr> ⟷ <abbr>JSON</abbr> mapping rules: <a href="https://github.com/VKCOM/tl/blob/master/TLJSON.md">TLJSON.md</a></li>
</ul>
<h1>Functions</h1>
Expand Down
Loading
Loading