-
Notifications
You must be signed in to change notification settings - Fork 1.7k
C#: Add assembly attributes to assemblies built with Bazel #16705
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
beffc2a
C#: Remove unneeded source folder from Bazel build scripts
tamasvajk 16f8be4
C#: Add product name to assemblies
tamasvajk 6731bcc
C#: Provide skeleton to generate an assemblyInfo file.
criemen 5f98f2a
Add assembly attributes to bazel build script
tamasvajk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 0 additions & 4 deletions
4
csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/Properties/AssemblyInfo.cs
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 0 additions & 4 deletions
4
csharp/extractor/Semmle.Extraction.CSharp.StubGenerator/Properties/AssemblyInfo.cs
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,21 @@ | ||
py_binary( | ||
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__"], | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,34 @@ | ||
""" | ||
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 | ||
|
||
|
||
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: AssemblyTitle("{opts.name}")] | ||
[assembly: AssemblyProduct("CodeQL")] | ||
[assembly: AssemblyVersion("1.0.0.0")] | ||
[assembly: AssemblyFileVersion("1.0.0.0")] | ||
[assembly: AssemblyCompany("GitHub")] | ||
[assembly: AssemblyCopyright("Copyright © 2024 GitHub")] | ||
|
||
[assembly: System.Runtime.Versioning.TargetFramework(".NETCoreApp,Version=v8.0", FrameworkDisplayName = ".NET 8.0")] | ||
|
||
""" | ||
output_file.write_text(output_file_contents) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we record in the C# wiki that this requires updating when we upgrade .NET?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I'm doing it.