From 29a2ac664e9010b8bc6f600ba4d735111eeb0a9e Mon Sep 17 00:00:00 2001 From: Jim Evans Date: Mon, 20 Jan 2020 12:42:33 -0800 Subject: [PATCH] Adding assembly version stamping to .NET Bazel build process --- WORKSPACE | 6 ++-- dotnet/AssemblyInfo.cs.template | 11 ++++++ dotnet/BUILD.bazel | 2 +- dotnet/assembly-info.bzl | 35 +++++++++++++++++++ dotnet/merge-assemblies.bzl | 30 ++++++++++++++-- dotnet/selenium-dotnet-version.bzl | 5 +++ dotnet/src/support/BUILD.bazel | 24 ++++++++++--- dotnet/src/webdriver/BUILD.bazel | 24 ++++++++++--- .../src/webdriverbackedselenium/BUILD.bazel | 24 ++++++++++--- 9 files changed, 142 insertions(+), 19 deletions(-) create mode 100644 dotnet/AssemblyInfo.cs.template create mode 100644 dotnet/assembly-info.bzl diff --git a/WORKSPACE b/WORKSPACE index 189c410a275f9..99ce220402add 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -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", ], ) diff --git a/dotnet/AssemblyInfo.cs.template b/dotnet/AssemblyInfo.cs.template new file mode 100644 index 0000000000000..996f62287a945 --- /dev/null +++ b/dotnet/AssemblyInfo.cs.template @@ -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}")] diff --git a/dotnet/BUILD.bazel b/dotnet/BUILD.bazel index 521148f28f62e..94bf1ec4518eb 100644 --- a/dotnet/BUILD.bazel +++ b/dotnet/BUILD.bazel @@ -1 +1 @@ -exports_files(["WebDriver.snk"]) +exports_files(["WebDriver.snk", "AssemblyInfo.cs.template"]) diff --git a/dotnet/assembly-info.bzl b/dotnet/assembly-info.bzl new file mode 100644 index 0000000000000..cec1e6842cd84 --- /dev/null +++ b/dotnet/assembly-info.bzl @@ -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"}, +) diff --git a/dotnet/merge-assemblies.bzl b/dotnet/merge-assemblies.bzl index 717627dec52ba..db805fc6ca5ec 100644 --- a/dotnet/merge-assemblies.bzl +++ b/dotnet/merge-assemblies.bzl @@ -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 @@ -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, diff --git a/dotnet/selenium-dotnet-version.bzl b/dotnet/selenium-dotnet-version.bzl index 1e5f619bdbafc..f7a60f92a8e8f 100644 --- a/dotnet/selenium-dotnet-version.bzl +++ b/dotnet/selenium-dotnet-version.bzl @@ -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" diff --git a/dotnet/src/support/BUILD.bazel b/dotnet/src/support/BUILD.bazel index 5c1355ec01bbe..d4852d52836ab 100644 --- a/dotnet/src/support/BUILD.bazel +++ b/dotnet/src/support/BUILD.bazel @@ -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( @@ -15,7 +31,7 @@ load( "Extensions/*.cs", "PageObjects/**/*.cs", "UI/*.cs", - ]), + ]) + [":assembly-info"], out = "merged/{}/WebDriver.Support".format(framework), target_frameworks = [ "{}".format(framework), @@ -39,7 +55,7 @@ csharp_library( "Extensions/*.cs", "PageObjects/**/*.cs", "UI/*.cs", - ]), + ]) + [":assembly-info"], out = "merged/netstandard2.0/WebDriver.Support", target_frameworks = [ "netstandard2.0", @@ -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 = [ @@ -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 = [ diff --git a/dotnet/src/webdriver/BUILD.bazel b/dotnet/src/webdriver/BUILD.bazel index 21a9d2ccd38bf..090bfb11b43fb 100644 --- a/dotnet/src/webdriver/BUILD.bazel +++ b/dotnet/src/webdriver/BUILD.bazel @@ -1,5 +1,6 @@ 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( @@ -7,6 +8,21 @@ load( "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( @@ -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", @@ -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", @@ -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", @@ -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", diff --git a/dotnet/src/webdriverbackedselenium/BUILD.bazel b/dotnet/src/webdriverbackedselenium/BUILD.bazel index a8abc16122420..f9cb879b95668 100644 --- a/dotnet/src/webdriverbackedselenium/BUILD.bazel +++ b/dotnet/src/webdriverbackedselenium/BUILD.bazel @@ -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 RC API using WebDriver .NET Bindings", + product = ASSEMBLY_PRODUCT, + title = "Selenium WebDriver WebDriverBackedSelenium", + informational_version = ASSEMBLY_INFORMATIONAL_VERSION, ) [csharp_library( @@ -12,7 +28,7 @@ load( srcs = glob([ "*.cs", "Internal/**/*.cs", - ]), + ]) + [":assembly-info"], out = "merged/{}/Selenium.WebDriverBackedSelenium".format(framework), resources = [ "//java/client/src/com/thoughtworks/selenium/webdriven:htmlutils.js", @@ -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", @@ -83,7 +99,7 @@ csharp_library( srcs = glob([ "*.cs", "Internal/**/*.cs", - ]), + ]) + [":assembly-info"], out = "strongnamed/{}/Selenium.WebDriverBackedSelenium".format(framework), keyfile = "//dotnet:WebDriver.snk", resources = [ @@ -124,7 +140,7 @@ csharp_library( srcs = glob([ "*.cs", "Internal/**/*.cs", - ]), + ]) + [":assembly-info"], out = "strongnamed/netstandard2.0/Selenium.WebDriverBackedSelenium", keyfile = "//dotnet:WebDriver.snk", resources = [