Skip to content

Commit

Permalink
Merge #58479
Browse files Browse the repository at this point in the history
58479: build: Generating eg.go files within the colexecagg package in bazel r=irfansharif a=alan-mas

build: Generating eg.go files within the colexecagg package in bazel

Fixes: ##58421 We apply the same treatment as 52c5f51.

Release note: None

Co-authored-by: Alanmas <[email protected]>
  • Loading branch information
craig[bot] and alan-mas committed Jan 6, 2021
2 parents 7d44183 + 4e4cbd2 commit f62055c
Show file tree
Hide file tree
Showing 16 changed files with 209 additions and 26 deletions.
31 changes: 8 additions & 23 deletions pkg/sql/colexec/colexecagg/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,33 +1,12 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")

# TODO(irfansharif): The dependency tree for the *.eg.go needs sorting out. It
# depends on execgen+templates from a parent package. Look towards colexec for
# how this should be done. For now we just lazily depend on the already
# generated+checked in file.
load(":COLEXECAGG.bzl", "eg_go_filegroup", "gen_eg_go_rules")

go_library(
name = "colexecagg",
srcs = [
"aggregate_funcs.go",
"aggregators_util.go",
"hash_any_not_null_agg.eg.go", # keep
"hash_avg_agg.eg.go", # keep
"hash_bool_and_or_agg.eg.go", # keep
"hash_concat_agg.eg.go", # keep
"hash_count_agg.eg.go", # keep
"hash_default_agg.eg.go", # keep
"hash_min_max_agg.eg.go", # keep
"hash_sum_agg.eg.go", # keep
"hash_sum_int_agg.eg.go", # keep
"ordered_any_not_null_agg.eg.go", # keep
"ordered_avg_agg.eg.go", # keep
"ordered_bool_and_or_agg.eg.go", # keep
"ordered_concat_agg.eg.go", # keep
"ordered_count_agg.eg.go", # keep
"ordered_default_agg.eg.go", # keep
"ordered_min_max_agg.eg.go", # keep
"ordered_sum_agg.eg.go", # keep
"ordered_sum_int_agg.eg.go", # keep
":gen-exec", # keep
],
importpath = "github.com/cockroachdb/cockroach/pkg/sql/colexec/colexecagg",
visibility = ["//visibility:public"],
Expand All @@ -50,3 +29,9 @@ go_library(
"@com_github_cockroachdb_errors//:errors",
],
)

# Define a file group for all the .eg.go targets.
eg_go_filegroup(name = "gen-exec")

# Define gen rules for individual eg.go files.
gen_eg_go_rules()
73 changes: 73 additions & 0 deletions pkg/sql/colexec/colexecagg/COLEXECAGG.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# NB: The helpers here were grafted from pkg/sql/colexec/COLEXEC.bzl.
# Future changes here may apply there.

# Map between target name and relevant template.
targets = [
('hash_any_not_null_agg.eg.go', 'any_not_null_agg_tmpl.go'),
('hash_avg_agg.eg.go', 'avg_agg_tmpl.go'),
('hash_bool_and_or_agg.eg.go', 'bool_and_or_agg_tmpl.go'),
('hash_concat_agg.eg.go', 'concat_agg_tmpl.go'),
('hash_count_agg.eg.go', 'count_agg_tmpl.go'),
('hash_default_agg.eg.go', 'default_agg_tmpl.go'),
('hash_min_max_agg.eg.go', 'min_max_agg_tmpl.go'),
('hash_sum_agg.eg.go', 'sum_agg_tmpl.go'),
('hash_sum_int_agg.eg.go', 'sum_agg_tmpl.go'),
('ordered_any_not_null_agg.eg.go', 'any_not_null_agg_tmpl.go'),
('ordered_avg_agg.eg.go', 'avg_agg_tmpl.go'),
('ordered_bool_and_or_agg.eg.go', 'bool_and_or_agg_tmpl.go'),
('ordered_concat_agg.eg.go', 'concat_agg_tmpl.go'),
('ordered_count_agg.eg.go', 'count_agg_tmpl.go'),
('ordered_default_agg.eg.go', 'default_agg_tmpl.go'),
('ordered_min_max_agg.eg.go', 'min_max_agg_tmpl.go'),
('ordered_sum_agg.eg.go', 'sum_agg_tmpl.go'),
('ordered_sum_int_agg.eg.go', 'sum_agg_tmpl.go'),
]

def rule_name_for(target):
# e.g. 'vec_comparators.eg.go' -> 'gen-vec-comparators'
return 'gen-{}'.format(target.replace('.eg.go', '').replace('_', '-'))

# Define a file group for all the .eg.go targets.
def eg_go_filegroup(name):
native.filegroup(
name = name,
srcs = [':{}'.format(rule_name_for(target)) for target, _ in targets],
)

# Define gen rules for individual eg.go files.
def gen_eg_go_rules():
# Define some aliases for ease of use.
native.alias(
name = "execgen",
actual = "//pkg/sql/colexec/execgen/cmd/execgen",
)
native.alias(
name = "goimports",
actual = "@com_github_cockroachdb_gostdlib//x/tools/cmd/goimports",
)

for target, template in targets:
name = rule_name_for(target)

native.genrule(
name = name,
srcs = [template],
outs = [target],
# `$@` lets us substitute in the output path[1]. The symlink below
# is frowned upon for genrules[2]. That said, when testing
# pkg/sql/colexec through bazel it expects to find the template
# files in a path other than what SRCS would suggest. We haven't
# really investigated why. For now lets just symlink the relevant
# files into the "right" path within the bazel sandbox[3].
#
# [1]: https://docs.bazel.build/versions/3.7.0/be/general.html#genrule_args
# [2]: https://docs.bazel.build/versions/3.7.0/be/general.html#general-advice
# [3]: https://github.com/cockroachdb/cockroach/pull/57027
cmd = """
ln -s external/cockroach/pkg pkg
$(location :execgen) -template $(SRCS) \
-fmt=false pkg/sql/colexec/$@ > $@
$(location :goimports) -w $@
""",
tools = [":execgen", ":goimports"],
)
12 changes: 11 additions & 1 deletion pkg/sql/colexec/colexecagg/any_not_null_agg_tmpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,25 @@ package colexecagg
import (
"unsafe"

"github.com/cockroachdb/apd/v2"
"github.com/cockroachdb/cockroach/pkg/col/coldata"
"github.com/cockroachdb/cockroach/pkg/col/coldataext"
"github.com/cockroachdb/cockroach/pkg/col/typeconv"
"github.com/cockroachdb/cockroach/pkg/sql/colexec/execgen"
"github.com/cockroachdb/cockroach/pkg/sql/colmem"
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
"github.com/cockroachdb/cockroach/pkg/sql/types"
"github.com/cockroachdb/cockroach/pkg/util/duration"
"github.com/cockroachdb/errors"
)

// Workaround for bazel auto-generated code. goimports does not automatically
// pick up the right packages when run within the bazel sandbox.
var (
_ tree.AggType
_ apd.Context
_ duration.Duration
)

// {{/*

// Declarations to make the template compile properly.
Expand Down
11 changes: 11 additions & 0 deletions pkg/sql/colexec/colexecagg/avg_agg_tmpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,25 @@ package colexecagg
import (
"unsafe"

"github.com/cockroachdb/apd/v2"
"github.com/cockroachdb/cockroach/pkg/col/coldata"
"github.com/cockroachdb/cockroach/pkg/sql/colexec/execgen"
"github.com/cockroachdb/cockroach/pkg/sql/colexecbase/colexecerror"
"github.com/cockroachdb/cockroach/pkg/sql/colmem"
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
"github.com/cockroachdb/cockroach/pkg/sql/types"
"github.com/cockroachdb/cockroach/pkg/util/duration"
"github.com/cockroachdb/errors"
)

// Workaround for bazel auto-generated code. goimports does not automatically
// pick up the right packages when run within the bazel sandbox.
var (
_ tree.AggType
_ apd.Context
_ duration.Duration
)

// {{/*
// Declarations to make the template compile properly

Expand Down
8 changes: 8 additions & 0 deletions pkg/sql/colexec/colexecagg/hash_any_not_null_agg.eg.go

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

8 changes: 8 additions & 0 deletions pkg/sql/colexec/colexecagg/hash_avg_agg.eg.go

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

8 changes: 8 additions & 0 deletions pkg/sql/colexec/colexecagg/hash_min_max_agg.eg.go

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

8 changes: 8 additions & 0 deletions pkg/sql/colexec/colexecagg/hash_sum_agg.eg.go

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

10 changes: 10 additions & 0 deletions pkg/sql/colexec/colexecagg/hash_sum_int_agg.eg.go

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

13 changes: 11 additions & 2 deletions pkg/sql/colexec/colexecagg/min_max_agg_tmpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,23 @@ package colexecagg
import (
"unsafe"

"github.com/cockroachdb/apd/v2"
"github.com/cockroachdb/cockroach/pkg/col/coldata"
"github.com/cockroachdb/cockroach/pkg/col/coldataext"
"github.com/cockroachdb/cockroach/pkg/col/typeconv"
"github.com/cockroachdb/cockroach/pkg/sql/colexec/execgen"
"github.com/cockroachdb/cockroach/pkg/sql/colexecbase/colexecerror"
"github.com/cockroachdb/cockroach/pkg/sql/colmem"
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
"github.com/cockroachdb/cockroach/pkg/sql/types"
"github.com/cockroachdb/errors"
"github.com/cockroachdb/cockroach/pkg/util/duration"
)

// Workaround for bazel auto-generated code. goimports does not automatically
// pick up the right packages when run within the bazel sandbox.
var (
_ tree.AggType
_ apd.Context
_ duration.Duration
)

// Remove unused warning.
Expand Down
8 changes: 8 additions & 0 deletions pkg/sql/colexec/colexecagg/ordered_any_not_null_agg.eg.go

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

8 changes: 8 additions & 0 deletions pkg/sql/colexec/colexecagg/ordered_avg_agg.eg.go

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

8 changes: 8 additions & 0 deletions pkg/sql/colexec/colexecagg/ordered_min_max_agg.eg.go

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

8 changes: 8 additions & 0 deletions pkg/sql/colexec/colexecagg/ordered_sum_agg.eg.go

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

10 changes: 10 additions & 0 deletions pkg/sql/colexec/colexecagg/ordered_sum_int_agg.eg.go

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

11 changes: 11 additions & 0 deletions pkg/sql/colexec/colexecagg/sum_agg_tmpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,25 @@ import (
"strings"
"unsafe"

"github.com/cockroachdb/apd/v2"
"github.com/cockroachdb/cockroach/pkg/col/coldata"
"github.com/cockroachdb/cockroach/pkg/sql/colexec/execgen"
"github.com/cockroachdb/cockroach/pkg/sql/colexecbase/colexecerror"
"github.com/cockroachdb/cockroach/pkg/sql/colmem"
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
"github.com/cockroachdb/cockroach/pkg/sql/types"
"github.com/cockroachdb/cockroach/pkg/util/duration"
"github.com/cockroachdb/errors"
)

// Workaround for bazel auto-generated code. goimports does not automatically
// pick up the right packages when run within the bazel sandbox.
var (
_ tree.AggType
_ apd.Context
_ duration.Duration
)

// {{/*
// Declarations to make the template compile properly

Expand Down

0 comments on commit f62055c

Please sign in to comment.