Skip to content

Commit

Permalink
Merge pull request #15854 from tamasvajk/buildless/change-assembly-id
Browse files Browse the repository at this point in the history
C#: Change ID of buildless output assembly
  • Loading branch information
tamasvajk authored Mar 11, 2024
2 parents 42acd9c + 9b5cfc9 commit 35a8e7c
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions csharp/extractor/Semmle.Extraction.CSharp/Entities/Assembly.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,20 @@ internal class Assembly : Extraction.Entities.Location

private readonly string assemblyPath;
private readonly IAssemblySymbol assembly;
private readonly bool isOutputAssembly;

private Assembly(Context cx, Microsoft.CodeAnalysis.Location? init)
: base(cx, init)
{
if (init is null)
isOutputAssembly = init is null;
if (isOutputAssembly)
{
// This is the output assembly
assemblyPath = cx.Extractor.OutputPath;
assembly = cx.Compilation.Assembly;
}
else
{
assembly = init.MetadataModule!.ContainingAssembly;
assembly = init!.MetadataModule!.ContainingAssembly;
var identity = assembly.Identity;
var idString = identity.Name + " " + identity.Version;
assemblyPath = cx.Extractor.GetAssemblyFile(idString);
Expand All @@ -32,8 +33,13 @@ public override void Populate(TextWriter trapFile)
{
if (assemblyPath is not null)
{
trapFile.assemblies(this, File.Create(Context, assemblyPath), assembly.ToString() ?? "",
assembly.Identity.Name, assembly.Identity.Version.ToString());
var isBuildlessOutputAssembly = isOutputAssembly && Context.Extractor.Mode.HasFlag(ExtractorMode.Standalone);
var identifier = isBuildlessOutputAssembly
? ""
: assembly.ToString() ?? "";
var name = isBuildlessOutputAssembly ? "" : assembly.Identity.Name;
var version = isBuildlessOutputAssembly ? "" : assembly.Identity.Version.ToString();
trapFile.assemblies(this, File.Create(Context, assemblyPath), identifier, name, version);
}
}

Expand Down Expand Up @@ -68,8 +74,16 @@ public static Assembly CreateOutputAssembly(Context cx)

public override void WriteId(EscapingTextWriter trapFile)
{
trapFile.Write(assembly.ToString());
if (!(assemblyPath is null))
if (isOutputAssembly && Context.Extractor.Mode.HasFlag(ExtractorMode.Standalone))
{
trapFile.Write("buildlessOutputAssembly");
}
else
{
trapFile.Write(assembly.ToString());
}

if (assemblyPath is not null)
{
trapFile.Write("#file:///");
trapFile.Write(assemblyPath.Replace("\\", "/"));
Expand Down

0 comments on commit 35a8e7c

Please sign in to comment.