Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions dotnet/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ load("//dotnet/private:nuget_pack.bzl", _nuget_pack = "nuget_pack")
load("//dotnet/private:nuget_package.bzl", _nuget_package = "nuget_package")
load("//dotnet/private:nuget_push.bzl", _nuget_push = "nuget_push")
load("//dotnet/private:paket_deps.bzl", _paket_deps = "paket_deps")
load("//dotnet/private:sourcelink.bzl", _csharp_sourcelink_library = "csharp_sourcelink_library")

def devtools_version_targets():
targets = []
Expand All @@ -18,6 +19,7 @@ def devtools_version_targets():

csharp_binary = _csharp_binary
csharp_library = _csharp_library
csharp_sourcelink_library = _csharp_sourcelink_library
csharp_test = _csharp_test
dotnet_format = _dotnet_format
dotnet_nunit_test_suite = _dotnet_nunit_test_suite
Expand Down
5 changes: 5 additions & 0 deletions dotnet/private/nuget_pack.bzl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
load("@rules_dotnet//dotnet/private:common.bzl", "is_debug")
load("@rules_dotnet//dotnet/private:providers.bzl", "DotnetAssemblyRuntimeInfo")
load(":dotnet_utils.bzl", "dotnet_preamble")
load(":providers.bzl", "NugetPackageInfo")

_CSPROJ_TEMPLATE = """\
<Project Sdk="Microsoft.NET.Sdk">
Expand Down Expand Up @@ -134,6 +135,10 @@ def nuget_pack_impl(ctx):
files = depset([pkg, symbols_pkg]),
runfiles = ctx.runfiles(files = [pkg, symbols_pkg]),
),
NugetPackageInfo(
package = pkg,
symbols = symbols_pkg,
),
]

nuget_pack = rule(
Expand Down
6 changes: 5 additions & 1 deletion dotnet/private/nuget_push.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ def _create_unix_script(ctx, dotnet, nupkg_files):
"""Create bash script for Unix/macOS/Linux."""
push_commands = []
for nupkg in nupkg_files:
if nupkg.basename.endswith(".snupkg"):
Comment thread
AutomatedTester marked this conversation as resolved.
continue
nupkg_runfiles_path = _to_runfiles_path(nupkg.short_path)
push_commands.append(
'"$DOTNET" nuget push "$RUNFILES_DIR/{nupkg}" --api-key "$NUGET_API_KEY" --source "$NUGET_SOURCE" --skip-duplicate'.format(nupkg = nupkg_runfiles_path),
Expand Down Expand Up @@ -77,6 +79,8 @@ def _create_windows_script(ctx, dotnet, nupkg_files):
"""Create batch script for Windows."""
push_commands = []
for nupkg in nupkg_files:
if nupkg.basename.endswith(".snupkg"):
continue
nupkg_runfiles_path = _to_runfiles_path(nupkg.short_path).replace("/", "\\")
push_commands.append(
'"%%DOTNET%%" nuget push "%%~dp0%s" --api-key "%%NUGET_API_KEY%%" --source "%%NUGET_SOURCE%%" --skip-duplicate' % nupkg_runfiles_path,
Expand Down Expand Up @@ -107,7 +111,7 @@ nuget_push = rule(
"packages": attr.label_list(
doc = "The nupkg files to push",
mandatory = True,
allow_files = [".nupkg"],
allow_files = [".nupkg", ".snupkg"],
),
"_windows_constraint": attr.label(
default = "@platforms//os:windows",
Expand Down
93 changes: 93 additions & 0 deletions dotnet/private/sourcelink.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
"""C# library rule with SourceLink metadata embedded in PDB files."""

load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
load("@rules_dotnet//dotnet/private:common.bzl", "is_debug")
load("@rules_dotnet//dotnet/private/rules/common:attrs.bzl", "CSHARP_LIBRARY_COMMON_ATTRS")
load("@rules_dotnet//dotnet/private/rules/common:library.bzl", "build_library")
load("@rules_dotnet//dotnet/private/rules/csharp/actions:csharp_assembly.bzl", "AssemblyAction")
load("@rules_dotnet//dotnet/private/transitions:tfm_transition.bzl", "tfm_transition")

def _generate_sourcelink_json(ctx):
output = ctx.actions.declare_file(ctx.label.name + "_sourcelink.json")
ctx.actions.run_shell(
inputs = [ctx.version_file],
outputs = [output],
command = """
COMMIT=$(grep "^STABLE_GIT_REVISION " "{status}" | cut -d' ' -f2 | tr -d '*')
[ -z "$COMMIT" ] && COMMIT=HEAD
printf '{{"documents":{{"*":"{repo}/raw/%s/*"}}}}\\n' "$COMMIT" > "{output}"
""".format(
status = ctx.version_file.path,
repo = ctx.attr.repo_url.rstrip("/"),
output = output.path,
),
mnemonic = "GenSourcelinkJson",
progress_message = "Generating sourcelink.json for " + str(ctx.label),
)
return output

def _compile_action(ctx, tfm):
toolchain = ctx.toolchains["@rules_dotnet//dotnet:toolchain_type"]
is_windows = ctx.target_platform_has_constraint(
ctx.attr._windows_constraint[platform_common.ConstraintValueInfo],
)
sourcelink_json = _generate_sourcelink_json(ctx)
return AssemblyAction(
ctx.actions,
ctx.executable._compiler_wrapper_bat if is_windows else ctx.executable._compiler_wrapper_sh,
label = ctx.label,
additionalfiles = ctx.files.additionalfiles,
debug = is_debug(ctx),
defines = ctx.attr.defines,
deps = ctx.attr.deps,
exports = ctx.attr.exports,
targeting_pack = ctx.attr._targeting_pack[0],
internals_visible_to = ctx.attr.internals_visible_to,
keyfile = ctx.file.keyfile,
langversion = ctx.attr.langversion,
resources = ctx.files.resources,
srcs = ctx.files.srcs,
data = ctx.files.data,
appsetting_files = [],
compile_data = ctx.files.compile_data + [sourcelink_json],
out = ctx.attr.out,
target = "library",
target_name = ctx.attr.name,
target_framework = tfm,
toolchain = toolchain,
strict_deps = toolchain.strict_deps[BuildSettingInfo].value,
generate_documentation_file = ctx.attr.generate_documentation_file,
include_host_model_dll = False,
treat_warnings_as_errors = ctx.attr.treat_warnings_as_errors,
warnings_as_errors = ctx.attr.warnings_as_errors,
warnings_not_as_errors = ctx.attr.warnings_not_as_errors,
warning_level = ctx.attr.warning_level,
nowarn = ctx.attr.nowarn,
project_sdk = ctx.attr.project_sdk,
allow_unsafe_blocks = ctx.attr.allow_unsafe_blocks,
nullable = ctx.attr.nullable,
run_analyzers = ctx.attr.run_analyzers,
is_analyzer = ctx.attr.is_analyzer,
is_language_specific_analyzer = ctx.attr.is_language_specific_analyzer,
analyzer_configs = ctx.files.analyzer_configs,
compiler_options = ctx.attr.compiler_options + ["/sourcelink:" + sourcelink_json.path],
is_windows = is_windows,
)

def _csharp_sourcelink_library_impl(ctx):
return build_library(ctx, _compile_action)

_SOURCELINK_ATTRS = dict(CSHARP_LIBRARY_COMMON_ATTRS)
_SOURCELINK_ATTRS["repo_url"] = attr.string(
doc = "Source repository URL for SourceLink metadata (e.g. https://github.com/owner/repo).",
default = "https://github.com/SeleniumHQ/selenium",
)

csharp_sourcelink_library = rule(
_csharp_sourcelink_library_impl,
doc = "Compile a C# DLL with SourceLink metadata embedded in the PDB.",
attrs = _SOURCELINK_ATTRS,
executable = False,
toolchains = ["@rules_dotnet//dotnet:toolchain_type"],
cfg = tfm_transition,
)
4 changes: 2 additions & 2 deletions dotnet/src/support/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
load(
"//dotnet:defs.bzl",
"csharp_library",
"csharp_sourcelink_library",
"generated_assembly_info",
"nuget_pack",
"nuget_package",
Expand All @@ -26,7 +26,7 @@ generated_assembly_info(
version = ASSEMBLY_VERSION,
)

csharp_library(
csharp_sourcelink_library(
name = "support",
srcs = glob([
"**/*.cs",
Expand Down
8 changes: 4 additions & 4 deletions dotnet/src/webdriver/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("//common:defs.bzl", "copy_file")
load("//dotnet:defs.bzl", "csharp_library", "devtools_version_targets", "generated_assembly_info", "generated_resource_utilities", "nuget_pack", "nuget_package")
load("//dotnet:defs.bzl", "csharp_sourcelink_library", "devtools_version_targets", "generated_assembly_info", "generated_resource_utilities", "nuget_pack", "nuget_package")
load(
"//dotnet:version.bzl",
"ASSEMBLY_COMPANY",
Expand Down Expand Up @@ -41,7 +41,7 @@ generated_resource_utilities(
},
)

csharp_library(
csharp_sourcelink_library(
name = "webdriver-net462",
srcs = [
":assembly-info",
Expand Down Expand Up @@ -72,7 +72,7 @@ csharp_library(
],
)

csharp_library(
csharp_sourcelink_library(
name = "webdriver-netstandard2.0",
srcs = [
":assembly-info",
Expand Down Expand Up @@ -104,7 +104,7 @@ csharp_library(
],
)

csharp_library(
csharp_sourcelink_library(
name = "webdriver-net8.0",
srcs = [
":assembly-info",
Expand Down
Loading