Skip to content

Commit

Permalink
Expose NuGet files as a filegroup
Browse files Browse the repository at this point in the history
  • Loading branch information
purkhusid committed Oct 7, 2024
1 parent 11d2307 commit 8f01bbd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
5 changes: 3 additions & 2 deletions dotnet/private/rules/nuget/nuget_archive.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ def _nuget_archive_impl(ctx):
for name in names:
ctx.symlink(file_name, name)

files = sorted(_read_dir(ctx, ".").replace(str(ctx.path(".")) + "/", "").splitlines())
all_files = sorted(_read_dir(ctx, ".").replace(str(ctx.path(".")) + "/", "").splitlines())

# The NuGet package format
groups = {
Expand Down Expand Up @@ -400,7 +400,7 @@ def _nuget_archive_impl(ctx):
},
}

for file in files:
for file in all_files:
file = _sanitize_path(file)
i = file.find("/")
key = file[:i]
Expand Down Expand Up @@ -493,6 +493,7 @@ load("@rules_dotnet//dotnet/private/rules/nuget:nuget_archive.bzl", "tfm_filegro
"filegroup(name = \"data\", srcs = [])",
_create_rid_native_select("native", native) or "filegroup(name = \"native\", srcs = [])",
"filegroup(name = \"content_files\", srcs = [%s])" % ",".join(["\n \"%s\"" % a for a in groups.get("contentFiles")["any"]]),
"filegroup(name = \"files\", srcs = [%s])" % ",".join(["\n \"%s\"" % _sanitize_path(a) for a in all_files]),
"exports_files([\"%s\"])" % nupkg_name,
]))

Expand Down
1 change: 1 addition & 0 deletions dotnet/private/rules/nuget/nuget_repo.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def _nuget_repo_impl(ctx):
ctx.file("{}/BUILD.bazel".format(name.lower()), r"""package(default_visibility = ["//visibility:public"])
alias(name = "{name}", actual = "//{id}/{version}")
alias(name = "content_files", actual = "@{prefix}.{id}.v{version}//:content_files")
alias(name = "files", actual = "@{prefix}.{id}.v{version}//:files")
""".format(prefix = _GLOBAL_NUGET_PREFIX, name = name.lower(), id = id.lower(), version = version))

_nuget_repo = repository_rule(
Expand Down
8 changes: 8 additions & 0 deletions dotnet/private/tests/nuget_structure/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load("@bazel_skylib//rules:select_file.bzl", "select_file")
load(":analyzers.bzl", "analyzers_structure")
load(":resolution.bzl", "resolution_structure")
load(":runtimes.bzl", "runtimes_structure")
Expand Down Expand Up @@ -51,3 +52,10 @@ bzl_library(
visibility = ["//dotnet:__subpackages__"],
deps = [":common"],
)

select_file(
name = "should_expose_files_as_filegroup",
srcs = "@paket.rules_dotnet_dev_nuget_packages//fsharp.core:files",
subpath = "lib/netstandard2.1/it/FSharp.Core.resources.dll",
visibility = ["//dotnet:__subpackages__"],
)

0 comments on commit 8f01bbd

Please sign in to comment.