Skip to content

Commit 36922f2

Browse files
committed
Remove GitInfo dependency.
GitInfo doesn't work with the bazel-based build. Instead, we pull in the information from bazel, which correctly works with the bazel cache.
1 parent 71372bc commit 36922f2

File tree

7 files changed

+30
-23
lines changed

7 files changed

+30
-23
lines changed

csharp/extractor/Semmle.Extraction/BUILD.bazel

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ codeql_csharp_library(
3030
visibility = ["//csharp:__subpackages__"],
3131
deps = [
3232
"//csharp/extractor/Semmle.Util",
33-
# "@paket.main//gitinfo",
34-
# "@paket.main//thisassembly.git",
3533
"@paket.main//microsoft.build",
3634
"@paket.main//microsoft.codeanalysis",
3735
],

csharp/extractor/Semmle.Extraction/Extractor/Extractor.cs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Collections.Generic;
2+
using System.Reflection;
3+
using System.IO;
24
using Semmle.Util.Logging;
3-
45
using CompilationInfo = (string key, string value);
56

67
namespace Semmle.Extraction
@@ -102,7 +103,23 @@ public void MissingNamespace(string fqdn, bool fromSource)
102103

103104
public ILogger Logger { get; private set; }
104105

105-
public static string Version => $"";
106+
public static string Version
107+
{
108+
get
109+
{
110+
// the resources for git information are always attached to the entry` assembly by our build system
111+
var assembly = Assembly.GetEntryAssembly();
112+
var describeAllStream = assembly.GetManifestResourceStream("git-ql-describe-all.log");
113+
var headSHAStream = assembly.GetManifestResourceStream("git-ql-rev-parse.log");
114+
if (describeAllStream == null || headSHAStream == null)
115+
{
116+
return "unknown (not built from internal bazel workspace)";
117+
}
118+
var describeAll = new StreamReader(describeAllStream).ReadToEnd().Trim('\n');
119+
var headSHA = new StreamReader(headSHAStream).ReadToEnd().Trim('\n');
120+
return $"{describeAll} ({headSHA})";
121+
}
122+
}
106123

107124
public PathTransformer PathTransformer { get; }
108125
}
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
Microsoft.Build
22
Microsoft.CodeAnalysis
3-
GitInfo

csharp/paket.dependencies

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,3 @@ nuget System.Net.Primitives
1818
nuget System.Security.Principal
1919
nuget System.Threading.ThreadPool
2020
nuget System.IO.FileSystem
21-
nuget GitInfo 3.3.3

csharp/paket.lock

Lines changed: 0 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

csharp/paket.main.bzl

Lines changed: 5 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

misc/bazel/csharp.bzl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,15 @@ def codeql_xunit_test(name, **kwargs):
3838
def codeql_csharp_binary(name, **kwargs):
3939
nullable = kwargs.pop("nullable", "enable")
4040
visibility = kwargs.pop("visibility", ["//visibility:public"])
41+
resources = kwargs.pop("resources", [])
42+
43+
# the entry assembly always has the git info embedded
44+
resources.append("@semmle_code//:git_info")
45+
4146
target_frameworks = kwargs.pop("target_frameworks", [TARGET_FRAMEWORK])
4247
csharp_binary_target = "bin/" + name
4348
publish_binary_target = "publish/" + name
44-
csharp_binary(name = csharp_binary_target, nullable = nullable, target_frameworks = target_frameworks, visibility = visibility, **kwargs)
49+
csharp_binary(name = csharp_binary_target, nullable = nullable, target_frameworks = target_frameworks, resources = resources, visibility = visibility, **kwargs)
4550
publish_binary(
4651
name = publish_binary_target,
4752
binary = csharp_binary_target,

0 commit comments

Comments
 (0)