11import { Uri } from "vscode" ;
2- import type { Log } from "sarif" ;
3- import { pathExists } from "fs-extra" ;
4- import { sarifParser } from "../common/sarif-parser" ;
2+ import { join } from "path" ;
53import type { CompletedLocalQueryInfo } from "../query-results" ;
64import type { DatabaseManager } from "../databases/local-databases" ;
75import type { CodeQLCliServer } from "../codeql-cli/cli" ;
86import type { InterpretedQueryCompareResult } from "../common/interface-types" ;
97
108import { sarifDiff } from "./sarif-diff" ;
119
12- async function getInterpretedResults (
13- interpretedResultsPath : string ,
14- ) : Promise < Log | undefined > {
15- if ( ! ( await pathExists ( interpretedResultsPath ) ) ) {
16- return undefined ;
17- }
18-
19- return await sarifParser ( interpretedResultsPath ) ;
20- }
21-
2210export async function compareInterpretedResults (
2311 databaseManager : DatabaseManager ,
2412 cliServer : CodeQLCliServer ,
@@ -34,37 +22,65 @@ export async function compareInterpretedResults(
3422 ) ;
3523 }
3624
37- const [ fromResultSet , toResultSet , sourceLocationPrefix ] = await Promise . all ( [
38- getInterpretedResults (
39- fromQuery . completedQuery . query . interpretedResultsPath ,
40- ) ,
41- getInterpretedResults ( toQuery . completedQuery . query . interpretedResultsPath ) ,
42- database . getSourceLocationPrefix ( cliServer ) ,
43- ] ) ;
25+ const { uniquePath1, uniquePath2, path, cleanup } = await cliServer . bqrsDiff (
26+ fromQuery . completedQuery . query . resultsPath ,
27+ toQuery . completedQuery . query . resultsPath ,
28+ { retainResultSets : [ "nodes" , "edges" , "subpaths" ] } ,
29+ ) ;
30+ try {
31+ const sarifOutput1 = join ( path , "from.sarif" ) ;
32+ const sarifOutput2 = join ( path , "to.sarif" ) ;
4433
45- if ( ! fromResultSet || ! toResultSet ) {
46- throw new Error (
47- "Could not find interpreted results for one or both queries." ,
34+ const sourceLocationPrefix =
35+ await database . getSourceLocationPrefix ( cliServer ) ;
36+ const sourceArchiveUri = database . sourceArchive ;
37+ const sourceInfo =
38+ sourceArchiveUri === undefined
39+ ? undefined
40+ : {
41+ sourceArchive : sourceArchiveUri . fsPath ,
42+ sourceLocationPrefix,
43+ } ;
44+
45+ const fromResultSet = await cliServer . interpretBqrsSarif (
46+ toQuery . completedQuery . query . metadata ! ,
47+ uniquePath1 ,
48+ sarifOutput1 ,
49+ sourceInfo ,
50+ ) ;
51+ const toResultSet = await cliServer . interpretBqrsSarif (
52+ toQuery . completedQuery . query . metadata ! ,
53+ uniquePath2 ,
54+ sarifOutput2 ,
55+ sourceInfo ,
4856 ) ;
49- }
5057
51- const fromResults = fromResultSet . runs [ 0 ] . results ;
52- const toResults = toResultSet . runs [ 0 ] . results ;
58+ if ( ! fromResultSet || ! toResultSet ) {
59+ throw new Error (
60+ "Could not find interpreted results for one or both queries." ,
61+ ) ;
62+ }
5363
54- if ( ! fromResults ) {
55- throw new Error ( "No results found in the 'from' query." ) ;
56- }
64+ const fromResults = fromResultSet . runs [ 0 ] . results ;
65+ const toResults = toResultSet . runs [ 0 ] . results ;
5766
58- if ( ! toResults ) {
59- throw new Error ( "No results found in the 'to' query." ) ;
60- }
67+ if ( ! fromResults ) {
68+ throw new Error ( "CodeQL Compare: Source query has no results." ) ;
69+ }
70+
71+ if ( ! toResults ) {
72+ throw new Error ( "CodeQL Compare: Target query has no results." ) ;
73+ }
6174
62- const { from, to } = sarifDiff ( fromResults , toResults ) ;
75+ const { from, to } = sarifDiff ( fromResults , toResults ) ;
6376
64- return {
65- kind : "interpreted" ,
66- sourceLocationPrefix,
67- from,
68- to,
69- } ;
77+ return {
78+ kind : "interpreted" ,
79+ sourceLocationPrefix,
80+ from,
81+ to,
82+ } ;
83+ } finally {
84+ await cleanup ( ) ;
85+ }
7086}
0 commit comments