Skip to content

Commit

Permalink
Breaking out .NET custom Bazel rules into descriptive-named files by …
Browse files Browse the repository at this point in the history
…function
  • Loading branch information
jimevans committed May 3, 2019
1 parent f905b53 commit e853da7
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 44 deletions.
41 changes: 41 additions & 0 deletions dotnet/merge-assemblies.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
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"],
)
42 changes: 1 addition & 41 deletions dotnet/build-rules.bzl → dotnet/nuget.bzl
Original file line number Diff line number Diff line change
@@ -1,45 +1,5 @@
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",
Expand Down Expand Up @@ -98,4 +58,4 @@ nuget_package = rule(
allow_single_file = True
),
}
)
)
2 changes: 1 addition & 1 deletion dotnet/src/support/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
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:nuget.bzl", "nuget_package")
load("//dotnet:selenium-dotnet-version.bzl",
"SE_VERSION",
"ASSEMBLY_VERSION",
Expand Down
3 changes: 2 additions & 1 deletion dotnet/src/webdriver/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
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:merge-assemblies.bzl", "merged_assembly")
load("//dotnet:nuget.bzl", "nuget_package")
load("//dotnet:selenium-dotnet-version.bzl",
"SE_VERSION",
"ASSEMBLY_VERSION",
Expand Down
2 changes: 1 addition & 1 deletion dotnet/src/webdriverbackedselenium/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("@io_bazel_rules_dotnet//dotnet:defs.bzl", "net_library", "core_library", "core_resource")
load("//dotnet:build-rules.bzl", "nuget_package")
load("//dotnet:nuget.bzl", "nuget_package")
load("//dotnet:selenium-dotnet-version.bzl",
"SE_VERSION",
"ASSEMBLY_VERSION",
Expand Down

0 comments on commit e853da7

Please sign in to comment.