mirror of
https://github.com/github/codeql.git
synced 2025-12-18 01:33:15 +01:00
Merge pull request #16544 from github/redsun82/bazel-csharp-2
Bazel/C#: avoid zipmerge
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
load("@rules_pkg//pkg:mappings.bzl", "pkg_filegroup", "pkg_files")
|
load("@rules_pkg//pkg:mappings.bzl", "pkg_filegroup", "pkg_files")
|
||||||
load("@semmle_code//:common.bzl", "zipmerge")
|
|
||||||
load("@semmle_code//:dist.bzl", "dist")
|
load("@semmle_code//:dist.bzl", "dist")
|
||||||
|
load("//misc/bazel:pkg.bzl", "codeql_pkg_files_overlay")
|
||||||
|
|
||||||
package(default_visibility = ["//visibility:public"])
|
package(default_visibility = ["//visibility:public"])
|
||||||
|
|
||||||
@@ -50,15 +50,18 @@ pkg_files(
|
|||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
# See `csharp.bzl` for an explanation of why we need zipmerge here
|
codeql_pkg_files_overlay(
|
||||||
zipmerge(
|
name = "extractor-arch-overlay",
|
||||||
name = "extractor-arch",
|
|
||||||
srcs = [
|
srcs = [
|
||||||
"//csharp/autobuilder/Semmle.Autobuild.CSharp:Semmle.Autobuild.CSharp.zip",
|
"//csharp/autobuilder/Semmle.Autobuild.CSharp",
|
||||||
"//csharp/extractor/Semmle.Extraction.CSharp.Driver:Semmle.Extraction.CSharp.Driver.zip",
|
"//csharp/extractor/Semmle.Extraction.CSharp.Driver",
|
||||||
"//csharp/extractor/Semmle.Extraction.CSharp.Standalone:Semmle.Extraction.CSharp.Standalone.zip",
|
"//csharp/extractor/Semmle.Extraction.CSharp.Standalone",
|
||||||
],
|
],
|
||||||
out = "extractor-arch.zip",
|
)
|
||||||
|
|
||||||
|
dist(
|
||||||
|
name = "extractor-arch",
|
||||||
|
srcs = [":extractor-arch-overlay"],
|
||||||
)
|
)
|
||||||
|
|
||||||
dist(
|
dist(
|
||||||
|
|||||||
@@ -61,14 +61,10 @@ def codeql_csharp_binary(name, **kwargs):
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
# we need to declare individual zip targets for each binary, as `self_contained=True` means that every binary target
|
|
||||||
# contributes the same runtime files. Bazel (rightfully) complains about this, so we work around this by creating individual zip files,
|
|
||||||
# and using zipmerge to produce the final extractor-arch file. For overlapping files, zipmerge chooses just one.
|
|
||||||
pack_zip(
|
pack_zip(
|
||||||
name = name,
|
name = name,
|
||||||
srcs = [publish_binary_target],
|
srcs = [publish_binary_target],
|
||||||
prefix = "csharp/tools/" + codeql_platform,
|
prefix = "csharp/tools/" + codeql_platform,
|
||||||
strip_prefix = strip_prefix.files_only(),
|
strip_prefix = strip_prefix.files_only(),
|
||||||
compression_level = 0,
|
|
||||||
visibility = visibility,
|
visibility = visibility,
|
||||||
)
|
)
|
||||||
|
|||||||
37
misc/bazel/pkg.bzl
Normal file
37
misc/bazel/pkg.bzl
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
load("@rules_pkg//pkg:providers.bzl", "PackageFilegroupInfo", "PackageFilesInfo")
|
||||||
|
|
||||||
|
def _pkg_overlay_impl(ctx):
|
||||||
|
destinations = {}
|
||||||
|
files = []
|
||||||
|
depsets = []
|
||||||
|
|
||||||
|
for src in reversed(ctx.attr.srcs):
|
||||||
|
pfi = src[PackageFilesInfo]
|
||||||
|
dest_src_map = {k: v for k, v in pfi.dest_src_map.items() if k not in destinations}
|
||||||
|
destinations.update({k: True for k in dest_src_map})
|
||||||
|
if dest_src_map:
|
||||||
|
new_pfi = PackageFilesInfo(
|
||||||
|
dest_src_map = dest_src_map,
|
||||||
|
attributes = pfi.attributes,
|
||||||
|
)
|
||||||
|
files.append((new_pfi, src.label))
|
||||||
|
depsets.append(depset(dest_src_map.values()))
|
||||||
|
return [
|
||||||
|
PackageFilegroupInfo(
|
||||||
|
pkg_files = reversed(files),
|
||||||
|
pkg_dirs = [],
|
||||||
|
pkg_symlinks = [],
|
||||||
|
),
|
||||||
|
DefaultInfo(
|
||||||
|
files = depset(transitive = reversed(depsets)),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
||||||
|
codeql_pkg_files_overlay = rule(
|
||||||
|
implementation = _pkg_overlay_impl,
|
||||||
|
doc = "Combine `pkg_files` targets so that later targets overwrite earlier ones without warnings",
|
||||||
|
attrs = {
|
||||||
|
# this could be updated to handle PackageFilegroupInfo as well if we ever need it
|
||||||
|
"srcs": attr.label_list(providers = [PackageFilesInfo, DefaultInfo]),
|
||||||
|
},
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user