|
| 1 | +diff --git a/dotnet/private/providers.bzl b/dotnet/private/providers.bzl |
| 2 | +index df00a25..0b06638 100644 |
| 3 | +--- a/dotnet/private/providers.bzl |
| 4 | ++++ b/dotnet/private/providers.bzl |
| 5 | +@@ -44,6 +44,7 @@ NuGetInfo = provider( |
| 6 | + fields = { |
| 7 | + "targeting_pack_overrides": "map[string, string]: 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", |
| 8 | + "sha512": "string: the SHA512 SRI string for the package", |
| 9 | ++ "nupkg": "File: the underlying `.nupkg` file which provides this package", |
| 10 | + }, |
| 11 | + ) |
| 12 | + |
| 13 | +diff --git a/dotnet/private/rules/nuget/imports.bzl b/dotnet/private/rules/nuget/imports.bzl |
| 14 | +index a41bc70..79ebc94 100644 |
| 15 | +--- a/dotnet/private/rules/nuget/imports.bzl |
| 16 | ++++ b/dotnet/private/rules/nuget/imports.bzl |
| 17 | +@@ -59,6 +59,7 @@ def _import_library(ctx): |
| 18 | + ), NuGetInfo( |
| 19 | + targeting_pack_overrides = ctx.attr.targeting_pack_overrides, |
| 20 | + sha512 = ctx.attr.sha512, |
| 21 | ++ nupkg = ctx.file.nupkg, |
| 22 | + )] |
| 23 | + |
| 24 | + import_library = rule( |
| 25 | +@@ -107,6 +108,10 @@ import_library = rule( |
| 26 | + "sha512": attr.string( |
| 27 | + doc = "The SHA512 sum of the NuGet package", |
| 28 | + ), |
| 29 | ++ "nupkg": attr.label( |
| 30 | ++ doc = "The `.nupkg` file providing this import", |
| 31 | ++ allow_single_file = True, |
| 32 | ++ ), |
| 33 | + }, |
| 34 | + toolchains = [ |
| 35 | + "@rules_dotnet//dotnet:toolchain_type", |
| 36 | +diff --git a/dotnet/private/rules/nuget/nuget_archive.bzl b/dotnet/private/rules/nuget/nuget_archive.bzl |
| 37 | +index 38a9473..683abdd 100644 |
| 38 | +--- a/dotnet/private/rules/nuget/nuget_archive.bzl |
| 39 | ++++ b/dotnet/private/rules/nuget/nuget_archive.bzl |
| 40 | +@@ -19,6 +19,8 @@ load( |
| 41 | + "RUNTIME_GRAPH", |
| 42 | + ) |
| 43 | + |
| 44 | ++GLOBAL_NUGET_PREFIX = "nuget" |
| 45 | ++ |
| 46 | + def _is_windows(repository_ctx): |
| 47 | + """Returns true if the host operating system is windows.""" |
| 48 | + os_name = repository_ctx.os.name.lower() |
| 49 | +@@ -321,7 +323,17 @@ def _nuget_archive_impl(ctx): |
| 50 | + |
| 51 | + # Then get the auth dict for the package base urls |
| 52 | + auth = _get_auth_dict(ctx, ctx.attr.netrc, urls) |
| 53 | +- ctx.download_and_extract(urls, type = "zip", integrity = ctx.attr.sha512, auth = auth) |
| 54 | ++ file_name = "%s.zip" % ctx.name |
| 55 | ++ nupkg_name = "%s.%s.nupkg" % (ctx.attr.id, ctx.attr.version) |
| 56 | ++ names = [nupkg_name] |
| 57 | ++ if nupkg_name.startswith(GLOBAL_NUGET_PREFIX): |
| 58 | ++ nupkg_name = nupkg_name[len(GLOBAL_NUGET_PREFIX) + 1:] |
| 59 | ++ names.append(nupkg_name) |
| 60 | ++ |
| 61 | ++ ctx.download(urls, output = file_name, integrity = ctx.attr.sha512, auth = auth) |
| 62 | ++ ctx.extract(archive = file_name) |
| 63 | ++ for name in names: |
| 64 | ++ ctx.symlink(file_name, name) |
| 65 | + |
| 66 | + files = _read_dir(ctx, ".").replace(str(ctx.path(".")) + "/", "").splitlines() |
| 67 | + |
| 68 | +@@ -447,6 +459,7 @@ load("@rules_dotnet//dotnet/private/rules/nuget:nuget_archive.bzl", "tfm_filegro |
| 69 | + "filegroup(name = \"data\", srcs = [])", |
| 70 | + _create_rid_native_select("native", native) or "filegroup(name = \"native\", srcs = [])", |
| 71 | + "filegroup(name = \"content_files\", srcs = [%s])" % ",".join(["\n \"%s\"" % a for a in groups.get("contentFiles")["any"]]), |
| 72 | ++ "exports_files([\"%s\"])" % nupkg_name, |
| 73 | + ])) |
| 74 | + |
| 75 | + nuget_archive = repository_rule( |
| 76 | +diff --git a/dotnet/private/rules/nuget/nuget_repo.bzl b/dotnet/private/rules/nuget/nuget_repo.bzl |
| 77 | +index 77c2a67..c5cc56d 100644 |
| 78 | +--- a/dotnet/private/rules/nuget/nuget_repo.bzl |
| 79 | ++++ b/dotnet/private/rules/nuget/nuget_repo.bzl |
| 80 | +@@ -1,9 +1,7 @@ |
| 81 | + "NuGet Repo" |
| 82 | + |
| 83 | + load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") |
| 84 | +-load("@rules_dotnet//dotnet/private/rules/nuget:nuget_archive.bzl", "nuget_archive") |
| 85 | +- |
| 86 | +-_GLOBAL_NUGET_PREFIX = "nuget" |
| 87 | ++load("@rules_dotnet//dotnet/private/rules/nuget:nuget_archive.bzl", "GLOBAL_NUGET_PREFIX", "nuget_archive") |
| 88 | + |
| 89 | + def _nuget_repo_impl(ctx): |
| 90 | + for package in ctx.attr.packages: |
| 91 | +@@ -22,8 +20,15 @@ def _nuget_repo_impl(ctx): |
| 92 | + targeting_pack_overrides = ctx.attr.targeting_pack_overrides[name.lower()] |
| 93 | + template = Label("@rules_dotnet//dotnet/private/rules/nuget:template.BUILD") |
| 94 | + |
| 95 | ++ nupkg_path = "@{PREFIX}.{NAME_LOWER}.v{VERSION}//:{NAME_LOWER}.{VERSION}.nupkg".format( |
| 96 | ++ PREFIX = GLOBAL_NUGET_PREFIX, |
| 97 | ++ NAME = name, |
| 98 | ++ NAME_LOWER = name.lower(), |
| 99 | ++ VERSION = version, |
| 100 | ++ ) |
| 101 | ++ |
| 102 | + ctx.template("{}/{}/BUILD.bazel".format(name.lower(), version), template, { |
| 103 | +- "{PREFIX}": _GLOBAL_NUGET_PREFIX, |
| 104 | ++ "{PREFIX}": GLOBAL_NUGET_PREFIX, |
| 105 | + "{NAME}": name, |
| 106 | + "{NAME_LOWER}": name.lower(), |
| 107 | + "{VERSION}": version, |
| 108 | +@@ -36,7 +41,7 @@ def _nuget_repo_impl(ctx): |
| 109 | + ctx.file("{}/BUILD.bazel".format(name.lower()), r"""package(default_visibility = ["//visibility:public"]) |
| 110 | + alias(name = "{name}", actual = "//{name}/{version}") |
| 111 | + alias(name = "content_files", actual = "@{prefix}.{name}.v{version}//:content_files") |
| 112 | +-""".format(prefix = _GLOBAL_NUGET_PREFIX, name = name.lower(), version = version)) |
| 113 | ++""".format(prefix = GLOBAL_NUGET_PREFIX, name = name.lower(), version = version)) |
| 114 | + |
| 115 | + _nuget_repo = repository_rule( |
| 116 | + _nuget_repo_impl, |
| 117 | +@@ -63,7 +68,7 @@ def nuget_repo(name, packages): |
| 118 | + # maybe another nuget_repo has the same nuget package dependency |
| 119 | + maybe( |
| 120 | + nuget_archive, |
| 121 | +- name = "{}.{}.v{}".format(_GLOBAL_NUGET_PREFIX, package_name, version), |
| 122 | ++ name = "{}.{}.v{}".format(GLOBAL_NUGET_PREFIX, package_name, version), |
| 123 | + sources = package["sources"], |
| 124 | + netrc = package.get("netrc", None), |
| 125 | + id = package_name, |
| 126 | +diff --git a/dotnet/private/rules/nuget/template.BUILD b/dotnet/private/rules/nuget/template.BUILD |
| 127 | +index 783f025..b62bce2 100644 |
| 128 | +--- a/dotnet/private/rules/nuget/template.BUILD |
| 129 | ++++ b/dotnet/private/rules/nuget/template.BUILD |
| 130 | +@@ -16,4 +16,5 @@ import_library( |
| 131 | + deps = select({ |
| 132 | + {DEPS}, |
| 133 | + }), |
| 134 | ++ nupkg = "@{PREFIX}.{NAME_LOWER}.v{VERSION}//:{NAME_LOWER}.{VERSION}.nupkg" |
| 135 | + ) |
0 commit comments