Add beta Bazel JVM manifest support#1312
Conversation
Martin Torp (mtorp)
left a comment
There was a problem hiding this comment.
Looks good 👏
| const FIXTURE = path.join( | ||
| process.env['HOME'] as string, | ||
| 'src', | ||
| 'bazel-bench', | ||
| 'constructed', | ||
| 'java-maven', | ||
| ) |
There was a problem hiding this comment.
Looks like this may be a reference to a local path. Is than intentional?
There was a problem hiding this comment.
Good catch. All three test files referencing ~/src/bazel-bench have been removed — they depended on a local fixture not available to open-source users.
| - `--bazel-flags <str>` — flags forwarded to every bazel invocation (single quoted string). | ||
| - `--bazel-output-base <dir>` — Bazel `--output_base` for read-only-cache CI environments. | ||
| - `--out <dir>` — output directory; default `./.socket/bazel-manifests/`. | ||
| - `--dry-run`, `--verbose`, `--json`, `--markdown` — standard diagnostic flags. |
There was a problem hiding this comment.
Claude says --json and --markdown aren't implemented for this subcommand. They're probably not necessary, so I suggest removing them from this readme.
There was a problem hiding this comment.
Removed --json and --markdown from the options list.
| const output = await spawn(opts.bin, argv, { | ||
| cwd: opts.cwd, | ||
| ...(opts.env ? { env: opts.env } : {}), | ||
| }) |
There was a problem hiding this comment.
How long do Bazel queries typically take to execute? Would it make sense to add some default generous timeout to this operation just in case it hangs in a CI run for whatever reason.
There was a problem hiding this comment.
Added a BAZEL_QUERY_TIMEOUT_MS = 600_000 (10 min) constant and passed it to both spawn() calls. Bazel cold-cache starts can take a few minutes; 10 min should be generous without letting a hung server block CI indefinitely.
| function extractAttr(body: string, attr: string): string | undefined { | ||
| // Match `<attr> = "VALUE"` — quoted-string attrs only. | ||
| // Quoted value capped at 4 KiB; canonical Maven URLs are ~150 bytes. | ||
| const re = new RegExp(`\\b${attr}\\s*=\\s*"([^"\\n]{0,4096})"`) |
There was a problem hiding this comment.
I suggest moving the regex construction out of the function body to avoid having to recreate it at every call.
There was a problem hiding this comment.
Done. Added ATTR_RE_CACHE and TAG_RE_CACHE Maps at module level; both extractAttr and extractTagValue now check the cache before constructing a new regex.
- Remove three integration test files that depend on ~/src/bazel-bench, a local fixture not available to open-source users - Drop --json and --markdown from the manifest bazel README options since those flags are not implemented for this subcommand - Add a 10-minute timeout to bazel spawn calls to prevent CI hangs on cold-cache or stalled bazel server invocations - Cache per-attr and per-tag-key regexes at module level in bazel-build-parser to avoid recompiling on every rule block
Summary
Adds beta Bazel JVM SBOM support to Socket CLI.
Bazel is multi-language, but this PR starts with Bazel + Maven because many Bazel JVM repos declare Maven dependencies through
rules_jvm_externalinMODULE.bazelorWORKSPACEinstead of committing a manifest Socket can already scan. The extractor asks Bazel what Maven artifacts it resolved, converts that into amaven_install.json-shaped manifest, and sends it through the existing scan pipeline.What changed
socket manifest bazel [beta], a generation-only command for producing Bazel JVM SBOM manifests.socket scan create --auto-manifestso Bazel workspaces are detected automatically and scanned through the normal scan-create flow.MODULE.bazel,WORKSPACE, orWORKSPACE.bazel.@maven.jvm_importandaar_importrules frombazel query --output=build.unsorted_deps.jsonwhen available as a faster structured source..socket-auto-manifest/maven_install.jsonso we do not overwrite a repo's checked-inmaven_install.json.socket.jsondefaults, fixtures, and test coverage.User flow
Generate only:
socket manifest bazel .Generate and upload in one step:
socket scan create --auto-manifest .Testing
Tested with unit and integration coverage for:
jvm_import/aar_importparsing.unsorted_deps.jsonparsing.maven_install.json..socket-auto-manifest/output behavior.Also tested against a corpus of Bazel repositories covering constructed and real-world Maven extraction cases, Bzlmod, legacy WORKSPACE, custom repo names, pinned and unpinned lockfile flows, and scan-create auto-manifest behavior.
Local checks: