Skip to content

Commit 41b0231

Browse files
authored
add rpc interface for dependency resolution (#288)
Adds the RPC types that will be necessary to perform dependency resolution in OCaml. These changes comprise new types to represent a resolution request, response, and resolved relationships, and an additional optional `id` field on `found_dependency` that is used to associate a dependency with its dependency relationships. - [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. Closes SC-1732.
1 parent 512c0bd commit 41b0231

7 files changed

+1819
-337
lines changed

semgrep_output_v1.atd

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,7 +1089,7 @@ type dependency_pattern = {
10891089
semver_range: string;
10901090
}
10911091

1092-
type dependency_child = {
1092+
type dependency_child <python decorator="dataclass(frozen=True)"> = {
10931093
package: string;
10941094
version: string;
10951095
}
@@ -1114,12 +1114,15 @@ type found_dependency = {
11141114
* lockfile_path, this can identify the location of the dependency in the lockfile.
11151115
*)
11161116
?line_number: int option;
1117-
(* store child dependency information for calculating path to transitivity*)
1117+
(* If we have dependency relationship information for this dependency, this field will include
1118+
* the name and version of other found_dependency items that this dependency requires.
1119+
* These fields must match values in `package` and `version` of another `found_dependency`
1120+
* in the same set *)
11181121
?children: dependency_child list option;
11191122
(* Git ref of the dependency if the dependency comes directly from a git repo.
11201123
* Examples: refs/heads/main, refs/tags/v1.0.0, e5c704df4d308690fed696faf4c86453b4d88a95
11211124
* since 1.66.0 *)
1122-
?git_ref: string option
1125+
?git_ref: string option;
11231126
}
11241127

11251128
(* json names are to maintain backwards compatibility with the python enum it is replacing *)
@@ -1806,6 +1809,39 @@ type output_format = [
18061809
| Emacs
18071810
]
18081811

1812+
(* TODO: merge with Manifest_kind.ml *)
1813+
type manifest_kind = [
1814+
| PomXml
1815+
| BuildGradle
1816+
]
1817+
1818+
type manifest = {
1819+
kind: manifest_kind;
1820+
path: fpath;
1821+
}
1822+
1823+
1824+
type resolution_error
1825+
<python decorator="dataclass(frozen=True)"> = [
1826+
| UnsupportedManifest
1827+
| MissingRequirement of string
1828+
| ResolutionCmdFailed of resolution_cmd_failed
1829+
| ParseDependenciesFailed of string
1830+
]
1831+
1832+
type resolution_cmd_failed
1833+
<python decorator="dataclass(frozen=True)"> = {
1834+
command: string;
1835+
message: string;
1836+
}
1837+
1838+
type resolution_result = [
1839+
(* dependency_relationship items each reference an id from found_dependency.id
1840+
and the IDs of the dependencies that that item depends on *)
1841+
| ResolutionOk of found_dependency list
1842+
| ResolutionError of resolution_error
1843+
]
1844+
18091845
type function_call
18101846
<python decorator="dataclass(frozen=True)"> = [
18111847
| CallContributions
@@ -1817,6 +1853,7 @@ type function_call
18171853
the RPC pipe.
18181854
*)
18191855
| CallValidate of fpath
1856+
| CallResolveDependencies of manifest list
18201857
]
18211858

18221859
type function_return
@@ -1827,4 +1864,5 @@ type function_return
18271864
| RetContributions of contributions
18281865
| RetFormatter of string
18291866
| RetValidate of bool
1867+
| RetResolveDependencies of (manifest * resolution_result) list
18301868
]

semgrep_output_v1.jsonschema

Lines changed: 106 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

semgrep_output_v1.proto

Lines changed: 11 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)