Skip to content

Commit

Permalink
Simplify NuGet parsing (#370)
Browse files Browse the repository at this point in the history
## What?
Simplifies NuGet package parsing and fixes an error where `lib` files were not added as compile time dlls when there were no `refs` for the target framework.
  • Loading branch information
purkhusid committed Sep 6, 2023
1 parent 6cf6da5 commit 22f8f89
Show file tree
Hide file tree
Showing 27 changed files with 209 additions and 191 deletions.
2 changes: 1 addition & 1 deletion BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load("@bazel_gazelle//:def.bzl", "gazelle", "gazelle_binary")
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")

package(default_visibility = ["//visibility:public"])

Expand Down
5 changes: 3 additions & 2 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
workspace(name = "rules_dotnet")

load(":internal_deps.bzl", "rules_dotnet_internal_deps")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load(":internal_deps.bzl", "rules_dotnet_internal_deps")

# Fetch deps needed only locally for development
rules_dotnet_internal_deps()
Expand Down Expand Up @@ -40,10 +40,11 @@ load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies")

rules_pkg_dependencies()

load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")

############################################
# Gazelle, for generating bzl_library targets
load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")

go_rules_dependencies()

Expand Down
10 changes: 5 additions & 5 deletions dotnet/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load(
"//dotnet/private/macros:register_tfms.bzl",
"register_tfms",
)
load("//dotnet/private:resolved_toolchain.bzl", "resolved_toolchain")
load(
"//dotnet/private/macros:register_rids.bzl",
"register_rids",
)
load("//dotnet/private:resolved_toolchain.bzl", "resolved_toolchain")
load(
"//dotnet/private/macros:register_tfms.bzl",
"register_tfms",
)

toolchain_type(
name = "toolchain_type",
Expand Down
30 changes: 15 additions & 15 deletions dotnet/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,29 @@ load(
_csharp_binary = "csharp_binary",
)
load(
"@rules_dotnet//dotnet/private/rules/fsharp:binary.bzl",
_fsharp_binary = "fsharp_binary",
"@rules_dotnet//dotnet/private/rules/csharp:library.bzl",
_csharp_library = "csharp_library",
)
load(
"@rules_dotnet//dotnet/private/rules/publish_binary:publish_binary.bzl",
_publish_binary = "publish_binary",
_publish_binary_wrapper = "publish_binary_wrapper",
"@rules_dotnet//dotnet/private/rules/csharp:nunit_test.bzl",
_csharp_nunit_test = "csharp_nunit_test",
)
load(
"@rules_dotnet//dotnet/private/rules/csharp:library.bzl",
_csharp_library = "csharp_library",
"@rules_dotnet//dotnet/private/rules/csharp:test.bzl",
_csharp_test = "csharp_test",
)
load(
"@rules_dotnet//dotnet/private/rules/fsharp:library.bzl",
_fsharp_library = "fsharp_library",
"@rules_dotnet//dotnet/private/rules/fsharp:binary.bzl",
_fsharp_binary = "fsharp_binary",
)
load(
"@rules_dotnet//dotnet/private/rules/csharp:nunit_test.bzl",
_csharp_nunit_test = "csharp_nunit_test",
"@rules_dotnet//dotnet/private/rules/fsharp:library.bzl",
_fsharp_library = "fsharp_library",
)
load(
"@rules_dotnet//dotnet/private/rules/fsharp:nunit_test.bzl",
_fsharp_nunit_test = "fsharp_nunit_test",
)
load(
"@rules_dotnet//dotnet/private/rules/csharp:test.bzl",
_csharp_test = "csharp_test",
)
load(
"@rules_dotnet//dotnet/private/rules/fsharp:test.bzl",
_fsharp_test = "fsharp_test",
Expand All @@ -53,6 +48,11 @@ load(
"@rules_dotnet//dotnet/private/rules/nuget:nuget_repo.bzl",
_nuget_repo = "nuget_repo",
)
load(
"@rules_dotnet//dotnet/private/rules/publish_binary:publish_binary.bzl",
_publish_binary = "publish_binary",
_publish_binary_wrapper = "publish_binary_wrapper",
)

def _get_runtime_runtime_identifier(rid):
if rid:
Expand Down
2 changes: 1 addition & 1 deletion dotnet/private/common.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Rules for compatability resolution of dependencies for .NET frameworks.
"""

load("@aspect_bazel_lib//lib:paths.bzl", "to_manifest_path")
load("@bazel_skylib//lib:sets.bzl", "sets")
load(
"//dotnet/private:providers.bzl",
Expand All @@ -10,7 +11,6 @@ load(
"NuGetInfo",
)
load("//dotnet/private:rids.bzl", "RUNTIME_GRAPH")
load("@aspect_bazel_lib//lib:paths.bzl", "to_manifest_path")

def _collect_transitive():
t = {}
Expand Down
2 changes: 1 addition & 1 deletion dotnet/private/macros/register_tfms.bzl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"Register TFM flags and set up the compatibility chains"

load("@bazel_skylib//lib:sets.bzl", "sets")
load("@bazel_skylib//lib:dicts.bzl", "dicts")
load("@bazel_skylib//lib:sets.bzl", "sets")
load("@bazel_skylib//rules:common_settings.bzl", "bool_setting", "string_flag")
load(
"//dotnet/private:common.bzl",
Expand Down
2 changes: 1 addition & 1 deletion dotnet/private/rules/common/attrs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

load("@bazel_skylib//lib:dicts.bzl", "dicts")
load("//dotnet/private:providers.bzl", "DotnetAssemblyInfo")
load("//dotnet/private/transitions:tfm_transition.bzl", "tfm_transition")
load("//dotnet/private/transitions:default_transition.bzl", "default_transition")
load("//dotnet/private/transitions:tfm_transition.bzl", "tfm_transition")

# These are attributes that are common across all the binary/library/test .Net rules
COMMON_ATTRS = {
Expand Down
8 changes: 4 additions & 4 deletions dotnet/private/rules/common/binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
Base rule for building .Net binaries
"""

load("//dotnet/private:providers.bzl", "DotnetBinaryInfo")
load("@aspect_bazel_lib//lib:paths.bzl", "to_manifest_path")
load("@bazel_skylib//lib:paths.bzl", "paths")
load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
load(
"//dotnet/private:common.bzl",
"generate_depsjson",
"generate_runtimeconfig",
"is_core_framework",
"is_standard_framework",
)
load("@bazel_skylib//lib:paths.bzl", "paths")
load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
load("@aspect_bazel_lib//lib:paths.bzl", "to_manifest_path")
load("//dotnet/private:providers.bzl", "DotnetBinaryInfo")

def _create_shim_exe(ctx, dll):
windows_constraint = ctx.attr._windows_constraint[platform_common.ConstraintValueInfo]
Expand Down
6 changes: 3 additions & 3 deletions dotnet/private/rules/csharp/binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
Rule for compiling C# binaries.
"""

load("//dotnet/private/rules/csharp/actions:csharp_assembly.bzl", "AssemblyAction")
load("@bazel_skylib//lib:dicts.bzl", "dicts")
load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
load(
"//dotnet/private:common.bzl",
"is_debug",
)
load("//dotnet/private/rules/common:binary.bzl", "build_binary")
load("//dotnet/private/rules/common:attrs.bzl", "CSHARP_BINARY_COMMON_ATTRS")
load("//dotnet/private/rules/common:binary.bzl", "build_binary")
load("//dotnet/private/rules/csharp/actions:csharp_assembly.bzl", "AssemblyAction")
load("//dotnet/private/transitions:tfm_transition.bzl", "tfm_transition")
load("@bazel_skylib//lib:dicts.bzl", "dicts")

def _compile_action(ctx, tfm):
toolchain = ctx.toolchains["@rules_dotnet//dotnet:toolchain_type"]
Expand Down
8 changes: 4 additions & 4 deletions dotnet/private/rules/csharp/library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
Rule for compiling C# libraries.
"""

load("//dotnet/private/rules/csharp/actions:csharp_assembly.bzl", "AssemblyAction")
load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
load("//dotnet/private/rules/common:library.bzl", "build_library")
load("//dotnet/private/rules/common:attrs.bzl", "CSHARP_LIBRARY_COMMON_ATTRS")
load("//dotnet/private/transitions:tfm_transition.bzl", "tfm_transition")
load(
"//dotnet/private:common.bzl",
"is_debug",
)
load("//dotnet/private/rules/common:attrs.bzl", "CSHARP_LIBRARY_COMMON_ATTRS")
load("//dotnet/private/rules/common:library.bzl", "build_library")
load("//dotnet/private/rules/csharp/actions:csharp_assembly.bzl", "AssemblyAction")
load("//dotnet/private/transitions:tfm_transition.bzl", "tfm_transition")

def _compile_action(ctx, tfm):
toolchain = ctx.toolchains["@rules_dotnet//dotnet:toolchain_type"]
Expand Down
4 changes: 2 additions & 2 deletions dotnet/private/rules/csharp/test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ This rule can be used to compile and run any C# binary and run it as
a Bazel test.
"""

load("//dotnet/private/rules/csharp/actions:csharp_assembly.bzl", "AssemblyAction")
load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
load(
"//dotnet/private:common.bzl",
"is_debug",
)
load("//dotnet/private/rules/common:binary.bzl", "build_binary")
load("//dotnet/private/rules/common:attrs.bzl", "CSHARP_BINARY_COMMON_ATTRS")
load("//dotnet/private/rules/common:binary.bzl", "build_binary")
load("//dotnet/private/rules/csharp/actions:csharp_assembly.bzl", "AssemblyAction")
load("//dotnet/private/transitions:tfm_transition.bzl", "tfm_transition")

def _compile_action(ctx, tfm):
Expand Down
6 changes: 3 additions & 3 deletions dotnet/private/rules/fsharp/binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
Rule for compiling F# binaries.
"""

load("//dotnet/private/rules/fsharp/actions:fsharp_assembly.bzl", "AssemblyAction")
load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
load(
"//dotnet/private:common.bzl",
"is_debug",
)
load("//dotnet/private/rules/common:binary.bzl", "build_binary")
load("//dotnet/private/rules/common:attrs.bzl", "FSHARP_BINARY_COMMON_ATTRS")
load("//dotnet/private/rules/common:binary.bzl", "build_binary")
load("//dotnet/private/rules/fsharp/actions:fsharp_assembly.bzl", "AssemblyAction")
load("//dotnet/private/transitions:tfm_transition.bzl", "tfm_transition")
load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")

def _compile_action(ctx, tfm):
toolchain = ctx.toolchains["@rules_dotnet//dotnet:toolchain_type"]
Expand Down
10 changes: 5 additions & 5 deletions dotnet/private/rules/fsharp/library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
Rule for compiling F# libraries.
"""

load("//dotnet/private/rules/fsharp/actions:fsharp_assembly.bzl", "AssemblyAction")
load("//dotnet/private/rules/common:library.bzl", "build_library")
load("//dotnet/private/rules/common:attrs.bzl", "FSHARP_LIBRARY_COMMON_ATTRS")
load("//dotnet/private/transitions:tfm_transition.bzl", "tfm_transition")
load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
load(
"//dotnet/private:common.bzl",
"is_debug",
)
load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
load("//dotnet/private/rules/common:attrs.bzl", "FSHARP_LIBRARY_COMMON_ATTRS")
load("//dotnet/private/rules/common:library.bzl", "build_library")
load("//dotnet/private/rules/fsharp/actions:fsharp_assembly.bzl", "AssemblyAction")
load("//dotnet/private/transitions:tfm_transition.bzl", "tfm_transition")

def _compile_action(ctx, tfm):
toolchain = ctx.toolchains["@rules_dotnet//dotnet:toolchain_type"]
Expand Down
6 changes: 3 additions & 3 deletions dotnet/private/rules/fsharp/test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ This rule can be used to compile and run any F# binary and run it as
a Bazel test.
"""

load("//dotnet/private/rules/fsharp/actions:fsharp_assembly.bzl", "AssemblyAction")
load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
load(
"//dotnet/private:common.bzl",
"is_debug",
)
load("//dotnet/private/rules/common:binary.bzl", "build_binary")
load("//dotnet/private/rules/common:attrs.bzl", "FSHARP_BINARY_COMMON_ATTRS")
load("//dotnet/private/rules/common:binary.bzl", "build_binary")
load("//dotnet/private/rules/fsharp/actions:fsharp_assembly.bzl", "AssemblyAction")
load("//dotnet/private/transitions:tfm_transition.bzl", "tfm_transition")
load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")

def _compile_action(ctx, tfm):
toolchain = ctx.toolchains["@rules_dotnet//dotnet:toolchain_type"]
Expand Down
2 changes: 1 addition & 1 deletion dotnet/private/rules/nuget/imports.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
Rules for importing assemblies for .NET frameworks.
"""

load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
load(
"//dotnet/private:common.bzl",
"collect_transitive_info",
"transform_deps",
)
load("//dotnet/private:providers.bzl", "DotnetAssemblyInfo", "NuGetInfo")
load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")

def _import_library(ctx):
(
Expand Down
Loading

0 comments on commit 22f8f89

Please sign in to comment.