| load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library") |
| load("@bazel_gazelle//:def.bzl", "gazelle") |
| load("@com_github_bazelbuild_buildtools//buildifier:def.bzl", "buildifier") |
| load("//:elements-sk-scss.bzl", "generate_tilde_prefixed_elements_sk_scss_files") |
| load("@exec_properties//:constants.bzl", "NETWORK_ON") |
| |
| # 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". This convention is enforced by unittest.ManualTest(). 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_* |
| # # 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( |
| ["tsconfig.json"], |
| visibility = ["//visibility:public"], |
| ) |
| |
| buildifier( |
| name = "buildifier", |
| exclude_patterns = [ |
| "./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"], |
| ) |
| |
| ############################################################################# |
| # 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"], |
| ) |
| |
| ################## |
| # Miscellaneous. # |
| ################## |
| |
| # Generate a copy of the elements-sk SCSS stylesheets under //_bazel_bin/~elements-sk for |
| # compatibility with Webpack-style tilde-prefixed SCSS imports. See the macro docstring for details. |
| generate_tilde_prefixed_elements_sk_scss_files( |
| name = "~elements-sk", |
| ) |
| |
| go_library( |
| name = "infra_lib", |
| srcs = ["run_unittests.go"], |
| importpath = "go.skia.org/infra", |
| visibility = ["//visibility:private"], |
| deps = [ |
| "//go/common", |
| "//go/sklog", |
| "//go/testutils/unittest", |
| "//go/timer", |
| "//go/util", |
| ], |
| ) |
| |
| go_binary( |
| name = "infra", |
| embed = [":infra_lib"], |
| visibility = ["//visibility:public"], |
| ) |
| |
| # 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/infra_tests", |
| "//infra/bots/task_drivers/roll_cipd_packages", |
| "//infra/bots/task_drivers/validate_autoroll_configs", |
| ], |
| 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", |
| ) |
| |
| ######### |
| # gofmt # |
| ######### |
| |
| alias( |
| name = "gofmt", |
| actual = "@go_sdk//:bin/gofmt", |
| visibility = ["//visibility:public"], |
| ) |
| |
| ############ |
| # Errcheck # |
| ############ |
| |
| # Sample usage: "bazel run //:errcheck --run_under="cd $PWD &&" -- go.skia.org/infra/...". |
| # |
| # Note: The "errcheck go.skia.org/infra/..." command fails when executed outside of the |
| # repository's root directory. The "bazel run" command executes binaries with their working |
| # directory set to their runfiles tree (see https://stackoverflow.com/a/70265855). As a workaround, |
| # be sure to run Bazel from the repository's root directory and to pass --run_under="cd $PWD &&" in |
| # your "bazel run" invocation (see https://bazel.build/docs/user-manual#run-under) as in the sample |
| # usage above. |
| alias( |
| name = "errcheck", |
| actual = "@com_github_kisielk_errcheck//:errcheck", |
| visibility = ["//visibility:public"], |
| ) |
| |
| ########### |
| # Mockery # |
| ########### |
| |
| alias( |
| name = "mockery", |
| actual = "@com_github_vektra_mockery_v2//:v2", |
| visibility = ["//visibility:public"], |
| ) |