From 9c5609cee6b018d2a1ab59ce493c6b8673903e96 Mon Sep 17 00:00:00 2001 From: Ben Kettle Date: Wed, 6 Nov 2024 22:21:45 -0800 Subject: [PATCH 1/5] chore(dep-resolution): update dep-resolution RPC interface to support lockfiles --- semgrep_output_v1.atd | 43 ++- semgrep_output_v1.jsonschema | 71 ++++- semgrep_output_v1.proto | 7 +- semgrep_output_v1.py | 460 +++++++++++++++++++++++++++- semgrep_output_v1.ts | 157 +++++++++- semgrep_output_v1_j.ml | 576 +++++++++++++++++++++++++++++++++-- semgrep_output_v1_j.mli | 84 ++++- 7 files changed, 1358 insertions(+), 40 deletions(-) diff --git a/semgrep_output_v1.atd b/semgrep_output_v1.atd index e30aee4e..de883689 100644 --- a/semgrep_output_v1.atd +++ b/semgrep_output_v1.atd @@ -71,7 +71,7 @@ type raw_json = abstract (*****************************************************************************) (* File path. less: could convert directly to Path class of pathlib library for Python *) -type fpath = string wrap +type fpath = string wrap type uri = string wrap @@ -1857,6 +1857,27 @@ type format_context is_using_registry: bool; } +type lockfile_kind + + = [ + | PipRequirementsTxt + | PoetryLock + | PipfileLock + | NpmPackageLockJson + | YarnLock + | PnpmLock + | GemfileLock + | GoMod + | CargoLock + | MavenDepTree (* Not a real lockfile *) + | GradleLockfile + | ComposerLock + | NugetPackageLockJson + | PubspecLock (* https://dart.dev/tools/pub/glossary#lockfile *) + | SwiftPackageResolved (* not a real lockfile *) + | MixLock +] + type manifest_kind = [ @@ -1887,11 +1908,27 @@ type manifest_kind ] type manifest + = { kind: manifest_kind; path: fpath; } +type lockfile + + = { + kind: lockfile_kind; + path: fpath; +} + +type dependency_source + + = [ + | ManifestOnlyDependencySource of manifest + | LockfileOnlyDependencySource of lockfile + | ManifestLockfileDependencySource of (manifest * lockfile) +] + type resolution_error = [ @@ -1936,7 +1973,7 @@ type function_call the RPC pipe. *) | CallValidate of fpath - | CallResolveDependencies of manifest list + | CallResolveDependencies of dependency_source list | CallDumpRulePartitions of dump_rule_partitions_params ] @@ -1952,7 +1989,7 @@ type function_return | RetContributions of contributions | RetFormatter of string | RetValidate of bool - | RetResolveDependencies of (manifest * resolution_result) list + | RetResolveDependencies of (dependency_source * resolution_result) list | RetDumpRulePartitions of bool ] diff --git a/semgrep_output_v1.jsonschema b/semgrep_output_v1.jsonschema index 6e8959b8..6ca4d456 100644 --- a/semgrep_output_v1.jsonschema +++ b/semgrep_output_v1.jsonschema @@ -1542,6 +1542,26 @@ "is_using_registry": { "type": "boolean" } } }, + "lockfile_kind": { + "oneOf": [ + { "const": "PipRequirementsTxt" }, + { "const": "PoetryLock" }, + { "const": "PipfileLock" }, + { "const": "NpmPackageLockJson" }, + { "const": "YarnLock" }, + { "const": "PnpmLock" }, + { "const": "GemfileLock" }, + { "const": "GoMod" }, + { "const": "CargoLock" }, + { "const": "MavenDepTree" }, + { "const": "GradleLockfile" }, + { "const": "ComposerLock" }, + { "const": "NugetPackageLockJson" }, + { "const": "PubspecLock" }, + { "const": "SwiftPackageResolved" }, + { "const": "MixLock" } + ] + }, "manifest_kind": { "oneOf": [ { "const": "RequirementsIn" }, @@ -1568,6 +1588,53 @@ "path": { "$ref": "#/definitions/fpath" } } }, + "lockfile": { + "type": "object", + "required": [ "kind", "path" ], + "properties": { + "kind": { "$ref": "#/definitions/lockfile_kind" }, + "path": { "$ref": "#/definitions/fpath" } + } + }, + "dependency_source": { + "oneOf": [ + { + "type": "array", + "minItems": 2, + "items": false, + "prefixItems": [ + { "const": "ManifestOnlyDependencySource" }, + { "$ref": "#/definitions/manifest" } + ] + }, + { + "type": "array", + "minItems": 2, + "items": false, + "prefixItems": [ + { "const": "LockfileOnlyDependencySource" }, + { "$ref": "#/definitions/lockfile" } + ] + }, + { + "type": "array", + "minItems": 2, + "items": false, + "prefixItems": [ + { "const": "ManifestLockfileDependencySource" }, + { + "type": "array", + "minItems": 2, + "items": false, + "prefixItems": [ + { "$ref": "#/definitions/manifest" }, + { "$ref": "#/definitions/lockfile" } + ] + } + ] + } + ] + }, "resolution_error": { "oneOf": [ { "const": "UnsupportedManifest" }, @@ -1695,7 +1762,7 @@ { "const": "CallResolveDependencies" }, { "type": "array", - "items": { "$ref": "#/definitions/manifest" } + "items": { "$ref": "#/definitions/dependency_source" } } ] }, @@ -1774,7 +1841,7 @@ "minItems": 2, "items": false, "prefixItems": [ - { "$ref": "#/definitions/manifest" }, + { "$ref": "#/definitions/dependency_source" }, { "$ref": "#/definitions/resolution_result" } ] } diff --git a/semgrep_output_v1.proto b/semgrep_output_v1.proto index 08894003..ecfd78d4 100644 --- a/semgrep_output_v1.proto +++ b/semgrep_output_v1.proto @@ -1,6 +1,6 @@ // Generated by jsonschema2protobuf. DO NOT EDIT! // Source file: semgrep_output_v1.jsonschema -// Source file sha256 digest: 235ced0bfa8997aadde6ebe23db1441374f7efd076cf97f00a47d55a95582b2d +// Source file sha256 digest: 400662cd3b6a0c7166397675a4419f3a5f2cf0dda1d506dcbc09a0a69a9d21e3 syntax = "proto3"; @@ -637,6 +637,11 @@ message Manifest { string path = 3212859; } +message Lockfile { + google.protobuf.Any kind = 3088172; + string path = 3212859; +} + message ResolutionCmdFailed { string command = 187585974; string message = 337998899; diff --git a/semgrep_output_v1.py b/semgrep_output_v1.py index 701cc6b7..86d15cac 100644 --- a/semgrep_output_v1.py +++ b/semgrep_output_v1.py @@ -7072,6 +7072,369 @@ def to_json_string(self, **kw: Any) -> str: return json.dumps(self.to_json(), **kw) +@dataclass(frozen=True) +class PipRequirementsTxt: + """Original type: lockfile_kind = [ ... | PipRequirementsTxt | ... ]""" + + @property + def kind(self) -> str: + """Name of the class representing this variant.""" + return 'PipRequirementsTxt' + + @staticmethod + def to_json() -> Any: + return 'PipRequirementsTxt' + + def to_json_string(self, **kw: Any) -> str: + return json.dumps(self.to_json(), **kw) + + +@dataclass(frozen=True) +class PoetryLock_: + """Original type: lockfile_kind = [ ... | PoetryLock | ... ]""" + + @property + def kind(self) -> str: + """Name of the class representing this variant.""" + return 'PoetryLock_' + + @staticmethod + def to_json() -> Any: + return 'PoetryLock' + + def to_json_string(self, **kw: Any) -> str: + return json.dumps(self.to_json(), **kw) + + +@dataclass(frozen=True) +class PipfileLock: + """Original type: lockfile_kind = [ ... | PipfileLock | ... ]""" + + @property + def kind(self) -> str: + """Name of the class representing this variant.""" + return 'PipfileLock' + + @staticmethod + def to_json() -> Any: + return 'PipfileLock' + + def to_json_string(self, **kw: Any) -> str: + return json.dumps(self.to_json(), **kw) + + +@dataclass(frozen=True) +class NpmPackageLockJson: + """Original type: lockfile_kind = [ ... | NpmPackageLockJson | ... ]""" + + @property + def kind(self) -> str: + """Name of the class representing this variant.""" + return 'NpmPackageLockJson' + + @staticmethod + def to_json() -> Any: + return 'NpmPackageLockJson' + + def to_json_string(self, **kw: Any) -> str: + return json.dumps(self.to_json(), **kw) + + +@dataclass(frozen=True) +class YarnLock: + """Original type: lockfile_kind = [ ... | YarnLock | ... ]""" + + @property + def kind(self) -> str: + """Name of the class representing this variant.""" + return 'YarnLock' + + @staticmethod + def to_json() -> Any: + return 'YarnLock' + + def to_json_string(self, **kw: Any) -> str: + return json.dumps(self.to_json(), **kw) + + +@dataclass(frozen=True) +class PnpmLock_: + """Original type: lockfile_kind = [ ... | PnpmLock | ... ]""" + + @property + def kind(self) -> str: + """Name of the class representing this variant.""" + return 'PnpmLock_' + + @staticmethod + def to_json() -> Any: + return 'PnpmLock' + + def to_json_string(self, **kw: Any) -> str: + return json.dumps(self.to_json(), **kw) + + +@dataclass(frozen=True) +class GemfileLock_: + """Original type: lockfile_kind = [ ... | GemfileLock | ... ]""" + + @property + def kind(self) -> str: + """Name of the class representing this variant.""" + return 'GemfileLock_' + + @staticmethod + def to_json() -> Any: + return 'GemfileLock' + + def to_json_string(self, **kw: Any) -> str: + return json.dumps(self.to_json(), **kw) + + +@dataclass(frozen=True) +class GoMod2: + """Original type: lockfile_kind = [ ... | GoMod | ... ]""" + + @property + def kind(self) -> str: + """Name of the class representing this variant.""" + return 'GoMod2' + + @staticmethod + def to_json() -> Any: + return 'GoMod' + + def to_json_string(self, **kw: Any) -> str: + return json.dumps(self.to_json(), **kw) + + +@dataclass(frozen=True) +class CargoLock: + """Original type: lockfile_kind = [ ... | CargoLock | ... ]""" + + @property + def kind(self) -> str: + """Name of the class representing this variant.""" + return 'CargoLock' + + @staticmethod + def to_json() -> Any: + return 'CargoLock' + + def to_json_string(self, **kw: Any) -> str: + return json.dumps(self.to_json(), **kw) + + +@dataclass(frozen=True) +class MavenDepTree: + """Original type: lockfile_kind = [ ... | MavenDepTree | ... ]""" + + @property + def kind(self) -> str: + """Name of the class representing this variant.""" + return 'MavenDepTree' + + @staticmethod + def to_json() -> Any: + return 'MavenDepTree' + + def to_json_string(self, **kw: Any) -> str: + return json.dumps(self.to_json(), **kw) + + +@dataclass(frozen=True) +class GradleLockfile_: + """Original type: lockfile_kind = [ ... | GradleLockfile | ... ]""" + + @property + def kind(self) -> str: + """Name of the class representing this variant.""" + return 'GradleLockfile_' + + @staticmethod + def to_json() -> Any: + return 'GradleLockfile' + + def to_json_string(self, **kw: Any) -> str: + return json.dumps(self.to_json(), **kw) + + +@dataclass(frozen=True) +class ComposerLock_: + """Original type: lockfile_kind = [ ... | ComposerLock | ... ]""" + + @property + def kind(self) -> str: + """Name of the class representing this variant.""" + return 'ComposerLock_' + + @staticmethod + def to_json() -> Any: + return 'ComposerLock' + + def to_json_string(self, **kw: Any) -> str: + return json.dumps(self.to_json(), **kw) + + +@dataclass(frozen=True) +class NugetPackageLockJson: + """Original type: lockfile_kind = [ ... | NugetPackageLockJson | ... ]""" + + @property + def kind(self) -> str: + """Name of the class representing this variant.""" + return 'NugetPackageLockJson' + + @staticmethod + def to_json() -> Any: + return 'NugetPackageLockJson' + + def to_json_string(self, **kw: Any) -> str: + return json.dumps(self.to_json(), **kw) + + +@dataclass(frozen=True) +class PubspecLock_: + """Original type: lockfile_kind = [ ... | PubspecLock | ... ]""" + + @property + def kind(self) -> str: + """Name of the class representing this variant.""" + return 'PubspecLock_' + + @staticmethod + def to_json() -> Any: + return 'PubspecLock' + + def to_json_string(self, **kw: Any) -> str: + return json.dumps(self.to_json(), **kw) + + +@dataclass(frozen=True) +class SwiftPackageResolved: + """Original type: lockfile_kind = [ ... | SwiftPackageResolved | ... ]""" + + @property + def kind(self) -> str: + """Name of the class representing this variant.""" + return 'SwiftPackageResolved' + + @staticmethod + def to_json() -> Any: + return 'SwiftPackageResolved' + + def to_json_string(self, **kw: Any) -> str: + return json.dumps(self.to_json(), **kw) + + +@dataclass(frozen=True) +class MixLock_: + """Original type: lockfile_kind = [ ... | MixLock | ... ]""" + + @property + def kind(self) -> str: + """Name of the class representing this variant.""" + return 'MixLock_' + + @staticmethod + def to_json() -> Any: + return 'MixLock' + + def to_json_string(self, **kw: Any) -> str: + return json.dumps(self.to_json(), **kw) + + +@dataclass(frozen=True) +class LockfileKind: + """Original type: lockfile_kind = [ ... ]""" + + value: Union[PipRequirementsTxt, PoetryLock_, PipfileLock, NpmPackageLockJson, YarnLock, PnpmLock_, GemfileLock_, GoMod2, CargoLock, MavenDepTree, GradleLockfile_, ComposerLock_, NugetPackageLockJson, PubspecLock_, SwiftPackageResolved, MixLock_] + + @property + def kind(self) -> str: + """Name of the class representing this variant.""" + return self.value.kind + + @classmethod + def from_json(cls, x: Any) -> 'LockfileKind': + if isinstance(x, str): + if x == 'PipRequirementsTxt': + return cls(PipRequirementsTxt()) + if x == 'PoetryLock': + return cls(PoetryLock_()) + if x == 'PipfileLock': + return cls(PipfileLock()) + if x == 'NpmPackageLockJson': + return cls(NpmPackageLockJson()) + if x == 'YarnLock': + return cls(YarnLock()) + if x == 'PnpmLock': + return cls(PnpmLock_()) + if x == 'GemfileLock': + return cls(GemfileLock_()) + if x == 'GoMod': + return cls(GoMod2()) + if x == 'CargoLock': + return cls(CargoLock()) + if x == 'MavenDepTree': + return cls(MavenDepTree()) + if x == 'GradleLockfile': + return cls(GradleLockfile_()) + if x == 'ComposerLock': + return cls(ComposerLock_()) + if x == 'NugetPackageLockJson': + return cls(NugetPackageLockJson()) + if x == 'PubspecLock': + return cls(PubspecLock_()) + if x == 'SwiftPackageResolved': + return cls(SwiftPackageResolved()) + if x == 'MixLock': + return cls(MixLock_()) + _atd_bad_json('LockfileKind', x) + _atd_bad_json('LockfileKind', x) + + def to_json(self) -> Any: + return self.value.to_json() + + @classmethod + def from_json_string(cls, x: str) -> 'LockfileKind': + return cls.from_json(json.loads(x)) + + def to_json_string(self, **kw: Any) -> str: + return json.dumps(self.to_json(), **kw) + + +@dataclass(frozen=True) +class Lockfile: + """Original type: lockfile = { ... }""" + + kind: LockfileKind + path: Fpath + + @classmethod + def from_json(cls, x: Any) -> 'Lockfile': + if isinstance(x, dict): + return cls( + kind=LockfileKind.from_json(x['kind']) if 'kind' in x else _atd_missing_json_field('Lockfile', 'kind'), + path=Fpath.from_json(x['path']) if 'path' in x else _atd_missing_json_field('Lockfile', 'path'), + ) + else: + _atd_bad_json('Lockfile', x) + + def to_json(self) -> Any: + res: Dict[str, Any] = {} + res['kind'] = (lambda x: x.to_json())(self.kind) + res['path'] = (lambda x: x.to_json())(self.path) + return res + + @classmethod + def from_json_string(cls, x: str) -> 'Lockfile': + return cls.from_json(json.loads(x)) + + def to_json_string(self, **kw: Any) -> str: + return json.dumps(self.to_json(), **kw) + + @dataclass class HasFeatures: """Original type: has_features = { ... }""" @@ -7109,6 +7472,95 @@ def to_json_string(self, **kw: Any) -> str: return json.dumps(self.to_json(), **kw) +@dataclass(frozen=True) +class ManifestOnlyDependencySource: + """Original type: dependency_source = [ ... | ManifestOnlyDependencySource of ... | ... ]""" + + value: Manifest + + @property + def kind(self) -> str: + """Name of the class representing this variant.""" + return 'ManifestOnlyDependencySource' + + def to_json(self) -> Any: + return ['ManifestOnlyDependencySource', (lambda x: x.to_json())(self.value)] + + def to_json_string(self, **kw: Any) -> str: + return json.dumps(self.to_json(), **kw) + + +@dataclass(frozen=True) +class LockfileOnlyDependencySource: + """Original type: dependency_source = [ ... | LockfileOnlyDependencySource of ... | ... ]""" + + value: Lockfile + + @property + def kind(self) -> str: + """Name of the class representing this variant.""" + return 'LockfileOnlyDependencySource' + + def to_json(self) -> Any: + return ['LockfileOnlyDependencySource', (lambda x: x.to_json())(self.value)] + + def to_json_string(self, **kw: Any) -> str: + return json.dumps(self.to_json(), **kw) + + +@dataclass(frozen=True) +class ManifestLockfileDependencySource: + """Original type: dependency_source = [ ... | ManifestLockfileDependencySource of ... | ... ]""" + + value: Tuple[Manifest, Lockfile] + + @property + def kind(self) -> str: + """Name of the class representing this variant.""" + return 'ManifestLockfileDependencySource' + + def to_json(self) -> Any: + return ['ManifestLockfileDependencySource', (lambda x: [(lambda x: x.to_json())(x[0]), (lambda x: x.to_json())(x[1])] if isinstance(x, tuple) and len(x) == 2 else _atd_bad_python('tuple of length 2', x))(self.value)] + + def to_json_string(self, **kw: Any) -> str: + return json.dumps(self.to_json(), **kw) + + +@dataclass(frozen=True) +class DependencySource: + """Original type: dependency_source = [ ... ]""" + + value: Union[ManifestOnlyDependencySource, LockfileOnlyDependencySource, ManifestLockfileDependencySource] + + @property + def kind(self) -> str: + """Name of the class representing this variant.""" + return self.value.kind + + @classmethod + def from_json(cls, x: Any) -> 'DependencySource': + if isinstance(x, List) and len(x) == 2: + cons = x[0] + if cons == 'ManifestOnlyDependencySource': + return cls(ManifestOnlyDependencySource(Manifest.from_json(x[1]))) + if cons == 'LockfileOnlyDependencySource': + return cls(LockfileOnlyDependencySource(Lockfile.from_json(x[1]))) + if cons == 'ManifestLockfileDependencySource': + return cls(ManifestLockfileDependencySource((lambda x: (Manifest.from_json(x[0]), Lockfile.from_json(x[1])) if isinstance(x, list) and len(x) == 2 else _atd_bad_json('array of length 2', x))(x[1]))) + _atd_bad_json('DependencySource', x) + _atd_bad_json('DependencySource', x) + + def to_json(self) -> Any: + return self.value.to_json() + + @classmethod + def from_json_string(cls, x: str) -> 'DependencySource': + return cls.from_json(json.loads(x)) + + def to_json_string(self, **kw: Any) -> str: + return json.dumps(self.to_json(), **kw) + + @dataclass(frozen=True) class ApplyFixesReturn: """Original type: apply_fixes_return = { ... }""" @@ -7252,7 +7704,7 @@ def to_json_string(self, **kw: Any) -> str: class RetResolveDependencies: """Original type: function_return = [ ... | RetResolveDependencies of ... | ... ]""" - value: List[Tuple[Manifest, ResolutionResult]] + value: List[Tuple[DependencySource, ResolutionResult]] @property def kind(self) -> str: @@ -7312,7 +7764,7 @@ def from_json(cls, x: Any) -> 'FunctionReturn': if cons == 'RetValidate': return cls(RetValidate(_atd_read_bool(x[1]))) if cons == 'RetResolveDependencies': - return cls(RetResolveDependencies(_atd_read_list((lambda x: (Manifest.from_json(x[0]), ResolutionResult.from_json(x[1])) if isinstance(x, list) and len(x) == 2 else _atd_bad_json('array of length 2', x)))(x[1]))) + return cls(RetResolveDependencies(_atd_read_list((lambda x: (DependencySource.from_json(x[0]), ResolutionResult.from_json(x[1])) if isinstance(x, list) and len(x) == 2 else _atd_bad_json('array of length 2', x)))(x[1]))) if cons == 'RetDumpRulePartitions': return cls(RetDumpRulePartitions(_atd_read_bool(x[1]))) _atd_bad_json('FunctionReturn', x) @@ -7619,7 +8071,7 @@ def to_json_string(self, **kw: Any) -> str: class CallResolveDependencies: """Original type: function_call = [ ... | CallResolveDependencies of ... | ... ]""" - value: List[Manifest] + value: List[DependencySource] @property def kind(self) -> str: @@ -7679,7 +8131,7 @@ def from_json(cls, x: Any) -> 'FunctionCall': if cons == 'CallValidate': return cls(CallValidate(Fpath.from_json(x[1]))) if cons == 'CallResolveDependencies': - return cls(CallResolveDependencies(_atd_read_list(Manifest.from_json)(x[1]))) + return cls(CallResolveDependencies(_atd_read_list(DependencySource.from_json)(x[1]))) if cons == 'CallDumpRulePartitions': return cls(CallDumpRulePartitions(DumpRulePartitionsParams.from_json(x[1]))) _atd_bad_json('FunctionCall', x) diff --git a/semgrep_output_v1.ts b/semgrep_output_v1.ts index fdcae3f2..005e5342 100644 --- a/semgrep_output_v1.ts +++ b/semgrep_output_v1.ts @@ -851,6 +851,24 @@ export type FormatContext = { is_using_registry: boolean; } +export type LockfileKind = +| { kind: 'PipRequirementsTxt' } +| { kind: 'PoetryLock' } +| { kind: 'PipfileLock' } +| { kind: 'NpmPackageLockJson' } +| { kind: 'YarnLock' } +| { kind: 'PnpmLock' } +| { kind: 'GemfileLock' } +| { kind: 'GoMod' } +| { kind: 'CargoLock' } +| { kind: 'MavenDepTree' } +| { kind: 'GradleLockfile' } +| { kind: 'ComposerLock' } +| { kind: 'NugetPackageLockJson' } +| { kind: 'PubspecLock' } +| { kind: 'SwiftPackageResolved' } +| { kind: 'MixLock' } + export type ManifestKind = | { kind: 'RequirementsIn' } | { kind: 'PackageJson' } @@ -872,6 +890,16 @@ export type Manifest = { path: Fpath; } +export type Lockfile = { + kind: LockfileKind; + path: Fpath; +} + +export type DependencySource = +| { kind: 'ManifestOnlyDependencySource'; value: Manifest } +| { kind: 'LockfileOnlyDependencySource'; value: Lockfile } +| { kind: 'ManifestLockfileDependencySource'; value: [Manifest, Lockfile] } + export type ResolutionError = | { kind: 'UnsupportedManifest' } | { kind: 'MissingRequirement'; value: string } @@ -899,7 +927,7 @@ export type FunctionCall = | { kind: 'CallSarifFormat'; value: SarifFormatParams } | { kind: 'CallFormatter'; value: [OutputFormat, FormatContext, CliOutput] } | { kind: 'CallValidate'; value: Fpath } -| { kind: 'CallResolveDependencies'; value: Manifest[] } +| { kind: 'CallResolveDependencies'; value: DependencySource[] } | { kind: 'CallDumpRulePartitions'; value: DumpRulePartitionsParams } export type FunctionReturn = @@ -909,7 +937,7 @@ export type FunctionReturn = | { kind: 'RetContributions'; value: Contributions } | { kind: 'RetFormatter'; value: string } | { kind: 'RetValidate'; value: boolean } -| { kind: 'RetResolveDependencies'; value: [Manifest, ResolutionResult][] } +| { kind: 'RetResolveDependencies'; value: [DependencySource, ResolutionResult][] } | { kind: 'RetDumpRulePartitions'; value: boolean } export type PartialScanResult = @@ -3475,6 +3503,83 @@ export function readFormatContext(x: any, context: any = x): FormatContext { }; } +export function writeLockfileKind(x: LockfileKind, context: any = x): any { + switch (x.kind) { + case 'PipRequirementsTxt': + return 'PipRequirementsTxt' + case 'PoetryLock': + return 'PoetryLock' + case 'PipfileLock': + return 'PipfileLock' + case 'NpmPackageLockJson': + return 'NpmPackageLockJson' + case 'YarnLock': + return 'YarnLock' + case 'PnpmLock': + return 'PnpmLock' + case 'GemfileLock': + return 'GemfileLock' + case 'GoMod': + return 'GoMod' + case 'CargoLock': + return 'CargoLock' + case 'MavenDepTree': + return 'MavenDepTree' + case 'GradleLockfile': + return 'GradleLockfile' + case 'ComposerLock': + return 'ComposerLock' + case 'NugetPackageLockJson': + return 'NugetPackageLockJson' + case 'PubspecLock': + return 'PubspecLock' + case 'SwiftPackageResolved': + return 'SwiftPackageResolved' + case 'MixLock': + return 'MixLock' + } +} + +export function readLockfileKind(x: any, context: any = x): LockfileKind { + switch (x) { + case 'PipRequirementsTxt': + return { kind: 'PipRequirementsTxt' } + case 'PoetryLock': + return { kind: 'PoetryLock' } + case 'PipfileLock': + return { kind: 'PipfileLock' } + case 'NpmPackageLockJson': + return { kind: 'NpmPackageLockJson' } + case 'YarnLock': + return { kind: 'YarnLock' } + case 'PnpmLock': + return { kind: 'PnpmLock' } + case 'GemfileLock': + return { kind: 'GemfileLock' } + case 'GoMod': + return { kind: 'GoMod' } + case 'CargoLock': + return { kind: 'CargoLock' } + case 'MavenDepTree': + return { kind: 'MavenDepTree' } + case 'GradleLockfile': + return { kind: 'GradleLockfile' } + case 'ComposerLock': + return { kind: 'ComposerLock' } + case 'NugetPackageLockJson': + return { kind: 'NugetPackageLockJson' } + case 'PubspecLock': + return { kind: 'PubspecLock' } + case 'SwiftPackageResolved': + return { kind: 'SwiftPackageResolved' } + case 'MixLock': + return { kind: 'MixLock' } + default: + _atd_bad_json('LockfileKind', x, context) + throw new Error('impossible') + } +} + export function writeManifestKind(x: ManifestKind, context: any = x): any { switch (x.kind) { case 'RequirementsIn': @@ -3558,6 +3663,46 @@ export function readManifest(x: any, context: any = x): Manifest { }; } +export function writeLockfile(x: Lockfile, context: any = x): any { + return { + 'kind': _atd_write_required_field('Lockfile', 'kind', writeLockfileKind, x.kind, x), + 'path': _atd_write_required_field('Lockfile', 'path', writeFpath, x.path, x), + }; +} + +export function readLockfile(x: any, context: any = x): Lockfile { + return { + kind: _atd_read_required_field('Lockfile', 'kind', readLockfileKind, x['kind'], x), + path: _atd_read_required_field('Lockfile', 'path', readFpath, x['path'], x), + }; +} + +export function writeDependencySource(x: DependencySource, context: any = x): any { + switch (x.kind) { + case 'ManifestOnlyDependencySource': + return ['ManifestOnlyDependencySource', writeManifest(x.value, x)] + case 'LockfileOnlyDependencySource': + return ['LockfileOnlyDependencySource', writeLockfile(x.value, x)] + case 'ManifestLockfileDependencySource': + return ['ManifestLockfileDependencySource', ((x, context) => [writeManifest(x[0], x), writeLockfile(x[1], x)])(x.value, x)] + } +} + +export function readDependencySource(x: any, context: any = x): DependencySource { + _atd_check_json_tuple(2, x, context) + switch (x[0]) { + case 'ManifestOnlyDependencySource': + return { kind: 'ManifestOnlyDependencySource', value: readManifest(x[1], x) } + case 'LockfileOnlyDependencySource': + return { kind: 'LockfileOnlyDependencySource', value: readLockfile(x[1], x) } + case 'ManifestLockfileDependencySource': + return { kind: 'ManifestLockfileDependencySource', value: ((x, context): [Manifest, Lockfile] => { _atd_check_json_tuple(2, x, context); return [readManifest(x[0], x), readLockfile(x[1], x)] })(x[1], x) } + default: + _atd_bad_json('DependencySource', x, context) + throw new Error('impossible') + } +} + export function writeResolutionError(x: ResolutionError, context: any = x): any { switch (x.kind) { case 'UnsupportedManifest': @@ -3662,7 +3807,7 @@ export function writeFunctionCall(x: FunctionCall, context: any = x): any { case 'CallValidate': return ['CallValidate', writeFpath(x.value, x)] case 'CallResolveDependencies': - return ['CallResolveDependencies', _atd_write_array(writeManifest)(x.value, x)] + return ['CallResolveDependencies', _atd_write_array(writeDependencySource)(x.value, x)] case 'CallDumpRulePartitions': return ['CallDumpRulePartitions', writeDumpRulePartitionsParams(x.value, x)] } @@ -3690,7 +3835,7 @@ export function readFunctionCall(x: any, context: any = x): FunctionCall { case 'CallValidate': return { kind: 'CallValidate', value: readFpath(x[1], x) } case 'CallResolveDependencies': - return { kind: 'CallResolveDependencies', value: _atd_read_array(readManifest)(x[1], x) } + return { kind: 'CallResolveDependencies', value: _atd_read_array(readDependencySource)(x[1], x) } case 'CallDumpRulePartitions': return { kind: 'CallDumpRulePartitions', value: readDumpRulePartitionsParams(x[1], x) } default: @@ -3715,7 +3860,7 @@ export function writeFunctionReturn(x: FunctionReturn, context: any = x): any { case 'RetValidate': return ['RetValidate', _atd_write_bool(x.value, x)] case 'RetResolveDependencies': - return ['RetResolveDependencies', _atd_write_array(((x, context) => [writeManifest(x[0], x), writeResolutionResult(x[1], x)]))(x.value, x)] + return ['RetResolveDependencies', _atd_write_array(((x, context) => [writeDependencySource(x[0], x), writeResolutionResult(x[1], x)]))(x.value, x)] case 'RetDumpRulePartitions': return ['RetDumpRulePartitions', _atd_write_bool(x.value, x)] } @@ -3737,7 +3882,7 @@ export function readFunctionReturn(x: any, context: any = x): FunctionReturn { case 'RetValidate': return { kind: 'RetValidate', value: _atd_read_bool(x[1], x) } case 'RetResolveDependencies': - return { kind: 'RetResolveDependencies', value: _atd_read_array(((x, context): [Manifest, ResolutionResult] => { _atd_check_json_tuple(2, x, context); return [readManifest(x[0], x), readResolutionResult(x[1], x)] }))(x[1], x) } + return { kind: 'RetResolveDependencies', value: _atd_read_array(((x, context): [DependencySource, ResolutionResult] => { _atd_check_json_tuple(2, x, context); return [readDependencySource(x[0], x), readResolutionResult(x[1], x)] }))(x[1], x) } case 'RetDumpRulePartitions': return { kind: 'RetDumpRulePartitions', value: _atd_read_bool(x[1], x) } default: diff --git a/semgrep_output_v1_j.ml b/semgrep_output_v1_j.ml index d2c3849b..9e5ef03a 100644 --- a/semgrep_output_v1_j.ml +++ b/semgrep_output_v1_j.ml @@ -3,7 +3,7 @@ type datetime = Semgrep_output_v1_t.datetime -type fpath = Semgrep_output_v1_t.fpath [@@deriving show] +type fpath = Semgrep_output_v1_t.fpath [@@deriving show, eq, yojson] type match_severity = Semgrep_output_v1_t.match_severity [@@deriving show, eq] @@ -671,6 +671,21 @@ type manifest = Semgrep_output_v1_t.manifest = { kind: manifest_kind; path: fpath } + [@@deriving show, eq, yojson] + +type lockfile_kind = Semgrep_output_v1_t.lockfile_kind = + PipRequirementsTxt | PoetryLock | PipfileLock | NpmPackageLockJson + | YarnLock | PnpmLock | GemfileLock | GoMod | CargoLock | MavenDepTree + | GradleLockfile | ComposerLock | NugetPackageLockJson | PubspecLock + | SwiftPackageResolved | MixLock + + [@@deriving show, eq, yojson] + +type lockfile = Semgrep_output_v1_t.lockfile = { + kind: lockfile_kind; + path: fpath +} + [@@deriving show, eq, yojson] type has_features = Semgrep_output_v1_t.has_features = { has_autofix: bool; @@ -679,6 +694,13 @@ type has_features = Semgrep_output_v1_t.has_features = { has_dependency_query: bool } +type dependency_source = Semgrep_output_v1_t.dependency_source = + ManifestOnlyDependencySource of manifest + | LockfileOnlyDependencySource of lockfile + | ManifestLockfileDependencySource of (manifest * lockfile) + + [@@deriving show] + type apply_fixes_return = Semgrep_output_v1_t.apply_fixes_return = { modified_file_count: int; fixed_lines: (int * string list) list @@ -26762,6 +26784,311 @@ let read_manifest = ( ) let manifest_of_string s = read_manifest (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_lockfile_kind : _ -> lockfile_kind -> _ = ( + fun ob (x : lockfile_kind) -> + match x with + | PipRequirementsTxt -> Buffer.add_string ob "\"PipRequirementsTxt\"" + | PoetryLock -> Buffer.add_string ob "\"PoetryLock\"" + | PipfileLock -> Buffer.add_string ob "\"PipfileLock\"" + | NpmPackageLockJson -> Buffer.add_string ob "\"NpmPackageLockJson\"" + | YarnLock -> Buffer.add_string ob "\"YarnLock\"" + | PnpmLock -> Buffer.add_string ob "\"PnpmLock\"" + | GemfileLock -> Buffer.add_string ob "\"GemfileLock\"" + | GoMod -> Buffer.add_string ob "\"GoMod\"" + | CargoLock -> Buffer.add_string ob "\"CargoLock\"" + | MavenDepTree -> Buffer.add_string ob "\"MavenDepTree\"" + | GradleLockfile -> Buffer.add_string ob "\"GradleLockfile\"" + | ComposerLock -> Buffer.add_string ob "\"ComposerLock\"" + | NugetPackageLockJson -> Buffer.add_string ob "\"NugetPackageLockJson\"" + | PubspecLock -> Buffer.add_string ob "\"PubspecLock\"" + | SwiftPackageResolved -> Buffer.add_string ob "\"SwiftPackageResolved\"" + | MixLock -> Buffer.add_string ob "\"MixLock\"" +) +let string_of_lockfile_kind ?(len = 1024) x = + let ob = Buffer.create len in + write_lockfile_kind ob x; + Buffer.contents ob +let read_lockfile_kind = ( + fun p lb -> + Yojson.Safe.read_space p lb; + match Yojson.Safe.start_any_variant p lb with + | `Edgy_bracket -> ( + match Yojson.Safe.read_ident p lb with + | "PipRequirementsTxt" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (PipRequirementsTxt : lockfile_kind) + | "PoetryLock" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (PoetryLock : lockfile_kind) + | "PipfileLock" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (PipfileLock : lockfile_kind) + | "NpmPackageLockJson" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (NpmPackageLockJson : lockfile_kind) + | "YarnLock" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (YarnLock : lockfile_kind) + | "PnpmLock" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (PnpmLock : lockfile_kind) + | "GemfileLock" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (GemfileLock : lockfile_kind) + | "GoMod" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (GoMod : lockfile_kind) + | "CargoLock" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (CargoLock : lockfile_kind) + | "MavenDepTree" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (MavenDepTree : lockfile_kind) + | "GradleLockfile" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (GradleLockfile : lockfile_kind) + | "ComposerLock" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (ComposerLock : lockfile_kind) + | "NugetPackageLockJson" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (NugetPackageLockJson : lockfile_kind) + | "PubspecLock" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (PubspecLock : lockfile_kind) + | "SwiftPackageResolved" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (SwiftPackageResolved : lockfile_kind) + | "MixLock" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (MixLock : lockfile_kind) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Double_quote -> ( + match Yojson.Safe.finish_string p lb with + | "PipRequirementsTxt" -> + (PipRequirementsTxt : lockfile_kind) + | "PoetryLock" -> + (PoetryLock : lockfile_kind) + | "PipfileLock" -> + (PipfileLock : lockfile_kind) + | "NpmPackageLockJson" -> + (NpmPackageLockJson : lockfile_kind) + | "YarnLock" -> + (YarnLock : lockfile_kind) + | "PnpmLock" -> + (PnpmLock : lockfile_kind) + | "GemfileLock" -> + (GemfileLock : lockfile_kind) + | "GoMod" -> + (GoMod : lockfile_kind) + | "CargoLock" -> + (CargoLock : lockfile_kind) + | "MavenDepTree" -> + (MavenDepTree : lockfile_kind) + | "GradleLockfile" -> + (GradleLockfile : lockfile_kind) + | "ComposerLock" -> + (ComposerLock : lockfile_kind) + | "NugetPackageLockJson" -> + (NugetPackageLockJson : lockfile_kind) + | "PubspecLock" -> + (PubspecLock : lockfile_kind) + | "SwiftPackageResolved" -> + (SwiftPackageResolved : lockfile_kind) + | "MixLock" -> + (MixLock : lockfile_kind) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Square_bracket -> ( + match Atdgen_runtime.Oj_run.read_string p lb with + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) +) +let lockfile_kind_of_string s = + read_lockfile_kind (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_lockfile : _ -> lockfile -> _ = ( + fun ob (x : lockfile) -> + Buffer.add_char ob '{'; + let is_first = ref true in + if !is_first then + is_first := false + else + Buffer.add_char ob ','; + Buffer.add_string ob "\"kind\":"; + ( + write_lockfile_kind + ) + ob x.kind; + if !is_first then + is_first := false + else + Buffer.add_char ob ','; + Buffer.add_string ob "\"path\":"; + ( + write_fpath + ) + ob x.path; + Buffer.add_char ob '}'; +) +let string_of_lockfile ?(len = 1024) x = + let ob = Buffer.create len in + write_lockfile ob x; + Buffer.contents ob +let read_lockfile = ( + fun p lb -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_lcurl p lb; + let field_kind = ref (None) in + let field_path = ref (None) in + try + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_end lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg (Printf.sprintf "out-of-bounds substring position or length: string = %S, requested position = %i, requested length = %i" s pos len); + if len = 4 then ( + match String.unsafe_get s pos with + | 'k' -> ( + if String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'n' && String.unsafe_get s (pos+3) = 'd' then ( + 0 + ) + else ( + -1 + ) + ) + | 'p' -> ( + if String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 't' && String.unsafe_get s (pos+3) = 'h' then ( + 1 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + else ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + field_kind := ( + Some ( + ( + read_lockfile_kind + ) p lb + ) + ); + | 1 -> + field_path := ( + Some ( + ( + read_fpath + ) p lb + ) + ); + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + while true do + Yojson.Safe.read_space p lb; + Yojson.Safe.read_object_sep p lb; + Yojson.Safe.read_space p lb; + let f = + fun s pos len -> + if pos < 0 || len < 0 || pos + len > String.length s then + invalid_arg (Printf.sprintf "out-of-bounds substring position or length: string = %S, requested position = %i, requested length = %i" s pos len); + if len = 4 then ( + match String.unsafe_get s pos with + | 'k' -> ( + if String.unsafe_get s (pos+1) = 'i' && String.unsafe_get s (pos+2) = 'n' && String.unsafe_get s (pos+3) = 'd' then ( + 0 + ) + else ( + -1 + ) + ) + | 'p' -> ( + if String.unsafe_get s (pos+1) = 'a' && String.unsafe_get s (pos+2) = 't' && String.unsafe_get s (pos+3) = 'h' then ( + 1 + ) + else ( + -1 + ) + ) + | _ -> ( + -1 + ) + ) + else ( + -1 + ) + in + let i = Yojson.Safe.map_ident p f lb in + Atdgen_runtime.Oj_run.read_until_field_value p lb; + ( + match i with + | 0 -> + field_kind := ( + Some ( + ( + read_lockfile_kind + ) p lb + ) + ); + | 1 -> + field_path := ( + Some ( + ( + read_fpath + ) p lb + ) + ); + | _ -> ( + Yojson.Safe.skip_json p lb + ) + ); + done; + assert false; + with Yojson.End_of_object -> ( + ( + { + kind = (match !field_kind with Some x -> x | None -> Atdgen_runtime.Oj_run.missing_field p "kind"); + path = (match !field_path with Some x -> x | None -> Atdgen_runtime.Oj_run.missing_field p "path"); + } + : lockfile) + ) +) +let lockfile_of_string s = + read_lockfile (Yojson.Safe.init_lexer ()) (Lexing.from_string s) let write_has_features : _ -> has_features -> _ = ( fun ob (x : has_features) -> Buffer.add_char ob '{'; @@ -27001,6 +27328,209 @@ let read_has_features = ( ) let has_features_of_string s = read_has_features (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write_dependency_source : _ -> dependency_source -> _ = ( + fun ob (x : dependency_source) -> + match x with + | ManifestOnlyDependencySource x -> + Buffer.add_string ob "[\"ManifestOnlyDependencySource\","; + ( + write_manifest + ) ob x; + Buffer.add_char ob ']' + | LockfileOnlyDependencySource x -> + Buffer.add_string ob "[\"LockfileOnlyDependencySource\","; + ( + write_lockfile + ) ob x; + Buffer.add_char ob ']' + | ManifestLockfileDependencySource x -> + Buffer.add_string ob "[\"ManifestLockfileDependencySource\","; + ( + fun ob x -> + Buffer.add_char ob '['; + (let x, _ = x in + ( + write_manifest + ) ob x + ); + Buffer.add_char ob ','; + (let _, x = x in + ( + write_lockfile + ) ob x + ); + Buffer.add_char ob ']'; + ) ob x; + Buffer.add_char ob ']' +) +let string_of_dependency_source ?(len = 1024) x = + let ob = Buffer.create len in + write_dependency_source ob x; + Buffer.contents ob +let read_dependency_source = ( + fun p lb -> + Yojson.Safe.read_space p lb; + match Yojson.Safe.start_any_variant p lb with + | `Edgy_bracket -> ( + match Yojson.Safe.read_ident p lb with + | "ManifestOnlyDependencySource" -> + Atdgen_runtime.Oj_run.read_until_field_value p lb; + let x = ( + read_manifest + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (ManifestOnlyDependencySource x : dependency_source) + | "LockfileOnlyDependencySource" -> + Atdgen_runtime.Oj_run.read_until_field_value p lb; + let x = ( + read_lockfile + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (LockfileOnlyDependencySource x : dependency_source) + | "ManifestLockfileDependencySource" -> + Atdgen_runtime.Oj_run.read_until_field_value p lb; + let x = ( + fun p lb -> + Yojson.Safe.read_space p lb; + let std_tuple = Yojson.Safe.start_any_tuple p lb in + let len = ref 0 in + let end_of_tuple = ref false in + (try + let x0 = + let x = + ( + read_manifest + ) p lb + in + incr len; + Yojson.Safe.read_space p lb; + Yojson.Safe.read_tuple_sep2 p std_tuple lb; + x + in + let x1 = + let x = + ( + read_lockfile + ) p lb + in + incr len; + (try + Yojson.Safe.read_space p lb; + Yojson.Safe.read_tuple_sep2 p std_tuple lb; + with Yojson.End_of_tuple -> end_of_tuple := true); + x + in + if not !end_of_tuple then ( + try + while true do + Yojson.Safe.skip_json p lb; + Yojson.Safe.read_space p lb; + Yojson.Safe.read_tuple_sep2 p std_tuple lb; + done + with Yojson.End_of_tuple -> () + ); + (x0, x1) + with Yojson.End_of_tuple -> + Atdgen_runtime.Oj_run.missing_tuple_fields p !len [ 0; 1 ]); + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + (ManifestLockfileDependencySource x : dependency_source) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Double_quote -> ( + match Yojson.Safe.finish_string p lb with + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) + | `Square_bracket -> ( + match Atdgen_runtime.Oj_run.read_string p lb with + | "ManifestOnlyDependencySource" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_comma p lb; + Yojson.Safe.read_space p lb; + let x = ( + read_manifest + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_rbr p lb; + (ManifestOnlyDependencySource x : dependency_source) + | "LockfileOnlyDependencySource" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_comma p lb; + Yojson.Safe.read_space p lb; + let x = ( + read_lockfile + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_rbr p lb; + (LockfileOnlyDependencySource x : dependency_source) + | "ManifestLockfileDependencySource" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_comma p lb; + Yojson.Safe.read_space p lb; + let x = ( + fun p lb -> + Yojson.Safe.read_space p lb; + let std_tuple = Yojson.Safe.start_any_tuple p lb in + let len = ref 0 in + let end_of_tuple = ref false in + (try + let x0 = + let x = + ( + read_manifest + ) p lb + in + incr len; + Yojson.Safe.read_space p lb; + Yojson.Safe.read_tuple_sep2 p std_tuple lb; + x + in + let x1 = + let x = + ( + read_lockfile + ) p lb + in + incr len; + (try + Yojson.Safe.read_space p lb; + Yojson.Safe.read_tuple_sep2 p std_tuple lb; + with Yojson.End_of_tuple -> end_of_tuple := true); + x + in + if not !end_of_tuple then ( + try + while true do + Yojson.Safe.skip_json p lb; + Yojson.Safe.read_space p lb; + Yojson.Safe.read_tuple_sep2 p std_tuple lb; + done + with Yojson.End_of_tuple -> () + ); + (x0, x1) + with Yojson.End_of_tuple -> + Atdgen_runtime.Oj_run.missing_tuple_fields p !len [ 0; 1 ]); + ) p lb + in + Yojson.Safe.read_space p lb; + Yojson.Safe.read_rbr p lb; + (ManifestLockfileDependencySource x : dependency_source) + | x -> + Atdgen_runtime.Oj_run.invalid_variant_tag p x + ) +) +let dependency_source_of_string s = + read_dependency_source (Yojson.Safe.init_lexer ()) (Lexing.from_string s) let write__int_string_list_list = ( Atdgen_runtime.Oj_run.write_list ( fun ob x -> @@ -27224,13 +27754,13 @@ let read_apply_fixes_return = ( ) let apply_fixes_return_of_string s = read_apply_fixes_return (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write__manifest_resolution_result_list = ( +let write__dependency_source_resolution_result_list = ( Atdgen_runtime.Oj_run.write_list ( fun ob x -> Buffer.add_char ob '['; (let x, _ = x in ( - write_manifest + write_dependency_source ) ob x ); Buffer.add_char ob ','; @@ -27242,11 +27772,11 @@ let write__manifest_resolution_result_list = ( Buffer.add_char ob ']'; ) ) -let string_of__manifest_resolution_result_list ?(len = 1024) x = +let string_of__dependency_source_resolution_result_list ?(len = 1024) x = let ob = Buffer.create len in - write__manifest_resolution_result_list ob x; + write__dependency_source_resolution_result_list ob x; Buffer.contents ob -let read__manifest_resolution_result_list = ( +let read__dependency_source_resolution_result_list = ( Atdgen_runtime.Oj_run.read_list ( fun p lb -> Yojson.Safe.read_space p lb; @@ -27257,7 +27787,7 @@ let read__manifest_resolution_result_list = ( let x0 = let x = ( - read_manifest + read_dependency_source ) p lb in incr len; @@ -27292,8 +27822,8 @@ let read__manifest_resolution_result_list = ( Atdgen_runtime.Oj_run.missing_tuple_fields p !len [ 0; 1 ]); ) ) -let _manifest_resolution_result_list_of_string s = - read__manifest_resolution_result_list (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let _dependency_source_resolution_result_list_of_string s = + read__dependency_source_resolution_result_list (Yojson.Safe.init_lexer ()) (Lexing.from_string s) let write_function_return = ( fun ob x -> match x with @@ -27336,7 +27866,7 @@ let write_function_return = ( | `RetResolveDependencies x -> Buffer.add_string ob "[\"RetResolveDependencies\","; ( - write__manifest_resolution_result_list + write__dependency_source_resolution_result_list ) ob x; Buffer.add_char ob ']' | `RetDumpRulePartitions x -> @@ -27413,7 +27943,7 @@ let read_function_return = ( | "RetResolveDependencies" -> Atdgen_runtime.Oj_run.read_until_field_value p lb; let x = ( - read__manifest_resolution_result_list + read__dependency_source_resolution_result_list ) p lb in Yojson.Safe.read_space p lb; @@ -27509,7 +28039,7 @@ let read_function_return = ( Yojson.Safe.read_comma p lb; Yojson.Safe.read_space p lb; let x = ( - read__manifest_resolution_result_list + read__dependency_source_resolution_result_list ) p lb in Yojson.Safe.read_space p lb; @@ -29137,22 +29667,22 @@ let read_apply_fixes_params = ( ) let apply_fixes_params_of_string s = read_apply_fixes_params (Yojson.Safe.init_lexer ()) (Lexing.from_string s) -let write__manifest_list = ( +let write__dependency_source_list = ( Atdgen_runtime.Oj_run.write_list ( - write_manifest + write_dependency_source ) ) -let string_of__manifest_list ?(len = 1024) x = +let string_of__dependency_source_list ?(len = 1024) x = let ob = Buffer.create len in - write__manifest_list ob x; + write__dependency_source_list ob x; Buffer.contents ob -let read__manifest_list = ( +let read__dependency_source_list = ( Atdgen_runtime.Oj_run.read_list ( - read_manifest + read_dependency_source ) ) -let _manifest_list_of_string s = - read__manifest_list (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let _dependency_source_list_of_string s = + read__dependency_source_list (Yojson.Safe.init_lexer ()) (Lexing.from_string s) let write_function_call = ( fun ob x -> match x with @@ -29203,7 +29733,7 @@ let write_function_call = ( | `CallResolveDependencies x -> Buffer.add_string ob "[\"CallResolveDependencies\","; ( - write__manifest_list + write__dependency_source_list ) ob x; Buffer.add_char ob ']' | `CallDumpRulePartitions x -> @@ -29318,7 +29848,7 @@ let read_function_call = ( | "CallResolveDependencies" -> Atdgen_runtime.Oj_run.read_until_field_value p lb; let x = ( - read__manifest_list + read__dependency_source_list ) p lb in Yojson.Safe.read_space p lb; @@ -29446,7 +29976,7 @@ let read_function_call = ( Yojson.Safe.read_comma p lb; Yojson.Safe.read_space p lb; let x = ( - read__manifest_list + read__dependency_source_list ) p lb in Yojson.Safe.read_space p lb; diff --git a/semgrep_output_v1_j.mli b/semgrep_output_v1_j.mli index 05e4edfb..fa412537 100644 --- a/semgrep_output_v1_j.mli +++ b/semgrep_output_v1_j.mli @@ -3,7 +3,7 @@ type datetime = Semgrep_output_v1_t.datetime -type fpath = Semgrep_output_v1_t.fpath [@@deriving show] +type fpath = Semgrep_output_v1_t.fpath [@@deriving show, eq, yojson] type match_severity = Semgrep_output_v1_t.match_severity [@@deriving show, eq] @@ -671,6 +671,21 @@ type manifest = Semgrep_output_v1_t.manifest = { kind: manifest_kind; path: fpath } + [@@deriving show, eq, yojson] + +type lockfile_kind = Semgrep_output_v1_t.lockfile_kind = + PipRequirementsTxt | PoetryLock | PipfileLock | NpmPackageLockJson + | YarnLock | PnpmLock | GemfileLock | GoMod | CargoLock | MavenDepTree + | GradleLockfile | ComposerLock | NugetPackageLockJson | PubspecLock + | SwiftPackageResolved | MixLock + + [@@deriving show, eq, yojson] + +type lockfile = Semgrep_output_v1_t.lockfile = { + kind: lockfile_kind; + path: fpath +} + [@@deriving show, eq, yojson] type has_features = Semgrep_output_v1_t.has_features = { has_autofix: bool; @@ -679,6 +694,13 @@ type has_features = Semgrep_output_v1_t.has_features = { has_dependency_query: bool } +type dependency_source = Semgrep_output_v1_t.dependency_source = + ManifestOnlyDependencySource of manifest + | LockfileOnlyDependencySource of lockfile + | ManifestLockfileDependencySource of (manifest * lockfile) + + [@@deriving show] + type apply_fixes_return = Semgrep_output_v1_t.apply_fixes_return = { modified_file_count: int; fixed_lines: (int * string list) list @@ -2927,6 +2949,46 @@ val manifest_of_string : string -> manifest (** Deserialize JSON data of type {!type:manifest}. *) +val write_lockfile_kind : + Buffer.t -> lockfile_kind -> unit + (** Output a JSON value of type {!type:lockfile_kind}. *) + +val string_of_lockfile_kind : + ?len:int -> lockfile_kind -> string + (** Serialize a value of type {!type:lockfile_kind} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_lockfile_kind : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> lockfile_kind + (** Input JSON data of type {!type:lockfile_kind}. *) + +val lockfile_kind_of_string : + string -> lockfile_kind + (** Deserialize JSON data of type {!type:lockfile_kind}. *) + +val write_lockfile : + Buffer.t -> lockfile -> unit + (** Output a JSON value of type {!type:lockfile}. *) + +val string_of_lockfile : + ?len:int -> lockfile -> string + (** Serialize a value of type {!type:lockfile} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_lockfile : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> lockfile + (** Input JSON data of type {!type:lockfile}. *) + +val lockfile_of_string : + string -> lockfile + (** Deserialize JSON data of type {!type:lockfile}. *) + val write_has_features : Buffer.t -> has_features -> unit (** Output a JSON value of type {!type:has_features}. *) @@ -2947,6 +3009,26 @@ val has_features_of_string : string -> has_features (** Deserialize JSON data of type {!type:has_features}. *) +val write_dependency_source : + Buffer.t -> dependency_source -> unit + (** Output a JSON value of type {!type:dependency_source}. *) + +val string_of_dependency_source : + ?len:int -> dependency_source -> string + (** Serialize a value of type {!type:dependency_source} + into a JSON string. + @param len specifies the initial length + of the buffer used internally. + Default: 1024. *) + +val read_dependency_source : + Yojson.Safe.lexer_state -> Lexing.lexbuf -> dependency_source + (** Input JSON data of type {!type:dependency_source}. *) + +val dependency_source_of_string : + string -> dependency_source + (** Deserialize JSON data of type {!type:dependency_source}. *) + val write_apply_fixes_return : Buffer.t -> apply_fixes_return -> unit (** Output a JSON value of type {!type:apply_fixes_return}. *) From b8eb8c5505db7ddffe995ee32ebe557b59cfcc68 Mon Sep 17 00:00:00 2001 From: Ben Kettle Date: Thu, 7 Nov 2024 10:15:11 -0800 Subject: [PATCH 2/5] update to allow errors from succesful resolution --- semgrep_output_v1.atd | 10 +-- semgrep_output_v1.jsonschema | 18 ++++- semgrep_output_v1.proto | 2 +- semgrep_output_v1.py | 12 ++-- semgrep_output_v1.ts | 12 ++-- semgrep_output_v1_j.ml | 123 +++++++++++++++++++++++++++++++++-- 6 files changed, 152 insertions(+), 25 deletions(-) diff --git a/semgrep_output_v1.atd b/semgrep_output_v1.atd index de883689..765fc257 100644 --- a/semgrep_output_v1.atd +++ b/semgrep_output_v1.atd @@ -1945,11 +1945,13 @@ type resolution_cmd_failed message: string; } +(* Resolution can either succeed or fail, but in either case errors can be produced + (e.g. one resolution method might fail while a worse one succeeds, lockfile parsing + might partially fail but recover and still produce results) +*) type resolution_result = [ - (* dependency_relationship items each reference an id from found_dependency.id - and the IDs of the dependencies that that item depends on *) - | ResolutionOk of found_dependency list - | ResolutionError of resolution_error + | ResolutionOk of (found_dependency list * resolution_error list) + | ResolutionError of resolution_error list ] type dump_rule_partitions_params = { diff --git a/semgrep_output_v1.jsonschema b/semgrep_output_v1.jsonschema index 6ca4d456..d15b0644 100644 --- a/semgrep_output_v1.jsonschema +++ b/semgrep_output_v1.jsonschema @@ -1683,7 +1683,18 @@ { "const": "ResolutionOk" }, { "type": "array", - "items": { "$ref": "#/definitions/found_dependency" } + "minItems": 2, + "items": false, + "prefixItems": [ + { + "type": "array", + "items": { "$ref": "#/definitions/found_dependency" } + }, + { + "type": "array", + "items": { "$ref": "#/definitions/resolution_error" } + } + ] } ] }, @@ -1693,7 +1704,10 @@ "items": false, "prefixItems": [ { "const": "ResolutionError" }, - { "$ref": "#/definitions/resolution_error" } + { + "type": "array", + "items": { "$ref": "#/definitions/resolution_error" } + } ] } ] diff --git a/semgrep_output_v1.proto b/semgrep_output_v1.proto index ecfd78d4..84af2819 100644 --- a/semgrep_output_v1.proto +++ b/semgrep_output_v1.proto @@ -1,6 +1,6 @@ // Generated by jsonschema2protobuf. DO NOT EDIT! // Source file: semgrep_output_v1.jsonschema -// Source file sha256 digest: 400662cd3b6a0c7166397675a4419f3a5f2cf0dda1d506dcbc09a0a69a9d21e3 +// Source file sha256 digest: d93eb3e9e592605825907cf6d9778161fcfd0a44c65ce9b14158745ee0572a80 syntax = "proto3"; diff --git a/semgrep_output_v1.py b/semgrep_output_v1.py index 86d15cac..a84e7236 100644 --- a/semgrep_output_v1.py +++ b/semgrep_output_v1.py @@ -5848,7 +5848,7 @@ def to_json_string(self, **kw: Any) -> str: class ResolutionOk: """Original type: resolution_result = [ ... | ResolutionOk of ... | ... ]""" - value: List[FoundDependency] + value: Tuple[List[FoundDependency], List[ResolutionError]] @property def kind(self) -> str: @@ -5856,7 +5856,7 @@ def kind(self) -> str: return 'ResolutionOk' def to_json(self) -> Any: - return ['ResolutionOk', _atd_write_list((lambda x: x.to_json()))(self.value)] + return ['ResolutionOk', (lambda x: [_atd_write_list((lambda x: x.to_json()))(x[0]), _atd_write_list((lambda x: x.to_json()))(x[1])] if isinstance(x, tuple) and len(x) == 2 else _atd_bad_python('tuple of length 2', x))(self.value)] def to_json_string(self, **kw: Any) -> str: return json.dumps(self.to_json(), **kw) @@ -5866,7 +5866,7 @@ def to_json_string(self, **kw: Any) -> str: class ResolutionError_: """Original type: resolution_result = [ ... | ResolutionError of ... | ... ]""" - value: ResolutionError + value: List[ResolutionError] @property def kind(self) -> str: @@ -5874,7 +5874,7 @@ def kind(self) -> str: return 'ResolutionError_' def to_json(self) -> Any: - return ['ResolutionError', (lambda x: x.to_json())(self.value)] + return ['ResolutionError', _atd_write_list((lambda x: x.to_json()))(self.value)] def to_json_string(self, **kw: Any) -> str: return json.dumps(self.to_json(), **kw) @@ -5896,9 +5896,9 @@ def from_json(cls, x: Any) -> 'ResolutionResult': if isinstance(x, List) and len(x) == 2: cons = x[0] if cons == 'ResolutionOk': - return cls(ResolutionOk(_atd_read_list(FoundDependency.from_json)(x[1]))) + return cls(ResolutionOk((lambda x: (_atd_read_list(FoundDependency.from_json)(x[0]), _atd_read_list(ResolutionError.from_json)(x[1])) if isinstance(x, list) and len(x) == 2 else _atd_bad_json('array of length 2', x))(x[1]))) if cons == 'ResolutionError': - return cls(ResolutionError_(ResolutionError.from_json(x[1]))) + return cls(ResolutionError_(_atd_read_list(ResolutionError.from_json)(x[1]))) _atd_bad_json('ResolutionResult', x) _atd_bad_json('ResolutionResult', x) diff --git a/semgrep_output_v1.ts b/semgrep_output_v1.ts index 005e5342..665f300b 100644 --- a/semgrep_output_v1.ts +++ b/semgrep_output_v1.ts @@ -912,8 +912,8 @@ export type ResolutionCmdFailed = { } export type ResolutionResult = -| { kind: 'ResolutionOk'; value: FoundDependency[] } -| { kind: 'ResolutionError'; value: ResolutionError } +| { kind: 'ResolutionOk'; value: [FoundDependency[], ResolutionError[]] } +| { kind: 'ResolutionError'; value: ResolutionError[] } export type DumpRulePartitionsParams = { rules: RawJson; @@ -3759,9 +3759,9 @@ export function readResolutionCmdFailed(x: any, context: any = x): ResolutionCmd export function writeResolutionResult(x: ResolutionResult, context: any = x): any { switch (x.kind) { case 'ResolutionOk': - return ['ResolutionOk', _atd_write_array(writeFoundDependency)(x.value, x)] + return ['ResolutionOk', ((x, context) => [_atd_write_array(writeFoundDependency)(x[0], x), _atd_write_array(writeResolutionError)(x[1], x)])(x.value, x)] case 'ResolutionError': - return ['ResolutionError', writeResolutionError(x.value, x)] + return ['ResolutionError', _atd_write_array(writeResolutionError)(x.value, x)] } } @@ -3769,9 +3769,9 @@ export function readResolutionResult(x: any, context: any = x): ResolutionResult _atd_check_json_tuple(2, x, context) switch (x[0]) { case 'ResolutionOk': - return { kind: 'ResolutionOk', value: _atd_read_array(readFoundDependency)(x[1], x) } + return { kind: 'ResolutionOk', value: ((x, context): [FoundDependency[], ResolutionError[]] => { _atd_check_json_tuple(2, x, context); return [_atd_read_array(readFoundDependency)(x[0], x), _atd_read_array(readResolutionError)(x[1], x)] })(x[1], x) } case 'ResolutionError': - return { kind: 'ResolutionError', value: readResolutionError(x[1], x) } + return { kind: 'ResolutionError', value: _atd_read_array(readResolutionError)(x[1], x) } default: _atd_bad_json('ResolutionResult', x, context) throw new Error('impossible') diff --git a/semgrep_output_v1_j.ml b/semgrep_output_v1_j.ml index 9e5ef03a..3cdbfe79 100644 --- a/semgrep_output_v1_j.ml +++ b/semgrep_output_v1_j.ml @@ -21604,6 +21604,22 @@ let read_rule_id_and_engine_kind = ( ) let rule_id_and_engine_kind_of_string s = read_rule_id_and_engine_kind (Yojson.Safe.init_lexer ()) (Lexing.from_string s) +let write__resolution_error_list = ( + Atdgen_runtime.Oj_run.write_list ( + write_resolution_error + ) +) +let string_of__resolution_error_list ?(len = 1024) x = + let ob = Buffer.create len in + write__resolution_error_list ob x; + Buffer.contents ob +let read__resolution_error_list = ( + Atdgen_runtime.Oj_run.read_list ( + read_resolution_error + ) +) +let _resolution_error_list_of_string s = + read__resolution_error_list (Yojson.Safe.init_lexer ()) (Lexing.from_string s) let write__found_dependency_list = ( Atdgen_runtime.Oj_run.write_list ( write_found_dependency @@ -21626,13 +21642,26 @@ let write_resolution_result = ( | `ResolutionOk x -> Buffer.add_string ob "[\"ResolutionOk\","; ( - write__found_dependency_list + fun ob x -> + Buffer.add_char ob '['; + (let x, _ = x in + ( + write__found_dependency_list + ) ob x + ); + Buffer.add_char ob ','; + (let _, x = x in + ( + write__resolution_error_list + ) ob x + ); + Buffer.add_char ob ']'; ) ob x; Buffer.add_char ob ']' | `ResolutionError x -> Buffer.add_string ob "[\"ResolutionError\","; ( - write_resolution_error + write__resolution_error_list ) ob x; Buffer.add_char ob ']' ) @@ -21649,7 +21678,48 @@ let read_resolution_result = ( | "ResolutionOk" -> Atdgen_runtime.Oj_run.read_until_field_value p lb; let x = ( - read__found_dependency_list + fun p lb -> + Yojson.Safe.read_space p lb; + let std_tuple = Yojson.Safe.start_any_tuple p lb in + let len = ref 0 in + let end_of_tuple = ref false in + (try + let x0 = + let x = + ( + read__found_dependency_list + ) p lb + in + incr len; + Yojson.Safe.read_space p lb; + Yojson.Safe.read_tuple_sep2 p std_tuple lb; + x + in + let x1 = + let x = + ( + read__resolution_error_list + ) p lb + in + incr len; + (try + Yojson.Safe.read_space p lb; + Yojson.Safe.read_tuple_sep2 p std_tuple lb; + with Yojson.End_of_tuple -> end_of_tuple := true); + x + in + if not !end_of_tuple then ( + try + while true do + Yojson.Safe.skip_json p lb; + Yojson.Safe.read_space p lb; + Yojson.Safe.read_tuple_sep2 p std_tuple lb; + done + with Yojson.End_of_tuple -> () + ); + (x0, x1) + with Yojson.End_of_tuple -> + Atdgen_runtime.Oj_run.missing_tuple_fields p !len [ 0; 1 ]); ) p lb in Yojson.Safe.read_space p lb; @@ -21658,7 +21728,7 @@ let read_resolution_result = ( | "ResolutionError" -> Atdgen_runtime.Oj_run.read_until_field_value p lb; let x = ( - read_resolution_error + read__resolution_error_list ) p lb in Yojson.Safe.read_space p lb; @@ -21679,7 +21749,48 @@ let read_resolution_result = ( Yojson.Safe.read_comma p lb; Yojson.Safe.read_space p lb; let x = ( - read__found_dependency_list + fun p lb -> + Yojson.Safe.read_space p lb; + let std_tuple = Yojson.Safe.start_any_tuple p lb in + let len = ref 0 in + let end_of_tuple = ref false in + (try + let x0 = + let x = + ( + read__found_dependency_list + ) p lb + in + incr len; + Yojson.Safe.read_space p lb; + Yojson.Safe.read_tuple_sep2 p std_tuple lb; + x + in + let x1 = + let x = + ( + read__resolution_error_list + ) p lb + in + incr len; + (try + Yojson.Safe.read_space p lb; + Yojson.Safe.read_tuple_sep2 p std_tuple lb; + with Yojson.End_of_tuple -> end_of_tuple := true); + x + in + if not !end_of_tuple then ( + try + while true do + Yojson.Safe.skip_json p lb; + Yojson.Safe.read_space p lb; + Yojson.Safe.read_tuple_sep2 p std_tuple lb; + done + with Yojson.End_of_tuple -> () + ); + (x0, x1) + with Yojson.End_of_tuple -> + Atdgen_runtime.Oj_run.missing_tuple_fields p !len [ 0; 1 ]); ) p lb in Yojson.Safe.read_space p lb; @@ -21690,7 +21801,7 @@ let read_resolution_result = ( Yojson.Safe.read_comma p lb; Yojson.Safe.read_space p lb; let x = ( - read_resolution_error + read__resolution_error_list ) p lb in Yojson.Safe.read_space p lb; From 4f3838cda81b8eec366401f275d414fa71694f67 Mon Sep 17 00:00:00 2001 From: Ben Kettle Date: Tue, 12 Nov 2024 17:52:54 -0800 Subject: [PATCH 3/5] fix composer lockfile name --- semgrep_output_v1.atd | 4 ++-- semgrep_output_v1.jsonschema | 2 +- semgrep_output_v1.proto | 2 +- semgrep_output_v1.py | 14 +++++++------- semgrep_output_v1.ts | 10 +++++----- semgrep_output_v1_j.ml | 12 ++++++------ semgrep_output_v1_j.mli | 2 +- 7 files changed, 23 insertions(+), 23 deletions(-) diff --git a/semgrep_output_v1.atd b/semgrep_output_v1.atd index 765fc257..889c9cbc 100644 --- a/semgrep_output_v1.atd +++ b/semgrep_output_v1.atd @@ -1872,8 +1872,8 @@ type lockfile_kind | MavenDepTree (* Not a real lockfile *) | GradleLockfile | ComposerLock - | NugetPackageLockJson - | PubspecLock (* https://dart.dev/tools/pub/glossary#lockfile *) + | NugetPackagesLockJson + | PubspecLock | SwiftPackageResolved (* not a real lockfile *) | MixLock ] diff --git a/semgrep_output_v1.jsonschema b/semgrep_output_v1.jsonschema index d15b0644..ba93dc36 100644 --- a/semgrep_output_v1.jsonschema +++ b/semgrep_output_v1.jsonschema @@ -1556,7 +1556,7 @@ { "const": "MavenDepTree" }, { "const": "GradleLockfile" }, { "const": "ComposerLock" }, - { "const": "NugetPackageLockJson" }, + { "const": "NugetPackagesLockJson" }, { "const": "PubspecLock" }, { "const": "SwiftPackageResolved" }, { "const": "MixLock" } diff --git a/semgrep_output_v1.proto b/semgrep_output_v1.proto index 84af2819..9451b9c0 100644 --- a/semgrep_output_v1.proto +++ b/semgrep_output_v1.proto @@ -1,6 +1,6 @@ // Generated by jsonschema2protobuf. DO NOT EDIT! // Source file: semgrep_output_v1.jsonschema -// Source file sha256 digest: d93eb3e9e592605825907cf6d9778161fcfd0a44c65ce9b14158745ee0572a80 +// Source file sha256 digest: d7fa35bebca16422389593f23385671fdbe4eac9a228022dc975bcdf12e1d7d1 syntax = "proto3"; diff --git a/semgrep_output_v1.py b/semgrep_output_v1.py index a84e7236..b40500e8 100644 --- a/semgrep_output_v1.py +++ b/semgrep_output_v1.py @@ -7277,17 +7277,17 @@ def to_json_string(self, **kw: Any) -> str: @dataclass(frozen=True) -class NugetPackageLockJson: - """Original type: lockfile_kind = [ ... | NugetPackageLockJson | ... ]""" +class NugetPackagesLockJson: + """Original type: lockfile_kind = [ ... | NugetPackagesLockJson | ... ]""" @property def kind(self) -> str: """Name of the class representing this variant.""" - return 'NugetPackageLockJson' + return 'NugetPackagesLockJson' @staticmethod def to_json() -> Any: - return 'NugetPackageLockJson' + return 'NugetPackagesLockJson' def to_json_string(self, **kw: Any) -> str: return json.dumps(self.to_json(), **kw) @@ -7348,7 +7348,7 @@ def to_json_string(self, **kw: Any) -> str: class LockfileKind: """Original type: lockfile_kind = [ ... ]""" - value: Union[PipRequirementsTxt, PoetryLock_, PipfileLock, NpmPackageLockJson, YarnLock, PnpmLock_, GemfileLock_, GoMod2, CargoLock, MavenDepTree, GradleLockfile_, ComposerLock_, NugetPackageLockJson, PubspecLock_, SwiftPackageResolved, MixLock_] + value: Union[PipRequirementsTxt, PoetryLock_, PipfileLock, NpmPackageLockJson, YarnLock, PnpmLock_, GemfileLock_, GoMod2, CargoLock, MavenDepTree, GradleLockfile_, ComposerLock_, NugetPackagesLockJson, PubspecLock_, SwiftPackageResolved, MixLock_] @property def kind(self) -> str: @@ -7382,8 +7382,8 @@ def from_json(cls, x: Any) -> 'LockfileKind': return cls(GradleLockfile_()) if x == 'ComposerLock': return cls(ComposerLock_()) - if x == 'NugetPackageLockJson': - return cls(NugetPackageLockJson()) + if x == 'NugetPackagesLockJson': + return cls(NugetPackagesLockJson()) if x == 'PubspecLock': return cls(PubspecLock_()) if x == 'SwiftPackageResolved': diff --git a/semgrep_output_v1.ts b/semgrep_output_v1.ts index 665f300b..b819c2bb 100644 --- a/semgrep_output_v1.ts +++ b/semgrep_output_v1.ts @@ -864,7 +864,7 @@ export type LockfileKind = | { kind: 'MavenDepTree' } | { kind: 'GradleLockfile' } | { kind: 'ComposerLock' } -| { kind: 'NugetPackageLockJson' } +| { kind: 'NugetPackagesLockJson' } | { kind: 'PubspecLock' } | { kind: 'SwiftPackageResolved' } | { kind: 'MixLock' } @@ -3529,8 +3529,8 @@ export function writeLockfileKind(x: LockfileKind, context: any = x): any { return 'GradleLockfile' case 'ComposerLock': return 'ComposerLock' - case 'NugetPackageLockJson': - return 'NugetPackageLockJson' + case 'NugetPackagesLockJson': + return 'NugetPackagesLockJson' case 'PubspecLock': return 'PubspecLock' case 'SwiftPackageResolved': @@ -3566,8 +3566,8 @@ export function readLockfileKind(x: any, context: any = x): LockfileKind { return { kind: 'GradleLockfile' } case 'ComposerLock': return { kind: 'ComposerLock' } - case 'NugetPackageLockJson': - return { kind: 'NugetPackageLockJson' } + case 'NugetPackagesLockJson': + return { kind: 'NugetPackagesLockJson' } case 'PubspecLock': return { kind: 'PubspecLock' } case 'SwiftPackageResolved': diff --git a/semgrep_output_v1_j.ml b/semgrep_output_v1_j.ml index 3cdbfe79..b445a2fb 100644 --- a/semgrep_output_v1_j.ml +++ b/semgrep_output_v1_j.ml @@ -676,7 +676,7 @@ type manifest = Semgrep_output_v1_t.manifest = { type lockfile_kind = Semgrep_output_v1_t.lockfile_kind = PipRequirementsTxt | PoetryLock | PipfileLock | NpmPackageLockJson | YarnLock | PnpmLock | GemfileLock | GoMod | CargoLock | MavenDepTree - | GradleLockfile | ComposerLock | NugetPackageLockJson | PubspecLock + | GradleLockfile | ComposerLock | NugetPackagesLockJson | PubspecLock | SwiftPackageResolved | MixLock [@@deriving show, eq, yojson] @@ -26910,7 +26910,7 @@ let write_lockfile_kind : _ -> lockfile_kind -> _ = ( | MavenDepTree -> Buffer.add_string ob "\"MavenDepTree\"" | GradleLockfile -> Buffer.add_string ob "\"GradleLockfile\"" | ComposerLock -> Buffer.add_string ob "\"ComposerLock\"" - | NugetPackageLockJson -> Buffer.add_string ob "\"NugetPackageLockJson\"" + | NugetPackagesLockJson -> Buffer.add_string ob "\"NugetPackagesLockJson\"" | PubspecLock -> Buffer.add_string ob "\"PubspecLock\"" | SwiftPackageResolved -> Buffer.add_string ob "\"SwiftPackageResolved\"" | MixLock -> Buffer.add_string ob "\"MixLock\"" @@ -26973,10 +26973,10 @@ let read_lockfile_kind = ( Yojson.Safe.read_space p lb; Yojson.Safe.read_gt p lb; (ComposerLock : lockfile_kind) - | "NugetPackageLockJson" -> + | "NugetPackagesLockJson" -> Yojson.Safe.read_space p lb; Yojson.Safe.read_gt p lb; - (NugetPackageLockJson : lockfile_kind) + (NugetPackagesLockJson : lockfile_kind) | "PubspecLock" -> Yojson.Safe.read_space p lb; Yojson.Safe.read_gt p lb; @@ -27018,8 +27018,8 @@ let read_lockfile_kind = ( (GradleLockfile : lockfile_kind) | "ComposerLock" -> (ComposerLock : lockfile_kind) - | "NugetPackageLockJson" -> - (NugetPackageLockJson : lockfile_kind) + | "NugetPackagesLockJson" -> + (NugetPackagesLockJson : lockfile_kind) | "PubspecLock" -> (PubspecLock : lockfile_kind) | "SwiftPackageResolved" -> diff --git a/semgrep_output_v1_j.mli b/semgrep_output_v1_j.mli index fa412537..cf2be117 100644 --- a/semgrep_output_v1_j.mli +++ b/semgrep_output_v1_j.mli @@ -676,7 +676,7 @@ type manifest = Semgrep_output_v1_t.manifest = { type lockfile_kind = Semgrep_output_v1_t.lockfile_kind = PipRequirementsTxt | PoetryLock | PipfileLock | NpmPackageLockJson | YarnLock | PnpmLock | GemfileLock | GoMod | CargoLock | MavenDepTree - | GradleLockfile | ComposerLock | NugetPackageLockJson | PubspecLock + | GradleLockfile | ComposerLock | NugetPackagesLockJson | PubspecLock | SwiftPackageResolved | MixLock [@@deriving show, eq, yojson] From c78ebe88a419bb6afb85899d2a845360be0a767f Mon Sep 17 00:00:00 2001 From: Ben Kettle Date: Wed, 13 Nov 2024 14:57:19 -0800 Subject: [PATCH 4/5] add settingsgradle manifest kind --- semgrep_output_v1.atd | 5 ++++- semgrep_output_v1.jsonschema | 1 + semgrep_output_v1.proto | 2 +- semgrep_output_v1.py | 21 ++++++++++++++++++++- semgrep_output_v1.ts | 5 +++++ semgrep_output_v1_j.ml | 7 +++++++ 6 files changed, 38 insertions(+), 3 deletions(-) diff --git a/semgrep_output_v1.atd b/semgrep_output_v1.atd index 889c9cbc..f7635e1d 100644 --- a/semgrep_output_v1.atd +++ b/semgrep_output_v1.atd @@ -1893,7 +1893,10 @@ type manifest_kind | PomXml (* A Maven pom.xml manifest file - https://maven.apache.org/guides/introduction/introduction-to-the-pom.html *) | BuildGradle - (* A Gradle build.gradle build file - https://docs.gradle.org/current/userguide/build_file_basics.html *) + (* A Gradle build.gradle build file - https://docs.gradle.org/current/userguide/build_file_basics.html *) + | SettingsGradle + (* A Gradle settings.gradle file - https://docs.gradle.org/current/userguide/settings_file_basics.html. + * Multi-project builds are defined by settings.gradle rather than build.gradle: https://docs.gradle.org/current/userguide/multi_project_builds.html#multi_project_builds *) | ComposerJson (* composer.json - https://getcomposer.org/doc/04-schema.md *) | NugetManifestJson (* manifest for nuget - could not find a reference; this may not actually exist *) diff --git a/semgrep_output_v1.jsonschema b/semgrep_output_v1.jsonschema index ba93dc36..d28bd05a 100644 --- a/semgrep_output_v1.jsonschema +++ b/semgrep_output_v1.jsonschema @@ -1571,6 +1571,7 @@ { "const": "CargoToml" }, { "const": "PomXml" }, { "const": "BuildGradle" }, + { "const": "SettingsGradle" }, { "const": "ComposerJson" }, { "const": "NugetManifestJson" }, { "const": "PubspecYaml" }, diff --git a/semgrep_output_v1.proto b/semgrep_output_v1.proto index 9451b9c0..f6580b3b 100644 --- a/semgrep_output_v1.proto +++ b/semgrep_output_v1.proto @@ -1,6 +1,6 @@ // Generated by jsonschema2protobuf. DO NOT EDIT! // Source file: semgrep_output_v1.jsonschema -// Source file sha256 digest: d7fa35bebca16422389593f23385671fdbe4eac9a228022dc975bcdf12e1d7d1 +// Source file sha256 digest: 1e74e1e50c97e4ff7c94c9d0c45134b61b53533d69d28342203e3cb2bc7373eb syntax = "proto3"; diff --git a/semgrep_output_v1.py b/semgrep_output_v1.py index b40500e8..66cb5190 100644 --- a/semgrep_output_v1.py +++ b/semgrep_output_v1.py @@ -6866,6 +6866,23 @@ def to_json_string(self, **kw: Any) -> str: return json.dumps(self.to_json(), **kw) +@dataclass(frozen=True) +class SettingsGradle: + """Original type: manifest_kind = [ ... | SettingsGradle | ... ]""" + + @property + def kind(self) -> str: + """Name of the class representing this variant.""" + return 'SettingsGradle' + + @staticmethod + def to_json() -> Any: + return 'SettingsGradle' + + def to_json_string(self, **kw: Any) -> str: + return json.dumps(self.to_json(), **kw) + + @dataclass(frozen=True) class ComposerJson: """Original type: manifest_kind = [ ... | ComposerJson | ... ]""" @@ -6989,7 +7006,7 @@ def to_json_string(self, **kw: Any) -> str: class ManifestKind: """Original type: manifest_kind = [ ... ]""" - value: Union[RequirementsIn, PackageJson, Gemfile, GoMod_, CargoToml, PomXml, BuildGradle, ComposerJson, NugetManifestJson, PubspecYaml, PackageSwift_, MixExs, Pipfile_, PyprojectToml_] + value: Union[RequirementsIn, PackageJson, Gemfile, GoMod_, CargoToml, PomXml, BuildGradle, SettingsGradle, ComposerJson, NugetManifestJson, PubspecYaml, PackageSwift_, MixExs, Pipfile_, PyprojectToml_] @property def kind(self) -> str: @@ -7013,6 +7030,8 @@ def from_json(cls, x: Any) -> 'ManifestKind': return cls(PomXml()) if x == 'BuildGradle': return cls(BuildGradle()) + if x == 'SettingsGradle': + return cls(SettingsGradle()) if x == 'ComposerJson': return cls(ComposerJson()) if x == 'NugetManifestJson': diff --git a/semgrep_output_v1.ts b/semgrep_output_v1.ts index b819c2bb..5520207a 100644 --- a/semgrep_output_v1.ts +++ b/semgrep_output_v1.ts @@ -877,6 +877,7 @@ export type ManifestKind = | { kind: 'CargoToml' } | { kind: 'PomXml' } | { kind: 'BuildGradle' } +| { kind: 'SettingsGradle' } | { kind: 'ComposerJson' } | { kind: 'NugetManifestJson' } | { kind: 'PubspecYaml' } @@ -3596,6 +3597,8 @@ export function writeManifestKind(x: ManifestKind, context: any = x): any { return 'PomXml' case 'BuildGradle': return 'BuildGradle' + case 'SettingsGradle': + return 'SettingsGradle' case 'ComposerJson': return 'ComposerJson' case 'NugetManifestJson': @@ -3629,6 +3632,8 @@ export function readManifestKind(x: any, context: any = x): ManifestKind { return { kind: 'PomXml' } case 'BuildGradle': return { kind: 'BuildGradle' } + case 'SettingsGradle': + return { kind: 'SettingsGradle' } case 'ComposerJson': return { kind: 'ComposerJson' } case 'NugetManifestJson': diff --git a/semgrep_output_v1_j.ml b/semgrep_output_v1_j.ml index b445a2fb..5721ecce 100644 --- a/semgrep_output_v1_j.ml +++ b/semgrep_output_v1_j.ml @@ -26614,6 +26614,7 @@ let write_manifest_kind = ( | `CargoToml -> Buffer.add_string ob "\"CargoToml\"" | `PomXml -> Buffer.add_string ob "\"PomXml\"" | `BuildGradle -> Buffer.add_string ob "\"BuildGradle\"" + | `SettingsGradle -> Buffer.add_string ob "\"SettingsGradle\"" | `ComposerJson -> Buffer.add_string ob "\"ComposerJson\"" | `NugetManifestJson -> Buffer.add_string ob "\"NugetManifestJson\"" | `PubspecYaml -> Buffer.add_string ob "\"PubspecYaml\"" @@ -26660,6 +26661,10 @@ let read_manifest_kind = ( Yojson.Safe.read_space p lb; Yojson.Safe.read_gt p lb; `BuildGradle + | "SettingsGradle" -> + Yojson.Safe.read_space p lb; + Yojson.Safe.read_gt p lb; + `SettingsGradle | "ComposerJson" -> Yojson.Safe.read_space p lb; Yojson.Safe.read_gt p lb; @@ -26707,6 +26712,8 @@ let read_manifest_kind = ( `PomXml | "BuildGradle" -> `BuildGradle + | "SettingsGradle" -> + `SettingsGradle | "ComposerJson" -> `ComposerJson | "NugetManifestJson" -> From 0a5de4582dc2418c7e23fbc5bf46186786d619ab Mon Sep 17 00:00:00 2001 From: Ben Kettle Date: Thu, 14 Nov 2024 10:15:10 -0800 Subject: [PATCH 5/5] remove unnecessary yojson derivations --- semgrep_output_v1.atd | 6 +++--- semgrep_output_v1_j.ml | 6 +++--- semgrep_output_v1_j.mli | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/semgrep_output_v1.atd b/semgrep_output_v1.atd index f7635e1d..e535374f 100644 --- a/semgrep_output_v1.atd +++ b/semgrep_output_v1.atd @@ -71,7 +71,7 @@ type raw_json = abstract (*****************************************************************************) (* File path. less: could convert directly to Path class of pathlib library for Python *) -type fpath = string wrap +type fpath = string wrap type uri = string wrap @@ -1911,14 +1911,14 @@ type manifest_kind ] type manifest - + = { kind: manifest_kind; path: fpath; } type lockfile - + = { kind: lockfile_kind; path: fpath; diff --git a/semgrep_output_v1_j.ml b/semgrep_output_v1_j.ml index 5721ecce..cbaa99b3 100644 --- a/semgrep_output_v1_j.ml +++ b/semgrep_output_v1_j.ml @@ -3,7 +3,7 @@ type datetime = Semgrep_output_v1_t.datetime -type fpath = Semgrep_output_v1_t.fpath [@@deriving show, eq, yojson] +type fpath = Semgrep_output_v1_t.fpath [@@deriving show, eq] type match_severity = Semgrep_output_v1_t.match_severity [@@deriving show, eq] @@ -671,7 +671,7 @@ type manifest = Semgrep_output_v1_t.manifest = { kind: manifest_kind; path: fpath } - [@@deriving show, eq, yojson] + [@@deriving show, eq] type lockfile_kind = Semgrep_output_v1_t.lockfile_kind = PipRequirementsTxt | PoetryLock | PipfileLock | NpmPackageLockJson @@ -685,7 +685,7 @@ type lockfile = Semgrep_output_v1_t.lockfile = { kind: lockfile_kind; path: fpath } - [@@deriving show, eq, yojson] + [@@deriving show, eq] type has_features = Semgrep_output_v1_t.has_features = { has_autofix: bool; diff --git a/semgrep_output_v1_j.mli b/semgrep_output_v1_j.mli index cf2be117..94be4dd9 100644 --- a/semgrep_output_v1_j.mli +++ b/semgrep_output_v1_j.mli @@ -3,7 +3,7 @@ type datetime = Semgrep_output_v1_t.datetime -type fpath = Semgrep_output_v1_t.fpath [@@deriving show, eq, yojson] +type fpath = Semgrep_output_v1_t.fpath [@@deriving show, eq] type match_severity = Semgrep_output_v1_t.match_severity [@@deriving show, eq] @@ -671,7 +671,7 @@ type manifest = Semgrep_output_v1_t.manifest = { kind: manifest_kind; path: fpath } - [@@deriving show, eq, yojson] + [@@deriving show, eq] type lockfile_kind = Semgrep_output_v1_t.lockfile_kind = PipRequirementsTxt | PoetryLock | PipfileLock | NpmPackageLockJson @@ -685,7 +685,7 @@ type lockfile = Semgrep_output_v1_t.lockfile = { kind: lockfile_kind; path: fpath } - [@@deriving show, eq, yojson] + [@@deriving show, eq] type has_features = Semgrep_output_v1_t.has_features = { has_autofix: bool;