Skip to content

Commit

Permalink
Merge #57030 #57039
Browse files Browse the repository at this point in the history
57030: execgen: permit customization of template path r=jordanlewis a=jordanlewis

Closes #56982

This commit adds a new argument to execgen, -template, which allows
customization of the file path of the input template for a given output
file.

Here's an example of how to run execgen with cutomized paths:

```
execgen -template path/to/template_tmpl.go path/to/eventual/generated/code.eg.go > path/to/wherever/you/want/to/write/the/file.eg.o
```

The second argument is important because it is used as an argument to
`goimports`, which needs to the actual, eventual path that the generated
code will live at. Note that it doesn't actually need to *write* to that
filepath - just needs to know what the name will be, eventually.

Release note: None

57039: bazel: add freebsd support r=irfansharif a=irfansharif

Fixes #56013. We're picking up bazel-contrib/rules_foreign_cc/pull/387
(included in our new fork at [cockroachdb/rules_foreign_cc](https://github.com/cockroachdb/rules_foreign_cc/)). We've also
picked up Oliver's PR adding autoconf support
(bazel-contrib/rules_foreign_cc/pull/432); we were pointing to Oliver's own
fork previously to pick up those changes.

Release note: None

---

@knz, wanna try this branch out and see if it works? If not, I should probably spin up a freebsd AMI next once someone shows me how.

Co-authored-by: Jordan Lewis <[email protected]>
Co-authored-by: irfan sharif <[email protected]>
  • Loading branch information
3 people committed Nov 24, 2020
3 parents 48f860b + 08bd15a + ed964c0 commit fccf248
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 29 deletions.
13 changes: 8 additions & 5 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,17 @@ load("//c-deps:REPOSITORIES.bzl", "c_deps")
c_deps()


# Load the bazel utility that lets us build C/C++ projects using cmake/make/etc.
# Load the bazel utility that lets us build C/C++ projects using
# cmake/make/etc. We point our fork which adds autoconf support
# (https://github.com/bazelbuild/rules_foreign_cc/pull/432) and BSD support
# (https://github.com/bazelbuild/rules_foreign_cc/pull/387).
#
# TODO(irfansharif): Point to an upstream SHA once it picks up Oliver's changes
# that add autoconf support.
# TODO(irfansharif): Point to an upstream SHA once maintainers pick up the
# aforementioned PRs.
git_repository(
name = "rules_foreign_cc",
commit = "605c77171f20840464301d7d01d6cd9e3a982888",
remote = "https://github.com/otan-cockroach/rules_foreign_cc",
commit = "8fdca4480f3fa9c084f4a73749a46fa17996beb1",
remote = "https://github.com/cockroachdb/rules_foreign_cc",
)
load("@rules_foreign_cc//:workspace_definitions.bzl", "rules_foreign_cc_dependencies")
rules_foreign_cc_dependencies()
44 changes: 20 additions & 24 deletions pkg/sql/colexec/execgen/cmd/execgen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ import (
"github.com/cockroachdb/gostdlib/x/tools/imports"
)

var (
errInvalidArgCount = errors.New("invalid number of arguments")
)

func main() {
gen := execgenTool{stdErr: os.Stderr}
if !gen.run(os.Args[1:]...) {
Expand Down Expand Up @@ -71,45 +67,45 @@ func registerGenerator(g generator, outputFile, inputFile string) {
func (g *execgenTool) run(args ...string) bool {
// Parse command line.
var printDeps bool
var template string
g.cmdLine = flag.NewFlagSet("execgen", flag.ContinueOnError)
g.cmdLine.SetOutput(g.stdErr)
g.cmdLine.Usage = g.usage
g.cmdLine.BoolVar(&g.fmtSources, "fmt", true, "format and imports-process generated code")
g.cmdLine.BoolVar(&g.verbose, "verbose", false, "print out debug information to stderr")
g.cmdLine.BoolVar(&printDeps, "M", false, "print the dependency list")
g.cmdLine.StringVar(&template, "template", "", "path")
err := g.cmdLine.Parse(args)
if err != nil {
return false
}

// Get remaining args after any flags have been parsed.
args = g.cmdLine.Args()
if len(args) < 1 {
if len(args) != 1 {
g.cmdLine.Usage()
g.reportError(errInvalidArgCount)
g.reportError(errors.New("invalid number of arguments"))
return false
}

for _, out := range args {
_, file := filepath.Split(out)
e := generators[file]
if e.fn == nil {
g.reportError(errors.Errorf("unrecognized filename: %s", file))
outPath := args[0]

_, file := filepath.Split(outPath)
e := generators[file]
if e.fn == nil {
g.reportError(errors.Errorf("unrecognized filename: %s", file))
return false
}
if template != "" {
if e.inputFile == "" {
g.reportError(errors.Errorf("file %s expected no input template, found %s", file, template))
return false
}
if printDeps {
if e.inputFile == "" {
// This output file has no template dependency (its template
// is embedded entirely in execgenTool). Skip it.
continue
}
fmt.Printf("%s: %s\n", out, e.inputFile)
} else {
if err := g.generate(out, e); err != nil {
g.reportError(err)
return false
}
}
e.inputFile = template
}
if err := g.generate(outPath, e); err != nil {
g.reportError(err)
return false
}
return true
}
Expand Down

0 comments on commit fccf248

Please sign in to comment.