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

lint for boxed true types and bool types under fields mask #42

Merged
merged 3 commits into from
Jul 12, 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
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ TL_BYTE_VERSIONS := ch_proxy.,ab.
all: build

build:
@echo "Building tlgen"
@$(GO) build -ldflags "$(COMMON_LDFLAGS)" -buildvcs=false -o target/bin/tlgen ./cmd/tlgen

tlo-bootstrap: build
Expand Down Expand Up @@ -147,3 +146,9 @@ cpp_gen: build
cpp:
$(MAKE) cpp_gen
$(MAKE) cpp_build

# target should be as close as possible to github actions used to enable merge
.PHONY: check
check: build
@go test $(shell go list ./cmd/... ./internal/... ./pkg/... | grep -v /internal/tlcodegen/test/gen/)
@go run honnef.co/go/tools/cmd/[email protected] ./... # update version together with github actions
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ The TL format is characterized by compactness and high efficiency.
TL is schema-driven format. Tool caled `tlgen` is used to generate structs/classes and (de)serialization methods.


## Running without installation

You can run tool without installation. This is recommended way for most use cases.

```
go run github.com/vkcom/tl/cmd/tlgen@latest <options>
```

For build scripts, you can pin particular version instead of `latest`.

## Installation

Install `tlgen` with the following command
Expand Down
14 changes: 8 additions & 6 deletions cmd/tlgen/main2.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ func parseFlags(opt *tlcodegen.Gen2Options) {
"treat all warnings as errors")
flag.BoolVar(&opt.Verbose, "v", false,
"verbose mode that prints debug info")
flag.BoolVar(&opt.PrintDiff, "print-diff", false,
"prints diff of outdir contents before and after generating")
flag.BoolVar(&opt.SplitInternal, "split-internal", false,
"generated code will be split into independent packages (in a simple word: speeds up compilation)")

Expand Down Expand Up @@ -92,17 +94,17 @@ func run(opt tlcodegen.Gen2Options) {
log.Println(err.Error())
}
if opt.Language == "" {
log.Printf("TL Linter Failed")
log.Printf("TL Linter Failed") // do not check Verbose
} else {
log.Printf("TL Generation Failed")
log.Printf("TL Generation Failed") // do not check Verbose
}
os.Exit(1)
return
}
if opt.Language == "" {
log.Printf("TL Linter Success")
log.Printf("TL Linter Success") // do not check Verbose
} else {
log.Printf("TL Generation Success")
log.Printf("TL Generation Success") // do not check Verbose
}
}

Expand Down Expand Up @@ -146,7 +148,7 @@ func runMain(opt *tlcodegen.Gen2Options) error {
}
if opt.TLOPath != "" {
if opt.Verbose {
log.Print("generating tlo file")
log.Print("generating TLO file...")
}
s, err := fullAst.GenerateTLO(uint32(opt.SchemaTimestamp))
if err != nil {
Expand All @@ -173,7 +175,7 @@ func runMain(opt *tlcodegen.Gen2Options) error {
}
if opt.CanonicalFormPath != "" {
if opt.Verbose {
log.Print("generating file with combinators in canonical form")
log.Print("generating file with combinators in canonical form,,,")
}
var buf bytes.Buffer
fullAst.WriteGenerate2TL(&buf)
Expand Down
266 changes: 261 additions & 5 deletions internal/tlcodegen/combined_tl_legacy.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,40 @@

package tlcodegen

import (
"fmt"
"sort"
)

// All compatibility code that will be removed after some fixes to TL itself

func EnableWarningsUnionNamespaceSkipLegacy(conNamespace string, typeNamespace string) bool {
type legacyPair struct {
conName string
fieldName string
}

var legacyExceptions []legacyPair // use it to populate this file with content of combined tl

func LegacyPrintGlobalMap() {
sort.Slice(legacyExceptions, func(i, j int) bool {
if legacyExceptions[i].conName != legacyExceptions[j].conName {
return legacyExceptions[i].conName < legacyExceptions[j].conName
}
return legacyExceptions[i].fieldName < legacyExceptions[j].fieldName
})

for _, v := range legacyExceptions {
fmt.Printf(` if conFullName == %q && fieldName == %q {
return true
}
`, v.conName, v.fieldName)
}
if len(legacyExceptions) != 0 {
fmt.Printf("--- Total %d exceptions\n", len(legacyExceptions))
}
}

func LegacyEnableWarningsUnionNamespaceSkip(conNamespace string, typeNamespace string) bool {
if conNamespace == "messagesLong" && typeNamespace == "messages" {
return true
}
Expand All @@ -34,7 +65,7 @@ func EnableWarningsUnionNamespaceSkipLegacy(conNamespace string, typeNamespace s
return false
}

func EnableWarningsSimpleTypeNameSkipLegacy(conFullName string) bool {
func LegacyEnableWarningsSimpleTypeNameSkip(conFullName string) bool {
if conFullName == "healthLoyalty.tmpGetCatalogResultOk" {
return true
}
Expand Down Expand Up @@ -125,11 +156,12 @@ func EnableWarningsSimpleTypeNameSkipLegacy(conFullName string) bool {
return false
}

func EnableWarningsUnionNamePrefixSkipLegacy(conName string, typePrefix string, typeSuffix string) bool {
// too many of them, impractical
func LegacyEnableWarningsUnionNamePrefixSkip(conName string, typePrefix string, typeSuffix string) bool {
return true // skip all warnings for now
}

func EnableWarningsUnionNameExactSkipLegacy(conFullName string) bool {
func LegacyEnableWarningsUnionNameExactSkip(conFullName string) bool {
if conFullName == "engine.queryResult" {
return true
}
Expand Down Expand Up @@ -158,6 +190,230 @@ func EnableWarningsUnionNameExactSkipLegacy(conFullName string) bool {
return false
}

func GenerateUnusedNatTemplates(conFullName string) bool {
func LegacyGenerateUnusedNatTemplates(conFullName string) bool {
return conFullName == "rpcInvokeReqExtra" || conFullName == "rpcReqResultExtra"
}

func LegacyAllowTrueBoxed(conFullName string, fieldName string) bool {
if conFullName == "genericModel.predict" && fieldName == "need_results_float" {
return true
}
if conFullName == "gopusher2.apnsPush" && fieldName == "is_voip" {
return true
}
if conFullName == "storage2.namespacePolicyBlocksCreation" && fieldName == "enable_blocks_creation" {
return true
}
if conFullName == "urlBoss.impParams" && fieldName == "keepAspectRatio" {
return true
}
if conFullName == "urlBoss.impParams" && fieldName == "proxy" {
return true
}
if conFullName == "urlBoss2.impParams" && fieldName == "keepAspectRatio" {
return true
}
if conFullName == "urlBoss2.impParams" && fieldName == "proxy" {
return true
}
if conFullName == "urlBoss2.routingParams" && fieldName == "randomSeed" {
return true
}
// below is goldmaster, we keep it to test generated code for this case
if conFullName == "useTrue" && fieldName == "b" {
return true
}
if conFullName == "useTrue" && fieldName == "d" {
return true
}
return false
}

func LegacyAllowBoolFieldsmask(conFullName string, fieldName string) bool {
if conFullName == "adsLalProcessing.processing" && fieldName == "is_deleted" {
return true
}
if conFullName == "adsLalProcessing.startProcessing" && fieldName == "use_apps" {
return true
}
if conFullName == "adsLalProcessing.startProcessing" && fieldName == "use_keywords" {
return true
}
if conFullName == "audiofpgen.genToPMCEx" && fieldName == "allow_short" {
return true
}
if conFullName == "audiofpgen.genToPMCEx" && fieldName == "delete_after_gen" {
return true
}
if conFullName == "blockchainNftCli.getNftDataRequestItem" && fieldName == "img_update" {
return true
}
if conFullName == "ch_proxy.params" && fieldName == "as_post" {
return true
}
if conFullName == "donutLevels.getResponse" && fieldName == "can_add" {
return true
}
if conFullName == "messages.keyboard" && fieldName == "inline" {
return true
}
if conFullName == "messages.keyboard" && fieldName == "one_time" {
return true
}
if conFullName == "messages.setPeerNotificationsSettings" && fieldName == "muted" {
return true
}
if conFullName == "messagesChat.setNotificationsStatus" && fieldName == "is_push_muted" {
return true
}
if conFullName == "messagesChatLong.changeChatMembers" && fieldName == "response_idlong" {
return true
}
if conFullName == "messagesChatLong.setNotificationsStatus" && fieldName == "is_push_muted" {
return true
}
if conFullName == "messagesLong.setFolderNotificationsSettings" && fieldName == "muted" {
return true
}
if conFullName == "messagesLong.setPeerNotificationsSettings" && fieldName == "muted" {
return true
}
if conFullName == "news2.joinedNews" && fieldName == "hidden_by_privacy" {
return true
}
if conFullName == "news2.modifiedNewsEntry" && fieldName == "hidden_by_privacy" {
return true
}
if conFullName == "news2.typeSettings" && fieldName == "deleted" {
return true
}
if conFullName == "news2.typeSettings" && fieldName == "non_std_lengths" {
return true
}
if conFullName == "news2.typeSettings" && fieldName == "normalize_id_lengths" {
return true
}
if conFullName == "online.setFriendOnlineExtraTyped" && fieldName == "invisible_mode" {
return true
}
if conFullName == "sandbox.attachProcessSettings" && fieldName == "store_stats" {
return true
}
if conFullName == "sandbox.createProcessSettings" && fieldName == "store_stats" {
return true
}
if conFullName == "sandbox.storeResultSettings" && fieldName == "store_stderr" {
return true
}
if conFullName == "sandbox.storeResultSettings" && fieldName == "store_stdout" {
return true
}
if conFullName == "searchService.searchMarket" && fieldName == "has_video" {
return true
}
if conFullName == "service.adsTargAdEngineInfo" && fieldName == "user_ad_has_click" {
return true
}
if conFullName == "socket.operateResponse" && fieldName == "closed" {
return true
}
if conFullName == "storage2Impl.engineState" && fieldName == "too_many_uploads" {
return true
}
if conFullName == "targ.ad" && fieldName == "enabled" {
return true
}
if conFullName == "targ.ad" && fieldName == "result_active" {
return true
}
if conFullName == "targ.ad" && fieldName == "schedule_active" {
return true
}
if conFullName == "targ.ad" && fieldName == "suspended" {
return true
}
if conFullName == "targ.adCampaign" && fieldName == "enabled" {
return true
}
if conFullName == "targ.banner" && fieldName == "enabled" {
return true
}
if conFullName == "targ.lal" && fieldName == "is_user_scores_fill_finished" {
return true
}
if conFullName == "targ.searchAdsFilter" && fieldName == "enabled_status" {
return true
}
if conFullName == "targ.searchAdsFilter" && fieldName == "suspended_status" {
return true
}
if conFullName == "targ.user" && fieldName == "has_photo" {
return true
}
if conFullName == "targ.user" && fieldName == "hidden" {
return true
}
if conFullName == "targ.user" && fieldName == "is_online" {
return true
}
if conFullName == "targ.user" && fieldName == "online_invisible" {
return true
}
if conFullName == "targ.user" && fieldName == "pays_money" {
return true
}
if conFullName == "targ.user" && fieldName == "uses_apps" {
return true
}
if conFullName == "targ.userAdApplyViewOptions" && fieldName == "use_for_predictions" {
return true
}
if conFullName == "targLong.user" && fieldName == "has_photo" {
return true
}
if conFullName == "targLong.user" && fieldName == "hidden" {
return true
}
if conFullName == "targLong.user" && fieldName == "is_online" {
return true
}
if conFullName == "targLong.user" && fieldName == "online_invisible" {
return true
}
if conFullName == "targLong.user" && fieldName == "pays_money" {
return true
}
if conFullName == "targLong.user" && fieldName == "uses_apps" {
return true
}
if conFullName == "targUser.adDetails" && fieldName == "is_fake" {
return true
}
if conFullName == "targUser.campaignDetails" && fieldName == "is_fake" {
return true
}
if conFullName == "tasks.queueTypeSettings" && fieldName == "is_blocking" {
return true
}
if conFullName == "tasks.queueTypeSettings" && fieldName == "is_enabled" {
return true
}
if conFullName == "tasks.queueTypeSettings" && fieldName == "is_persistent" {
return true
}
if conFullName == "tasks.queueTypeSettings" && fieldName == "is_staging" {
return true
}
if conFullName == "tasks.queueTypeSettings" && fieldName == "move_to_queue_begin_on_retry" {
return true
}
if conFullName == "wall.searchV2" && fieldName == "reverse" {
return true
}
// below is goldmaster, we keep it to test generated code for this case
if conFullName == "useTrue" && fieldName == "e" {
return true
}
// legacyExceptions = append(legacyExceptions, legacyPair{conName: conFullName, fieldName: fieldName})
return false
}
Loading
Loading