[bazel] Add copy_file_from_npm_pkg macro.

The goal of this CL is to prepare our repository to migrate from rules_nodejs[1] to rules_js[2].

The rules_js ruleset exposes NPM packages in a way that makes it difficult to access individual files. As discussed in this Slack thread[3], the recommended way to access individual files from NPM packages under rules_js is by creating a local copy of the file using helper rules from the aspect-build/bazel_lib[4] ruleset.

Note that this does not affect JS and TS dependencies from NPM, as rules_js (and rules_ts[5]) handle those differently.

Our repository has a few use cases where we pick files directly from NPM packages via Bazel labels of the form "@npm//package/path/to/file.ext". This CL replaces all such labels with local copies of those files, which are created with the copy_file_from_npm_pkg macro. This macro simply copies files with a genrule that shells out to "cp". In follow-up CLs, I will migrate our repository to rules_js and I will update copy_file_from_npm_pkg to use rules from the aspect-build/bazel_lib ruleset as recommended in the aforementioned Slack thread.

Regarding Sass and CSS dependencies from NPM packages: Unfortunately the rules_sass[6] ruleset is not compatible with rules_js. The recommended way to deal with Sass dependencies is to leverage rules_js's support for binaries published to NPM[7] and write a macro that shells out to the Sass compiler from the "sass" NPM package[8]. With this approach, any Sass or CSS files from NPM packages need to be copied as previously mentioned, e.g. by using the copy_file_from_npm_pkg macro.

Given that this CL replaces all references to NPM files with local copies, including Sass and CSS files from NPM, there is no longer a need for our "sass_library" wrapper macro defined in //infra-sk/sass_library.bzl, which we used to add support for NPM imports in an ad-hoc way. Thus, this CL deletes //infra-sk/sass_library.bzl. A nice side-effect of this change is that we are better positioned to drop rules_sass in favor of a custom macro as described earlier.

Likewise, our Gazelle extension no longer needs to support Sass and CSS imports from NPM, so this CL deletes those features from our Gazelle extension.

[1] https://github.com/bazelbuild/rules_nodejs
[2] https://github.com/aspect-build/rules_js
[3] https://bazelbuild.slack.com/archives/CEZUUKQ6P/p1661466555661629
[4] https://github.com/aspect-build/bazel-lib
[5] https://github.com/aspect-build/rules_ts
[6] https://github.com/bazelbuild/rules_sass
[7] https://docs.aspect.build/rulesets/aspect_rules_js/docs/#using-binaries-published-to-npm
[8] https://www.npmjs.com/package/sass

Bug: b/314813928
Change-Id: I9769c13d7748807ad78e607ee722e586283f7aa1
Reviewed-on: https://skia-review.googlesource.com/c/buildbot/+/787203
Reviewed-by: Kevin Lubick <kjlubick@google.com>
Commit-Queue: Leandro Lovisolo <lovisolo@google.com>
22 files changed
tree: 75f47d0d27d318329c1d3ed7f9f82abae43552f6
  1. am/
  2. android_ingest/
  3. android_stats/
  4. api/
  5. autoroll/
  6. bash/
  7. bazel/
  8. bisection/
  9. blamer/
  10. bugs-central/
  11. cabe/
  12. cd/
  13. cherrypick-watcher/
  14. cmd/
  15. codereview-watcher/
  16. codesize/
  17. comments/
  18. cq_watcher/
  19. ct/
  20. datahopper/
  21. debugger-app/
  22. demos/
  23. docker/
  24. docker_pushes_watcher/
  25. docs/
  26. docsyserver/
  27. ds/
  28. elements-sk/
  29. email/
  30. external/
  31. fiddlek/
  32. firestore/
  33. get_service_account/
  34. gitsync/
  35. go/
  36. gold-client/
  37. golden/
  38. helloworld/
  39. infra/
  40. infra-sk/
  41. jsdoc/
  42. jsfiddle/
  43. k8s-checker/
  44. k8s-deployer/
  45. kube/
  46. leasing/
  47. licenses/
  48. machine/
  49. make/
  50. modules/
  51. named-fiddles/
  52. new_element/
  53. npm-audit-mirror/
  54. perdiff/
  55. perf/
  56. periodic-trigger/
  57. proberk/
  58. promk/
  59. puppeteer-tests/
  60. sa-keys-checker/
  61. scrap/
  62. scripts/
  63. shaders/
  64. sk/
  65. skbug/
  66. skcq/
  67. skfe/
  68. skolo/
  69. skottie/
  70. static_server/
  71. status/
  72. task_driver/
  73. task_scheduler/
  74. temporal/
  75. test-service/
  76. tools/
  77. tree_status/
  78. trybot_updater/
  79. .bazelignore
  80. .bazelrc
  81. .bazelversion
  82. .eslintrc.js
  83. .gitattributes
  84. .gitignore
  85. .mockery.yaml
  86. .npmrc
  87. .prettierignore
  88. .prettierrc.json
  89. .puppeteerrc.js
  90. .vpython
  91. BAZEL_CHEATSHEET.md
  92. BUILD.bazel
  93. build_infra_prod.sh
  94. CDB.md
  95. cipd.ensure
  96. codereview.settings
  97. DATASTORE.md
  98. demopage.sh
  99. DEPS
  100. go.mod
  101. go.sum
  102. go_repositories.bzl
  103. karmatest.sh
  104. launch.md
  105. LICENSE
  106. Makefile
  107. OWNERS
  108. package-lock.json
  109. package.json
  110. PRESUBMIT.py
  111. PRIVACY_POLICY.md
  112. README.md
  113. STYLEGUIDE.md
  114. tools.go
  115. tsconfig.json
  116. whitespace.txt
  117. WORKSPACE
README.md

Skia-Buildbot Repository

This repo contains infrastructure code for Skia.

Getting the Source Code

The main source code repository is a Git repository hosted at https://skia.googlesource.com/buildbot.git. It is possible to check out this repository directly with git clone or via go get.

Using git clone allows you to work in whatever directory you want. You will still need to set GOPATH in order to build some apps (recommended to put this in a cache dir). E.g.:

$ cd ${WORKDIR}
$ git clone https://skia.googlesource.com/buildbot.git
$ export GOPATH=${HOME}/.cache/gopath/$(basename ${WORKDIR})
$ mkdir $GOPATH
$ cd buildbot

Install dependencies

Almost all applications are built with Bazel, and bazelisk is the recommended tool to ensure you have the right version of bazel installed:

go install github.com/bazelbuild/bazelisk@latest
go install github.com/bazelbuild/buildtools/buildifier@latest
go install github.com/kisielk/errcheck@latest
go install golang.org/x/tools/cmd/goimports@latest
go install github.com/mikefarah/yq/v4@latest
go install go.chromium.org/luci/client/cmd/...@latest

Install other dependencies:

sudo apt-get install jq

Build ~everything

bazelisk build --config=mayberemote //...

Test everything

bazelisk test --config=mayberemote //...

Generated Code

To update generated code run the following in any directory:

go generate ./...

Running unit tests

Install Cloud SDK.

Use this command to run the presubmit tests:

./run_unittests --small