Skip to content

Commit

Permalink
Fix the out attribute (#342)
Browse files Browse the repository at this point in the history
## What?
The `out` attribute was broken after we started  generating deps.json and runtimeconfig.json files.
The internals visible to handling was also not correct when using the `out` attribute

Fixes #341
  • Loading branch information
purkhusid authored Mar 21, 2023
1 parent ec73829 commit a138bd0
Show file tree
Hide file tree
Showing 10 changed files with 136 additions and 10 deletions.
4 changes: 2 additions & 2 deletions dotnet/private/rules/common/binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def build_binary(ctx, compile_action):
depsjson = None
if is_core_framework(tfm):
# Create the runtimeconfig.json for the binary
runtimeconfig = ctx.actions.declare_file("bazelout/%s/%s.runtimeconfig.json" % (tfm, ctx.attr.name))
runtimeconfig = ctx.actions.declare_file("bazelout/%s/%s.runtimeconfig.json" % (tfm, ctx.attr.out or ctx.attr.name))
runtimeconfig_struct = generate_runtimeconfig(
target_framework = tfm,
project_sdk = ctx.attr.project_sdk,
Expand All @@ -117,7 +117,7 @@ def build_binary(ctx, compile_action):
content = json.encode_indent(runtimeconfig_struct),
)

depsjson = ctx.actions.declare_file("bazelout/%s/%s.deps.json" % (tfm, ctx.attr.name))
depsjson = ctx.actions.declare_file("bazelout/%s/%s.deps.json" % (tfm, ctx.attr.out or ctx.attr.name))
depsjson_struct = generate_depsjson(
ctx,
target_framework = tfm,
Expand Down
4 changes: 2 additions & 2 deletions dotnet/private/rules/csharp/actions/csharp_assembly.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def AssemblyAction(
exports_files,
overrides,
) = collect_transitive_info(
target_name,
assembly_name,
deps + [toolchain.host_model] if include_host_model_dll else deps,
private_deps,
exports,
Expand Down Expand Up @@ -186,7 +186,7 @@ def AssemblyAction(

internals_visible_to_cs = _write_internals_visible_to_csharp(
actions,
name = target_name,
name = assembly_name,
others = internals_visible_to,
)

Expand Down
4 changes: 2 additions & 2 deletions dotnet/private/rules/fsharp/actions/fsharp_assembly.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def AssemblyAction(
exports_files,
overrides,
) = collect_transitive_info(
target_name,
assembly_name,
deps,
private_deps,
exports,
Expand Down Expand Up @@ -196,7 +196,7 @@ def AssemblyAction(

internals_visible_to_fs = _write_internals_visible_to_fsharp(
actions,
name = target_name,
name = assembly_name,
others = internals_visible_to,
)
_compile(
Expand Down
35 changes: 35 additions & 0 deletions dotnet/private/tests/out/csharp/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"Test that the `out` attribute works as expected"

load(
"@rules_dotnet//dotnet:defs.bzl",
"csharp_library",
"csharp_nunit_test",
)

csharp_nunit_test(
name = "lib_test",
srcs = ["libtest.cs"],
out = "OtherLibTest",
private_deps = [
"@rules_dotnet_dev_nuget_packages//microsoft.netcore.app.ref",
],
target_frameworks = ["net6.0"],
deps = [
":lib",
],
)

csharp_library(
name = "lib",
srcs = ["lib.cs"],
out = "OtherLib",
# Note that the we use the name that is used in the `out` attribute of the `lib_test` target.
internals_visible_to = [
"OtherLibTest",
],
private_deps = [
"@rules_dotnet_dev_nuget_packages//microsoft.netcore.app.ref",
],
target_frameworks = ["net6.0"],
deps = [],
)
18 changes: 18 additions & 0 deletions dotnet/private/tests/out/csharp/lib.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;

namespace Lib
{
public static class Stuff
{
public static bool IsTrue()
{
return true;
}
internal static bool IsTrueInternal()
{
return true;
}
}
}
20 changes: 20 additions & 0 deletions dotnet/private/tests/out/csharp/libtest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Lib;
using NUnit.Framework;
using System.Linq;

[TestFixture]
public sealed class LibTests
{
[Test]
public void SomeTest()
{
Assert.AreEqual(true, Stuff.IsTrue());
}

[Test]
public void SomeTestInternal()
{
Assert.AreEqual(true, Stuff.IsTrueInternal());
}
}

38 changes: 38 additions & 0 deletions dotnet/private/tests/out/fsharp/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"Test that the `out` attribute works as expected"

load(
"@rules_dotnet//dotnet:defs.bzl",
"fsharp_library",
"fsharp_nunit_test",
)

fsharp_nunit_test(
name = "lib_test",
srcs = ["libtest.fs"],
out = "OtherLibTest",
private_deps = [
"@rules_dotnet_dev_nuget_packages//microsoft.netcore.app.ref",
],
target_frameworks = ["net6.0"],
deps = [
":lib",
"@rules_dotnet_dev_nuget_packages//fsharp.core",
],
)

fsharp_library(
name = "lib",
srcs = ["lib.fs"],
out = "OtherLib",
# Note that the we use the name that is used in the `out` attribute of the `lib_test` target.
internals_visible_to = [
"OtherLibTest",
],
private_deps = [
"@rules_dotnet_dev_nuget_packages//microsoft.netcore.app.ref",
],
target_frameworks = ["net6.0"],
deps = [
"@rules_dotnet_dev_nuget_packages//fsharp.core",
],
)
5 changes: 5 additions & 0 deletions dotnet/private/tests/out/fsharp/lib.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace Lib

module Stuff =
let isTrue () = true
let internal isTrueInternal () = true
14 changes: 14 additions & 0 deletions dotnet/private/tests/out/fsharp/libtest.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module Tests

open Lib
open NUnit.Framework
open System.Linq

[<TestFixture>]
type LibTests() =
[<Test>]
member this.SomeTest() = Assert.AreEqual(true, Stuff.isTrue ())

[<Test>]
member this.SomeTestInternal() =
Assert.AreEqual(true, Stuff.isTrueInternal ())
4 changes: 0 additions & 4 deletions examples/basic_csharp/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ csharp_binary(
],
)

# bazel test //examples:lib_test
# NOTE: this doesn't work yet because we aren't setting up the runfiles
# correctly. If you copy out all the dlls/exes to a common folder it does
# though.
csharp_nunit_test(
name = "lib_test",
srcs = ["libtest.cs"],
Expand Down

0 comments on commit a138bd0

Please sign in to comment.