build: make bazel integrations compatible with windows (#43431)

The bazel integration tests are currently not compatible with Windows.
Tests never get to run because the created tar packages for NPM packages
are built using an outdated `pkg_tar` rule that creates invalid
tarballs. We fix this by using the non-deprecated windows-compatible
`rules_pkg` implementation.

Additionally, we copy all `package.json` files of integration tests to
the bazel bin directory as otherwise the file would be accidentally
modified as a source on Windows.

PR Close #43431
This commit is contained in:
Paul Gschwendtner 2021-09-21 11:19:25 +02:00 committed by Dylan Hunn
parent 0c7ceb99fb
commit a274de088a
3 changed files with 29 additions and 4 deletions

View file

@ -12,6 +12,17 @@ http_archive(
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/4.3.0/rules_nodejs-4.3.0.tar.gz"],
)
# The PKG rules are needed to build tar packages for integration tests. The builtin
# rule in `@bazel_tools` is not Windows compatible and outdated.
http_archive(
name = "rules_pkg",
sha256 = "a89e203d3cf264e564fcb96b6e06dd70bc0557356eb48400ce4b5d97c2c3720d",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_pkg/releases/download/0.5.1/rules_pkg-0.5.1.tar.gz",
"https://github.com/bazelbuild/rules_pkg/releases/download/0.5.1/rules_pkg-0.5.1.tar.gz",
],
)
# Check the rules_nodejs version and download npm dependencies
# Note: bazel (version 2 and after) will check the .bazelversion file so we don't need to
# assert on that.
@ -52,6 +63,10 @@ load("@build_bazel_rules_nodejs//toolchains/esbuild:esbuild_repositories.bzl", "
esbuild_repositories()
load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies")
rules_pkg_dependencies()
load("//packages/common/locales/generate-locales-tool:cldr-data.bzl", "cldr_data_repository")
cldr_data_repository(

View file

@ -6,6 +6,7 @@
"""
load("//tools/npm_integration_test:npm_integration_test.bzl", "npm_integration_test")
load("@build_bazel_rules_nodejs//:index.bzl", "copy_to_bin")
# The @npm packages at the root node_modules are used by integration tests
# with `file:../../node_modules/foobar` references
@ -68,7 +69,7 @@ FRAMEWORK_PACKAGES = [
def npm_package_archives():
"""Function to generate pkg_tar definitions for WORKSPACE yarn_install manual_build_file_contents"""
npm_packages_to_archive = NPM_PACKAGE_ARCHIVES
result = """load("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar")
result = """load("@rules_pkg//:pkg.bzl", "pkg_tar")
"""
for name in npm_packages_to_archive:
label_name = _npm_package_archive_label(name)
@ -77,7 +78,7 @@ def npm_package_archives():
name = "{label_name}",
srcs = ["//{name}:{last_segment_name}__all_files"],
extension = "tar.gz",
strip_prefix = "./node_modules/{name}",
strip_prefix = "/external/npm/node_modules/{name}",
# should not be built unless it is a dependency of another rule
tags = ["manual"],
)
@ -168,11 +169,20 @@ def _angular_integration_test(name, **kwargs):
def angular_integration_test(name, **kwargs):
"Sets up the integration test target based on the test folder name"
# Note: We copy the `package.json` file to the `bazel-bin` as otherwise
# the actual source file `package.json` file would be modified on Windows.
copy_to_bin(
name = "%s_package_json" % name,
srcs = ["%s/package.json" % name],
)
native.filegroup(
name = "_%s_sources" % name,
srcs = native.glob(
srcs = ["%s_package_json" % name] + native.glob(
include = ["%s/**" % name],
exclude = [
"%s/package.json",
"%s/node_modules/**" % name,
"%s/.yarn_local_cache/**" % name,
],

View file

@ -1,6 +1,6 @@
"""Re-export of some bazel rules with repository-wide defaults."""
load("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar")
load("@rules_pkg//:pkg.bzl", "pkg_tar")
load("@build_bazel_rules_nodejs//:index.bzl", _nodejs_binary = "nodejs_binary", _pkg_npm = "pkg_npm")
load("@npm//@bazel/jasmine:index.bzl", _jasmine_node_test = "jasmine_node_test")
load("@npm//@bazel/concatjs:index.bzl", _concatjs_devserver = "concatjs_devserver", _karma_web_test = "karma_web_test", _karma_web_test_suite = "karma_web_test_suite")