Skip to content

C#: Change ID of buildless output assembly #15854

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 2 commits into from
Mar 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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