summaryrefslogtreecommitdiffhomepage
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/bazel.mk40
-rw-r--r--tools/bigquery/bigquery.go5
-rwxr-xr-xtools/go_branch.sh16
-rw-r--r--tools/go_generics/imports.go4
-rw-r--r--tools/go_marshal/test/escape/escape.go1
-rw-r--r--tools/go_marshal/test/test.go2
-rw-r--r--tools/parsers/BUILD6
-rw-r--r--tools/parsers/go_parser.go8
-rw-r--r--tools/parsers/go_parser_test.go2
-rw-r--r--tools/parsers/parser_main.go28
-rw-r--r--tools/parsers/version.go18
11 files changed, 84 insertions, 46 deletions
diff --git a/tools/bazel.mk b/tools/bazel.mk
index 88431ce66..3a7de427f 100644
--- a/tools/bazel.mk
+++ b/tools/bazel.mk
@@ -26,13 +26,13 @@ BRANCH_NAME := $(shell (git branch --show-current 2>/dev/null || \
BUILD_ROOTS := bazel-bin/ bazel-out/
# Bazel container configuration (see below).
-USER ?= gvisor
-HASH ?= $(shell readlink -m $(CURDIR) | md5sum | cut -c1-8)
+USER := $(shell whoami)
+HASH := $(shell readlink -m $(CURDIR) | md5sum | cut -c1-8)
BUILDER_BASE := gvisor.dev/images/default
BUILDER_IMAGE := gvisor.dev/images/builder
-BUILDER_NAME ?= gvisor-builder-$(HASH)
-DOCKER_NAME ?= gvisor-bazel-$(HASH)
-DOCKER_PRIVILEGED ?= --privileged
+BUILDER_NAME := gvisor-builder-$(HASH)
+DOCKER_NAME := gvisor-bazel-$(HASH)
+DOCKER_PRIVILEGED := --privileged
BAZEL_CACHE := $(shell readlink -m ~/.cache/bazel/)
GCLOUD_CONFIG := $(shell readlink -m ~/.config/gcloud/)
DOCKER_SOCKET := /var/run/docker.sock
@@ -59,6 +59,25 @@ ifeq (true,$(shell [[ -t 0 ]] && echo true))
FULL_DOCKER_EXEC_OPTIONS += --tty
endif
+# Add basic UID/GID options.
+#
+# Note that USERADD_DOCKER and GROUPADD_DOCKER are both defined as "deferred"
+# variables in Make terminology, that is they will be expanded at time of use
+# and may include other variables, including those defined below.
+#
+# NOTE: we pass -l to useradd below because otherwise you can hit a bug
+# best described here:
+# https://github.com/moby/moby/issues/5419#issuecomment-193876183
+# TLDR; trying to add to /var/log/lastlog (sparse file) runs the machine out
+# out of disk space.
+ifneq ($(UID),0)
+USERADD_DOCKER += useradd -l --uid $(UID) --non-unique --no-create-home \
+ --gid $(GID) $(USERADD_OPTIONS) -d $(HOME) $(USER) &&
+endif
+ifneq ($(GID),0)
+GROUPADD_DOCKER += groupadd --gid $(GID) --non-unique $(USER) &&
+endif
+
# Add docker passthrough options.
ifneq ($(DOCKER_PRIVILEGED),)
FULL_DOCKER_RUN_OPTIONS += -v "$(DOCKER_SOCKET):$(DOCKER_SOCKET)"
@@ -91,19 +110,12 @@ ifneq (,$(BAZEL_CONFIG))
OPTIONS += --config=$(BAZEL_CONFIG)
endif
-# NOTE: we pass -l to useradd below because otherwise you can hit a bug
-# best described here:
-# https://github.com/moby/moby/issues/5419#issuecomment-193876183
-# TLDR; trying to add to /var/log/lastlog (sparse file) runs the machine out
-# out of disk space.
bazel-image: load-default
@if docker ps --all | grep $(BUILDER_NAME); then docker rm -f $(BUILDER_NAME); fi
docker run --user 0:0 --entrypoint "" --name $(BUILDER_NAME) \
$(BUILDER_BASE) \
- sh -c "groupadd --gid $(GID) --non-unique $(USER) && \
- $(GROUPADD_DOCKER) \
- useradd -l --uid $(UID) --non-unique --no-create-home \
- --gid $(GID) $(USERADD_OPTIONS) -d $(HOME) $(USER) && \
+ sh -c "$(GROUPADD_DOCKER) \
+ $(USERADD_DOCKER) \
if [[ -e /dev/kvm ]]; then chmod a+rw /dev/kvm; fi"
docker commit $(BUILDER_NAME) $(BUILDER_IMAGE)
@docker rm -f $(BUILDER_NAME)
diff --git a/tools/bigquery/bigquery.go b/tools/bigquery/bigquery.go
index 34b270cc0..544af3876 100644
--- a/tools/bigquery/bigquery.go
+++ b/tools/bigquery/bigquery.go
@@ -105,7 +105,7 @@ func (bm *Benchmark) AddMetric(metricName, unit string, sample float64) {
}
// NewBenchmark initializes a new benchmark.
-func NewBenchmark(name string, iters int, official bool) *Benchmark {
+func NewBenchmark(name string, iters int) *Benchmark {
return &Benchmark{
Name: name,
Metric: make([]*Metric, 0),
@@ -113,12 +113,13 @@ func NewBenchmark(name string, iters int, official bool) *Benchmark {
}
// NewSuite initializes a new Suite.
-func NewSuite(name string) *Suite {
+func NewSuite(name string, official bool) *Suite {
return &Suite{
Name: name,
Timestamp: time.Now().UTC(),
Benchmarks: make([]*Benchmark, 0),
Conditions: make([]*Condition, 0),
+ Official: official,
}
}
diff --git a/tools/go_branch.sh b/tools/go_branch.sh
index 100c4ae41..71d036b12 100755
--- a/tools/go_branch.sh
+++ b/tools/go_branch.sh
@@ -61,14 +61,6 @@ go_branch=$( \
)
readonly go_branch
-declare commit
-commit=$(git rev-parse HEAD)
-readonly commit
-if [[ -n "$(git branch --contains="${commit}" go)" ]]; then
- # The go branch already has the commit.
- exit 0
-fi
-
# Clone the current repository to the temporary directory, and check out the
# current go_branch directory. We move to the new repository for convenience.
declare repo_orig
@@ -117,7 +109,7 @@ EOF
# There are a few solitary files that can get left behind due to the way bazel
# constructs the gopath target. Note that we don't find all Go files here
# because they may correspond to unused templates, etc.
-declare -ar binaries=( "runsc" "shim/v1" "shim/v2" )
+declare -ar binaries=( "runsc" "shim/v1" "shim/v2" "webhook" )
for target in "${binaries[@]}"; do
mkdir -p "${target}"
cp "${repo_orig}/${target}"/*.go "${target}/"
@@ -130,7 +122,11 @@ find . -type f -exec chmod 0644 {} \;
find . -type d -exec chmod 0755 {} \;
# Update the current working set and commit.
-git add . && git commit -m "Merge ${head} (automated)"
+# If the current working commit has already been committed to the remote go
+# branch, then we have nothing to commit here. So allow empty commit. This can
+# occur when this script is run parallely (via pull_request and push events)
+# and the push workflow finishes before the pull_request workflow can run this.
+git add . && git commit --allow-empty -m "Merge ${head} (automated)"
# Push the branch back to the original repository.
git remote add orig "${repo_orig}" && git push -f orig go:go
diff --git a/tools/go_generics/imports.go b/tools/go_generics/imports.go
index 90d3aa1e0..370650e46 100644
--- a/tools/go_generics/imports.go
+++ b/tools/go_generics/imports.go
@@ -48,7 +48,7 @@ func updateImportIdent(orig string, imports mapValue, id *ast.Ident, used map[st
// Create a new entry in the used map.
path := imports[importName]
if path == "" {
- return fmt.Errorf("Unknown path to package '%s', used in '%s'", importName, orig)
+ return fmt.Errorf("unknown path to package '%s', used in '%s'", importName, orig)
}
m = &importedPackage{
@@ -72,7 +72,7 @@ func convertExpression(s string, imports mapValue, used map[string]*importedPack
// Parse the expression in the input string.
expr, err := parser.ParseExpr(s)
if err != nil {
- return "", fmt.Errorf("Unable to parse \"%s\": %v", s, err)
+ return "", fmt.Errorf("unable to parse \"%s\": %v", s, err)
}
// Go through the AST and update references.
diff --git a/tools/go_marshal/test/escape/escape.go b/tools/go_marshal/test/escape/escape.go
index 7f62b0a2b..df14ae98e 100644
--- a/tools/go_marshal/test/escape/escape.go
+++ b/tools/go_marshal/test/escape/escape.go
@@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+// Package escape contains test cases for escape analysis.
package escape
import (
diff --git a/tools/go_marshal/test/test.go b/tools/go_marshal/test/test.go
index d9e9f341b..e7e3ed74a 100644
--- a/tools/go_marshal/test/test.go
+++ b/tools/go_marshal/test/test.go
@@ -161,7 +161,7 @@ type TestArray [sizeA]int32
// +marshal
type TestArray2 [sizeA * sizeB]int32
-// TestArray2 is a newtype on an array with a simple arithmetic expression of
+// TestArray3 is a newtype on an array with a simple arithmetic expression of
// mixed constants and literals for the array length.
//
// +marshal
diff --git a/tools/parsers/BUILD b/tools/parsers/BUILD
index dab954e25..6932bba9a 100644
--- a/tools/parsers/BUILD
+++ b/tools/parsers/BUILD
@@ -31,8 +31,12 @@ go_library(
go_binary(
name = "parser",
testonly = 1,
- srcs = ["parser_main.go"],
+ srcs = [
+ "parser_main.go",
+ "version.go",
+ ],
nogo = False,
+ x_defs = {"main.version": "{STABLE_VERSION}"},
deps = [
":parsers",
"//runsc/flag",
diff --git a/tools/parsers/go_parser.go b/tools/parsers/go_parser.go
index df4875e6a..57e538149 100644
--- a/tools/parsers/go_parser.go
+++ b/tools/parsers/go_parser.go
@@ -30,10 +30,10 @@ import (
// ParseOutput expects golang benchmark output and returns a struct formatted
// for BigQuery.
func ParseOutput(output string, name string, official bool) (*bigquery.Suite, error) {
- suite := bigquery.NewSuite(name)
+ suite := bigquery.NewSuite(name, official)
lines := strings.Split(output, "\n")
for _, line := range lines {
- bm, err := parseLine(line, official)
+ bm, err := parseLine(line)
if err != nil {
return nil, fmt.Errorf("failed to parse line '%s': %v", line, err)
}
@@ -60,7 +60,7 @@ func ParseOutput(output string, name string, official bool) (*bigquery.Suite, er
// {Name: requests_per_second, Unit: QPS, Sample: 140 }
// }
//}
-func parseLine(line string, official bool) (*bigquery.Benchmark, error) {
+func parseLine(line string) (*bigquery.Benchmark, error) {
fields := strings.Fields(line)
// Check if this line is a Benchmark line. Otherwise ignore the line.
@@ -78,7 +78,7 @@ func parseLine(line string, official bool) (*bigquery.Benchmark, error) {
return nil, fmt.Errorf("parse name/params: %v", err)
}
- bm := bigquery.NewBenchmark(name, iters, official)
+ bm := bigquery.NewBenchmark(name, iters)
for _, p := range params {
bm.AddCondition(p.Name, p.Value)
}
diff --git a/tools/parsers/go_parser_test.go b/tools/parsers/go_parser_test.go
index 0aa1152a2..f0737d46b 100644
--- a/tools/parsers/go_parser_test.go
+++ b/tools/parsers/go_parser_test.go
@@ -94,7 +94,7 @@ func TestParseLine(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
- got, err := parseLine(tc.data, false)
+ got, err := parseLine(tc.data)
if err != nil {
t.Fatalf("parseLine failed with: %v", err)
}
diff --git a/tools/parsers/parser_main.go b/tools/parsers/parser_main.go
index 6c6182464..7cce69e03 100644
--- a/tools/parsers/parser_main.go
+++ b/tools/parsers/parser_main.go
@@ -49,12 +49,11 @@ var (
parseCmd = flag.NewFlagSet(parseString, flag.ContinueOnError)
file = parseCmd.String("file", "", "file to parse for benchmarks")
name = parseCmd.String("suite_name", "", "name of the benchmark suite")
- clNumber = parseCmd.String("cl", "", "changelist number of this run")
- gitCommit = parseCmd.String("git_commit", "", "git commit sha for this run")
parseProject = parseCmd.String("project", "", "GCP project to send benchmarks.")
parseDataset = parseCmd.String("dataset", "", "dataset to send benchmarks data.")
parseTable = parseCmd.String("table", "", "table to send benchmarks data.")
official = parseCmd.Bool("official", false, "mark input data as official.")
+ runtime = parseCmd.String("runtime", "", "runtime used to run the benchmark")
)
// initBenchmarks initializes a dataset/table in a BigQuery project.
@@ -67,23 +66,29 @@ func initBenchmarks(ctx context.Context) error {
func parseBenchmarks(ctx context.Context) error {
data, err := ioutil.ReadFile(*file)
if err != nil {
- return fmt.Errorf("failed to read file: %v", err)
+ return fmt.Errorf("failed to read file %s: %v", *file, err)
}
suite, err := parsers.ParseOutput(string(data), *name, *official)
if err != nil {
return fmt.Errorf("failed parse data: %v", err)
}
+ if len(suite.Benchmarks) < 1 {
+ fmt.Fprintf(os.Stderr, "Failed to find benchmarks for file: %s", *file)
+ return nil
+ }
+
extraConditions := []*bq.Condition{
{
- Name: "change_list",
- Value: *clNumber,
+ Name: "runtime",
+ Value: *runtime,
},
{
- Name: "commit",
- Value: *gitCommit,
+ Name: "version",
+ Value: version,
},
}
+ suite.Official = *official
suite.Conditions = append(suite.Conditions, extraConditions...)
return bq.SendBenchmarks(ctx, suite, *parseProject, *parseDataset, *parseTable, nil)
}
@@ -94,26 +99,27 @@ func main() {
// the "init" command
case len(os.Args) >= 2 && os.Args[1] == initString:
if err := initCmd.Parse(os.Args[2:]); err != nil {
- fmt.Fprintf(os.Stderr, "failed parse flags: %v", err)
+ fmt.Fprintf(os.Stderr, "failed parse flags: %v\n", err)
os.Exit(1)
}
if err := initBenchmarks(ctx); err != nil {
- failure := "failed to initialize project: %s dataset: %s table: %s: %v"
+ failure := "failed to initialize project: %s dataset: %s table: %s: %v\n"
fmt.Fprintf(os.Stderr, failure, *parseProject, *parseDataset, *parseTable, err)
os.Exit(1)
}
// the "parse" command.
case len(os.Args) >= 2 && os.Args[1] == parseString:
if err := parseCmd.Parse(os.Args[2:]); err != nil {
- fmt.Fprintf(os.Stderr, "failed parse flags: %v", err)
+ fmt.Fprintf(os.Stderr, "failed parse flags: %v\n", err)
os.Exit(1)
}
if err := parseBenchmarks(ctx); err != nil {
- fmt.Fprintf(os.Stderr, "failed parse benchmarks: %v", err)
+ fmt.Fprintf(os.Stderr, "failed parse benchmarks: %v\n", err)
os.Exit(1)
}
default:
printUsage()
+ os.Exit(1)
}
}
diff --git a/tools/parsers/version.go b/tools/parsers/version.go
new file mode 100644
index 000000000..ab9194b9d
--- /dev/null
+++ b/tools/parsers/version.go
@@ -0,0 +1,18 @@
+// Copyright 2019 The gVisor Authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package main
+
+// version is set during linking.
+var version = "VERSION_MISSING"