Skip to content

Commit

Permalink
simplify the RPC for SARIF (#336)
Browse files Browse the repository at this point in the history
The goal is to make it as close as possible as the general
CallFormat so at some point we can merge them.

test plan:
see related PR in semgrep


- [x] I ran `make setup && make` to update the generated code after
editing a `.atd` file (TODO: have a CI check)
- [x] I made sure we're still backward compatible with old versions of
the CLI.
For example, the Semgrep backend need to still be able to *consume* data
	  generated by Semgrep 1.50.0.
See
https://atd.readthedocs.io/en/latest/atdgen-tutorial.html#smooth-protocol-upgrades
	  Note that the types related to the semgrep-core JSON output or the
	  semgrep-core RPC do not need to be backward compatible!

Co-authored-by: pad <[email protected]>
  • Loading branch information
aryx and pad authored Jan 14, 2025
1 parent aec607b commit b54e43b
Show file tree
Hide file tree
Showing 7 changed files with 6,240 additions and 6,658 deletions.
38 changes: 9 additions & 29 deletions semgrep_output_v1.atd
Original file line number Diff line number Diff line change
Expand Up @@ -1939,35 +1939,15 @@ type apply_fixes_return <python decorator="dataclass(frozen=True)"> = {
fixed_lines: (int * string list) list;
}

(* TODO: remove many fields so that CallSarifFormat gets close to CallFormatter.
* I think we just need the 'rules: fpath' as it can't be reconstructed
* from cli_output.
*)
type sarif_format_params <python decorator="dataclass(frozen=True)"> = {
(* Path the the rules file *)
type sarif_format <python decorator="dataclass(frozen=True)"> = {
(* Path to the rules file. We need it because rules can't be reconstructed
* from cli_output (which is one of the other param of CallSarifFormat) *)
rules: fpath;

(* TODO: remove, just use cli_output *)
cli_matches: cli_match list;
cli_errors: cli_error list;
(* TODO: remove, should be able to derive those from format_context *)
hide_nudge: bool;
engine_label: string;
(* TODO? move to format_context? *)
is_pro: bool;
show_dataflow_traces: bool;
}

(* TODO: remove, reuse RetFormatter *)
type sarif_format_return <python decorator="dataclass(frozen=True)"> = {
(* The formatted output. *)
output: string;
(* Time (in seconds) it took to format the output.
* This helps tracking how much actual formatting time is needed
* compared to the whole RPC call, so we can profile and improve
* performace when needed.
*)
format_time_seconds: float;
}

type output_format
<ocaml attr="deriving show">
<python decorator="dataclass(frozen=True)"> =
Expand Down Expand Up @@ -2148,9 +2128,9 @@ type resolution_result = [
type function_call <python decorator="dataclass(frozen=True)"> = [
| CallContributions
| CallApplyFixes of apply_fixes_params
(* TODO: merge with CallFormatter at some point *)
| CallSarifFormat of (format_context * sarif_format_params)
| CallFormatter of (output_format * format_context * cli_output)
(* TODO: merge with CallFormatter at some point *)
| CallSarifFormat of (sarif_format * format_context * cli_output)
(* NOTE: fpath is most likely a temporary file that contains all the rules in
JSON format. In the future, we could send the rules via a big string through
the RPC pipe.
Expand All @@ -2168,9 +2148,9 @@ type function_return <python decorator="dataclass(frozen=True)"> = [
| RetError of string
| RetApplyFixes of apply_fixes_return
| RetContributions of contributions
(* TODO: remove and use RetFormatter for the return of CallSarifFormat too *)
| RetSarifFormat of sarif_format_return
| RetFormatter of string
(* alt: reuse RetFormatter *)
| RetSarifFormat of string
| RetValidate of bool
| RetResolveDependencies of (dependency_source * resolution_result) list
| RetDumpRulePartitions of bool
Expand Down
42 changes: 11 additions & 31 deletions semgrep_output_v1.jsonschema

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 3 additions & 11 deletions semgrep_output_v1.proto

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b54e43b

Please sign in to comment.