Skip to content

Commit

Permalink
Add .NET 6 support to .NET bindings (SeleniumHQ#11298)
Browse files Browse the repository at this point in the history
  • Loading branch information
jimevans committed Nov 22, 2022
1 parent a23df91 commit 4cc05e4
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 17 deletions.
6 changes: 3 additions & 3 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ pinned_maven_install()

http_archive(
name = "d2l_rules_csharp",
sha256 = "7b2a83621049904b6e898ffdbe7893a5b410aedf599d63f127ef81eac839b6c1",
strip_prefix = "rules_csharp-bf24e589bbadcc20f15a16e13f577a0abd42a1d1",
sha256 = "c0152befb1fd0e08527b38e41ef00b6627f9f0c2be6f2d23a4950f41701fa48a",
strip_prefix = "rules_csharp-50e2f6c79e7a53e50b4518239b5ebcc61279759e",
urls = [
"https://github.com/Brightspace/rules_csharp/archive/bf24e589bbadcc20f15a16e13f577a0abd42a1d1.tar.gz",
"https://github.com/Brightspace/rules_csharp/archive/50e2f6c79e7a53e50b4518239b5ebcc61279759e.tar.gz",
],
)

Expand Down
12 changes: 7 additions & 5 deletions dotnet/private/executable_assembly.bzl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
load("@d2l_rules_csharp//csharp/private:providers.bzl", "AnyTargetFrameworkInfo")
load("@d2l_rules_csharp//csharp/private:actions/assembly.bzl", "AssemblyAction")
load("@d2l_rules_csharp//csharp/private:actions/write_runtimeconfig.bzl", "write_runtimeconfig")
load("@d2l_rules_csharp//csharp/private:actions/misc.bzl", "write_runtimeconfig")
load(
"@d2l_rules_csharp//csharp/private:common.bzl",
"fill_in_missing_frameworks",
Expand All @@ -18,7 +18,7 @@ def _generate_execution_script_file(ctx, target):
if ctx.attr.is_windows:
shell_file_extension = "bat"
execution_line = "%~dp0" + assembly_file_name + " %*"
if is_core_framework(tfm) or tfm == "net5.0":
if is_core_framework(tfm) or tfm == "net5.0" or tfm == "net6.0":
execution_line = "dotnet " + execution_line
else:
execution_line = "mono " + execution_line
Expand Down Expand Up @@ -66,23 +66,25 @@ def create_executable_assembly(ctx, extra_srcs, extra_deps):

providers[tfm] = AssemblyAction(
ctx.actions,
name = ctx.attr.name,
additionalfiles = ctx.files.additionalfiles,
analyzers = ctx.attr.analyzers,
debug = is_debug(ctx),
defines = ctx.attr.defines,
deps = ctx.attr.deps + extra_deps + stdrefs,
keyfile = ctx.file.keyfile,
internals_visible_to = None,
internals_visible_to_cs = None,
langversion = ctx.attr.langversion,
resources = ctx.files.resources,
srcs = ctx.files.srcs + extra_srcs,
out = ctx.attr.out,
target = "exe",
target_name = ctx.attr.name,
target_framework = tfm,
toolchain = ctx.toolchains["@d2l_rules_csharp//csharp/private:toolchain_type"],
)

fill_in_missing_frameworks(providers)
fill_in_missing_frameworks(ctx.attr.out, providers)

result = providers.values()
dependency_files_list = _copy_dependency_files(ctx, result[0])
Expand All @@ -108,7 +110,7 @@ def create_executable_assembly(ctx, extra_srcs, extra_deps):
files = direct_runfiles,
transitive_files = depset(dependency_files_list, transitive = data_runfiles),
),
files = depset([result[0].out, result[0].refout, result[0].pdb, shell_file]),
files = depset([result[0].out, result[0].prefout, result[0].pdb, shell_file]),
))

return result
Expand Down
8 changes: 5 additions & 3 deletions dotnet/private/merge_assemblies.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def _merged_assembly_impl(ctx):

args.append("-out={}".format(output_assembly.path))
args.append(input_assembly.path)
(refs, runfiles, native_dlls) = collect_transitive_info(deps, target_framework)
(refs, runfiles, native_dlls) = collect_transitive_info(name, deps, target_framework)
for ref in refs.to_list():
args.append(ref.path)

Expand All @@ -56,7 +56,9 @@ def _merged_assembly_impl(ctx):

providers[target_framework] = CSharpAssemblyInfo[target_framework](
out = output_assembly,
refout = None,
prefout = None,
irefout = None,
internals_visible_to = [],
pdb = output_pdb,
native_dlls = native_dlls,
deps = deps,
Expand All @@ -66,7 +68,7 @@ def _merged_assembly_impl(ctx):
runtimeconfig = None,
)

fill_in_missing_frameworks(providers)
fill_in_missing_frameworks(name, providers)
returned_info = providers.values()
returned_info.append(
DefaultInfo(
Expand Down
2 changes: 1 addition & 1 deletion dotnet/selenium-dotnet-version.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
SE_VERSION = "4.6.0"
ASSEMBLY_VERSION = "4.0.0.0"
SUPPORTED_NET_FRAMEWORKS = ["net45", "net46", "net47", "net48"]
SUPPORTED_NET_STANDARD_VERSIONS = ["netstandard2.0", "netstandard2.1", "net5.0"]
SUPPORTED_NET_STANDARD_VERSIONS = ["netstandard2.0", "netstandard2.1", "net5.0", "net6.0"]

SUPPORTED_DEVTOOLS_VERSIONS = [
"v85",
Expand Down
2 changes: 2 additions & 0 deletions dotnet/src/support/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ nuget_package(
":net47",
":net48",
":net5.0",
":net6.0",
":netstandard2.0",
":netstandard2.1",
],
Expand All @@ -161,6 +162,7 @@ nuget_package(
":net47-strongnamed",
":net48-strongnamed",
":net5.0-strongnamed",
":net6.0-strongnamed",
":netstandard2.0-strongnamed",
":netstandard2.1-strongnamed",
],
Expand Down
3 changes: 3 additions & 0 deletions dotnet/src/support/WebDriver.Support.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
<group targetFramework="net5.0">
<dependency id="Selenium.WebDriver" version="$version$" exclude="Build,Analyzers" />
</group>
<group targetFramework="net6.0">
<dependency id="Selenium.WebDriver" version="$version$" exclude="Build,Analyzers" />
</group>
</dependencies>
<frameworkAssemblies>
<frameworkAssembly assemblyName="System.Drawing" />
Expand Down
2 changes: 2 additions & 0 deletions dotnet/src/webdriver/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ nuget_package(
":net47",
":net48",
":net5.0",
":net6.0",
":netstandard2.0",
":netstandard2.1",
],
Expand All @@ -307,6 +308,7 @@ nuget_package(
":net47-strongnamed",
":net48-strongnamed",
":net5.0-strongnamed",
":net6.0-strongnamed",
":netstandard2.0-strongnamed",
":netstandard2.1-strongnamed",
],
Expand Down
6 changes: 3 additions & 3 deletions dotnet/src/webdriver/Screenshot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// </copyright>

using System;
#if NETCOREAPP2_0 || NETSTANDARD2_0 || NETCOREAPP2_1 || NETSTANDARD2_1 || NET5_0
#if NETCOREAPP2_0 || NETSTANDARD2_0 || NETCOREAPP2_1 || NETSTANDARD2_1 || NET5_0 || NET6_0
#else
using System.Drawing;
using System.Drawing.Imaging;
Expand Down Expand Up @@ -100,7 +100,7 @@ public void SaveAsFile(string fileName, ScreenshotImageFormat format)
{
using (FileStream fileStream = new FileStream(fileName, FileMode.Create))
{
#if NETCOREAPP2_0 || NETSTANDARD2_0 || NETCOREAPP2_1 || NETSTANDARD2_1 || NET5_0
#if NETCOREAPP2_0 || NETSTANDARD2_0 || NETCOREAPP2_1 || NETSTANDARD2_1 || NET5_0 || NET6_0
imageStream.WriteTo(fileStream);
#else
using (Image screenshotImage = Image.FromStream(imageStream))
Expand All @@ -112,7 +112,7 @@ public void SaveAsFile(string fileName, ScreenshotImageFormat format)
}
}

#if NETCOREAPP2_0 || NETSTANDARD2_0 || NETCOREAPP2_1 || NETSTANDARD2_1 || NET5_0
#if NETCOREAPP2_0 || NETSTANDARD2_0 || NETCOREAPP2_1 || NETSTANDARD2_1 || NET5_0 || NET6_0
#else
private static ImageFormat ConvertScreenshotImageFormat(ScreenshotImageFormat format)
{
Expand Down
3 changes: 3 additions & 0 deletions dotnet/src/webdriver/WebDriver.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
<group targetFramework="net5.0">
<dependency id="Newtonsoft.Json" version="13.0.1" exclude="Build,Analyzers" />
</group>
<group targetFramework="net6.0">
<dependency id="Newtonsoft.Json" version="13.0.1" exclude="Build,Analyzers" />
</group>
</dependencies>
<frameworkAssemblies>
<frameworkAssembly assemblyName="System.Drawing" />
Expand Down
2 changes: 2 additions & 0 deletions dotnet/src/webdriverbackedselenium/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ nuget_package(
":net47",
":net48",
":net5.0",
":net6.0",
":netstandard2.0",
":netstandard2.1",
],
Expand All @@ -219,6 +220,7 @@ nuget_package(
":net47-strongnamed",
":net48-strongnamed",
":net5.0-strongnamed",
":net6.0-strongnamed",
":netstandard2.0-strongnamed",
":netstandard2.1-strongnamed",
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@
<group targetFramework="net5.0">
<dependency id="Selenium.WebDriver" version="$version$" exclude="Build,Analyzers" />
</group>
<group targetFramework="net6.0">
<dependency id="Selenium.WebDriver" version="$version$" exclude="Build,Analyzers" />
</group>
</dependencies>
<frameworkAssemblies>
<frameworkAssembly assemblyName="System.Drawing" />
Expand Down
2 changes: 1 addition & 1 deletion third_party/dotnet/devtools/src/generator/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ csharp_executable(
"//conditions:default": False,
}),
target_frameworks = [
"netcoreapp3.1",
"net6.0",
],
visibility = ["//visibility:public"],
deps = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net60</TargetFramework>
<RootNamespace>OpenQA.Selenium.DevToolsGenerator</RootNamespace>
</PropertyGroup>

Expand Down

0 comments on commit 4cc05e4

Please sign in to comment.