Skip to content
This repository was archived by the owner on Oct 31, 2024. It is now read-only.
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
3 changes: 0 additions & 3 deletions dotnet/nuget_repo.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ def _nuget_repo_impl(ctx):
if r.return_code != 0:
print(r.stdout)
fail("nuget_repository failed with exit code " + repr(r.return_code) + "\n\n" + r.stderr)

ctx.file("BUILD", r"""
)""")

nuget_repo = repository_rule(
_nuget_repo_impl,
Expand Down
25 changes: 24 additions & 1 deletion dotnet/private/actions/assembly.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ def _make_runner_arglist(dotnet, deps, transitive_analyzers, resources, output,
args.add(dotnet.analyzer_ruleset, format = "/ruleset:%s")
args.add(dotnet.analyzer_config, format = "/analyzerconfig:%s")
args.add_all(dotnet.analyzer_additionalfiles, format_each = "/additionalfile:%s")
else:
for a in transitive_analyzers.to_list():
if a.path.endswith("SourceGenerator.dll") or a.path.endswith("SourceGeneration.dll"):
args.add(a, format = "/analyzer:%s")

args.add_all(resources, format_each = "/resource:%s", map_each = _map_resource)
args.add_all(deps, format_each = "/reference:%s")
Expand Down Expand Up @@ -101,6 +105,8 @@ def emit_assembly_core(
# files could contain spaces. therefore quote
runner_args.add_all(all_srcs, format_each = '"%s"')

runner_args.add("/analyzer:external/nuget/newtonsoft.json/current/lib/netstandard2.0/Newtonsoft.Json.dll")

runner_args.use_param_file("@%s", use_always = True)
runner_args.set_param_file_format("multiline")

Expand Down Expand Up @@ -140,7 +146,7 @@ def emit_assembly_core(
unused_refs = dotnet.declare_file(dotnet, path = name + ".unused")
dotnet.actions.run(
# ensure propsfile is build when this action runs by making it an input
inputs = depset(direct = [paramfile, propsfile] + resource_files, transitive = [all_srcs, transitive_refs]),
inputs = depset(direct = [paramfile, propsfile] + resource_files, transitive = [all_srcs, transitive_refs, transitive_analyzers]),
input_manifests = input_manifests,
outputs = outputs + [unused_refs],
executable = server,
Expand All @@ -167,6 +173,23 @@ def emit_assembly_core(
),
)

if out and out.endswith("SourceGenerator.dll"):
transitive_analyzers = depset(direct = [result], transitive = [a[DotnetLibrary].transitive_analyzers for a in deps])

return DotnetLibrary(
name = dotnet.label.name if not name else name,
label = dotnet.label,
analyzer = result,
transitive_analyzers = transitive_analyzers,
deps = [],
result = None,
ref_result = None,
runfiles = depset(),
transitive_refs = depset(),
transitive = depset(),
output_groups = [OutputGroupInfo(targets = [propsfile])] if propsfile else [],
)

return dotnet.new_library(
dotnet = dotnet,
name = name,
Expand Down
20 changes: 17 additions & 3 deletions dotnet/private/rules/binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ load(
)
load("@bazel_skylib//lib:paths.bzl", "paths")

def _framework_transition_impl(settings, attr):
if Label("@nuget//netstandard.library") in attr.deps:
return {"@nuget//:framework" : "netstandard2.0"}
return settings

framework_transition = transition(
implementation = _framework_transition_impl,
inputs = ["@nuget//:framework"],
outputs = ["@nuget//:framework"]
)

# DotnetContext, DotnetLibrary
def create_launcher(dotnet, library, shim = None):
launch_target = shim if shim else library.result
Expand Down Expand Up @@ -92,10 +103,10 @@ def _rule_impl(ctx):
if ctx.attr._target_type == "exe":
shim = create_shim_exe(ctx, assembly.result)
result.append(create_launcher(dotnet, assembly, shim))
else:
elif assembly.result or assembly.analyzer:
# always output a DefaultInfo with a file so directly building this target will trigger actions
result.append(DefaultInfo(
files = depset([assembly.result]),
files = depset([assembly.result or assembly.analyzer]),
))

return result
Expand All @@ -106,7 +117,10 @@ def _rule(target_type,
return rule(
_rule_impl,
attrs = {
"deps": attr.label_list(providers = [DotnetLibrary]),
"_allowlist_function_transition": attr.label(
default = "@bazel_tools//tools/allowlists/function_transition_allowlist"
),
"deps": attr.label_list(providers = [DotnetLibrary], cfg = framework_transition),
"resources": attr.label_list(providers = [DotnetResourceList]),
"srcs": attr.label_list(allow_files = [".cs"]),
"out": attr.string(),
Expand Down
5 changes: 5 additions & 0 deletions tools/server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ string ScopePath(string path)
</CSCReference>
");
}
else if (line.StartsWith("/analyzer:") && (line.EndsWith("SourceGenerator.dll") || line.EndsWith("SourceGeneration.dll")))
{
var analyzerPath = line.Substring(10).Replace('/', '\\');
sb.Append($"<Analyzer Include=\"{ScopePath(analyzerPath)}\" />\n\n");
}
}

// obj/....csproj.bazel.props file
Expand Down