Skip to content

Commit

Permalink
[bazel] Update rules_dotnet to the latest version (SeleniumHQ#12784)
Browse files Browse the repository at this point in the history
[bazel + .net] Rework Bazel builds of .Net code on top of latest `rules_dotnet`

Co-authored-by: Jim Evans <james.h.evans.jr@gmail.com>
  • Loading branch information
shs96c and jimevans committed Oct 3, 2023
1 parent 2ffb772 commit b9d83bf
Show file tree
Hide file tree
Showing 61 changed files with 1,742 additions and 556 deletions.
22 changes: 21 additions & 1 deletion .bazelignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
buck-out
dotnet/test/firefox/bin
dotnet/test/firefox/obj
dotnet/test/edge/bin
dotnet/test/edge/obj
dotnet/test/common/bin
dotnet/test/common/obj
dotnet/test/support/bin
dotnet/test/support/obj
dotnet/test/safari/bin
dotnet/test/safari/obj
dotnet/test/chrome/bin
dotnet/test/chrome/obj
dotnet/test/ie/bin
dotnet/test/ie/obj
dotnet/test/remote/bin
dotnet/test/remote/obj
dotnet/src/support/bin
dotnet/src/support/obj
dotnet/src/webdriver/bin
dotnet/src/webdriver/obj
java/build/production
java/client/build
java/server/build
node_modules
java/build/production
1 change: 1 addition & 0 deletions .github/workflows/ci-rbe.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
name: Test
uses: ./.github/workflows/bazel.yml
with:
# TODO: experiment with turning off caches
name: All RBE tests
cache-key: rbe
ruby-version: jruby-9.4.2.0
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ test-output/
common/build
/build/
cpp/iedriver/IEReturnTypes.h
dotnet/.idea/
dotnet/packages/
java/client/src/org/openqa/selenium/ie/IeReturnTypes.java
java/server/test/org/openqa/selenium/example
javascript/deps.js
Expand Down
10 changes: 10 additions & 0 deletions .skipped-tests
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
-//dotnet/test/common:DevTools/DevToolsNetworkTest-chrome
-//dotnet/test/common:Interactions/BasicMouseInterfaceTest-chrome
-//dotnet/test/common:Interactions/BasicMouseInterfaceTest-firefox
-//dotnet/test/common:JavascriptEnabledBrowserTest-chrome
-//dotnet/test/common:NetworkInterceptionTests-chrome
-//dotnet/test/common:TakesScreenshotTest-chrome
-//dotnet/test/common:TakesScreenshotTest-firefox
-//dotnet/test/common:VirtualAuthn/VirtualAuthenticatorTest-chrome
-//dotnet/test/support/UI:SelectBrowserTests-firefox
-//dotnet/test/support/UI:SmallTests
-//java/test/org/openqa/selenium:FormHandlingTest-chrome
-//java/test/org/openqa/selenium/bidi:BiDiSessionTest-remote
-//java/test/org/openqa/selenium/bidi:BiDiTest-remote
Expand Down
38 changes: 31 additions & 7 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -166,17 +166,41 @@ load("@maven//:defs.bzl", "pinned_maven_install")
pinned_maven_install()

http_archive(
name = "d2l_rules_csharp",
sha256 = "c0152befb1fd0e08527b38e41ef00b6627f9f0c2be6f2d23a4950f41701fa48a",
strip_prefix = "rules_csharp-50e2f6c79e7a53e50b4518239b5ebcc61279759e",
urls = [
"https://github.com/Brightspace/rules_csharp/archive/50e2f6c79e7a53e50b4518239b5ebcc61279759e.tar.gz",
name = "rules_dotnet",
patch_args = ["-p1"],
patches = [
"//dotnet:0001-Include-more-of-the-SDK.patch",
"//dotnet:0002-Pass-through-information-about-location-of-the-nupkg.patch",
"//dotnet:0003-Make-Runfiles-library-compatible-with-net-standard-2-0.patch",
"//dotnet:0004-Ensure-data-runfiles-are-added-to-tests.patch",
"//dotnet:0005-Ensure-csharp_library-files-are-unique.patch",
],
sha256 = "f445400dac566eed9d7895aa0fb168a5453a07e5128dc1c4852cd9c537e0ca60",
strip_prefix = "rules_dotnet-0.10.7",
url = "https://github.com/bazelbuild/rules_dotnet/releases/download/v0.10.7/rules_dotnet-v0.10.7.tar.gz",
)

load(
"@rules_dotnet//dotnet:repositories.bzl",
"dotnet_register_toolchains",
"rules_dotnet_dependencies",
)

load("//dotnet:workspace.bzl", "selenium_register_dotnet")
rules_dotnet_dependencies()

dotnet_register_toolchains("dotnet", "7.0.400")

load("@rules_dotnet//dotnet:rules_dotnet_nuget_packages.bzl", "rules_dotnet_nuget_packages")

rules_dotnet_nuget_packages()

load("@rules_dotnet//dotnet:paket2bazel_dependencies.bzl", "paket2bazel_dependencies")

paket2bazel_dependencies()

load("//dotnet:paket.bzl", "paket")

selenium_register_dotnet()
paket()

http_archive(
name = "rules_rust",
Expand Down
18 changes: 18 additions & 0 deletions dotnet/.config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"version": 1,
"isRoot": true,
"tools": {
"paket": {
"version": "7.2.1",
"commands": [
"paket"
]
},
"aver": {
"version": "1.0.2",
"commands": [
"aver"
]
}
}
}
18 changes: 18 additions & 0 deletions dotnet/0001-Include-more-of-the-SDK.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
dotnet/repositories.bzl | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/dotnet/repositories.bzl b/dotnet/repositories.bzl
index 988559e..cf8fd6d 100644
--- a/dotnet/repositories.bzl
+++ b/dotnet/repositories.bzl
@@ -83,9 +83,7 @@ filegroup(
}}),
data = glob([
"host/**/*",
- "sdk/**/*.dll",
- "sdk/**/dotnet.runtimeconfig.json",
- "sdk/**/dotnet.deps.json",
+ "sdk/**/*",
"shared/Microsoft.NETCore.App/**/*",
]),
visibility = ["//visibility:public"],
135 changes: 135 additions & 0 deletions dotnet/0002-Pass-through-information-about-location-of-the-nupkg.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
diff --git a/dotnet/private/providers.bzl b/dotnet/private/providers.bzl
index df00a25..0b06638 100644
--- a/dotnet/private/providers.bzl
+++ b/dotnet/private/providers.bzl
@@ -44,6 +44,7 @@ NuGetInfo = provider(
fields = {
"targeting_pack_overrides": "map[string, string]: Targeting packs like e.g. Microsoft.NETCore.App.Ref have a PackageOverride.txt that includes a list of NuGet packages that should be omitted in a compiliation because they are included in the targeting pack",
"sha512": "string: the SHA512 SRI string for the package",
+ "nupkg": "File: the underlying `.nupkg` file which provides this package",
},
)

diff --git a/dotnet/private/rules/nuget/imports.bzl b/dotnet/private/rules/nuget/imports.bzl
index a41bc70..79ebc94 100644
--- a/dotnet/private/rules/nuget/imports.bzl
+++ b/dotnet/private/rules/nuget/imports.bzl
@@ -59,6 +59,7 @@ def _import_library(ctx):
), NuGetInfo(
targeting_pack_overrides = ctx.attr.targeting_pack_overrides,
sha512 = ctx.attr.sha512,
+ nupkg = ctx.file.nupkg,
)]

import_library = rule(
@@ -107,6 +108,10 @@ import_library = rule(
"sha512": attr.string(
doc = "The SHA512 sum of the NuGet package",
),
+ "nupkg": attr.label(
+ doc = "The `.nupkg` file providing this import",
+ allow_single_file = True,
+ ),
},
toolchains = [
"@rules_dotnet//dotnet:toolchain_type",
diff --git a/dotnet/private/rules/nuget/nuget_archive.bzl b/dotnet/private/rules/nuget/nuget_archive.bzl
index 38a9473..683abdd 100644
--- a/dotnet/private/rules/nuget/nuget_archive.bzl
+++ b/dotnet/private/rules/nuget/nuget_archive.bzl
@@ -19,6 +19,8 @@ load(
"RUNTIME_GRAPH",
)

+GLOBAL_NUGET_PREFIX = "nuget"
+
def _is_windows(repository_ctx):
"""Returns true if the host operating system is windows."""
os_name = repository_ctx.os.name.lower()
@@ -321,7 +323,17 @@ def _nuget_archive_impl(ctx):

# Then get the auth dict for the package base urls
auth = _get_auth_dict(ctx, ctx.attr.netrc, urls)
- ctx.download_and_extract(urls, type = "zip", integrity = ctx.attr.sha512, auth = auth)
+ file_name = "%s.zip" % ctx.name
+ nupkg_name = "%s.%s.nupkg" % (ctx.attr.id, ctx.attr.version)
+ names = [nupkg_name]
+ if nupkg_name.startswith(GLOBAL_NUGET_PREFIX):
+ nupkg_name = nupkg_name[len(GLOBAL_NUGET_PREFIX) + 1:]
+ names.append(nupkg_name)
+
+ ctx.download(urls, output = file_name, integrity = ctx.attr.sha512, auth = auth)
+ ctx.extract(archive = file_name)
+ for name in names:
+ ctx.symlink(file_name, name)

files = _read_dir(ctx, ".").replace(str(ctx.path(".")) + "/", "").splitlines()

@@ -447,6 +459,7 @@ load("@rules_dotnet//dotnet/private/rules/nuget:nuget_archive.bzl", "tfm_filegro
"filegroup(name = \"data\", srcs = [])",
_create_rid_native_select("native", native) or "filegroup(name = \"native\", srcs = [])",
"filegroup(name = \"content_files\", srcs = [%s])" % ",".join(["\n \"%s\"" % a for a in groups.get("contentFiles")["any"]]),
+ "exports_files([\"%s\"])" % nupkg_name,
]))

nuget_archive = repository_rule(
diff --git a/dotnet/private/rules/nuget/nuget_repo.bzl b/dotnet/private/rules/nuget/nuget_repo.bzl
index 77c2a67..c5cc56d 100644
--- a/dotnet/private/rules/nuget/nuget_repo.bzl
+++ b/dotnet/private/rules/nuget/nuget_repo.bzl
@@ -1,9 +1,7 @@
"NuGet Repo"

load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
-load("@rules_dotnet//dotnet/private/rules/nuget:nuget_archive.bzl", "nuget_archive")
-
-_GLOBAL_NUGET_PREFIX = "nuget"
+load("@rules_dotnet//dotnet/private/rules/nuget:nuget_archive.bzl", "GLOBAL_NUGET_PREFIX", "nuget_archive")

def _nuget_repo_impl(ctx):
for package in ctx.attr.packages:
@@ -22,8 +20,15 @@ def _nuget_repo_impl(ctx):
targeting_pack_overrides = ctx.attr.targeting_pack_overrides[name.lower()]
template = Label("@rules_dotnet//dotnet/private/rules/nuget:template.BUILD")

+ nupkg_path = "@{PREFIX}.{NAME_LOWER}.v{VERSION}//:{NAME_LOWER}.{VERSION}.nupkg".format(
+ PREFIX = GLOBAL_NUGET_PREFIX,
+ NAME = name,
+ NAME_LOWER = name.lower(),
+ VERSION = version,
+ )
+
ctx.template("{}/{}/BUILD.bazel".format(name.lower(), version), template, {
- "{PREFIX}": _GLOBAL_NUGET_PREFIX,
+ "{PREFIX}": GLOBAL_NUGET_PREFIX,
"{NAME}": name,
"{NAME_LOWER}": name.lower(),
"{VERSION}": version,
@@ -36,7 +41,7 @@ def _nuget_repo_impl(ctx):
ctx.file("{}/BUILD.bazel".format(name.lower()), r"""package(default_visibility = ["//visibility:public"])
alias(name = "{name}", actual = "//{name}/{version}")
alias(name = "content_files", actual = "@{prefix}.{name}.v{version}//:content_files")
-""".format(prefix = _GLOBAL_NUGET_PREFIX, name = name.lower(), version = version))
+""".format(prefix = GLOBAL_NUGET_PREFIX, name = name.lower(), version = version))

_nuget_repo = repository_rule(
_nuget_repo_impl,
@@ -63,7 +68,7 @@ def nuget_repo(name, packages):
# maybe another nuget_repo has the same nuget package dependency
maybe(
nuget_archive,
- name = "{}.{}.v{}".format(_GLOBAL_NUGET_PREFIX, package_name, version),
+ name = "{}.{}.v{}".format(GLOBAL_NUGET_PREFIX, package_name, version),
sources = package["sources"],
netrc = package.get("netrc", None),
id = package_name,
diff --git a/dotnet/private/rules/nuget/template.BUILD b/dotnet/private/rules/nuget/template.BUILD
index 783f025..b62bce2 100644
--- a/dotnet/private/rules/nuget/template.BUILD
+++ b/dotnet/private/rules/nuget/template.BUILD
@@ -16,4 +16,5 @@ import_library(
deps = select({
{DEPS},
}),
+ nupkg = "@{PREFIX}.{NAME_LOWER}.v{VERSION}//:{NAME_LOWER}.{VERSION}.nupkg"
)
Loading

0 comments on commit b9d83bf

Please sign in to comment.