Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose source-files and project structure #455

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
21 changes: 21 additions & 0 deletions dotnet/private/providers.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,24 @@ DotnetApphostPackInfo = provider(
"apphost": "File: The apphost file",
},
)

DotnetCompileInfo = provider(
doc = "Information about how a .Net target is to be compiled",
fields = {
"label": "Label: The label of the target",
"srcs": "list[File]: sources to be compiled",
"deps": "list[DotnetCompileDepVariantInfo]: The direct dependencies of the target",
"transitive_deps": "depset[DotnetCompileDepVariantInfo]: The transitive dependencies of the target",
},
)

DotnetCompileDepVariantInfo = provider(
doc = "A wrapper provider for a compilation dependency. The dependency can be a project " +
"dependency, in which case the `dotnet_compile_info` will be populated" +
"or a NuGet dependency, in which case `dotnet_assembly_compile_info` will be populated.",
fields = {
"label": "Label: The label of the dependency",
"dotnet_compile_info": "DotnetCompileInfo: The DotnetCompileInfo of a dependency",
"dotnet_assembly_compile_info": "DotnetAssemblyCompileInfo: The NuGet info of a dependency",
},
)
7 changes: 7 additions & 0 deletions dotnet/private/rules/common/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,10 @@ bzl_library(
"@bazel_skylib//lib:dicts",
],
)

bzl_library(
name = "compile_info",
srcs = ["compile_info.bzl"],
visibility = ["//dotnet:__subpackages__"],
deps = ["//dotnet/private:providers"],
)
8 changes: 7 additions & 1 deletion dotnet/private/rules/common/binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ load(
"to_rlocation_path",
)
load("//dotnet/private:providers.bzl", "DotnetApphostPackInfo", "DotnetBinaryInfo", "DotnetRuntimePackInfo")
load(
"//dotnet/private/rules/common:compile_info.bzl",
"gather_compile_info"
)

def _create_launcher(ctx, runfiles, executable):
runtime = ctx.toolchains["//dotnet:toolchain_type"].runtime
Expand Down Expand Up @@ -136,4 +140,6 @@ def build_binary(ctx, compile_action):
runtime_pack_info = ctx.attr._runtime_pack[0][DotnetRuntimePackInfo],
)

return [default_info, dotnet_binary_info, compile_provider, runtime_provider]
compile_info_provider = gather_compile_info(ctx)

return [default_info, dotnet_binary_info, compile_provider, runtime_provider, compile_info_provider]
42 changes: 42 additions & 0 deletions dotnet/private/rules/common/compile_info.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"Utility function for collecting compilation information from contexts"

load("//dotnet/private:providers.bzl", "NuGetInfo", "DotnetCompileInfo", "DotnetCompileDepVariantInfo", "DotnetAssemblyCompileInfo")


def gather_compile_info(ctx):
"""Collects compilation information from a context

Args:
ctx: Bazel build ctx.
Returns:
A collection of the source-files, dependencies and transitive dependencies
"""
direct_deps = []
transitive_deps = []

for dep in ctx.attr.deps:
if DotnetCompileInfo in dep:
variant = DotnetCompileDepVariantInfo(
label = dep.label,
dotnet_compile_info = dep[DotnetCompileInfo],
dotnet_assembly_compile_info = None,
)

direct_deps.append(variant)
transitive_deps.append(depset(dep[DotnetCompileInfo].deps, transitive = [ dep[DotnetCompileInfo].transitive_deps ]))

if NuGetInfo in dep and DotnetAssemblyCompileInfo in dep:
variant = DotnetCompileDepVariantInfo(
label = dep.label,
dotnet_compile_info = None,
dotnet_assembly_compile_info = dep[DotnetAssemblyCompileInfo],
)

direct_deps.append(variant)

return DotnetCompileInfo(
label = ctx.label,
srcs = ctx.files.srcs,
deps = direct_deps,
transitive_deps = depset([], transitive = transitive_deps),
)
7 changes: 7 additions & 0 deletions dotnet/private/rules/common/library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
load("//dotnet/private:common.bzl", "collect_transitive_runfiles")
load(
"//dotnet/private/rules/common:compile_info.bzl",
"gather_compile_info"
)

def build_library(ctx, compile_action):
"""Builds a .Net library from a compilation action
Expand All @@ -21,9 +25,12 @@ def build_library(ctx, compile_action):

(compile_provider, runtime_provider) = compile_action(ctx, tfm)

compile_info_provider = gather_compile_info(ctx)

return [
compile_provider,
runtime_provider,
compile_info_provider,
DefaultInfo(
files = depset(runtime_provider.libs + runtime_provider.xml_docs),
default_runfiles = collect_transitive_runfiles(
Expand Down
2 changes: 1 addition & 1 deletion dotnet/private/rules/fsharp/actions/fsharp_assembly.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def AssemblyAction(
keyfile: Specifies a strong name key file of the assembly.
langversion: Specify language version: Default, ISO-1, ISO-2, 3, 4, 5, 6, 7, 7.1, 7.2, 7.3, or Latest
resources: The list of resouces to be embedded in the assembly.
srcs: The list of source (.cs) files that are processed to create the assembly.
srcs: The list of source (.fs) files that are processed to create the assembly.
data: List of files that are a direct runtime dependency
appsetting_files: List of appsettings files to include in the output.
compile_data: List of files that are a direct compile time dependency
Expand Down
12 changes: 12 additions & 0 deletions dotnet/private/tests/appsettings/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load(":tests.bzl", "appsettings_test_suite")

appsettings_test_suite(name = "appsettings_test_suite")

bzl_library(
name = "tests",
srcs = ["tests.bzl"],
visibility = ["//dotnet:__subpackages__"],
deps = [
"//dotnet:defs",
"//dotnet/private/tests:utils",
"@rules_testing//lib:analysis_test",
],
)
8 changes: 8 additions & 0 deletions dotnet/private/tests/publish/cross_publish/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load(":tests.bzl", "tests")

tests()

bzl_library(
name = "tests",
srcs = ["tests.bzl"],
visibility = ["//dotnet:__subpackages__"],
deps = ["//dotnet:defs"],
)