Skip to content

Commit

Permalink
Updating Bazel build files to support .NET tests on non-Windows OSes
Browse files Browse the repository at this point in the history
Sandboxing rules on non-Windows OSes mean that tests will not run
properly unless the data attributes of the test target are fully
available.
  • Loading branch information
jimevans committed Apr 22, 2020
1 parent 7b09850 commit 8ba74c1
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 32 deletions.
30 changes: 19 additions & 11 deletions dotnet/nunit-test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@ CORE_FRAMEWORK_VERSIONS = {
"netcoreapp3.1": "3.1.1",
}

def _is_windows():
return select({
"@bazel_tools//src/conditions:windows": True,
"//conditions:default": False,
})

def _write_runtimeconfig(ctx, target):
tfm = target.actual_tfm
runtimeconfig_file_name = "bazelout/%s/%s.runtimeconfig.json" % (tfm, target.out.basename.replace("." + target.out.extension, ""))
Expand All @@ -46,13 +40,26 @@ def _generate_execution_script_file(ctx, target):
tfm = target.actual_tfm
test_file_name = target.out.basename
shell_file_extension = "sh"
shell_content = "$( cd \"$( dirname )\"$BASH_SOURCE[0]}\" )\" >/dev/null 2>&1 && pwd )/" + test_file_name + " $@"
if _is_windows():
execution_line = "$( cd \"$(dirname \"$BASH_SOURCE[0]}\")\" >/dev/null 2>&1 && pwd -P )/" + test_file_name + " $@"
if ctx.attr.is_windows:
shell_file_extension = "bat"
shell_content = "%~dp0" + test_file_name + " %*"
execution_line = "%~dp0" + test_file_name + " %*"

if is_core_framework(tfm):
shell_content = "dotnet " + shell_content
execution_line = "dotnet " + execution_line

dotnet_sdk_location = ""
environment = ""
if not ctx.attr.is_windows:
# This needs to be fixed here for non-Windows platforms.
environment += "export HOME=%s\n" % dotnet_sdk_location
environment += "export DOTNET_CLI_HOME=%s\n" % dotnet_sdk_location
environment += "export APPDATA=%s\n" % dotnet_sdk_location
environment += "export PROGRAMFILES=%s\n" % dotnet_sdk_location
environment += "export USERPROFILE=%s\n" % dotnet_sdk_location
environment += "export DOTNET_CLI_TELEMETRY_OPTOUT=1%s\n"

shell_content = environment + execution_line

shell_file_name = "bazelout/%s/%s.%s" % (tfm, test_file_name, shell_file_extension)
shell_file = ctx.actions.declare_file(shell_file_name)
Expand Down Expand Up @@ -121,7 +128,7 @@ def _copy_dependency_files(ctx, provider_value):
src_list = provider_value.transitive_runfiles.to_list()
target_dir = "bazelout/%s/" % (provider_value.actual_tfm)
dest_list = []
if _is_windows():
if ctx.attr.is_windows:
dest_list = _copy_cmd(ctx, src_list, target_dir)
else:
dest_list = _copy_bash(ctx, src_list, target_dir)
Expand Down Expand Up @@ -258,6 +265,7 @@ nunit_test = rule(
providers = AnyTargetFrameworkInfo,
default = "@NUnit//:nunit.framework",
),
"is_windows": attr.bool(default=False),
},
test = True,
executable = True,
Expand Down
47 changes: 26 additions & 21 deletions dotnet/test/common/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ config_setting(
data = [
"appconfig.json",
"//common/src/web",
"//java/client/test/org/openqa/selenium/environment:keystore",
"//java/client/test/org/openqa/selenium/environment:appserver_deploy.jar",
"//javascript/atoms",
"//third_party/closure/goog",
"//third_party/js/selenium:webdriver_json",
],
args = [
"--workers=1",
Expand All @@ -52,26 +56,27 @@ config_setting(
"//conditions:default": [ "netcoreapp2.1" ],
}),
deps = select({
":netframework":
[
"//dotnet/src/webdriver:net47",
"@json.net//:Newtonsoft.Json",
"@benderproxy//:BenderProxy",
"@moq//:Moq",
],
":netcore":
[
"//dotnet/src/webdriver:netstandard2.0assembly",
"@json.net//:Newtonsoft.Json",
"@benderproxy//:BenderProxy",
"@moq//:Moq",
],
"//conditions:default":
[
"//dotnet/src/webdriver:netstandard2.0assembly",
"@json.net//:Newtonsoft.Json",
"@benderproxy//:BenderProxy",
"@moq//:Moq",
],
":netframework": [
"//dotnet/src/webdriver:net47assembly",
"@json.net//:Newtonsoft.Json",
"@benderproxy//:BenderProxy",
"@moq//:Moq",
],
":netcore": [
"//dotnet/src/webdriver:netstandard2.0assembly",
"@json.net//:Newtonsoft.Json",
"@benderproxy//:BenderProxy",
"@moq//:Moq",
],
"//conditions:default": [
"//dotnet/src/webdriver:netstandard2.0assembly",
"@json.net//:Newtonsoft.Json",
"@benderproxy//:BenderProxy",
"@moq//:Moq",
],
}),
is_windows = select({
"@bazel_tools//src/conditions:host_windows": True,
"//conditions:default": False,
}),
) for (target_name, config_setting) in SUPPORTED_BROWSERS]
10 changes: 10 additions & 0 deletions java/client/test/org/openqa/selenium/environment/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
load("@rules_jvm_external//:defs.bzl", "artifact")
load("//java:defs.bzl", "java_test_suite")

filegroup(
name = "keystore",
srcs = [
"webserver/keystore",
],
visibility = [
"//dotnet/test:__subpackages__",
],
)

java_library(
name = "environment",
srcs = glob(
Expand Down
1 change: 1 addition & 0 deletions javascript/atoms/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ filegroup(
"**/*.svg",
]),
visibility = [
"//dotnet/test:__subpackages__",
"//java/client/test/org/openqa/selenium/environment:__pkg__",
"//javascript/node/selenium-webdriver:__pkg__",
],
Expand Down
1 change: 1 addition & 0 deletions third_party/closure/goog/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ filegroup(
"**/*.js",
]),
visibility = [
"//dotnet/test:__subpackages__",
"//java/client/test/org/openqa/selenium/environment:__pkg__",
],
)
1 change: 1 addition & 0 deletions third_party/js/selenium/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ copy_file(
out = "webdriver_prefs.json",
visibility = [
"//dotnet/src/webdriver:__pkg__",
"//dotnet/test:__subpackages__",
"//java/client/src/org/openqa/selenium/firefox:__pkg__",
"//java/client/test/org/openqa/selenium/environment:__pkg__",
"//py:__pkg__",
Expand Down

0 comments on commit 8ba74c1

Please sign in to comment.