blob: cdeb675bb5df6c3c9a398a904af0081ceccc3971 [file] [log] [blame] [edit]
load("@aspect_rules_js//js:defs.bzl", "js_library")
load("@aspect_rules_ts//ts:defs.bzl", "ts_config")
load("@bazel_gazelle//:def.bzl", "gazelle")
load("@com_github_bazelbuild_buildtools//buildifier:def.bzl", "buildifier")
load("@exec_properties//:constants.bzl", "NETWORK_ON")
load("@npm//:defs.bzl", "npm_link_all_packages")
# Disable generation of go_proto_library targets. Let Gazelle use checked-in .pb.go files instead.
#
# We opt out of this feature for the following reasons:
#
# 1) Generated files are invisible to code editors and IDEs, which breaks features such as code
# completion, automated refactors, etc. This can be fixed with editor plugins (see
# https://github.com/bazelbuild/rules_go/issues/512), but none are available at this time.
#
# 2) Leveraging the preexisting, checked-in .pb.go is the fastest way to roll out Bazel as the build
# system for our repository, and is the recommended approach for already established projects, or
# for projects that also need to build with "go build". See
# https://github.com/bazelbuild/rules_go/blob/master/proto/core.rst#option-2-use-pre-generated-pbgo-files.
#
# In the future, we might decide to leverage Gazelle's generation of go_proto_library rules. To
# address point 1) above, a potential approach is to check in any files generated via
# go_proto_library targets. This works because if there's a source file checked in the repository,
# and a build target that generates a file of the same name, Bazel will ignore the checked in file
# and use the generated file instead. To keep the checked in and generated files in sync, a rule
# such as generated_file_test can be used, as mentioned here:
# https://github.com/bazelbuild/rules_go/issues/512#issuecomment-747844469.
#
# Documentation for this directive: https://github.com/bazelbuild/bazel-gazelle#directives.
#
# gazelle:proto disable
# This directive tells Gazelle to use a custom macro instead of rules_go's go_test rule for any
# Gazelle-generated Go test targets.
#
# The custom macro generates separate go_test targets for manual Go tests, which will be tagged as
# manual. The macro relies on the assumption that any manual test cases will be placed on Go source
# files ending in "_manual_test.go". If the test target does not contain any manual test, the
# custom macro behaves exactly like rules_go's go_test rule.
#
# See the macro's docstring for details.
#
# Documentation for this directive: https://github.com/bazelbuild/bazel-gazelle#directives.
#
# gazelle:map_kind go_test go_test //bazel/go:go_test.bzl
# Exclude directories with Bazel outputs. The "_bazel_" prefix is defined in //.bazelrc.
#
# Without this, Gazelle can take several minutes to complete.
#
# gazelle:exclude _bazel_*
# Exclude directory generated by rbe_configs_gen.
# gazelle:exclude bazel/rbe/generated
# The new_element directory has templates which do not compile/run.
# gazelle:exclude new_element*
# gazelle:prefix go.skia.org/infra
gazelle(
name = "gazelle",
# We use a custom Gazelle binary that adds support for our front-end Bazel rules and macros.
gazelle = "//bazel/gazelle",
)
exports_files(
[
"package.json",
"tsconfig.json",
".puppeteerrc.js",
],
visibility = ["//visibility:public"],
)
buildifier(
name = "buildifier",
exclude_patterns = [
"./bazel/rbe/generated/*",
"./node_modules/*",
"./**/node_modules/*",
],
lint_mode = "warn",
)
############################
# Custom platform for RBE. #
############################
platform(
name = "rbe_custom_platform",
# Enable networking. Without this, tests that require network access will fail. Examples include
# go_test targets that try to clone the Skia Git repo from https://skia.googlesource.com/skia,
# tests that hit GCS, etc.
#
# See https://github.com/bazelbuild/bazel-toolchains/tree/master/rules/exec_properties.
#
# Note that depending on network resources breaks test hermeticity.
exec_properties = NETWORK_ON,
# Extend the platform generated with "rbe_configs_gen".
#
# See //bazel/rbe/generated/README.md for details.
parents = ["//bazel/rbe/generated/config:platform"],
)
######################################
# JavaScript and TypeScript support. #
######################################
# Make NPM packages available as dependencies under //:node_modules.
npm_link_all_packages(name = "node_modules")
# Global tsconfig.json file.
ts_config(
name = "ts_config",
src = "tsconfig.json",
visibility = ["//visibility:public"],
)
# Global Puppeteer configuration file.
js_library(
name = "puppeteer_rc",
srcs = [".puppeteerrc.js"],
visibility = ["//visibility:public"],
)
#############################################################################
# Utility tool to extract screenshots taken by Puppeteer tests under Bazel. #
#############################################################################
# Wrapper script so we can invoke the tool from the workspace root, instead of the directory where
# the tool's go_binary target is located.
genrule(
name = "extract_puppeteer_screenshots_wrapper_script",
srcs = ["//puppeteer-tests/bazel/extract_puppeteer_screenshots"],
outs = ["extract_puppeteer_screenshots.sh"],
cmd = " && ".join([
# The $@ variable holds the path to the genrule's only output file. The $$@ variable is the
# shell's $@ variable ($-escaped), which is used here to pipe through to the underlying Go
# program any command-line arguments passed to the wrapper shell script.
#
# See https://docs.bazel.build/versions/master/be/general.html#genrule.
"echo '#!/bin/bash' >> $@",
"echo '$(rootpath //puppeteer-tests/bazel/extract_puppeteer_screenshots) $$@' >> $@",
]),
)
# Usage: "bazel run //:extract_puppeteer_screenshots -- --output_dir=<output directory>".
sh_binary(
name = "extract_puppeteer_screenshots",
srcs = ["extract_puppeteer_screenshots.sh"],
data = ["//puppeteer-tests/bazel/extract_puppeteer_screenshots"],
)
#####################################
# Puppeteer screenshot viewer tool. #
#####################################
# Usage: "bazel run //:puppeteer_screenshot_server".
alias(
name = "puppeteer_screenshot_server",
actual = "//puppeteer-tests/bazel/puppeteer_screenshot_server",
visibility = ["//visibility:public"],
)
##################
# Miscellaneous. #
##################
# This rule is a convenient way to build all the task drivers and copy them all into a single
# place as a tar folder. Otherwise, we would need to run many separate bazel build commands and
# then fish the executables out of a deep folder structure like:
# _bazel_bin/infra/bots/task_drivers/bazel_build_all/bazel_build_all_/bazel_build_all
# After this runs, the executables will all be in //_bazel_bin/built_task_drivers.tar
# Why the tar file? Windows binaries are created with .exe and other platforms are not. However,
# outs *must* be static, thus we cannot use a select. Bazel requires us to define all outputs
# exactly, so the only way to support files with different names on different platforms is to
# package them up into a file with the same name.
# Cross compilation is handled as per https://github.com/bazelbuild/rules_go#how-do-i-cross-compile
genrule(
name = "all_task_drivers",
srcs = [
"//infra/bots/task_drivers/bazel_build_all",
"//infra/bots/task_drivers/bazel_test_all",
"//infra/bots/task_drivers/build_and_deploy_cipd",
"//infra/bots/task_drivers/build_push_docker_image",
"//infra/bots/task_drivers/canary",
"//infra/bots/task_drivers/command_wrapper",
"//infra/bots/task_drivers/presubmit",
],
outs = ["built_task_drivers.tar"],
# Make a temporary directory in the output directory, as recommended by
# https://bazel.build/reference/be/make-variables#predefined_genrule_variables
# Reminder that $(@D) refers to that output directory and $(SRCS) refers to all
# the input files, in a space separated list.
cmd = "mkdir -p $(@D)/tmp_task_drivers && " +
# Copy all the task drivers to the same folder
"cp $(SRCS) $(@D)/tmp_task_drivers && " +
# Tar them up from that folder (so they will be in the top level of the tar directory)
# The parent directory of our temp directory is where the output tar file should go.
"cd $(@D)/tmp_task_drivers && tar --file ../built_task_drivers.tar --create . && " +
# Delete the temp folder (as per the recommendation above)
"cd .. && rm -rf tmp_task_drivers",
)
######
# go #
######
# Sample usage: "bazel run //:go -- generate ./...".
alias(
name = "go",
actual = "//bazel/tools/go",
visibility = ["//visibility:public"],
)
#########
# gofmt #
#########
# Sample usage: "bazel run //:gofmt -- -s -w .".
alias(
name = "gofmt",
actual = "@go_sdk//:bin/gofmt",
visibility = ["//visibility:public"],
)
#############
# goimports #
#############
# Sample usage: "bazel run //:goimports "--run_under=cd $PWD &&" -- -w myfile.go".
alias(
name = "goimports",
actual = "@org_golang_x_tools//cmd/goimports",
visibility = ["//visibility:public"],
)
############
# Errcheck #
############
# Sample usage: "bazel run //:errcheck -- go.skia.org/infra/...".
alias(
name = "errcheck",
actual = "//bazel/tools/errcheck",
visibility = ["//visibility:public"],
)
###########
# Mockery #
###########
alias(
name = "mockery",
actual = "@com_github_vektra_mockery_v2//:v2",
visibility = ["//visibility:public"],
)
##########
# protoc #
##########
# Sample usage: "bazel run //:protoc -- --twirp_out=. --go_out=. myproto.proto"
alias(
name = "protoc",
actual = "//bazel/tools/protoc",
visibility = ["//visibility:public"],
)
#######
# npm #
#######
# Sample usage: "bazel run //:npm -- install some-package"
alias(
name = "npm",
actual = "//bazel/tools/npm",
visibility = ["//visibility:public"],
)
#######
# npx #
#######
# Sample usage: "bazel run //:npx -- eslint --fix ."
alias(
name = "npx",
actual = "//bazel/tools/npx",
visibility = ["//visibility:public"],
)
######
# sk #
######
# Sample usage: "bazel run //:sk -- asset download <asset name> <target directory>"
alias(
name = "sk",
actual = "//sk/go/sk",
visibility = ["//visibility:public"],
)