-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do some refactoring so that we don't have to repeat code in a bunch of places. The implementation is pretty straightforward and just involves building the docs then copying them over to the workspace. Closes #68563. Release note: None
- Loading branch information
1 parent
812ba83
commit b9691c4
Showing
15 changed files
with
387 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
This file lists all the targets you need to build to build all the generated | ||
documentation. Lines not beginning with // should be ignored. | ||
|
||
//docs/generated:gen-logging-md | ||
//docs/generated:gen-logsinks-md | ||
//docs/generated:gen-eventlog-md | ||
//docs/generated:gen-logformats-md | ||
//docs/generated/settings | ||
//docs/generated/settings:settings_for_tenants | ||
//docs/generated/sql | ||
//docs/generated/sql/bnf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") | ||
|
||
go_library( | ||
name = "util", | ||
srcs = ["util.go"], | ||
importpath = "github.com/cockroachdb/cockroach/pkg/build/util", | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
go_test( | ||
name = "util_test", | ||
srcs = ["util_test.go"], | ||
embed = [":util"], | ||
deps = ["@com_github_stretchr_testify//require"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// Copyright 2015 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
// | ||
// This file contains assorted utilities for working with Bazel internals. | ||
|
||
package util | ||
|
||
import ( | ||
"fmt" | ||
"path/filepath" | ||
"regexp" | ||
"strings" | ||
) | ||
|
||
// OutputOfBinaryRule returns the path of the binary produced by the | ||
// given build target, relative to bazel-bin. That is, | ||
// filepath.Join(bazelBin, OutputOfBinaryRule(target)) is the absolute | ||
// path to the build binary for the target. | ||
func OutputOfBinaryRule(target string) string { | ||
colon := strings.Index(target, ":") | ||
var bin string | ||
if colon >= 0 { | ||
bin = target[colon+1:] | ||
} else { | ||
bin = target[strings.LastIndex(target, "/")+1:] | ||
} | ||
var head string | ||
if strings.HasPrefix(target, "@") { | ||
doubleSlash := strings.Index(target, "//") | ||
head = filepath.Join("external", target[1:doubleSlash]) | ||
} else if colon >= 0 { | ||
head = strings.TrimPrefix(target[:colon], "//") | ||
} else { | ||
head = strings.TrimPrefix(target, "//") | ||
} | ||
return filepath.Join(head, bin+"_", bin) | ||
} | ||
|
||
// OutputsOfGenrule lists the outputs of a genrule. The first argument | ||
// is the name of the target (e.g. //docs/generated/sql), and the second | ||
// should be the output of `bazel query --output=xml $TARGET`. The | ||
// returned slice is the list of outputs, all of which are relative | ||
// paths atop `bazel-bin` as in `OutputOfBinaryRule`. | ||
func OutputsOfGenrule(target, xmlQueryOutput string) ([]string, error) { | ||
// XML parsing is a bit heavyweight here, and encoding/xml | ||
// refuses to parse the query output since it's XML 1.1 instead | ||
// of 1.0. Have fun with regexes instead. | ||
colon := strings.LastIndex(target, ":") | ||
if colon < 0 { | ||
colon = len(target) | ||
} | ||
regexStr := fmt.Sprintf("^<rule-output name=\"%s:(?P<Filename>.*)\"/>$", regexp.QuoteMeta(target[:colon])) | ||
re, err := regexp.Compile(regexStr) | ||
if err != nil { | ||
return nil, err | ||
} | ||
var ret []string | ||
for _, line := range strings.Split(xmlQueryOutput, "\n") { | ||
line = strings.TrimSpace(line) | ||
submatch := re.FindStringSubmatch(line) | ||
if submatch == nil { | ||
continue | ||
} | ||
relBinPath := filepath.Join(strings.TrimPrefix(target[:colon], "//"), submatch[1]) | ||
ret = append(ret, relBinPath) | ||
} | ||
return ret, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright 2021 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package util | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestOutputOfBinaryRule(t *testing.T) { | ||
require.Equal(t, OutputOfBinaryRule("//pkg/cmd/cockroach-short"), "pkg/cmd/cockroach-short/cockroach-short_/cockroach-short") | ||
require.Equal(t, OutputOfBinaryRule("//pkg/cmd/cockroach-short:cockroach-short"), "pkg/cmd/cockroach-short/cockroach-short_/cockroach-short") | ||
require.Equal(t, OutputOfBinaryRule("pkg/cmd/cockroach-short"), "pkg/cmd/cockroach-short/cockroach-short_/cockroach-short") | ||
|
||
require.Equal(t, OutputOfBinaryRule("@com_github_cockroachdb_stress//:stress"), "external/com_github_cockroachdb_stress/stress_/stress") | ||
} | ||
|
||
func TestOutputsOfGenrule(t *testing.T) { | ||
xmlQueryOutput := `<?xml version="1.1" encoding="UTF-8" standalone="no"?> | ||
<query version="2"> | ||
<rule class="genrule" location="/Users/ricky/go/src/github.com/cockroachdb/cockroach/docs/generated/sql/BUILD.bazel:1:8" name="//docs/generated/sql:sql"> | ||
<string name="name" value="sql"/> | ||
<list name="exec_tools"> | ||
<label value="//pkg/cmd/docgen:docgen"/> | ||
</list> | ||
<list name="outs"> | ||
<output value="//docs/generated/sql:aggregates.md"/> | ||
<output value="//docs/generated/sql:functions.md"/> | ||
<output value="//docs/generated/sql:operators.md"/> | ||
<output value="//docs/generated/sql:window_functions.md"/> | ||
</list> | ||
<string name="cmd" value=" $(location //pkg/cmd/docgen) functions $(RULEDIR) --quiet "/> | ||
<rule-input name="//pkg/cmd/docgen:docgen"/> | ||
<rule-input name="@bazel_tools//tools/genrule:genrule-setup.sh"/> | ||
<rule-output name="//docs/generated/sql:aggregates.md"/> | ||
<rule-output name="//docs/generated/sql:functions.md"/> | ||
<rule-output name="//docs/generated/sql:operators.md"/> | ||
<rule-output name="//docs/generated/sql:window_functions.md"/> | ||
</rule> | ||
</query>` | ||
expected := []string{ | ||
"docs/generated/sql/aggregates.md", | ||
"docs/generated/sql/functions.md", | ||
"docs/generated/sql/operators.md", | ||
"docs/generated/sql/window_functions.md", | ||
} | ||
out, err := OutputsOfGenrule("//docs/generated/sql:sql", xmlQueryOutput) | ||
require.NoError(t, err) | ||
require.Equal(t, out, expected) | ||
out, err = OutputsOfGenrule("//docs/generated/sql", xmlQueryOutput) | ||
require.NoError(t, err) | ||
require.Equal(t, out, expected) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.