Skip to content

Commit fb13126

Browse files
committed
C#: Store output assembly in compilation_assembly relation
1 parent 983c4d0 commit fb13126

File tree

10 files changed

+42
-2
lines changed

10 files changed

+42
-2
lines changed

csharp/extractor/Semmle.Extraction.CSharp/Entities/Compilation.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ public Compilation(Context cx, string cwd, string[] args) : base(cx)
2121

2222
protected override void Populate(TextWriter trapFile)
2323
{
24-
Extraction.Entities.Assembly.CreateOutputAssembly(cx);
24+
var assembly = Extraction.Entities.Assembly.CreateOutputAssembly(cx);
2525

2626
trapFile.compilations(this, FileUtils.ConvertToUnix(cwd));
27+
trapFile.compilation_assembly(this, assembly);
2728

2829
// Arguments
2930
var index = 0;

csharp/extractor/Semmle.Extraction.CSharp/Tuples.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ internal static void compilations(this TextWriter trapFile, Compilation compilat
111111
trapFile.WriteTuple("compilations", compilation, cwd);
112112
}
113113

114+
internal static void compilation_assembly(this TextWriter trapFile, Compilation compilation, Assembly assembly)
115+
{
116+
trapFile.WriteTuple("compilation_assembly", compilation, assembly);
117+
}
118+
114119
internal static void compiler_generated(this TextWriter trapFile, IEntity entity)
115120
{
116121
trapFile.WriteTuple("compiler_generated", entity);

csharp/extractor/Semmle.Extraction/Entities/Assembly.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ private class AssemblyConstructorFactory : ICachedEntityFactory<Microsoft.CodeAn
5858
}
5959

6060
private static readonly object outputAssemblyCacheKey = new object();
61-
public static Location CreateOutputAssembly(Context cx)
61+
62+
public static Assembly CreateOutputAssembly(Context cx)
6263
{
6364
if (cx.Extractor.OutputPath == null)
6465
throw new InternalError("Attempting to create the output assembly in standalone extraction mode");

csharp/ql/src/semmle/code/csharp/Location.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import File
1616
private import Attribute
17+
private import semmle.code.csharp.commons.Compilation
1718

1819
/**
1920
* A ___location of a program element.
@@ -171,6 +172,9 @@ class Assembly extends Location, Attributable, @assembly {
171172
/** Gets the version of this assembly. */
172173
Version getVersion() { assemblies(this, _, _, _, result) }
173174

175+
/** Gets the compilation producing this assembly if any. */
176+
Compilation getCompilation() { compilation_assembly(result, this) }
177+
174178
override File getFile() { assemblies(this, result, _, _, _) }
175179

176180
override string toString() { result = this.getFullName() }

csharp/ql/src/semmle/code/csharp/commons/Compilation.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ class Compilation extends @compilation {
99
/** Gets the directory in which this compilation was run, as a string. */
1010
string getDirectoryString() { compilations(this, result) }
1111

12+
/** Gets the output assembly. */
13+
Assembly getOutputAssembly() { compilation_assembly(this, result) }
14+
1215
/** Gets the folder in which this compilation was run. */
1316
Folder getFolder() { result.getAbsolutePath() = getDirectoryString() }
1417

csharp/ql/src/semmlecode.csharp.dbscheme

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,11 @@ compilation_finished(
151151
float elapsed_seconds : float ref
152152
);
153153

154+
compilation_assembly(
155+
unique int id : @compilation ref,
156+
int assembly: @assembly ref
157+
)
158+
154159
/*
155160
* External artifacts
156161
*/
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
| Assembly1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null | no compilation |
2+
| Locations, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null | has compilation |
3+
| System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 | no compilation |
4+
| System.Console, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a | no compilation |
5+
| System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 | no compilation |
6+
| System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e | no compilation |
7+
| System.Runtime, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a | no compilation |
8+
| System.Runtime.Extensions, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a | no compilation |
9+
| mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 | no compilation |
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import csharp
2+
3+
private string hasCompilation(Assembly a) {
4+
if exists(a.getCompilation()) then result = "has compilation" else result = "no compilation"
5+
}
6+
7+
from Assembly a
8+
select a.getFullName(), hasCompilation(a)

csharp/ql/test/library-tests/compilations/Compilations.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,5 @@ references
3535
| compilation | mscorlib.dll |
3636
timings
3737
| compilation |
38+
assembly
39+
| compilation | Program.dll:0:0:0:0 | Program, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null |

csharp/ql/test/library-tests/compilations/Compilations.ql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,5 @@ query predicate timings(Compilation c) {
3939
c.getCpuSeconds() > 0 and
4040
c.getElapsedSeconds() > 0
4141
}
42+
43+
query predicate assembly(Compilation c, Assembly a) { c.getOutputAssembly() = a }

0 commit comments

Comments
 (0)