mirror of
https://github.com/github/codeql.git
synced 2026-04-29 10:45:15 +02:00
C#: Provide skeleton to generate an assemblyInfo file.
Each unit gets a unique assemblyInfo file, on top of the ones for entrypoints that also gets the git info embedded.
This commit is contained in:
committed by
Tamas Vajk
parent
16f8be4ba4
commit
6731bccc92
@@ -1,17 +1,21 @@
|
||||
py_binary(
|
||||
name = "gen-assembly-info",
|
||||
srcs = ["gen-assembly-info.py"],
|
||||
name = "gen-git-assembly-info",
|
||||
srcs = ["gen-git-assembly-info.py"],
|
||||
deps = ["@rules_python//python/runfiles"],
|
||||
)
|
||||
|
||||
py_binary(
|
||||
name = "gen-assembly-info",
|
||||
srcs = ["gen-assembly-info.py"],
|
||||
visibility = ["//csharp:__subpackages__"],
|
||||
deps = ["@rules_python//python/runfiles"],
|
||||
)
|
||||
|
||||
# this is an instance of the dbscheme kept in the bazel build tree
|
||||
# this allows everything that bazel builds to be up-to-date,
|
||||
# independently from whether //go:gen was already run to update the checked in files
|
||||
genrule(
|
||||
name = "assembly-info-src",
|
||||
name = "git-assembly-info-src",
|
||||
srcs = ["@semmle_code//:git_info"],
|
||||
outs = ["AssemblyInfo.cs"],
|
||||
cmd = "$(execpath :gen-assembly-info) $@ $(SRCS)",
|
||||
tools = [":gen-assembly-info"],
|
||||
outs = ["GitAssemblyInfo.cs"],
|
||||
cmd = "$(execpath :gen-git-assembly-info) $@ $(SRCS)",
|
||||
tools = [":gen-git-assembly-info"],
|
||||
visibility = ["//csharp:__subpackages__"],
|
||||
)
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
"""
|
||||
Generates an `AssemblyInfo.cs` file that specifies the `AssemblyInformationalVersion` attribute.
|
||||
|
||||
This attribute is set to the git version string of the repository."""
|
||||
Generates an `AssemblyInfo.cs` file that specifies a bunch of useful attributes
|
||||
that we want to set on our assemblies."""
|
||||
|
||||
import pathlib
|
||||
import argparse
|
||||
@@ -9,26 +8,20 @@ import argparse
|
||||
|
||||
def options():
|
||||
p = argparse.ArgumentParser(
|
||||
description="Generate the assembly info file that contains the git SHA and branch name"
|
||||
description="Generate an assembly info file."
|
||||
)
|
||||
p.add_argument("output", help="The path to the output file")
|
||||
p.add_argument("gitinfo_files", nargs="+", help="The path to the gitinfo files")
|
||||
p.add_argument("name", help="The name of the assembly")
|
||||
return p.parse_args()
|
||||
|
||||
|
||||
opts = options()
|
||||
|
||||
gitfiles = dict()
|
||||
for file in map(pathlib.Path, opts.gitinfo_files):
|
||||
gitfiles[file.name] = file
|
||||
|
||||
version_string = gitfiles["git-ql-describe-all.log"].read_text().strip()
|
||||
version_string += f" ({gitfiles['git-ql-rev-parse.log'].read_text().strip()})"
|
||||
|
||||
output_file = pathlib.Path(opts.output)
|
||||
output_file_contents = f"""
|
||||
using System.Reflection;
|
||||
|
||||
[assembly: AssemblyInformationalVersion("{version_string}")]
|
||||
[assembly: XX("{opts.name}")]
|
||||
[assembly: YY("ZZ")]
|
||||
"""
|
||||
output_file.write_text(output_file_contents)
|
||||
|
||||
34
csharp/scripts/gen-git-assembly-info.py
Normal file
34
csharp/scripts/gen-git-assembly-info.py
Normal file
@@ -0,0 +1,34 @@
|
||||
"""
|
||||
Generates an `GitAssemblyInfo.cs` file that specifies the `AssemblyInformationalVersion` attribute.
|
||||
|
||||
This attribute is set to the git version string of the repository."""
|
||||
|
||||
import pathlib
|
||||
import argparse
|
||||
|
||||
|
||||
def options():
|
||||
p = argparse.ArgumentParser(
|
||||
description="Generate the git assembly info file that contains the git SHA and branch name"
|
||||
)
|
||||
p.add_argument("output", help="The path to the output file")
|
||||
p.add_argument("gitinfo_files", nargs="+", help="The path to the gitinfo files")
|
||||
return p.parse_args()
|
||||
|
||||
|
||||
opts = options()
|
||||
|
||||
gitfiles = dict()
|
||||
for file in map(pathlib.Path, opts.gitinfo_files):
|
||||
gitfiles[file.name] = file
|
||||
|
||||
version_string = gitfiles["git-ql-describe-all.log"].read_text().strip()
|
||||
version_string += f" ({gitfiles['git-ql-rev-parse.log'].read_text().strip()})"
|
||||
|
||||
output_file = pathlib.Path(opts.output)
|
||||
output_file_contents = f"""
|
||||
using System.Reflection;
|
||||
|
||||
[assembly: AssemblyInformationalVersion("{version_string}")]
|
||||
"""
|
||||
output_file.write_text(output_file_contents)
|
||||
Reference in New Issue
Block a user