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

Test structure #290

Merged
merged 7 commits into from
Jun 22, 2022
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
8 changes: 4 additions & 4 deletions .gitpod/gitpod.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,21 @@ ENV PATH=$PATH:$HOME/bin
### Bazel and Bazel releated binaries ###
#########################################
# Install bazelisk and make it available on PATH as it as bazel
RUN curl -o bazelisk-linux-amd64 -fsSL https://github.com/bazelbuild/bazelisk/releases/download/v1.10.1/bazelisk-linux-amd64 \
RUN curl -o bazelisk-linux-amd64 -fsSL https://github.com/bazelbuild/bazelisk/releases/download/v1.12.0/bazelisk-linux-amd64 \
&& mv ./bazelisk-linux-amd64 $HOME/bin/bazel \
&& chmod +x $HOME/bin/bazel

# Install bazel-watcher
RUN curl -o ibazel_linux_amd64 -fsSL https://github.com/bazelbuild/bazel-watcher/releases/download/v0.15.10/ibazel_linux_amd64 \
RUN curl -o ibazel_linux_amd64 -fsSL https://github.com/bazelbuild/bazel-watcher/releases/download/v0.16.2/ibazel_linux_amd64 \
&& mv ./ibazel_linux_amd64 $HOME/bin/ibazel \
&& chmod +x $HOME/bin/ibazel

# Install buildifier
RUN curl -o buildifier-linux-amd64 -fsSL https://github.com/bazelbuild/buildtools/releases/download/4.2.2/buildifier-linux-amd64 \
RUN curl -o buildifier-linux-amd64 -fsSL https://github.com/bazelbuild/buildtools/releases/download/5.1.0/buildifier-linux-amd64 \
&& mv ./buildifier-linux-amd64 $HOME/bin/buildifier \
&& chmod +x $HOME/bin/buildifier

# Install buildozer
RUN curl -o buildozer-linux-amd64 -fsSL https://github.com/bazelbuild/buildtools/releases/download/4.2.2/buildozer-linux-amd64 \
RUN curl -o buildozer-linux-amd64 -fsSL https://github.com/bazelbuild/buildtools/releases/download/5.1.0/buildozer-linux-amd64 \
&& mv ./buildozer-linux-amd64 $HOME/bin/buildozer \
&& chmod +x $HOME/bin/buildozer
4 changes: 4 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@ load(
rules_dotnet_dependencies()

dotnet_register_toolchains("dotnet", "6.0.300")

load("//tests:dependencies.bzl", "test_dependencies")

test_dependencies()
74 changes: 37 additions & 37 deletions docs/BUILD
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
load("@io_bazel_stardoc//stardoc:stardoc.bzl", "stardoc")
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
# load("@io_bazel_stardoc//stardoc:stardoc.bzl", "stardoc")
# load("@bazel_skylib//:bzl_library.bzl", "bzl_library")

bzl_library(
name = "bazel_dependencies",
srcs = [
"@bazel_skylib//lib:dicts",
"@bazel_skylib//lib:paths",
"@bazel_tools//tools:bzl_srcs",
],
)
# bzl_library(
# name = "bazel_dependencies",
# srcs = [
# "@bazel_skylib//lib:dicts",
# "@bazel_skylib//lib:paths",
# "@bazel_tools//tools:bzl_srcs",
# ],
# )

bzl_library(
name = "rules_dotnet",
srcs = [
"//dotnet/private:bzl_srcs",
],
)
# bzl_library(
# name = "rules_dotnet",
# srcs = [
# "//dotnet/private:bzl_srcs",
# ],
# )

stardoc(
name = "core",
out = "APIReference.md",
input = "//dotnet:defs.bzl",
symbol_names = [
"csharp_binary",
"csharp_library",
"csharp_nunit_test",
"dotnet_register_toolchains",
"dotnet_repositories",
"import_multiframework_library",
"import_library",
"import_nuget_package",
"nuget_package",
],
tags = ["fix-windows"],
deps = [
":bazel_dependencies",
":rules_dotnet",
],
)
# stardoc(
# name = "core",
# out = "APIReference.md",
# input = "//dotnet:defs.bzl",
# symbol_names = [
# "csharp_binary",
# "csharp_library",
# "csharp_nunit_test",
# "dotnet_register_toolchains",
# "dotnet_repositories",
# "import_multiframework_library",
# "import_library",
# "import_nuget_package",
# "nuget_package",
# ],
# tags = ["fix-windows"],
# deps = [
# ":bazel_dependencies",
# ":rules_dotnet",
# ],
# )
3 changes: 1 addition & 2 deletions dotnet/private/actions/csharp_assembly.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ Actions for compiling targets with C#.
load(
"//dotnet/private:common.bzl",
"collect_transitive_info",
"use_highentropyva",
"format_ref_arg",
"use_highentropyva",
)
load(
"//dotnet/private:providers.bzl",
Expand Down Expand Up @@ -40,7 +40,6 @@ def AssemblyAction(
Args:
actions: Bazel module providing functions to create actions.
additionalfiles: Names additional files that don't directly affect code generation but may be used by analyzers for producing errors or warnings.
analyzers: The list of analyzers to run from this assembly.
debug: Emits debugging information.
defines: The list of conditional compilation symbols.
deps: The list of other libraries to be linked in to the assembly.
Expand Down
2 changes: 1 addition & 1 deletion dotnet/private/actions/fsharp_assembly.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ Actions for compiling targets with C#.
load(
"//dotnet/private:common.bzl",
"collect_transitive_info",
"format_ref_arg",
"is_core_framework",
"is_standard_framework",
"use_highentropyva",
"format_ref_arg",
)
load(
"//dotnet/private:providers.bzl",
Expand Down
11 changes: 5 additions & 6 deletions dotnet/private/common.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def format_ref_arg(args, refs, targeting_pack_overrides):
Args:
args: The args object that will be sent into the compilation action
refs: List of all references that are being sent into the compilation action
targeting_pack_overrides: Dict of overrides that are declared by targeting packs
targeting_pack_overrides: Dict of overrides that are declared by targeting packs
Returns:
The updated args object
"""
Expand All @@ -41,8 +41,8 @@ def format_ref_arg(args, refs, targeting_pack_overrides):
return None

return "/r:" + assembly.path
args.add_all(refs, allow_closure= True, map_each = _format_ref_with_overrides)

args.add_all(refs, allow_closure = True, map_each = _format_ref_with_overrides)

return args

Expand Down Expand Up @@ -90,11 +90,10 @@ def collect_transitive_info(name, deps):
direct_analyzers.extend(assembly.analyzers)
transitive_analyzers.append(assembly.transitive_analyzers)


return (
depset(direct = direct_irefs, transitive = transitive_prefs),
depset(direct = direct_prefs, transitive = transitive_prefs),
depset(direct = direct_analyzers, transitive = transitive_analyzers),
depset(direct = direct_runfiles, transitive = transitive_runfiles),
overrides
)
overrides,
)
29 changes: 17 additions & 12 deletions dotnet/private/macros/register_tfms.bzl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"Register TFM flags and set up the compatibility chains"

load("@bazel_skylib//lib:sets.bzl", "sets")
load("@bazel_skylib//rules:common_settings.bzl", "string_flag", "bool_setting")
load("@bazel_skylib//rules:common_settings.bzl", "bool_setting", "string_flag")
load(
"//dotnet/private:providers.bzl",
"FRAMEWORK_COMPATIBILITY",
Expand All @@ -15,14 +17,15 @@ def _collect_transitive():
TRANSITIVE_FRAMEWORK_COMPATIBILITY = _collect_transitive()

# use pre-computed transition outputs
_transition_outputs = {
tfm: {
"@rules_dotnet//dotnet:framework_compatible_%s" % framework: sets.contains(tfm_compatible_set, framework) for framework in FRAMEWORK_COMPATIBILITY.keys()
} for (tfm, tfm_compatible_set) in TRANSITIVE_FRAMEWORK_COMPATIBILITY.items()
_transition_outputs = {
tfm: {
"@rules_dotnet//dotnet:framework_compatible_%s" % framework: sets.contains(tfm_compatible_set, framework)
for framework in FRAMEWORK_COMPATIBILITY.keys()
}
for (tfm, tfm_compatible_set) in TRANSITIVE_FRAMEWORK_COMPATIBILITY.items()
}

def _impl(settings, attr):
_ignore = attr
def _impl(settings, _attr):
tfm = settings["@rules_dotnet//dotnet:target_framework"]

if tfm not in _transition_outputs:
Expand All @@ -36,28 +39,30 @@ nuget_framework_transition = transition(
outputs = ["@rules_dotnet//dotnet:framework_compatible_%s" % framework for framework in FRAMEWORK_COMPATIBILITY.keys()],
)

# buildifier: disable=unnamed-macro
def register_tfms():
"Register TFM flags and set up the compatibility chains"
string_flag(
name = "target_framework",
values = FRAMEWORK_COMPATIBILITY.keys(),
build_setting_default = "net6.0",
visibility = ["//visibility:public"]
visibility = ["//visibility:public"],
)

for framework in FRAMEWORK_COMPATIBILITY.keys():
bool_setting(
name = "framework_compatible_%s" % framework,
build_setting_default = False,
visibility = ["//visibility:public"]
visibility = ["//visibility:public"],
)

# when activating a certain target framework there should be a transation
# that enables pricesly all compatible framework versions. This allows us to
# create config_settings for each tfm that a nuget package provides Where the
# that enables pricesly all compatible framework versions. This allows us to
# create config_settings for each tfm that a nuget package provides Where the
# best match is correctly picked because it has the largest set of compatible frameworks.

# e.g. a setting with {"net6.0": "True", "net5.0": "True", ...} takes precedence over {"net5.0": "True", ...}
flags = { ":framework_compatible_%s" % f: repr(True) for f in sets.to_list(TRANSITIVE_FRAMEWORK_COMPATIBILITY[framework]) }
flags = {":framework_compatible_%s" % f: repr(True) for f in sets.to_list(TRANSITIVE_FRAMEWORK_COMPATIBILITY[framework])}

native.config_setting(
name = "tfm_%s" % framework,
Expand Down
4 changes: 3 additions & 1 deletion dotnet/private/providers.bzl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"Providers"

DotnetAssemblyInfo = provider(
doc = "A DLL or exe.",
fields = {
Expand All @@ -16,7 +18,7 @@ DotnetAssemblyInfo = provider(
"actual_tfm": "The target framework of the actual dlls",
"runtimeconfig": "An optional runtimeconfig.json for executable assemblies",
"depsjson": "An optional deps.json for executable assemblies",
"targeting_pack_overrides": "Targeting packs like e.g. Microsoft.NETCore.App.Ref have a PackageOverride.txt that includes a list of NuGet packages that should be omitted in a compiliation because they are included in the targeting pack"
"targeting_pack_overrides": "Targeting packs like e.g. Microsoft.NETCore.App.Ref have a PackageOverride.txt that includes a list of NuGet packages that should be omitted in a compiliation because they are included in the targeting pack",
},
)

Expand Down
4 changes: 2 additions & 2 deletions dotnet/private/rules/common/attrs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ COMMON_ATTRS = {
doc = "Other libraries that can see the assembly's internal symbols. Using this rather than the InternalsVisibleTo assembly attribute will improve build caching.",
),
"_target_framework": attr.label(
default = "@rules_dotnet//dotnet:target_framework"
default = "@rules_dotnet//dotnet:target_framework",
),
"_windows_constraint": attr.label(default = "@platforms//os:windows"),
"_allowlist_function_transition": attr.label(
default = "@bazel_tools//tools/allowlists/function_transition_allowlist"
default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
),
}

Expand Down
6 changes: 3 additions & 3 deletions dotnet/private/rules/common/binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ def build_binary(ctx, compile_action):
A collection of the references, runfiles and native dlls.
"""
tfm = ctx.attr._target_framework[BuildSettingInfo].value

if is_standard_framework(tfm):
fail("It doesn't make sense to build an executable for " + tfm)
fail("It doesn't make sense to build an executable for " + tfm)

runtimeconfig = None
depsjson = None
Expand All @@ -115,7 +115,7 @@ def build_binary(ctx, compile_action):
result = compile_action(ctx, tfm, runtimeconfig, depsjson)
executable = result.libs[0]
data = result.data
prefs = result.prefs[0] if len(result.prefs) >0 else None
prefs = result.prefs[0] if len(result.prefs) > 0 else None
runtimeconfig = result.runtimeconfig
depsjson = result.depsjson

Expand Down
6 changes: 2 additions & 4 deletions dotnet/private/rules/common/library.bzl
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
"Common implementation for building .Net libraries"

"""
Common implementation for building a .Net library
"""
load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")

def build_library(ctx, compile_action):
"""Builds a .Net library from a compilation action
Expand Down
1 change: 1 addition & 0 deletions dotnet/private/rules/csharp/nunit_test.bzl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Rules for compiling NUnit tests.
"""

load("//dotnet/private:rules/csharp/test.bzl", "csharp_test")

def csharp_nunit_test(**kwargs):
Expand Down
18 changes: 13 additions & 5 deletions dotnet/private/rules/imports.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ load(
"collect_transitive_info",
)
load("//dotnet/private:providers.bzl", "DotnetAssemblyInfo")
load("//dotnet/private:macros/register_tfms.bzl", "nuget_framework_transition")

def _import_library(ctx):
(_irefs, prefs, analyzers, runfiles, _overrides) = collect_transitive_info(ctx.label.name, ctx.attr.deps)
Expand Down Expand Up @@ -34,35 +35,42 @@ import_library = rule(
doc = "Creates a target for a static C# DLL for a specific target framework",
attrs = {
"version": attr.string(
doc = "The version of the library"
doc = "The version of the library",
),
"libs": attr.label_list(
doc = "Static runtime DLLs",
allow_files = True, # [".dll"] currently does not work with empty file groups
allow_files = True, # [".dll"] currently does not work with empty file groups
allow_empty = True,
cfg = nuget_framework_transition,
),
"analyzers": attr.label_list(
doc = "Static analyzer DLLs",
allow_files = True, # [".dll"] currently does not work with empty file groups
allow_files = True, # [".dll"] currently does not work with empty file groups
allow_empty = True,
cfg = nuget_framework_transition,
),
# todo maybe add pdb's as data.
"refs": attr.label_list(
doc = "Compile time DLLs",
allow_files = True, # [".dll"] currently does not work with empty file groups
allow_files = True, # [".dll"] currently does not work with empty file groups
allow_empty = True,
cfg = nuget_framework_transition,
),
"deps": attr.label_list(
doc = "Other DLLs that this DLL depends on.",
providers = [DotnetAssemblyInfo],
cfg = nuget_framework_transition,
),
"data": attr.label_list(
doc = "Other files that this DLL depends on at runtime",
allow_files = True,
),
"targeting_pack_overrides": attr.string_dict(
doc = "Targeting packs like e.g. Microsoft.NETCore.App.Ref have a PackageOverride.txt that includes a list of NuGet packages that should be omitted in a compiliation because they are included in the targeting pack",
default = {}
default = {},
),
"_allowlist_function_transition": attr.label(
default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
),
},
executable = False,
Expand Down
Loading