mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
Apparently, when building a release build, we're getting `no-git` as first part o the version string for the submodule. If we do, fall back to the internal repo's branch name. For releases, that's the same anyways. Luckily, the commit SHA is correct.
37 lines
1.1 KiB
Python
37 lines
1.1 KiB
Python
"""
|
|
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()
|
|
if version_string == "no-git":
|
|
version_string = gitfiles["git-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)
|