From 33eb69164c8bd92e16a66ab9dd83dd6e321ee602 Mon Sep 17 00:00:00 2001 From: Tamas Vajk Date: Fri, 8 Mar 2024 11:20:04 +0100 Subject: [PATCH 1/2] C#: Change ID of buildless output assembly --- .../Entities/Assembly.cs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Assembly.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Assembly.cs index a997b7129df5..cf814c6087bd 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Assembly.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Assembly.cs @@ -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); @@ -68,8 +69,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("\\", "/")); From 9b5cfc9026515537ba4140a0399c5f483256986a Mon Sep 17 00:00:00 2001 From: Tamas Vajk Date: Fri, 8 Mar 2024 15:02:30 +0100 Subject: [PATCH 2/2] Change assembly population in buildless --- .../Semmle.Extraction.CSharp/Entities/Assembly.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Assembly.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Assembly.cs index cf814c6087bd..a826aa5e02c5 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Assembly.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Assembly.cs @@ -33,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); } }