-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding Bazel rules for building .NET targets
The rules added handle building the .NET assemblies for .NET Framework 4.5, 4.6, and 4.7, as well as .NET Standard 2.0. Additionally, the added rules will also merge the dependency Json.NET assembly into the base WebDriver.dll assembly, and will handle the creation of NuGet packages. All of these can be done for both the normal and the strong-named (the so-called "signed") case.
- Loading branch information
Showing
7 changed files
with
725 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
exports_files(["WebDriver.snk"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
load("@io_bazel_rules_dotnet//dotnet/private:context.bzl", "dotnet_context") | ||
|
||
def _merged_assembly_impl(ctx): | ||
args = [ | ||
"-v4", | ||
"-xmldocs", | ||
"-internalize", | ||
] | ||
|
||
if ctx.attr.keyfile != None: | ||
key_path = ctx.expand_location(ctx.attr.keyfile.files.to_list()[0].path) | ||
args.append("-keyfile:{}".format(key_path)) | ||
|
||
args.append("-out={}".format(ctx.outputs.out.path)) | ||
args.append(ctx.attr.src_assembly.files.to_list()[0].path) | ||
for dep in ctx.files.deps: | ||
args.append(ctx.expand_location(dep.path)) | ||
|
||
ctx.actions.run( | ||
executable = ctx.executable.merge_tool, | ||
arguments = args, | ||
inputs = ctx.attr.src_assembly.files, | ||
outputs = [ctx.outputs.out] | ||
) | ||
|
||
merged_assembly = rule( | ||
implementation = _merged_assembly_impl, | ||
attrs = { | ||
"src_assembly": attr.label(), | ||
"deps": attr.label_list(), | ||
"out": attr.output(mandatory = True), | ||
"keyfile": attr.label(allow_single_file = True), | ||
"merge_tool": attr.label( | ||
executable = True, | ||
cfg = "host", | ||
default = Label("//third_party/dotnet/ilmerge:ilmerge.exe"), | ||
allow_single_file = True | ||
), | ||
}, | ||
toolchains = ["@io_bazel_rules_dotnet//dotnet:toolchain_net"], | ||
) | ||
|
||
def _nuget_package_impl(ctx): | ||
args = [ | ||
"pack", | ||
] | ||
|
||
package_id = ctx.attr.package_id | ||
package_version = ctx.attr.package_version | ||
|
||
package_file = ctx.actions.declare_file("{}.{}.nupkg".format(package_id, package_version)) | ||
output_path = ctx.expand_location(package_file.dirname) | ||
|
||
# The dependencies are assembly output compiled into directories | ||
# with the appropriate target framework moniker ("<base>/net45", | ||
# "<base>/net46", etc.). The base path for creating the NuGet | ||
# package should be the "<base>" directory, which we need to | ||
# hard-code with the parent operator, because Bazel doesn't | ||
# provide proper path traversal for custom rules. | ||
base_path = ctx.files.deps[0].dirname + "/.." | ||
|
||
args.append(ctx.expand_location(ctx.attr.src.files.to_list()[0].path)) | ||
args.append("-Properties") | ||
args.append("packageid={}".format(package_id)) | ||
args.append("-Version") | ||
args.append(package_version) | ||
args.append("-BasePath") | ||
args.append(base_path) | ||
args.append("-OutputDirectory") | ||
args.append(output_path) | ||
|
||
ctx.actions.run( | ||
executable = ctx.executable.nuget_exe, | ||
arguments = args, | ||
inputs = ctx.attr.src.files + ctx.files.deps, | ||
outputs = [ | ||
package_file, | ||
] | ||
) | ||
|
||
return DefaultInfo(files = depset([ | ||
package_file, | ||
])) | ||
|
||
nuget_package = rule( | ||
implementation = _nuget_package_impl, | ||
attrs = { | ||
"src": attr.label( | ||
allow_single_file = True | ||
), | ||
"deps": attr.label_list(), | ||
"package_id": attr.string(), | ||
"package_version": attr.string(), | ||
"nuget_exe": attr.label( | ||
executable = True, | ||
cfg = "host", | ||
default = Label("//third_party/dotnet/nuget:nuget.exe"), | ||
allow_single_file = True | ||
), | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
|
||
SE_VERSION = "4.0.0-alpha01" | ||
ASSEMBLY_VERSION = "4.0.0.0" | ||
SUPPORTED_NET_FRAMEWORKS = ["net45", "net46", "net47"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
load("@io_bazel_rules_dotnet//dotnet:defs.bzl", "net_library", "core_library", "core_resource") | ||
load("//dotnet:build-rules.bzl", "merged_assembly", "nuget_package") | ||
load("//dotnet:selenium-dotnet-version.bzl", | ||
"SE_VERSION", | ||
"ASSEMBLY_VERSION", | ||
"SUPPORTED_NET_FRAMEWORKS") | ||
|
||
[net_library( | ||
name = "{}".format(framework), | ||
srcs = glob([ | ||
"*.cs", | ||
"Events/*.cs", | ||
"Extensions/*.cs", | ||
"PageObjects/**/*.cs", | ||
"UI/*.cs", | ||
]), | ||
deps = [ | ||
"@io_bazel_rules_dotnet//dotnet/stdlib.net:system.dll", | ||
"@io_bazel_rules_dotnet//dotnet/stdlib.net:system.core.dll", | ||
"@io_bazel_rules_dotnet//dotnet/stdlib.net:system.data.dll", | ||
"@io_bazel_rules_dotnet//dotnet/stdlib.net:system.drawing.dll", | ||
"@io_bazel_rules_dotnet//dotnet/stdlib.net:system.xml.dll", | ||
"//dotnet/src/webdriver:{}assembly".format(framework) | ||
], | ||
dotnet_context_data = "@io_bazel_rules_dotnet//:net_context_data_{}".format(framework), | ||
out = "merged/{}/WebDriver.Support.dll".format(framework), | ||
visibility = ["//visibility:public"], | ||
) for framework in SUPPORTED_NET_FRAMEWORKS] | ||
|
||
core_library( | ||
name = "netstandard2.0", | ||
srcs = glob([ | ||
"*.cs", | ||
"Events/*.cs", | ||
"Extensions/*.cs", | ||
"PageObjects/**/*.cs", | ||
"UI/*.cs", | ||
]), | ||
deps = [ | ||
"@io_bazel_rules_dotnet//dotnet/stdlib.core:netstandard.dll", | ||
"//dotnet/src/webdriver:netstandard2.0" | ||
], | ||
defines = [ | ||
"NETSTANDARD2_0" | ||
], | ||
out = "merged/netstandard2.0/WebDriver.Support.dll", | ||
visibility = ["//visibility:public"] | ||
) | ||
|
||
[net_library( | ||
name = "{}-strongnamed".format(framework), | ||
srcs = glob([ | ||
"*.cs", | ||
"Events/*.cs", | ||
"Extensions/*.cs", | ||
"PageObjects/**/*.cs", | ||
"UI/*.cs", | ||
]), | ||
deps = [ | ||
"@io_bazel_rules_dotnet//dotnet/stdlib.net:system.dll", | ||
"@io_bazel_rules_dotnet//dotnet/stdlib.net:system.core.dll", | ||
"@io_bazel_rules_dotnet//dotnet/stdlib.net:system.data.dll", | ||
"@io_bazel_rules_dotnet//dotnet/stdlib.net:system.drawing.dll", | ||
"@io_bazel_rules_dotnet//dotnet/stdlib.net:system.xml.dll", | ||
"//dotnet/src/webdriver:{}assembly-strongnamed".format(framework) | ||
], | ||
out = "strongnamed/{}/WebDriver.Support.dll".format(framework), | ||
keyfile = "//dotnet:WebDriver.snk", | ||
visibility = ["//visibility:public"], | ||
dotnet_context_data = "@io_bazel_rules_dotnet//:net_context_data_{}".format(framework) | ||
) for framework in SUPPORTED_NET_FRAMEWORKS] | ||
|
||
core_library( | ||
name = "netstandard2.0-strongnamed", | ||
srcs = glob([ | ||
"*.cs", | ||
"Events/*.cs", | ||
"Extensions/*.cs", | ||
"PageObjects/**/*.cs", | ||
"UI/*.cs", | ||
]), | ||
deps = [ | ||
"@io_bazel_rules_dotnet//dotnet/stdlib.core:netstandard.dll", | ||
"//dotnet/src/webdriver:netstandard2.0-strongnamed" | ||
], | ||
defines = [ | ||
"NETSTANDARD2_0" | ||
], | ||
keyfile = "//dotnet:WebDriver.snk", | ||
out = "strongnamed/netstandard2.0/WebDriver.Support.dll", | ||
visibility = ["//visibility:public"] | ||
) | ||
|
||
nuget_package( | ||
name = "package", | ||
src = "WebDriver.Support.nuspec", | ||
deps = [ | ||
":net45", | ||
":net46", | ||
":net47", | ||
":netstandard2.0", | ||
], | ||
package_id = "Selenium.Support", | ||
package_version = "{}".format(SE_VERSION), | ||
) | ||
|
||
nuget_package( | ||
name = "package-strongnamed", | ||
src = "WebDriver.Support.nuspec", | ||
deps = [ | ||
":net45-strongnamed", | ||
":net46-strongnamed", | ||
":net47-strongnamed", | ||
":netstandard2.0-strongnamed", | ||
], | ||
package_id = "Selenium.Support.StrongNamed", | ||
package_version = "{}".format(SE_VERSION), | ||
) |
Oops, something went wrong.