Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bazel-build for C# language pack #16519

Merged
merged 14 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from 8 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
2 changes: 2 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ common --enable_runfiles
common --registry=file:///%workspace%/misc/bazel/registry
common --registry=https://bcr.bazel.build

common --@rules_dotnet//dotnet/settings:strict_deps=false
redsun82 marked this conversation as resolved.
Show resolved Hide resolved

try-import %workspace%/local.bazelrc
6 changes: 6 additions & 0 deletions .bazelrc.internal
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,9 @@

common --registry=file:///%workspace%/ql/misc/bazel/registry
common --registry=https://bcr.bazel.build

# See bazelbuild/rules_dotnet#413: strict_deps in C# also appliy to 3rd-party deps, and when we pull
# in (for example) the xunit package, there's no code in this at all, it just depends transitively on
# its implementation packages without providing any code itself.
# We either can depend on internal implementation details, or turn of strict deps.
common --@rules_dotnet//dotnet/settings:strict_deps=false
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,5 @@ ruby/extractor/cargo-bazel-lock.json -merge
csharp/paket.lock linguist-generated=true
# needs eol=crlf, as `paket` touches this file and saves it als crlf
csharp/.paket/Paket.Restore.targets linguist-generated=true eol=crlf
csharp/paket.main.bzl linguist-generated=true
csharp/paket.main_extension.bzl linguist-generated=true
1 change: 1 addition & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exports_files(["LICENSE"])
10 changes: 10 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,19 @@ bazel_dep(name = "abseil-cpp", version = "20240116.0", repo_name = "absl")
bazel_dep(name = "nlohmann_json", version = "3.11.3", repo_name = "json")
bazel_dep(name = "fmt", version = "10.0.0")
bazel_dep(name = "gazelle", version = "0.36.0")
bazel_dep(name = "rules_dotnet", version = "0.15.1")

bazel_dep(name = "buildifier_prebuilt", version = "6.4.0", dev_dependency = True)

dotnet = use_extension("@rules_dotnet//dotnet:extensions.bzl", "dotnet")
dotnet.toolchain(dotnet_version = "8.0.101")
use_repo(dotnet, "dotnet_toolchains")

register_toolchains("@dotnet_toolchains//:all")

csharp_main_extension = use_extension("//csharp:paket.main_extension.bzl", "main_extension")
use_repo(csharp_main_extension, "paket.main")

pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")
pip.parse(
hub_name = "codegen_deps",
Expand Down
77 changes: 77 additions & 0 deletions csharp/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
load("@rules_pkg//pkg:mappings.bzl", "pkg_filegroup", "pkg_files")
load("@semmle_code//:dist.bzl", "dist")
load("//misc/bazel:pkg.bzl", "codeql_pkg_files_overlay")

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

alias(
Expand All @@ -9,3 +13,76 @@ alias(
name = "dbscheme-stats",
actual = "//csharp/ql/lib:dbscheme-stats",
)

pkg_files(
name = "dbscheme-group",
srcs = [
":dbscheme",
":dbscheme-stats",
],
strip_prefix = None,
)

pkg_files(
name = "extractor-asp",
srcs = [
"@semmle_code//extractor-asp:extractor-asp-fat",
],
prefix = "tools",
renames = {
"@semmle_code//extractor-asp:extractor-asp-fat": "extractor-asp.jar",
},
)

pkg_filegroup(
name = "db-files",
srcs = [
":dbscheme-group",
"//csharp/downgrades",
],
)

pkg_files(
name = "extra-files",
srcs = [
":codeql-extractor.yml",
"//:LICENSE",
],
)

codeql_pkg_files_overlay(
name = "extractor-arch-overlay",
srcs = [
"//csharp/autobuilder/Semmle.Autobuild.CSharp",
"//csharp/extractor/Semmle.Extraction.CSharp.Driver",
"//csharp/extractor/Semmle.Extraction.CSharp.Standalone",
],
)

dist(
name = "extractor-arch",
srcs = [":extractor-arch-overlay"],
)

dist(
name = "extractor-generic",
srcs = [
":dbscheme-group",
":extra-files",
":extractor-asp",
"//csharp/downgrades",
"//csharp/tools",
],
prefix = "csharp",
visibility = ["//visibility:public"],
)

test_suite(
name = "unit-tests",
tags = ["csharp"],
tests = [
"//csharp/autobuilder/Semmle.Autobuild.CSharp.Tests",
"//csharp/autobuilder/Semmle.Autobuild.Cpp.Tests",
"//csharp/extractor/Semmle.Extraction.Tests",
],
)
18 changes: 18 additions & 0 deletions csharp/autobuilder/Semmle.Autobuild.CSharp.Tests/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
load(
"//misc/bazel:csharp.bzl",
"codeql_xunit_test",
)

codeql_xunit_test(
name = "Semmle.Autobuild.CSharp.Tests",
srcs = glob([
"*.cs",
"Properties/*.cs",
]),
deps = [
"//csharp/autobuilder/Semmle.Autobuild.CSharp:bin/Semmle.Autobuild.CSharp",
"//csharp/autobuilder/Semmle.Autobuild.Shared",
"@paket.main//microsoft.net.test.sdk",
"@paket.main//system.io.filesystem",
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,9 @@ public void DownloadFile(string address, string fileName)

internal class TestDiagnosticWriter : IDiagnosticsWriter
{
public IList<DiagnosticMessage> Diagnostics { get; } = new List<DiagnosticMessage>();
public IList<Semmle.Util.DiagnosticMessage> Diagnostics { get; } = new List<Semmle.Util.DiagnosticMessage>();

public void AddEntry(DiagnosticMessage message) => this.Diagnostics.Add(message);
public void AddEntry(Semmle.Util.DiagnosticMessage message) => this.Diagnostics.Add(message);

public void Dispose() { }
}
Expand Down
21 changes: 21 additions & 0 deletions csharp/autobuilder/Semmle.Autobuild.CSharp/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
load(
"//misc/bazel:csharp.bzl",
"codeql_csharp_binary",
)

codeql_csharp_binary(
name = "Semmle.Autobuild.CSharp",
srcs = glob([
"*.cs",
"Properties/*.cs",
]),
visibility = ["//csharp:__subpackages__"],
deps = [
"//csharp/autobuilder/Semmle.Autobuild.Shared",
"//csharp/extractor/Semmle.Extraction.CSharp",
"//csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching",
"//csharp/extractor/Semmle.Util",
"@paket.main//microsoft.build",
"@paket.main//newtonsoft.json",
],
)
18 changes: 18 additions & 0 deletions csharp/autobuilder/Semmle.Autobuild.Cpp.Tests/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
load(
"//misc/bazel:csharp.bzl",
"codeql_xunit_test",
)

codeql_xunit_test(
name = "Semmle.Autobuild.Cpp.Tests",
srcs = glob([
"*.cs",
"Properties/*.cs",
]),
deps = [
"//csharp/autobuilder/Semmle.Autobuild.Cpp:bin/Semmle.Autobuild.Cpp",
"//csharp/autobuilder/Semmle.Autobuild.Shared",
"@paket.main//microsoft.net.test.sdk",
"@paket.main//system.io.filesystem",
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,9 @@ public void DownloadFile(string address, string fileName)

internal class TestDiagnosticWriter : IDiagnosticsWriter
{
public IList<DiagnosticMessage> Diagnostics { get; } = new List<DiagnosticMessage>();
public IList<Semmle.Util.DiagnosticMessage> Diagnostics { get; } = new List<Semmle.Util.DiagnosticMessage>();

public void AddEntry(DiagnosticMessage message) => this.Diagnostics.Add(message);
public void AddEntry(Semmle.Util.DiagnosticMessage message) => this.Diagnostics.Add(message);
tamasvajk marked this conversation as resolved.
Show resolved Hide resolved

public void Dispose() { }
}
Expand Down
18 changes: 18 additions & 0 deletions csharp/autobuilder/Semmle.Autobuild.Cpp/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
load(
"//misc/bazel:csharp.bzl",
"codeql_csharp_binary",
)

codeql_csharp_binary(
name = "Semmle.Autobuild.Cpp",
srcs = glob([
"*.cs",
"Properties/*.cs",
]),
visibility = ["//visibility:public"],
deps = [
"//csharp/autobuilder/Semmle.Autobuild.Shared",
"//csharp/extractor/Semmle.Util",
"@paket.main//microsoft.build",
],
)
17 changes: 17 additions & 0 deletions csharp/autobuilder/Semmle.Autobuild.Shared/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
load(
"//misc/bazel:csharp.bzl",
"codeql_csharp_library",
)

codeql_csharp_library(
name = "Semmle.Autobuild.Shared",
srcs = glob([
"*.cs",
"Properties/*.cs",
]),
visibility = ["//visibility:public"],
deps = [
"//csharp/extractor/Semmle.Util",
"@paket.main//microsoft.build",
],
)
12 changes: 12 additions & 0 deletions csharp/downgrades/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix")

pkg_files(
name = "downgrades",
srcs = glob(
["**"],
exclude = ["BUILD.bazel"],
),
prefix = "downgrades",
strip_prefix = strip_prefix.from_pkg(),
visibility = ["//csharp:__pkg__"],
)
Empty file added csharp/extractor/BUILD.bazel
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
load(
"//misc/bazel:csharp.bzl",
"codeql_csharp_library",
)

codeql_csharp_library(
name = "Semmle.Extraction.CSharp.DependencyFetching",
srcs = glob([
"*.cs",
"Properties/*.cs",
"SourceGenerators/**/*.cs",
]),
allow_unsafe_blocks = True,
internals_visible_to = ["Semmle.Extraction.Tests"],
nowarn = ["CA1822"],
visibility = ["//csharp:__subpackages__"],
deps = [
"//csharp/extractor/Semmle.Extraction",
"//csharp/extractor/Semmle.Util",
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
load(
"//misc/bazel:csharp.bzl",
"codeql_csharp_binary",
)

codeql_csharp_binary(
name = "Semmle.Extraction.CSharp.DependencyStubGenerator",
srcs = glob([
"*.cs",
"Properties/*.cs",
]),
visibility = ["//csharp:__pkg__"],
deps = [
"//csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching",
"//csharp/extractor/Semmle.Extraction.CSharp.StubGenerator",
"//csharp/extractor/Semmle.Util",
],
)
16 changes: 16 additions & 0 deletions csharp/extractor/Semmle.Extraction.CSharp.Driver/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
load(
"//misc/bazel:csharp.bzl",
"codeql_csharp_binary",
)

codeql_csharp_binary(
name = "Semmle.Extraction.CSharp.Driver",
srcs = glob([
"*.cs",
"Properties/*.cs",
]),
visibility = ["//csharp:__pkg__"],
deps = [
"//csharp/extractor/Semmle.Extraction.CSharp",
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
load(
"//misc/bazel:csharp.bzl",
"codeql_csharp_binary",
)

codeql_csharp_binary(
name = "Semmle.Extraction.CSharp.Standalone",
srcs = glob([
"*.cs",
"Properties/*.cs",
]),
visibility = ["//csharp:__subpackages__"],
deps = [
"//csharp/extractor/Semmle.Extraction.CSharp",
"//csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching",
"//csharp/extractor/Semmle.Util",
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
load(
"//misc/bazel:csharp.bzl",
"codeql_csharp_library",
)

codeql_csharp_library(
name = "Semmle.Extraction.CSharp.StubGenerator",
srcs = glob([
"*.cs",
"Properties/*.cs",
]),
internals_visible_to = ["Semmle.Extraction.Tests"],
visibility = ["//csharp:__subpackages__"],
deps = [
"//csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching",
"//csharp/extractor/Semmle.Extraction.CSharp.Util",
"//csharp/extractor/Semmle.Util",
"@paket.main//microsoft.codeanalysis.csharp",
],
)
17 changes: 17 additions & 0 deletions csharp/extractor/Semmle.Extraction.CSharp.Util/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
load(
"//misc/bazel:csharp.bzl",
"codeql_csharp_library",
)

codeql_csharp_library(
name = "Semmle.Extraction.CSharp.Util",
srcs = glob([
"Properties/*.cs",
"*.cs",
]),
visibility = ["//csharp:__subpackages__"],
deps = [
"//csharp/extractor/Semmle.Util",
"@paket.main//microsoft.codeanalysis.csharp",
],
)
Loading
Loading