Skip to content

Commit

Permalink
Adding assembly version stamping to .NET Bazel build process
Browse files Browse the repository at this point in the history
  • Loading branch information
jimevans committed Jan 23, 2020
1 parent c3de3ab commit 29a2ac6
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 19 deletions.
6 changes: 3 additions & 3 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ closure_repositories()

http_archive(
name = "d2l_rules_csharp",
sha256 = "0e688b0f9279855bef3e98657af44c29ac281c510e21919a03ceb69a910ebdf4",
strip_prefix = "rules_csharp-77997bbb79ba4294b1d88ae6f44211df8eb4075e",
sha256 = "3a2eaba9c2175ffb042337182b2295d49e9e913ec745207c339d792ff807aac2",
strip_prefix = "rules_csharp-e240a955d48028d51ba7ff49ed44b9429558d394",
urls = [
"https://github.com/Brightspace/rules_csharp/archive/77997bbb79ba4294b1d88ae6f44211df8eb4075e.tar.gz",
"https://github.com/Brightspace/rules_csharp/archive/e240a955d48028d51ba7ff49ed44b9429558d394.tar.gz",
],
)

Expand Down
11 changes: 11 additions & 0 deletions dotnet/AssemblyInfo.cs.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;
using System.Reflection;

[assembly: System.Reflection.AssemblyCompanyAttribute("{ASSEMBLY_COMPANY}")]
[assembly: System.Reflection.AssemblyCopyrightAttribute("{ASSEMBLY_COPYRIGHT}")]
[assembly: System.Reflection.AssemblyDescriptionAttribute("{ASSEMBLY_DESCRIPTION}")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("{ASSEMBLY_VERSION}")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("{ASSEMBLY_INFORMATIONAL_VERSION}")]
[assembly: System.Reflection.AssemblyProductAttribute("{ASSEMBLY_PRODUCT}")]
[assembly: System.Reflection.AssemblyTitleAttribute("{ASSEMBLY_TITLE}")]
[assembly: System.Reflection.AssemblyVersionAttribute("{ASSEMBLY_VERSION}")]
2 changes: 1 addition & 1 deletion dotnet/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1 +1 @@
exports_files(["WebDriver.snk"])
exports_files(["WebDriver.snk", "AssemblyInfo.cs.template"])
35 changes: 35 additions & 0 deletions dotnet/assembly-info.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Label of the template file to use.
_TEMPLATE = "//dotnet:AssemblyInfo.cs.template"

def _generated_assembly_info_impl(ctx):
ctx.actions.expand_template(
template = ctx.file.template,
output = ctx.outputs.source_file,
substitutions = {
"{ASSEMBLY_VERSION}": ctx.attr.version,
"{ASSEMBLY_COMPANY}": ctx.attr.company,
"{ASSEMBLY_COPYRIGHT}": ctx.attr.copyright,
"{ASSEMBLY_DESCRIPTION}": ctx.attr.description,
"{ASSEMBLY_PRODUCT}": ctx.attr.product,
"{ASSEMBLY_TITLE}": ctx.attr.title,
"{ASSEMBLY_INFORMATIONAL_VERSION}": ctx.attr.informational_version,
},
)

generated_assembly_info = rule(
implementation = _generated_assembly_info_impl,
attrs = {
"version": attr.string(mandatory = True),
"company": attr.string(mandatory = True),
"copyright": attr.string(mandatory = True),
"description": attr.string(mandatory = True),
"product": attr.string(mandatory = True),
"title": attr.string(mandatory = True),
"informational_version": attr.string(mandatory = True),
"template": attr.label(
default = Label(_TEMPLATE),
allow_single_file = True,
),
},
outputs = {"source_file": "%{name}.AssemblyInfo.cs"},
)
30 changes: 27 additions & 3 deletions dotnet/merge-assemblies.bzl
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
load("@d2l_rules_csharp//csharp/private:common.bzl", "collect_transitive_info")
load(
"@d2l_rules_csharp//csharp/private:common.bzl",
"collect_transitive_info",
"fill_in_missing_frameworks"
)
load(
"@d2l_rules_csharp//csharp/private:providers.bzl",
"CSharpAssemblyInfo"
)

def _merged_assembly_impl(ctx):
providers = {}
name = ctx.label.name

deps = ctx.attr.deps
Expand Down Expand Up @@ -39,11 +48,26 @@ def _merged_assembly_impl(ctx):
for dep in ctx.files.deps:
runfiles = runfiles.merge(dep[DefaultInfo].default_runfiles)

return [
providers[target_framework] = CSharpAssemblyInfo[target_framework](
out = ctx.outputs.out,
refout = None,
pdb = None,
native_dlls = native_dlls,
deps = deps,
transitive_refs = refs,
transitive_runfiles = depset([]),
actual_tfm = target_framework,
runtimeconfig = None,
)

fill_in_missing_frameworks(providers)
returned_info = providers.values()
returned_info.append(
DefaultInfo(
runfiles = runfiles,
),
]
)
return returned_info

merged_assembly = rule(
implementation = _merged_assembly_impl,
Expand Down
5 changes: 5 additions & 0 deletions dotnet/selenium-dotnet-version.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@
SE_VERSION = "4.0.0-alpha04"
ASSEMBLY_VERSION = "4.0.0.0"
SUPPORTED_NET_FRAMEWORKS = ["net45", "net46", "net47"]

ASSEMBLY_COMPANY = "Selenium Committers"
ASSEMBLY_COPYRIGHT = "Copyright © Software Freedom Conservancy 2018"
ASSEMBLY_INFORMATIONAL_VERSION = "4"
ASSEMBLY_PRODUCT = "Selenium"
24 changes: 20 additions & 4 deletions dotnet/src/support/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
load("@d2l_rules_csharp//csharp:defs.bzl", "csharp_library")
load("//dotnet:nuget.bzl", "nuget_package")
load("//dotnet:assembly-info.bzl", "generated_assembly_info")
load(
"//dotnet:selenium-dotnet-version.bzl",
"ASSEMBLY_VERSION",
"SE_VERSION",
"SUPPORTED_NET_FRAMEWORKS",
"ASSEMBLY_COMPANY",
"ASSEMBLY_COPYRIGHT",
"ASSEMBLY_INFORMATIONAL_VERSION",
"ASSEMBLY_PRODUCT",
)

generated_assembly_info(
name = "assembly-info",
version = ASSEMBLY_VERSION,
company = ASSEMBLY_COMPANY,
copyright = ASSEMBLY_COPYRIGHT,
description = "Selenium WebDriver .NET Bindings support classes",
product = ASSEMBLY_PRODUCT,
title = "Selenium WebDriver Support",
informational_version = ASSEMBLY_INFORMATIONAL_VERSION,
)

[csharp_library(
Expand All @@ -15,7 +31,7 @@ load(
"Extensions/*.cs",
"PageObjects/**/*.cs",
"UI/*.cs",
]),
]) + [":assembly-info"],
out = "merged/{}/WebDriver.Support".format(framework),
target_frameworks = [
"{}".format(framework),
Expand All @@ -39,7 +55,7 @@ csharp_library(
"Extensions/*.cs",
"PageObjects/**/*.cs",
"UI/*.cs",
]),
]) + [":assembly-info"],
out = "merged/netstandard2.0/WebDriver.Support",
target_frameworks = [
"netstandard2.0",
Expand All @@ -58,7 +74,7 @@ csharp_library(
"Extensions/*.cs",
"PageObjects/**/*.cs",
"UI/*.cs",
]),
]) + [":assembly-info"],
out = "strongnamed/{}/WebDriver.Support".format(framework),
keyfile = "//dotnet:WebDriver.snk",
target_frameworks = [
Expand All @@ -83,7 +99,7 @@ csharp_library(
"Extensions/*.cs",
"PageObjects/**/*.cs",
"UI/*.cs",
]),
]) + [":assembly-info"],
out = "strongnamed/netstandard2.0/WebDriver.Support",
keyfile = "//dotnet:WebDriver.snk",
target_frameworks = [
Expand Down
24 changes: 20 additions & 4 deletions dotnet/src/webdriver/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
load("@d2l_rules_csharp//csharp:defs.bzl", "csharp_library")
load("//dotnet:merge-assemblies.bzl", "merged_assembly")
load("//dotnet:assembly-info.bzl", "generated_assembly_info")
load("//:copy_file.bzl", "copy_file")
load("//dotnet:nuget.bzl", "nuget_package")
load(
"//dotnet:selenium-dotnet-version.bzl",
"ASSEMBLY_VERSION",
"SE_VERSION",
"SUPPORTED_NET_FRAMEWORKS",
"ASSEMBLY_COMPANY",
"ASSEMBLY_COPYRIGHT",
"ASSEMBLY_INFORMATIONAL_VERSION",
"ASSEMBLY_PRODUCT",
)

generated_assembly_info(
name = "assembly-info",
version = ASSEMBLY_VERSION,
company = ASSEMBLY_COMPANY,
copyright = ASSEMBLY_COPYRIGHT,
description = "Selenium WebDriver API .NET Bindings",
product = ASSEMBLY_PRODUCT,
title = "Selenium WebDriver",
informational_version = ASSEMBLY_INFORMATIONAL_VERSION,
)

[csharp_library(
Expand All @@ -26,7 +42,7 @@ load(
"Remote/**/*.cs",
"Safari/*.cs",
"Support/*.cs",
]),
]) + [":assembly-info"],
resources = [
"//javascript/atoms/fragments:find-elements.js",
"//javascript/atoms/fragments:is-displayed.js",
Expand Down Expand Up @@ -68,7 +84,7 @@ csharp_library(
"Remote/**/*.cs",
"Safari/*.cs",
"Support/*.cs",
]),
]) + [":assembly-info"],
resources = [
"//javascript/atoms/fragments:find-elements.js",
"//javascript/atoms/fragments:is-displayed.js",
Expand Down Expand Up @@ -101,7 +117,7 @@ csharp_library(
"Remote/**/*.cs",
"Safari/*.cs",
"Support/*.cs",
]),
]) + [":assembly-info"],
keyfile = "//dotnet:WebDriver.snk",
resources = [
"//javascript/atoms/fragments:find-elements.js",
Expand Down Expand Up @@ -144,7 +160,7 @@ csharp_library(
"Remote/**/*.cs",
"Safari/*.cs",
"Support/*.cs",
]),
]) + [":assembly-info"],
keyfile = "//dotnet:WebDriver.snk",
resources = [
"//javascript/atoms/fragments:find-elements.js",
Expand Down
24 changes: 20 additions & 4 deletions dotnet/src/webdriverbackedselenium/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,18 +1,34 @@
load("@d2l_rules_csharp//csharp:defs.bzl", "csharp_library")
load("//dotnet:nuget.bzl", "nuget_package")
load("//dotnet:assembly-info.bzl", "generated_assembly_info")
load(
"//dotnet:selenium-dotnet-version.bzl",
"ASSEMBLY_VERSION",
"SE_VERSION",
"SUPPORTED_NET_FRAMEWORKS",
"ASSEMBLY_COMPANY",
"ASSEMBLY_COPYRIGHT",
"ASSEMBLY_INFORMATIONAL_VERSION",
"ASSEMBLY_PRODUCT",
)

generated_assembly_info(
name = "assembly-info",
version = ASSEMBLY_VERSION,
company = ASSEMBLY_COMPANY,
copyright = ASSEMBLY_COPYRIGHT,
description = "Selenium RC API using WebDriver .NET Bindings",
product = ASSEMBLY_PRODUCT,
title = "Selenium WebDriver WebDriverBackedSelenium",
informational_version = ASSEMBLY_INFORMATIONAL_VERSION,
)

[csharp_library(
name = "{}".format(framework),
srcs = glob([
"*.cs",
"Internal/**/*.cs",
]),
]) + [":assembly-info"],
out = "merged/{}/Selenium.WebDriverBackedSelenium".format(framework),
resources = [
"//java/client/src/com/thoughtworks/selenium/webdriven:htmlutils.js",
Expand Down Expand Up @@ -52,7 +68,7 @@ csharp_library(
srcs = glob([
"*.cs",
"Internal/**/*.cs",
]),
]) + [":assembly-info"],
out = "merged/netstandard2.0/Selenium.WebDriverBackedSelenium",
resources = [
"//java/client/src/com/thoughtworks/selenium/webdriven:htmlutils.js",
Expand Down Expand Up @@ -83,7 +99,7 @@ csharp_library(
srcs = glob([
"*.cs",
"Internal/**/*.cs",
]),
]) + [":assembly-info"],
out = "strongnamed/{}/Selenium.WebDriverBackedSelenium".format(framework),
keyfile = "//dotnet:WebDriver.snk",
resources = [
Expand Down Expand Up @@ -124,7 +140,7 @@ csharp_library(
srcs = glob([
"*.cs",
"Internal/**/*.cs",
]),
]) + [":assembly-info"],
out = "strongnamed/netstandard2.0/Selenium.WebDriverBackedSelenium",
keyfile = "//dotnet:WebDriver.snk",
resources = [
Expand Down

0 comments on commit 29a2ac6

Please sign in to comment.