mirror of
https://github.com/peridotbuild/peridot.git
synced 2024-10-12 18:55:08 +00:00
Add taskrunner2 with ibazel baked in
This commit is contained in:
parent
6c95696717
commit
0f755dd434
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,5 +1,5 @@
|
||||
.idea
|
||||
.ijwb
|
||||
bazel-*
|
||||
/bazel-*
|
||||
node_modules
|
||||
.DS_Store
|
||||
|
@ -8,6 +8,7 @@ npm_link_all_packages(name = "node_modules")
|
||||
exports_files(["tsconfig.json"])
|
||||
|
||||
# gazelle:prefix go.resf.org/peridot
|
||||
# gazelle:go_visibility //third_party:__subpackages__
|
||||
# gazelle:exclude third_party/googleapis
|
||||
# gazelle:exclude vendor/go.resf.org/peridot
|
||||
# gazelle:exclude vendor/google.golang.org
|
||||
@ -15,6 +16,7 @@ exports_files(["tsconfig.json"])
|
||||
# gazelle:exclude vendor/golang.org/x/net
|
||||
# gazelle:exclude vendor.go
|
||||
# gazelle:go_grpc_compilers @io_bazel_rules_go//proto:go_grpc,//:go_gen_grpc_gateway
|
||||
# gazelle:resolve go github.com/bazelbuild/bazel-watcher/internal/ibazel/profiler //third_party/github.com/bazelbuild/bazel-watcher/internal/ibazel/profiler
|
||||
# gazelle:resolve proto proto google/api/annotations.proto @googleapis//google/api:annotations_proto
|
||||
# gazelle:resolve proto go google/api/annotations.proto @org_golang_google_genproto//googleapis/api/annotations
|
||||
gazelle(name = "gazelle")
|
||||
|
108
deps.bzl
108
deps.bzl
@ -58,6 +58,18 @@ def go_dependencies():
|
||||
sum = "h1:5sz/EEAK+ls5wF+NeqDpk5+iNdMDXrh3z3nPnH1Wvgk=",
|
||||
version = "v0.2.0",
|
||||
)
|
||||
go_repository(
|
||||
name = "com_github_bazelbuild_bazel_watcher",
|
||||
importpath = "github.com/bazelbuild/bazel-watcher",
|
||||
sum = "h1:EfJzkMxJuNBGMVdEvkhiW7pAMwhaegbmAMaFCjLjyTw=",
|
||||
version = "v0.23.7",
|
||||
)
|
||||
go_repository(
|
||||
name = "com_github_bazelbuild_rules_go",
|
||||
importpath = "github.com/bazelbuild/rules_go",
|
||||
sum = "h1:YWJ+hbwEOB/PtIFCRMDnvWVSpwPFFGEpdIB6E3bt8X4=",
|
||||
version = "v0.39.0",
|
||||
)
|
||||
|
||||
go_repository(
|
||||
name = "com_github_benbjohnson_clock",
|
||||
@ -190,6 +202,18 @@ def go_dependencies():
|
||||
sum = "h1:ZYRD89nammxQDWDi6taJE2CYjDuAoVc1TpEqRIYQryc=",
|
||||
version = "v1.23.0",
|
||||
)
|
||||
go_repository(
|
||||
name = "com_github_fsnotify_fsevents",
|
||||
importpath = "github.com/fsnotify/fsevents",
|
||||
sum = "h1:/125uxJvvoSDDBPen6yUZbil8J9ydKZnnl3TWWmvnkw=",
|
||||
version = "v0.1.1",
|
||||
)
|
||||
go_repository(
|
||||
name = "com_github_fsnotify_fsnotify",
|
||||
importpath = "github.com/fsnotify/fsnotify",
|
||||
sum = "h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=",
|
||||
version = "v1.6.0",
|
||||
)
|
||||
|
||||
go_repository(
|
||||
name = "com_github_gertd_go_pluralize",
|
||||
@ -362,6 +386,19 @@ def go_dependencies():
|
||||
sum = "h1:9V9PWXEsWnPpQhu/PeQIkS4eGzMlTLGgt80cUUI8Ki4=",
|
||||
version = "v2.11.0",
|
||||
)
|
||||
go_repository(
|
||||
name = "com_github_gopherjs_gopherjs",
|
||||
importpath = "github.com/gopherjs/gopherjs",
|
||||
sum = "h1:fQnZVsXk8uxXIStYb0N4bGk7jeyTalG/wsZjQ25dO0g=",
|
||||
version = "v1.17.2",
|
||||
)
|
||||
|
||||
go_repository(
|
||||
name = "com_github_gorilla_websocket",
|
||||
importpath = "github.com/gorilla/websocket",
|
||||
sum = "h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=",
|
||||
version = "v1.5.0",
|
||||
)
|
||||
|
||||
go_repository(
|
||||
name = "com_github_gregjones_httpcache",
|
||||
@ -406,6 +443,12 @@ def go_dependencies():
|
||||
sum = "h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=",
|
||||
version = "v1.1.0",
|
||||
)
|
||||
go_repository(
|
||||
name = "com_github_jaschaephraim_lrserver",
|
||||
importpath = "github.com/jaschaephraim/lrserver",
|
||||
sum = "h1:24NdJ5N6gtrcoeS4JwLMeruKFmg20QdF/5UnX5S/j18=",
|
||||
version = "v0.0.0-20171129202958-50d19f603f71",
|
||||
)
|
||||
|
||||
go_repository(
|
||||
name = "com_github_jhump_gopoet",
|
||||
@ -452,6 +495,13 @@ def go_dependencies():
|
||||
sum = "h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=",
|
||||
version = "v1.1.12",
|
||||
)
|
||||
go_repository(
|
||||
name = "com_github_jtolds_gls",
|
||||
importpath = "github.com/jtolds/gls",
|
||||
sum = "h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=",
|
||||
version = "v4.20.0+incompatible",
|
||||
)
|
||||
|
||||
go_repository(
|
||||
name = "com_github_julienschmidt_httprouter",
|
||||
importpath = "github.com/julienschmidt/httprouter",
|
||||
@ -528,6 +578,12 @@ def go_dependencies():
|
||||
sum = "h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=",
|
||||
version = "v0.0.9",
|
||||
)
|
||||
go_repository(
|
||||
name = "com_github_mattn_go_shellwords",
|
||||
importpath = "github.com/mattn/go-shellwords",
|
||||
sum = "h1:M2zGm7EW6UQJvDeQxo4T51eKPurbeFbe8WtebGE2xrk=",
|
||||
version = "v1.0.12",
|
||||
)
|
||||
|
||||
go_repository(
|
||||
name = "com_github_mattn_go_sqlite3",
|
||||
@ -587,6 +643,19 @@ def go_dependencies():
|
||||
sum = "h1:y5//uYreIhSUg3J1GEMiLbxo1LJaP8RfCpH6pymGZus=",
|
||||
version = "v0.0.0-20140419014527-cca7078d478f",
|
||||
)
|
||||
go_repository(
|
||||
name = "com_github_neelance_astrewrite",
|
||||
importpath = "github.com/neelance/astrewrite",
|
||||
sum = "h1:D6paGObi5Wud7xg83MaEFyjxQB1W5bz5d0IFppr+ymk=",
|
||||
version = "v0.0.0-20160511093645-99348263ae86",
|
||||
)
|
||||
go_repository(
|
||||
name = "com_github_neelance_sourcemap",
|
||||
importpath = "github.com/neelance/sourcemap",
|
||||
sum = "h1:bY6ktFuJkt+ZXkX0RChQch2FtHpWQLVS8Qo1YasiIVk=",
|
||||
version = "v0.0.0-20200213170602-2833bce08e4c",
|
||||
)
|
||||
|
||||
go_repository(
|
||||
name = "com_github_olekukonko_tablewriter",
|
||||
importpath = "github.com/olekukonko/tablewriter",
|
||||
@ -676,12 +745,45 @@ def go_dependencies():
|
||||
sum = "h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=",
|
||||
version = "v2.1.0",
|
||||
)
|
||||
go_repository(
|
||||
name = "com_github_shurcool_go",
|
||||
importpath = "github.com/shurcooL/go",
|
||||
sum = "h1:aSISeOcal5irEhJd1M+IrApc0PdcN7e7Aj4yuEnOrfQ=",
|
||||
version = "v0.0.0-20200502201357-93f07166e636",
|
||||
)
|
||||
go_repository(
|
||||
name = "com_github_shurcool_httpfs",
|
||||
importpath = "github.com/shurcooL/httpfs",
|
||||
sum = "h1:bUGsEnyNbVPw06Bs80sCeARAlK8lhwqGyi6UT8ymuGk=",
|
||||
version = "v0.0.0-20190707220628-8d4bc4ba7749",
|
||||
)
|
||||
go_repository(
|
||||
name = "com_github_shurcool_vfsgen",
|
||||
importpath = "github.com/shurcooL/vfsgen",
|
||||
sum = "h1:pXY9qYc/MP5zdvqWEUH6SjNiu7VhSjuVFTFiTcphaLU=",
|
||||
version = "v0.0.0-20200824052919-0d455de96546",
|
||||
)
|
||||
|
||||
go_repository(
|
||||
name = "com_github_sirupsen_logrus",
|
||||
importpath = "github.com/sirupsen/logrus",
|
||||
sum = "h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=",
|
||||
version = "v1.9.3",
|
||||
)
|
||||
go_repository(
|
||||
name = "com_github_smartystreets_assertions",
|
||||
importpath = "github.com/smartystreets/assertions",
|
||||
replace = "github.com/smarty/assertions",
|
||||
sum = "h1:812oFiXI+G55vxsFf+8bIZ1ux30qtkdqzKbEFwyX3Tk=",
|
||||
version = "v1.15.1",
|
||||
)
|
||||
|
||||
go_repository(
|
||||
name = "com_github_smartystreets_goconvey",
|
||||
importpath = "github.com/smartystreets/goconvey",
|
||||
sum = "h1:9RBaZCeXEQ3UselpuwUQHltGVXvdwm6cv1hgR6gDIPg=",
|
||||
version = "v1.7.2",
|
||||
)
|
||||
|
||||
go_repository(
|
||||
name = "com_github_spf13_cobra",
|
||||
@ -1477,6 +1579,12 @@ def go_dependencies():
|
||||
sum = "h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=",
|
||||
version = "v1.0.0-20201130134442-10cb98267c6c",
|
||||
)
|
||||
go_repository(
|
||||
name = "in_gopkg_fsnotify_v1",
|
||||
importpath = "gopkg.in/fsnotify.v1",
|
||||
sum = "h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=",
|
||||
version = "v1.4.7",
|
||||
)
|
||||
|
||||
go_repository(
|
||||
name = "in_gopkg_inf_v0",
|
||||
|
@ -11,4 +11,3 @@
|
||||
# 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.
|
||||
|
||||
|
22
devtools/taskrunner2/BUILD.bazel
Normal file
22
devtools/taskrunner2/BUILD.bazel
Normal file
@ -0,0 +1,22 @@
|
||||
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
|
||||
load("@aspect_bazel_lib//lib:copy_to_bin.bzl", "copy_to_bin")
|
||||
|
||||
go_library(
|
||||
name = "taskrunner2_lib",
|
||||
srcs = ["main.go"],
|
||||
importpath = "go.resf.org/peridot/devtools/taskrunner2",
|
||||
visibility = ["//visibility:private"],
|
||||
deps = [
|
||||
"//base/go",
|
||||
"//vendor/github.com/urfave/cli/v2:cli",
|
||||
],
|
||||
)
|
||||
|
||||
go_binary(
|
||||
name = "taskrunner2",
|
||||
data = [
|
||||
"//vendor/github.com/bazelbuild/bazel-watcher/cmd/ibazel",
|
||||
],
|
||||
embed = [":taskrunner2_lib"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
132
devtools/taskrunner2/main.go
Normal file
132
devtools/taskrunner2/main.go
Normal file
@ -0,0 +1,132 @@
|
||||
// Package main implements taskrunner2.
|
||||
// Taskrunner2 is used to specify a list of Bazel targets to run.
|
||||
// Useful for development. Also supports running certain targets with ibazel.
|
||||
// Does NOT require you to have ibazel installed.
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/urfave/cli/v2"
|
||||
base "go.resf.org/peridot/base/go"
|
||||
"os"
|
||||
"os/exec"
|
||||
"os/signal"
|
||||
"runtime"
|
||||
"sync"
|
||||
)
|
||||
|
||||
var ibazelPath = "vendor/github.com/bazelbuild/bazel-watcher/cmd/ibazel/ibazel_/ibazel"
|
||||
var interrupt = make(chan os.Signal, 1)
|
||||
|
||||
func getBazelArgs(target string) []string {
|
||||
args := []string{"run"}
|
||||
|
||||
// check if we're on macOS
|
||||
if runtime.GOOS == "darwin" {
|
||||
args = append(args, "--config=macdev")
|
||||
}
|
||||
|
||||
args = append(args, target)
|
||||
|
||||
return args
|
||||
}
|
||||
|
||||
func spawnCmd(bin string, target string) error {
|
||||
cmd := exec.Command(bin, getBazelArgs(target)...)
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
|
||||
err := cmd.Start()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// if user terminates the main process, kill the ibazel process
|
||||
go func() {
|
||||
<-interrupt
|
||||
cmd.Process.Kill()
|
||||
}()
|
||||
|
||||
return cmd.Wait()
|
||||
}
|
||||
|
||||
// spawnBazel spawns a simple bazel run call.
|
||||
// on macOS adds `--config=macdev`
|
||||
func spawnBazel(target string) error {
|
||||
return spawnCmd("bazel", target)
|
||||
}
|
||||
|
||||
// spawnIbazel spawns an ibazel run call.
|
||||
// similar to spawnBazel, but uses ibazel instead.
|
||||
func spawnIbazel(target string) error {
|
||||
return spawnCmd(ibazelPath, target)
|
||||
}
|
||||
|
||||
func run(ctx *cli.Context) error {
|
||||
// add interrupt handler
|
||||
signal.Notify(interrupt, os.Interrupt, os.Kill)
|
||||
|
||||
// get current wd and make the ibazel path relative to it
|
||||
wd, err := os.Getwd()
|
||||
if err != nil {
|
||||
return cli.Exit(err, 1)
|
||||
}
|
||||
|
||||
ibazelPath = wd + "/" + ibazelPath
|
||||
|
||||
// if ran with bazel run, move to the workspace
|
||||
if wrksp := os.Getenv("BUILD_WORKSPACE_DIRECTORY"); wrksp != "" {
|
||||
if err := os.Chdir(wrksp); err != nil {
|
||||
return cli.Exit(err, 1)
|
||||
}
|
||||
}
|
||||
|
||||
var wg sync.WaitGroup
|
||||
|
||||
// for each target, spawn a bazel run call
|
||||
for _, target := range ctx.StringSlice("targets") {
|
||||
wg.Add(1)
|
||||
go func(target string) {
|
||||
defer wg.Done()
|
||||
if err := spawnBazel(target); err != nil {
|
||||
base.LogFatalf("failed to spawn bazel run: %v", err)
|
||||
}
|
||||
}(target)
|
||||
}
|
||||
|
||||
// for each target, spawn an ibazel run call
|
||||
for _, target := range ctx.StringSlice("watch-targets") {
|
||||
wg.Add(1)
|
||||
go func(target string) {
|
||||
defer wg.Done()
|
||||
if err := spawnIbazel(target); err != nil {
|
||||
base.LogFatalf("failed to spawn ibazel run: %v", err)
|
||||
}
|
||||
}(target)
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
return nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
app := &cli.App{
|
||||
Name: "taskrunner2",
|
||||
Action: run,
|
||||
Flags: []cli.Flag{
|
||||
&cli.StringSliceFlag{
|
||||
Name: "targets",
|
||||
Aliases: []string{"t"},
|
||||
Usage: "bazel targets to run",
|
||||
},
|
||||
&cli.StringSliceFlag{
|
||||
Name: "watch-targets",
|
||||
Aliases: []string{"w"},
|
||||
Usage: "targets to watch for changes",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
if err := app.Run(os.Args); err != nil {
|
||||
base.LogFatalf("failed to start taskrunner2: %v", err)
|
||||
}
|
||||
}
|
12
go.mod
12
go.mod
@ -2,7 +2,10 @@ module go.resf.org/peridot
|
||||
|
||||
go 1.20
|
||||
|
||||
replace github.com/smartystreets/assertions v1.15.1 => github.com/smarty/assertions v1.15.1
|
||||
|
||||
require (
|
||||
github.com/bazelbuild/bazel-watcher v0.23.7
|
||||
github.com/googleapis/api-linter v1.56.1
|
||||
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0
|
||||
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
|
||||
@ -29,20 +32,27 @@ require (
|
||||
github.com/buger/jsonparser v1.1.1 // indirect
|
||||
github.com/cespare/xxhash/v2 v2.2.0 // indirect
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
|
||||
github.com/fsnotify/fsevents v0.1.1 // indirect
|
||||
github.com/fsnotify/fsnotify v1.6.0 // indirect
|
||||
github.com/gertd/go-pluralize v0.2.1 // indirect
|
||||
github.com/go-logr/logr v1.2.4 // indirect
|
||||
github.com/gogo/protobuf v1.3.2 // indirect
|
||||
github.com/golang/glog v1.1.0 // indirect
|
||||
github.com/golang/protobuf v1.5.3 // indirect
|
||||
github.com/google/gofuzz v1.2.0 // indirect
|
||||
github.com/gopherjs/gopherjs v1.17.2 // indirect
|
||||
github.com/gorilla/websocket v1.5.0 // indirect
|
||||
github.com/iancoleman/strcase v0.3.0 // indirect
|
||||
github.com/jaschaephraim/lrserver v0.0.0-20171129202958-50d19f603f71 // indirect
|
||||
github.com/jhump/protoreflect v1.15.1 // indirect
|
||||
github.com/jmoiron/sqlx v1.3.5 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/jtolds/gls v4.20.0+incompatible // indirect
|
||||
github.com/lib/pq v1.10.9 // indirect
|
||||
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de // indirect
|
||||
github.com/mailru/easyjson v0.7.7 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.9 // indirect
|
||||
github.com/mattn/go-shellwords v1.0.12 // indirect
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
@ -53,6 +63,8 @@ require (
|
||||
github.com/prometheus/procfs v0.10.1 // indirect
|
||||
github.com/russross/blackfriday/v2 v2.1.0 // indirect
|
||||
github.com/sirupsen/logrus v1.9.3 // indirect
|
||||
github.com/smarty/assertions v1.15.1 // indirect
|
||||
github.com/smartystreets/assertions v1.15.1 // indirect
|
||||
github.com/spf13/pflag v1.0.5 // indirect
|
||||
github.com/stoewer/go-strcase v1.3.0 // indirect
|
||||
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
|
||||
|
21
go.sum
21
go.sum
@ -8,6 +8,8 @@ github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230305170008-8188dc5388df h
|
||||
github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230305170008-8188dc5388df/go.mod h1:pSwJ0fSY5KhvocuWSx4fz3BA8OrA1bQn+K1Eli3BRwM=
|
||||
github.com/bahlo/generic-list-go v0.2.0 h1:5sz/EEAK+ls5wF+NeqDpk5+iNdMDXrh3z3nPnH1Wvgk=
|
||||
github.com/bahlo/generic-list-go v0.2.0/go.mod h1:2KvAjgMlE5NNynlg/5iLrrCCZ2+5xWbdbCW3pNTGyYg=
|
||||
github.com/bazelbuild/bazel-watcher v0.23.7 h1:EfJzkMxJuNBGMVdEvkhiW7pAMwhaegbmAMaFCjLjyTw=
|
||||
github.com/bazelbuild/bazel-watcher v0.23.7/go.mod h1:kLJ66pDAR3DVpTPF8Fw3kLQXmxpMT5ll7rbpsFuNmNs=
|
||||
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
|
||||
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
|
||||
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
|
||||
@ -35,6 +37,10 @@ github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.m
|
||||
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
|
||||
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
|
||||
github.com/fergusstrange/embedded-postgres v1.23.0 h1:ZYRD89nammxQDWDi6taJE2CYjDuAoVc1TpEqRIYQryc=
|
||||
github.com/fsnotify/fsevents v0.1.1 h1:/125uxJvvoSDDBPen6yUZbil8J9ydKZnnl3TWWmvnkw=
|
||||
github.com/fsnotify/fsevents v0.1.1/go.mod h1:+d+hS27T6k5J8CRaPLKFgwKYcpS7GwW3Ule9+SC2ZRc=
|
||||
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
|
||||
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
|
||||
github.com/gertd/go-pluralize v0.2.1 h1:M3uASbVjMnTsPb0PNqg+E/24Vwigyo/tvyMTtAlLgiA=
|
||||
github.com/gertd/go-pluralize v0.2.1/go.mod h1:rbYaKDbsXxmRfr8uygAEKhOWsjyrrqrkHVpZvoOp8zk=
|
||||
github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY=
|
||||
@ -77,6 +83,10 @@ github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
|
||||
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/googleapis/api-linter v1.56.1 h1:bxA1SNXfBl5gERSm/ED5m9eqOfDY1YlNmfNiEBJgIS4=
|
||||
github.com/googleapis/api-linter v1.56.1/go.mod h1:zKhUtzO+U44FQ+qKUURbKHL7WpiikvCZ7Q7hhvmZ/mE=
|
||||
github.com/gopherjs/gopherjs v1.17.2 h1:fQnZVsXk8uxXIStYb0N4bGk7jeyTalG/wsZjQ25dO0g=
|
||||
github.com/gopherjs/gopherjs v1.17.2/go.mod h1:pRRIvn/QzFLrKfvEz3qUuEhtE/zLCWfreZ6J5gM2i+k=
|
||||
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
|
||||
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 h1:UH//fgunKIs4JdUbpDl1VZCDaL56wXCB/5+wF6uHfaI=
|
||||
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0/go.mod h1:g5qyo/la0ALbONm6Vbp88Yd8NsDy6rZz+RcrMPxvld8=
|
||||
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 h1:Ovs26xHkKqVztRpIrF/92BcuyuQ/YW4NSIpoGtfXNho=
|
||||
@ -85,6 +95,8 @@ github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.2 h1:dygLcbEBA+t/P7ck6a8AkXv6juQ
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.2/go.mod h1:Ap9RLCIJVtgQg1/BBgVEfypOAySvvlcpcVQkSzJCH4Y=
|
||||
github.com/iancoleman/strcase v0.3.0 h1:nTXanmYxhfFAMjZL34Ov6gkzEsSJZ5DbhxWjvSASxEI=
|
||||
github.com/iancoleman/strcase v0.3.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
|
||||
github.com/jaschaephraim/lrserver v0.0.0-20171129202958-50d19f603f71 h1:24NdJ5N6gtrcoeS4JwLMeruKFmg20QdF/5UnX5S/j18=
|
||||
github.com/jaschaephraim/lrserver v0.0.0-20171129202958-50d19f603f71/go.mod h1:ozZLfjiLmXytkIUh200wMeuoQJ4ww06wN+KZtFP6j3g=
|
||||
github.com/jhump/protoreflect v1.15.1 h1:HUMERORf3I3ZdX05WaQ6MIpd/NJ434hTp5YiKgfCL6c=
|
||||
github.com/jhump/protoreflect v1.15.1/go.mod h1:jD/2GMKKE6OqX8qTjhADU1e6DShO+gavG9e0Q693nKo=
|
||||
github.com/jmoiron/sqlx v1.3.5 h1:vFFPA71p1o5gAeqtEAwLU4dnX2napprKtHr7PYIcN3g=
|
||||
@ -92,6 +104,8 @@ github.com/jmoiron/sqlx v1.3.5/go.mod h1:nRVWtLre0KfCLJvgxzCsLVMogSvQ1zNJtpYr2Cc
|
||||
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
|
||||
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
||||
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
||||
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
|
||||
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
|
||||
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
|
||||
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||
@ -110,6 +124,8 @@ github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0
|
||||
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
|
||||
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
|
||||
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
|
||||
github.com/mattn/go-shellwords v1.0.12 h1:M2zGm7EW6UQJvDeQxo4T51eKPurbeFbe8WtebGE2xrk=
|
||||
github.com/mattn/go-shellwords v1.0.12/go.mod h1:EZzvwXDESEeg03EKmM+RmDnNOPKG4lLtQsUlTZDWQ8Y=
|
||||
github.com/mattn/go-sqlite3 v1.14.6 h1:dNPt6NO46WmLVt2DLNpwczCmdV5boIZ6g/tlDrlRUbg=
|
||||
github.com/mattn/go-sqlite3 v1.14.6/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo=
|
||||
@ -142,6 +158,9 @@ github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQD
|
||||
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
|
||||
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
|
||||
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
|
||||
github.com/smarty/assertions v1.15.1 h1:812oFiXI+G55vxsFf+8bIZ1ux30qtkdqzKbEFwyX3Tk=
|
||||
github.com/smarty/assertions v1.15.1/go.mod h1:yABtdzeQs6l1brC900WlRNwj6ZR55d7B+E8C6HtKdec=
|
||||
github.com/smartystreets/goconvey v1.7.2 h1:9RBaZCeXEQ3UselpuwUQHltGVXvdwm6cv1hgR6gDIPg=
|
||||
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
|
||||
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||
github.com/stoewer/go-strcase v1.3.0 h1:g0eASXYtp+yvN9fK8sH94oCIk0fau9uV1/ZdJ0AVEzs=
|
||||
@ -214,6 +233,7 @@ golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7w
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM=
|
||||
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20220526004731-065cf7ba2467/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
@ -268,6 +288,7 @@ google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqw
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||
gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
|
||||
gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc=
|
||||
gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
|
18
third_party/github.com/bazelbuild/bazel-watcher/internal/ibazel/profiler/BUILD.bazel
vendored
Normal file
18
third_party/github.com/bazelbuild/bazel-watcher/internal/ibazel/profiler/BUILD.bazel
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
load("@io_bazel_rules_go//go:def.bzl", "go_library")
|
||||
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
# keep
|
||||
go_library(
|
||||
name = "profiler",
|
||||
srcs = [
|
||||
"js.go",
|
||||
"profiler.go",
|
||||
],
|
||||
importpath = "github.com/bazelbuild/bazel-watcher/internal/ibazel/profiler", # keep
|
||||
visibility = ["//vendor/github.com/bazelbuild/bazel-watcher:__subpackages__"], # keep
|
||||
deps = [
|
||||
"//vendor/github.com/bazelbuild/bazel-watcher/internal/ibazel/log",
|
||||
"//vendor/github.com/bazelbuild/bazel-watcher/third_party/bazel/master/src/main/protobuf/blaze_query",
|
||||
],
|
||||
)
|
5
third_party/github.com/bazelbuild/bazel-watcher/internal/ibazel/profiler/js.go
vendored
Executable file
5
third_party/github.com/bazelbuild/bazel-watcher/internal/ibazel/profiler/js.go
vendored
Executable file
@ -0,0 +1,5 @@
|
||||
// Generated by go_embed_data for //internal/ibazel/profiler:js. DO NOT EDIT.
|
||||
|
||||
package profiler
|
||||
|
||||
var js = []byte("// Copyright 2017 The Bazel Authors. All rights reserved.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n(function(){\n function extractUrl() {\n return [...window.document.getElementsByTagName('script') ]\n .filter(function(e) { return e.src; })\n .map(function(e) {\n const a = document.createElement('a');\n a.href = e.src;\n return a;\n })\n .filter(function (a) { return a.pathname == \"/profiler.js\"; })\n .map(function (a) { return `${a.protocol}//${a.host}/profiler-event`; })\n .reduce(function(acc, u) { return acc || u; });\n };\n\n const profilerEventUrl = extractUrl();\n if (!profilerEventUrl) {\n this.console.error(\"iBazel profiler disabled because it could not find its own <SCRIPT> tag\");\n return;\n }\n\n if (!window.navigator.sendBeacon) {\n console.error(\n \"iBazel profiler disabled because Beacon API is not available\")\n return;\n }\n\n function profilerEvent(eventType, eventData) {\n if (!eventType || typeof eventType != 'string') {\n console.error(\"Invalid iBazel profiler event type\", eventType);\n return;\n }\n if (typeof eventData == 'object') {\n eventData = JSON.stringify(eventData)\n }\n const event = { type: eventType, time: Date.now() };\n event.timeSinceNavigationStart = event.time - window.performance.timing.navigationStart;\n if (eventData) {\n event.data = eventData.toString();\n }\n const data = JSON.stringify(event)\n if (!window.navigator.sendBeacon(profilerEventUrl, data)) {\n console.error(\"Failed to send profile data to \", profilerEventUrl);\n }\n }\n\n // Expose a public window.IBazelProfileEvent API for the user space to be\n // able to send profile events\n window.IBazelProfileEvent = profilerEvent;\n\n window.addEventListener(\"load\", function() {\n let timing = window.performance.timing;\n\n profilerEvent(\"PAGE_LOAD\", {\n // deltas\n pageLoadTime: timing.loadEventStart - timing.navigationStart, // loadEventEnd is not set yet\n fetchTime: timing.responseEnd - timing.fetchStart,\n connectTime: timing.connectEnd - timing.connectStart,\n requestTime: timing.responseEnd - timing.requestStart,\n responseTime: timing.responseEnd - timing.responseStart,\n renderTime: timing.domComplete - timing.domLoading,\n\n // absolutes\n navigationStart: timing.navigationStart,\n unloadEventStart: timing.unloadEventStart,\n unloadEventEnd: timing.unloadEventEnd,\n redirectStart: timing.redirectStart,\n redirectEnd: timing.redirectEnd,\n fetchStart: timing.fetchStart,\n domainLookupStart: timing.domainLookupStart,\n domainLookupEnd: timing.domainLookupEnd,\n connectStart: timing.connectStart,\n connectEnd: timing.connectEnd,\n secureConnectionStart: timing.secureConnectionStart,\n requestStart: timing.requestStart,\n responseStart: timing.responseStart,\n responseEnd: timing.responseEnd,\n domLoading: timing.domLoading,\n domInteractive: timing.domInteractive,\n domContentLoadedEventStart: timing.domContentLoadedEventStart,\n domContentLoadedEventEnd: timing.domContentLoadedEventEnd,\n domComplete: timing.domComplete,\n loadEventStart: timing.loadEventStart,\n });\n }, false);\n})();")
|
427
third_party/github.com/bazelbuild/bazel-watcher/internal/ibazel/profiler/profiler.go
vendored
Normal file
427
third_party/github.com/bazelbuild/bazel-watcher/internal/ibazel/profiler/profiler.go
vendored
Normal file
@ -0,0 +1,427 @@
|
||||
// Copyright 2017 The Bazel Authors. All rights reserved.
|
||||
//
|
||||
// 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 profiler
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
golog "log"
|
||||
"math/rand"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"strconv"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/bazelbuild/bazel-watcher/internal/ibazel/log"
|
||||
"github.com/bazelbuild/bazel-watcher/third_party/bazel/master/src/main/protobuf/blaze_query"
|
||||
)
|
||||
|
||||
var profileDev = flag.String("profile_dev", "", "Turn on profiling and append report to file")
|
||||
|
||||
const (
|
||||
|
||||
// DefaultPort is the profiler Server's default server port
|
||||
DefaultPort uint16 = 30000
|
||||
)
|
||||
|
||||
type Profiler struct {
|
||||
server *http.Server
|
||||
file *os.File
|
||||
version string
|
||||
targets []string
|
||||
iteration string
|
||||
iterationStartTime int64
|
||||
iterationBuildStart bool
|
||||
iterationReloadTriggered bool
|
||||
changes []string
|
||||
lock sync.Mutex // guards events
|
||||
}
|
||||
|
||||
type profileEvent struct {
|
||||
// common
|
||||
Type string `json:"type"`
|
||||
Iteration string `json:"iteration"`
|
||||
Time int64 `json:"time"`
|
||||
Targets []string `json:"targets,omitempty"`
|
||||
Elapsed int64 `json:"elapsed,omitempty"`
|
||||
|
||||
// start event
|
||||
IBazelVersion string `json:"iBazelVersion,omitempty"`
|
||||
BazelVersion string `json:"bazelVersion,omitempty"`
|
||||
MaxHeapSize string `json:"maxHeapSize,omitempty"`
|
||||
CommittedHeapSize string `json:"committedHeapSize,omitempty"`
|
||||
|
||||
// change event
|
||||
Change string `json:"change,omitempty"`
|
||||
|
||||
// build & reload event
|
||||
Changes []string `json:"changes,omitempty"`
|
||||
|
||||
// browser event
|
||||
RemoteType string `json:"remoteType,omitempty"`
|
||||
RemoteTime int64 `json:"remoteTime,omitempty"`
|
||||
RemoteElapsed int64 `json:"remoteElapsed,omitempty"`
|
||||
RemoteData string `json:"remoteData,omitempty"`
|
||||
}
|
||||
|
||||
type profilerRemoteEvent struct {
|
||||
Type string `json:"type"`
|
||||
Time int64 `json:"time"`
|
||||
TimeSinceNavigationStart int64 `json:"timeSinceNavigationStart"`
|
||||
Data string `json:"data"`
|
||||
}
|
||||
|
||||
func New(version string) *Profiler {
|
||||
p := &Profiler{}
|
||||
p.version = version
|
||||
return p
|
||||
}
|
||||
|
||||
func (i *Profiler) Initialize(info *map[string]string) {
|
||||
if *profileDev == "" {
|
||||
return
|
||||
}
|
||||
|
||||
var err error
|
||||
i.file, err = os.OpenFile(*profileDev, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644)
|
||||
if err != nil {
|
||||
log.Errorf("Failed to open profile output file: %s", *profileDev)
|
||||
return
|
||||
}
|
||||
|
||||
log.Errorf("Profile output: %s", *profileDev)
|
||||
|
||||
i.iterationBuildStart = true
|
||||
i.newIteration()
|
||||
i.startEvent(info)
|
||||
i.startProfilerServer()
|
||||
}
|
||||
|
||||
func (i *Profiler) TargetDecider(rule *blaze_query.Rule) {}
|
||||
|
||||
func (i *Profiler) ChangeDetected(targets []string, changeType string, change string) {
|
||||
if i.file == nil {
|
||||
return
|
||||
}
|
||||
i.targets = targets
|
||||
switch changeType {
|
||||
case "source":
|
||||
i.changeEvent("SOURCE_CHANGE", change)
|
||||
case "graph":
|
||||
i.changeEvent("GRAPH_CHANGE", change)
|
||||
}
|
||||
}
|
||||
|
||||
func (i *Profiler) BeforeCommand(targets []string, command string) {
|
||||
if i.file == nil {
|
||||
return
|
||||
}
|
||||
i.targets = targets
|
||||
switch command {
|
||||
case "build":
|
||||
i.buildEvent("BUILD_START")
|
||||
case "test":
|
||||
i.buildEvent("TEST_START")
|
||||
case "run":
|
||||
i.buildEvent("RUN_START")
|
||||
}
|
||||
}
|
||||
|
||||
func (i *Profiler) AfterCommand(targets []string, command string, success bool, output *bytes.Buffer) {
|
||||
if i.file == nil {
|
||||
return
|
||||
}
|
||||
i.targets = targets
|
||||
if success {
|
||||
switch command {
|
||||
case "build":
|
||||
i.buildEvent("BUILD_DONE")
|
||||
case "test":
|
||||
i.buildEvent("TEST_DONE")
|
||||
case "run":
|
||||
i.buildEvent("RUN_DONE")
|
||||
}
|
||||
} else {
|
||||
switch command {
|
||||
case "build":
|
||||
i.buildEvent("BUILD_FAILED")
|
||||
case "test":
|
||||
i.buildEvent("TEST_FAILED")
|
||||
case "run":
|
||||
i.buildEvent("RUN_FAILED")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (i *Profiler) Cleanup() {
|
||||
if i.file != nil {
|
||||
i.file.Close()
|
||||
}
|
||||
i.closeServer()
|
||||
}
|
||||
|
||||
func (i *Profiler) ReloadTriggered(targets []string) {
|
||||
if i.file == nil {
|
||||
return
|
||||
}
|
||||
i.targets = targets
|
||||
i.reloadTriggeredEvent()
|
||||
}
|
||||
|
||||
func (i *Profiler) startProfilerServer() {
|
||||
port := DefaultPort
|
||||
for ; port < DefaultPort+100; port++ {
|
||||
if testPort(port) {
|
||||
go func() {
|
||||
err := i.listen(port)
|
||||
if err != nil {
|
||||
log.Errorf("Profiler server failed to start: %v", err)
|
||||
}
|
||||
}()
|
||||
url := fmt.Sprintf("http://localhost:%d/profiler.js", port)
|
||||
os.Setenv("IBAZEL_PROFILER_URL", url)
|
||||
return
|
||||
}
|
||||
}
|
||||
log.Log("Could not find open port for profiler server")
|
||||
}
|
||||
|
||||
func (i *Profiler) listen(port uint16) error {
|
||||
if i.server != nil {
|
||||
return errors.New("Profiler already listening")
|
||||
}
|
||||
|
||||
// Create router
|
||||
router := http.NewServeMux()
|
||||
|
||||
// Create server
|
||||
i.server = &http.Server{
|
||||
Handler: router,
|
||||
ErrorLog: golog.New(os.Stderr, "[profiler]", 0),
|
||||
}
|
||||
i.server.Addr = makeAddr(port)
|
||||
|
||||
// Handle profiler.js requests
|
||||
router.HandleFunc("/profiler.js", i.jsHandler)
|
||||
|
||||
// Handle profiler events
|
||||
router.HandleFunc("/profiler-event", i.profilerEventHandler)
|
||||
|
||||
// Create listener
|
||||
l, err := net.Listen("tcp", makeAddr(port))
|
||||
if err != nil {
|
||||
i.closeServer()
|
||||
return err
|
||||
}
|
||||
|
||||
log.Logf("[profiler] listening on %s", i.server.Addr)
|
||||
err = i.server.Serve(l)
|
||||
i.closeServer()
|
||||
return err
|
||||
}
|
||||
|
||||
func (i *Profiler) startEvent(info *map[string]string) {
|
||||
event := profileEvent{}
|
||||
event.Type = "IBAZEL_START"
|
||||
if info != nil {
|
||||
event.IBazelVersion = i.version
|
||||
event.BazelVersion = (*info)["release"]
|
||||
event.MaxHeapSize = (*info)["max-heap-size"]
|
||||
event.CommittedHeapSize = (*info)["committed-heap-size"]
|
||||
}
|
||||
i.lock.Lock()
|
||||
i.processEvent(&event)
|
||||
i.lock.Unlock()
|
||||
}
|
||||
|
||||
func (i *Profiler) buildEvent(eventType string) {
|
||||
i.lock.Lock()
|
||||
i.buildingIteration()
|
||||
event := profileEvent{}
|
||||
event.Type = eventType
|
||||
event.Changes = i.changes
|
||||
i.processEvent(&event)
|
||||
i.lock.Unlock()
|
||||
}
|
||||
|
||||
func (i *Profiler) changeEvent(eventType string, change string) {
|
||||
i.lock.Lock()
|
||||
i.newIteration()
|
||||
event := profileEvent{}
|
||||
event.Type = eventType
|
||||
event.Change = change
|
||||
i.processEvent(&event)
|
||||
i.changes = append(i.changes, change)
|
||||
i.lock.Unlock()
|
||||
}
|
||||
|
||||
func (i *Profiler) reloadTriggeredEvent() {
|
||||
i.lock.Lock()
|
||||
i.iterationReloadTriggered = true
|
||||
event := profileEvent{}
|
||||
event.Type = "RELOAD_TRIGGERED"
|
||||
event.Changes = i.changes
|
||||
i.processEvent(&event)
|
||||
i.lock.Unlock()
|
||||
}
|
||||
|
||||
func (i *Profiler) remoteEvent(remoteEvent *profilerRemoteEvent) {
|
||||
i.lock.Lock()
|
||||
if !i.iterationReloadTriggered {
|
||||
log.Logf("Ignoring unexpected remote event")
|
||||
return
|
||||
}
|
||||
event := profileEvent{}
|
||||
event.Type = "REMOTE_EVENT"
|
||||
event.RemoteType = remoteEvent.Type
|
||||
event.RemoteTime = remoteEvent.Time
|
||||
event.RemoteElapsed = remoteEvent.TimeSinceNavigationStart
|
||||
event.RemoteData = remoteEvent.Data
|
||||
i.processEvent(&event)
|
||||
i.lock.Unlock()
|
||||
}
|
||||
|
||||
func (i *Profiler) processEvent(event *profileEvent) {
|
||||
if i.file != nil && event != nil {
|
||||
// prepare the event
|
||||
event.Iteration = i.iteration
|
||||
event.Time = makeTimestamp()
|
||||
event.Targets = i.targets
|
||||
event.Elapsed = event.Time - i.iterationStartTime
|
||||
|
||||
// write the event to the output file
|
||||
eventJson, _ := json.Marshal(event)
|
||||
eventJson = append(eventJson, 10) // \n
|
||||
_, err := i.file.Write(eventJson)
|
||||
if err != nil {
|
||||
log.Errorf("Error writing to profile file: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (i *Profiler) newIteration() {
|
||||
if i.iterationBuildStart {
|
||||
i.iteration = randomString(16)
|
||||
i.changes = make([]string, 0, 100)
|
||||
i.iterationStartTime = makeTimestamp()
|
||||
i.iterationBuildStart = false
|
||||
i.iterationReloadTriggered = false
|
||||
}
|
||||
}
|
||||
|
||||
func (i *Profiler) buildingIteration() {
|
||||
i.iterationBuildStart = true
|
||||
}
|
||||
|
||||
func (i *Profiler) jsHandler(rw http.ResponseWriter, req *http.Request) {
|
||||
if req.Method != "GET" {
|
||||
log.Errorf("profiler.js invalid request method: %s", req.Method)
|
||||
rw.WriteHeader(http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
|
||||
rw.Header().Set("Content-Type", "application/javascript")
|
||||
_, err := rw.Write(js)
|
||||
if err != nil {
|
||||
log.Errorf("Error handling profile.js request: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (i *Profiler) profilerEventHandler(rw http.ResponseWriter, req *http.Request) {
|
||||
if req.Method != "POST" {
|
||||
log.Errorf("Profiler invalid request method: %s", req.Method)
|
||||
rw.WriteHeader(http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
|
||||
defer req.Body.Close()
|
||||
decoder := json.NewDecoder(req.Body)
|
||||
var remoteEvent profilerRemoteEvent
|
||||
err := decoder.Decode(&remoteEvent)
|
||||
|
||||
if err != nil {
|
||||
log.Errorf("Failed to decode profile post data: %v", err)
|
||||
rw.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
log.Logf("Remote event: %s", remoteEvent.Type)
|
||||
i.remoteEvent(&remoteEvent)
|
||||
}
|
||||
|
||||
func (i *Profiler) closeServer() {
|
||||
if i.server != nil {
|
||||
err := i.server.Close()
|
||||
if err != nil {
|
||||
log.Errorf("Error closing profiler server: %v", err)
|
||||
}
|
||||
i.server = nil
|
||||
}
|
||||
}
|
||||
|
||||
// makeAddr converts uint16(x) to ":x"
|
||||
func makeAddr(port uint16) string {
|
||||
return fmt.Sprintf(":%d", port)
|
||||
}
|
||||
|
||||
func makeTimestamp() int64 {
|
||||
return time.Now().UnixNano() / int64(time.Millisecond)
|
||||
}
|
||||
|
||||
func testPort(port uint16) bool {
|
||||
ln, err := net.Listen("tcp", ":"+strconv.FormatInt(int64(port), 10))
|
||||
|
||||
if err != nil {
|
||||
log.Errorf("Error opening port %d: %v", port, err)
|
||||
return false
|
||||
}
|
||||
|
||||
ln.Close()
|
||||
return true
|
||||
}
|
||||
|
||||
const letterBytes = "0123456789abcdef"
|
||||
const (
|
||||
letterIdxBits = 6 // 6 bits to represent a letter index
|
||||
letterIdxMask = 1<<letterIdxBits - 1 // All 1-bits, as many as letterIdxBits
|
||||
letterIdxMax = 63 / letterIdxBits // # of letter indices fitting in 63 bits
|
||||
)
|
||||
|
||||
var randSrc = rand.NewSource(time.Now().UnixNano())
|
||||
|
||||
// Fast random string generator
|
||||
// See: https://stackoverflow.com/questions/22892120/how-to-generate-a-random-string-of-a-fixed-length-in-golang
|
||||
func randomString(n int) string {
|
||||
b := make([]byte, n)
|
||||
// A randSrc.Int63() generates 63 random bits, enough for letterIdxMax characters!
|
||||
for i, cache, remain := n-1, randSrc.Int63(), letterIdxMax; i >= 0; {
|
||||
if remain == 0 {
|
||||
cache, remain = randSrc.Int63(), letterIdxMax
|
||||
}
|
||||
if idx := int(cache & letterIdxMask); idx < len(letterBytes) {
|
||||
b[i] = letterBytes[idx]
|
||||
i--
|
||||
}
|
||||
cache >>= letterIdxBits
|
||||
remain--
|
||||
}
|
||||
|
||||
return string(b)
|
||||
}
|
@ -11,4 +11,3 @@
|
||||
# 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.
|
||||
|
||||
|
@ -20,4 +20,6 @@ import (
|
||||
_ "github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
|
||||
// api-linter
|
||||
_ "github.com/googleapis/api-linter/cmd/api-linter"
|
||||
// ibazel
|
||||
_ "github.com/bazelbuild/bazel-watcher/cmd/ibazel"
|
||||
)
|
||||
|
9
vendor/github.com/bazelbuild/bazel-watcher/AUTHORS
generated
vendored
Normal file
9
vendor/github.com/bazelbuild/bazel-watcher/AUTHORS
generated
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
# This the official list of Bazel authors for copyright purposes.
|
||||
# This file is distinct from the CONTRIBUTORS files.
|
||||
# See the latter for an explanation.
|
||||
|
||||
# Names should be added to this file as:
|
||||
# Name or Organization <email address>
|
||||
# The email address is not required for organizations.
|
||||
|
||||
Google Inc.
|
33
vendor/github.com/bazelbuild/bazel-watcher/CONTRIBUTORS
generated
vendored
Normal file
33
vendor/github.com/bazelbuild/bazel-watcher/CONTRIBUTORS
generated
vendored
Normal file
@ -0,0 +1,33 @@
|
||||
# People who have agreed to one of the CLAs and can contribute patches.
|
||||
# The AUTHORS file lists the copyright holders; this file
|
||||
# lists people. For example, Google employees are listed here
|
||||
# but not in AUTHORS, because Google holds the copyright.
|
||||
#
|
||||
# https://developers.google.com/open-source/cla/individual
|
||||
# https://developers.google.com/open-source/cla/corporate
|
||||
#
|
||||
# Names should be added to this file as:
|
||||
# Name <email address>
|
||||
|
||||
Alex Eagle <alexeagle@google.com>
|
||||
Andrew Z Allen <achew@google.com>
|
||||
Bor Kae Hwang <borkaehw@lucidchart.com>
|
||||
Brendan Ryan <brendanjryan@users.noreply.github.com>
|
||||
Clint Harrison <243356+clintharrison@users.noreply.github.com>
|
||||
Cody Schroeder <schroederc@google.com>
|
||||
Doug Koch <doug@dougkoch.me>
|
||||
Greg Magolan <gmagolan@gmail.com>
|
||||
Igor Minar <iminar@google.com>
|
||||
Jakob Buchgraber <buchgr@google.com>
|
||||
Jason Banich <Jdban101@gmail.com>
|
||||
Jeff Hodges <jeff@somethingsimilar.com>
|
||||
Justin Buchanan <justbuchanan@gmail.com>
|
||||
Markus Padourek <markus.padourek@gmail.com>
|
||||
Martin Probst <martinprobst@google.com>
|
||||
Matt Moore <mattmoor@google.com>
|
||||
Matti Mehtonen <matti@vanils.fi>
|
||||
mrmeku <mrmeku@gmail.com>
|
||||
Steren Giannini <steren.giannini@gmail.com>
|
||||
Vladimir Moskva <vladmos@users.noreply.github.com>
|
||||
Wael M. Nasreddine <wael.nasreddine@gmail.com>
|
||||
Xavier Décoret <475285+Xadeck@users.noreply.github.com>
|
201
vendor/github.com/bazelbuild/bazel-watcher/LICENSE
generated
vendored
Normal file
201
vendor/github.com/bazelbuild/bazel-watcher/LICENSE
generated
vendored
Normal file
@ -0,0 +1,201 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
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.
|
51
vendor/github.com/bazelbuild/bazel-watcher/cmd/ibazel/BUILD.bazel
generated
vendored
Normal file
51
vendor/github.com/bazelbuild/bazel-watcher/cmd/ibazel/BUILD.bazel
generated
vendored
Normal file
@ -0,0 +1,51 @@
|
||||
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
|
||||
|
||||
go_library(
|
||||
name = "ibazel_lib",
|
||||
srcs = [
|
||||
"main.go",
|
||||
"main_bsd.go",
|
||||
"main_linux.go",
|
||||
"main_unix.go",
|
||||
"main_windows.go",
|
||||
],
|
||||
importmap = "go.resf.org/peridot/vendor/github.com/bazelbuild/bazel-watcher/cmd/ibazel",
|
||||
importpath = "github.com/bazelbuild/bazel-watcher/cmd/ibazel",
|
||||
visibility = ["//visibility:private"],
|
||||
deps = [
|
||||
"//vendor/github.com/bazelbuild/bazel-watcher/internal/ibazel",
|
||||
"//vendor/github.com/bazelbuild/bazel-watcher/internal/ibazel/log",
|
||||
] + select({
|
||||
"@io_bazel_rules_go//go/platform:android": [
|
||||
"//vendor/golang.org/x/sys/unix",
|
||||
],
|
||||
"@io_bazel_rules_go//go/platform:darwin": [
|
||||
"//vendor/golang.org/x/sys/unix",
|
||||
],
|
||||
"@io_bazel_rules_go//go/platform:dragonfly": [
|
||||
"//vendor/golang.org/x/sys/unix",
|
||||
],
|
||||
"@io_bazel_rules_go//go/platform:freebsd": [
|
||||
"//vendor/golang.org/x/sys/unix",
|
||||
],
|
||||
"@io_bazel_rules_go//go/platform:ios": [
|
||||
"//vendor/golang.org/x/sys/unix",
|
||||
],
|
||||
"@io_bazel_rules_go//go/platform:linux": [
|
||||
"//vendor/golang.org/x/sys/unix",
|
||||
],
|
||||
"@io_bazel_rules_go//go/platform:netbsd": [
|
||||
"//vendor/golang.org/x/sys/unix",
|
||||
],
|
||||
"@io_bazel_rules_go//go/platform:openbsd": [
|
||||
"//vendor/golang.org/x/sys/unix",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
)
|
||||
|
||||
go_binary(
|
||||
name = "ibazel",
|
||||
embed = [":ibazel_lib"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
239
vendor/github.com/bazelbuild/bazel-watcher/cmd/ibazel/main.go
generated
vendored
Normal file
239
vendor/github.com/bazelbuild/bazel-watcher/cmd/ibazel/main.go
generated
vendored
Normal file
@ -0,0 +1,239 @@
|
||||
// Copyright 2017 The Bazel Authors. All rights reserved.
|
||||
//
|
||||
// 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
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/bazelbuild/bazel-watcher/internal/ibazel"
|
||||
"github.com/bazelbuild/bazel-watcher/internal/ibazel/log"
|
||||
)
|
||||
|
||||
var Version = "Development"
|
||||
|
||||
var overrideableStartupFlags []string = []string{
|
||||
"--bazelrc",
|
||||
"--home_rc",
|
||||
"--nohome_rc",
|
||||
"--output_base",
|
||||
}
|
||||
|
||||
var overrideableBazelFlags []string = []string{
|
||||
"--action_env",
|
||||
"--announce_rc",
|
||||
"--aspects",
|
||||
"--build_tag_filters=",
|
||||
"--build_tests_only",
|
||||
"--check_visibility=",
|
||||
"--compilation_mode",
|
||||
"--compile_one_dependency",
|
||||
"--config=",
|
||||
"--copt=",
|
||||
"--curses=",
|
||||
"--cxxopt",
|
||||
"-c",
|
||||
"--define=",
|
||||
"--dynamic_mode=",
|
||||
"--features=",
|
||||
"--flaky_test_attempts=",
|
||||
"--host_jvmopt",
|
||||
"--isatty=",
|
||||
"--jvmopt",
|
||||
"--keep_going",
|
||||
"-k",
|
||||
"--nocache_test_results",
|
||||
"--nostamp",
|
||||
"--output_groups=",
|
||||
"--override_repository=",
|
||||
"--platforms",
|
||||
"--repo_env",
|
||||
"--runs_per_test=",
|
||||
"--run_under=",
|
||||
"--show_result=",
|
||||
"--stamp",
|
||||
"--strategy=",
|
||||
"--target_pattern_file=",
|
||||
"--test_arg=",
|
||||
"--test_env=",
|
||||
"--test_filter=",
|
||||
"--test_lang_filters=",
|
||||
"--test_output=",
|
||||
"--test_tag_filters=",
|
||||
"--test_timeout=",
|
||||
// Custom Starlark build settings
|
||||
// https://docs.bazel.build/versions/master/skylark/config.html#using-build-settings-on-the-command-line
|
||||
"--//",
|
||||
"--no//",
|
||||
}
|
||||
|
||||
var debounceDuration = flag.Duration("debounce", 100*time.Millisecond, "Debounce duration")
|
||||
var logToFile = flag.String("log_to_file", "-", "Log iBazel stderr to a file instead of os.Stderr")
|
||||
|
||||
func usage() {
|
||||
fmt.Fprintf(os.Stderr, `iBazel - Version %s
|
||||
|
||||
A file watcher for Bazel. Whenever a source file used in a specified
|
||||
target changes, run, build, or test the specified targets.
|
||||
|
||||
Usage:
|
||||
|
||||
ibazel build|test|run [flags] targets...
|
||||
|
||||
Example:
|
||||
|
||||
ibazel test //path/to/my/testing:target
|
||||
ibazel test //path/to/my/testing/targets/...
|
||||
ibazel run //path/to/my/runnable:target -- --arguments --for_your=binary
|
||||
ibazel build //path/to/my/buildable:target
|
||||
|
||||
Supported Bazel startup flags:
|
||||
%s
|
||||
|
||||
Supported Bazel command flags:
|
||||
%s
|
||||
|
||||
To add to this list, edit
|
||||
https://github.com/bazelbuild/bazel-watcher/blob/master/ibazel/main.go
|
||||
|
||||
iBazel flags:
|
||||
`, Version, strings.Join(overrideableStartupFlags, "\n "), strings.Join(overrideableBazelFlags, "\n "))
|
||||
flag.PrintDefaults()
|
||||
}
|
||||
|
||||
func isOverrideable(arg string, overrideables []string) bool {
|
||||
for _, overrideable := range overrideables {
|
||||
if strings.HasPrefix(arg, overrideable) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func isOverrideableStartupFlag(arg string) bool {
|
||||
return isOverrideable(arg, overrideableStartupFlags)
|
||||
}
|
||||
|
||||
func isOverrideableBazelFlag(arg string) bool {
|
||||
return isOverrideable(arg, overrideableBazelFlags)
|
||||
}
|
||||
|
||||
func parseArgs(in []string) (targets, startupArgs, bazelArgs, args []string) {
|
||||
afterDoubleDash := false
|
||||
for _, arg := range in {
|
||||
if afterDoubleDash {
|
||||
// Put it in the extra args section if we are after a double dash.
|
||||
args = append(args, arg)
|
||||
} else {
|
||||
// Check to see if this token is a double dash.
|
||||
if arg == "--" {
|
||||
afterDoubleDash = true
|
||||
continue
|
||||
}
|
||||
|
||||
// Check to see if this startup option or command flag is on the bazel whitelist of flags.
|
||||
if isOverrideableStartupFlag(arg) {
|
||||
startupArgs = append(startupArgs, arg)
|
||||
} else if isOverrideableBazelFlag(arg) {
|
||||
bazelArgs = append(bazelArgs, arg)
|
||||
} else {
|
||||
// If none of those things then it's probably a target.
|
||||
targets = append(targets, arg)
|
||||
}
|
||||
}
|
||||