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

removed sha256 of source code, using git comit now #32

Merged
merged 1 commit into from
Jun 19, 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
10 changes: 4 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -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) \
Expand All @@ -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) \
Expand Down
91 changes: 0 additions & 91 deletions cmd/sha256sum/sha256sum.go

This file was deleted.

2 changes: 1 addition & 1 deletion cmd/tlgen/main2.go
Original file line number Diff line number Diff line change
Expand Up @@ -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++
Expand Down
10 changes: 4 additions & 6 deletions internal/tlcodegen/qt_tljson_html.qtpl
Original file line number Diff line number Diff line change
@@ -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) -%}
<!DOCTYPE html>
<html lang="en">
<head>
Expand All @@ -17,8 +14,9 @@
<body>
<h1>Schema</h1>
<ul>
{%- if gen.options.SchemaURLTemplate != "" -%}
<li><abbr>TL</abbr> schema: <a href="{%s= fmt.Sprintf(gen.options.SchemaURLTemplate, build.Commit()) %}"><code>{%s build.Commit() %}</code></a> commit timestamp {%s time.Unix(int64(build.CommitTimestamp()), 0).Format(time.RFC3339) %} compiled at {%s build.Time() %}</li>
<li>tlgen version: {%s tlgenVersion %}</li>
{%- if gen.options.SchemaURL != "" -%}
<li><abbr>TL</abbr> <a href="{%s gen.options.SchemaURL %}">schema</a></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
31 changes: 12 additions & 19 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.

2 changes: 2 additions & 0 deletions internal/tlcodegen/test/gen/goldmaster/tljson.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
<body>
<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> ⟷ <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
2 changes: 2 additions & 0 deletions internal/tlcodegen/test/gen/goldmaster_nosplit/tljson.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
<body>
<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> ⟷ <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
9 changes: 4 additions & 5 deletions internal/tlcodegen/tlgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ const TlJSONHTML = "tljson.html"
// And we do not want stable checksum of go files tlgen folder, because checksums are not comparable and there is no idea how old that version is
const buildVersionString = "tlgen2 version "

var buildSHA256Checksum = "" // filled when building

var (
errSeeHere = fmt.Errorf("see here")
errFieldNameCollision = fmt.Errorf("field name collision")
Expand Down Expand Up @@ -326,7 +324,7 @@ type Gen2Options struct {
GenerateRandomCode bool
GenerateLegacyJsonRead bool
SchemaDocumentation bool
SchemaURLTemplate string
SchemaURL string

// C++
RootCPPNamespace string
Expand Down Expand Up @@ -701,7 +699,7 @@ func (gen *Gen2) WriteToDir(outdir string) error {
// motivation - do not modify marker file if no code changed. Greatly reduces efforts to refactor tlgen.
f := filepath.Join(outdir, markerFile)
_, version := TLGenBuildInfo()
code := buildVersionString + strings.TrimSpace(version) + "\n" // stupid editors insist on empty line at the end
code := buildVersionString + strings.TrimSpace(version) + "\n" // many editors insist on empty line at the end
written++
if err := os.WriteFile(f, []byte(code), 0644); err != nil {
return fmt.Errorf("error writing file %q: %w", f, err)
Expand Down Expand Up @@ -1193,7 +1191,8 @@ func GenerateCode(tl tlast.TL, options Gen2Options) (*Gen2, error) {
}

if options.SchemaDocumentation {
if err := gen.addCodeFile(TlJSONHTML, tlJSON(gen, buildSHA256Checksum)); err != nil {
_, version := TLGenBuildInfo()
if err := gen.addCodeFile(TlJSONHTML, tlJSON(gen, version)); err != nil {
return nil, err
}
}
Expand Down
Loading