Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions .github/workflows/bazel-maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ name: Bazel patch compatibility (Maven)
# mode that repository is a directory of the checkout with the committed
# jar: the flows hold the build from the checkout alone with no host to
# ask, the audit of the committed jar, the undo, and the way from hosted
# to vendored and back. bazel-compatibility.yml holds the legs and what
# to vendored and back. Agent mode patches the jar in the Maven local
# repository and no hub: its flow holds the build to the upstream jar,
# every VEX document to `affected` with the command that patches the hub,
# and after that command the build and the document to the patched jar.
# bazel-compatibility.yml holds the legs and what
# every ecosystem
# shares; this file says when the Maven legs run and on which releases.
#
Expand Down Expand Up @@ -62,15 +66,20 @@ on:
# rewriter's index of a pom, the model of what Maven selects with the
# pom walk under it (the hosted lane pins only where Maven selects the
# patch's version), the crawler that says where the Maven local
# repository is, lock discovery and the upstream restore of `rollback`
# repository is, the upstream restore of `rollback`
# (for a pom and for the block of MODULE.bazel), the vendored Maven
# backend, which writes the hub's jar and its entry, the dispatch that
# hands a vendored command the hub's declines (vendor/refusals.rs), and what
# socket-patch reads and writes only in a Bazel workspace (`bazel/`: the
# hubs of MODULE.bazel, their locks and the block). Nothing another
# ecosystem's flow owns is here but that dispatch, which the Composer
# legs watch too, so a change to one ecosystem starts that ecosystem's
# legs only.
# legs only. Last, what the agent flow runs through: the three files
# with which agent mode patches a jar, and the VEX code (`vex/` of the
# core, where lock discovery is too, and the files of the `vex`
# command). That flow holds the exact
# document socket-patch writes about its build, so a change to how a
# document is built or worded starts the legs of every ecosystem.
#
# What it does not cover: shared engine code (`rewrite_maven_pom` is in
# patch/redirect/mod.rs, the file of every ecosystem's rewriter; hosted/,
Expand All @@ -92,13 +101,16 @@ on:
- 'crates/socket-patch-core/src/crawlers/maven_selection.rs'
- 'crates/socket-patch-core/src/crawlers/maven_scope.rs'
- 'crates/socket-patch-core/src/crawlers/maven_crawler.rs'
- 'crates/socket-patch-core/src/vex/discover/maven.rs'
- 'crates/socket-patch-core/src/vex/discover/bazel_maven.rs'
- 'crates/socket-patch-core/src/patch/redirect/upstream/maven.rs'
- 'crates/socket-patch-core/src/patch/redirect/upstream/bazel_maven.rs'
- 'crates/socket-patch-core/src/vendor/maven_repo.rs'
- 'crates/socket-patch-core/src/vendor/refusals.rs'
- 'crates/socket-patch-core/src/bazel/**'
- 'crates/socket-patch-core/src/patch/jvm_jar.rs'
- 'crates/socket-patch-core/src/patch/jar_members.rs'
- 'crates/socket-patch-core/src/patch/jar_manifest.rs'
- 'crates/socket-patch-core/src/vex/**'
- 'crates/socket-patch-cli/src/commands/vex*.rs'
push:
branches: [main]
# The pull request paths, and what only a push to main covers: the
Expand All @@ -120,13 +132,15 @@ on:
- 'crates/socket-patch-core/src/crawlers/maven_selection.rs'
- 'crates/socket-patch-core/src/crawlers/maven_scope.rs'
- 'crates/socket-patch-core/src/crawlers/maven_crawler.rs'
- 'crates/socket-patch-core/src/vex/discover/maven.rs'
- 'crates/socket-patch-core/src/vex/discover/bazel_maven.rs'
- 'crates/socket-patch-core/src/patch/redirect/upstream/maven.rs'
- 'crates/socket-patch-core/src/patch/redirect/upstream/bazel_maven.rs'
- 'crates/socket-patch-core/src/vendor/maven_repo.rs'
- 'crates/socket-patch-core/src/vendor/refusals.rs'
- 'crates/socket-patch-core/src/bazel/**'
- 'crates/socket-patch-core/src/patch/jvm_jar.rs'
- 'crates/socket-patch-core/src/patch/jar_members.rs'
- 'crates/socket-patch-core/src/patch/jar_manifest.rs'
- 'crates/socket-patch-core/src/vex/**'
- 'crates/socket-patch-cli/tests/e2e_bazel_build/main.rs'
- 'crates/socket-patch-core/src/patch/redirect/**'
- 'crates/socket-patch-core/src/hosted/**'
Expand Down
6 changes: 3 additions & 3 deletions crates/socket-patch-cli/CLI_CONTRACT.md

Large diffs are not rendered by default.

52 changes: 35 additions & 17 deletions crates/socket-patch-cli/src/commands/vex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1902,17 +1902,13 @@ const BAZEL_NOT_IN_BUILD: &str = "vex_bazel_not_in_build";
const AFFECTED_REASON: &str = "attested as affected, not as patched: Bazel does not build the \
patched copy of this package; the run warning names what it builds from";

/// The closing sentence of the action statement, and so of the run warning,
/// of a package that is affected because its patch is in the installed copy
/// alone.
const INSTALLED_TREE_SHIPS: &str = "If what you ship is the installed tree and not what Bazel \
builds, pass `--no-bazel` (`--vex-no-bazel` on scan, apply and vendor).";

/// In a Bazel workspace, a hub of aspect_rules_js, rules_python,
/// rules_ruby, rules_rust or rules_csharp builds a package from the lock a
/// workspace file names, never from the copy a package manager installed,
/// and rules_python builds nothing from a line that points at a copy under
/// `.socket/vendor` ([`socket_patch_core::bazel::built`]). A patch that is
/// rules_ruby, rules_rust, rules_csharp or rules_jvm_external builds a
/// package from the lock a workspace file names, never from the copy a
/// package manager installed (a jar of the Maven local repository only at
/// the lock's sha256), and rules_python builds nothing from a line
/// that points at a copy under `.socket/vendor`
/// ([`socket_patch_core::bazel::built`]). A patch that is
/// only in such a copy is in no build of Bazel's, so its package is not
/// attested as patched: it leaves `outcome.applied` and is returned with
/// what to do about it, for statements that say `affected`
Expand All @@ -1927,6 +1923,10 @@ const INSTALLED_TREE_SHIPS: &str = "If what you ship is the installed tree and n
/// be read with certainty: the statement stays the one of a project
/// without Bazel. So is a patch whose record names no advisory: no run
/// writes a statement for it, and it is left out for that reason alone.
/// A Maven patch is asked about whichever mode recorded it: no file of a
/// project decides what a rules_jvm_external hub fetches, so a pin of a
/// `pom.xml` or a Gradle file, and a copy vendored for such a build, are
/// in the Bazel build only through an entry of the root `MODULE.bazel`.
///
/// With `--no-bazel` / `--vex-no-bazel` (`params.no_bazel`) the user has
/// said that the document is about the installed tree, which is what the
Expand All @@ -1950,7 +1950,8 @@ async fn unbuilt_by_bazel(
}
let patched = |purl: &String| {
let record = plan.view.patches.get(purl)?;
let judged = !plan.hosted.contains_key(purl) && !record.vulnerabilities.is_empty();
let pinned = plan.hosted.contains_key(purl) && !purl.starts_with(MAVEN);
let judged = !pinned && !record.vulnerabilities.is_empty();
judged.then(|| Patched {
purl: purl.clone(),
uuid: record.uuid.clone(),
Expand All @@ -1975,32 +1976,49 @@ async fn unbuilt_by_bazel(
affected
}

/// The start of a Maven purl.
const MAVEN: &str = "pkg:maven/";

/// The action statement for `package`, whose patch Bazel does not build:
/// what `call` builds the package from, and what to run so that the build
/// holds the patch. For an installed copy that is the hub's own remedy
/// ([`Unbuilt::remedy`]). Hosted and vendored mode write in the project
/// they run in, so it names the directory of the lock.
/// they run in, so it names the directory of the lock, and for a Maven jar
/// the Bazel root, where the patch of a hub is written, or what keeps
/// those modes from writing it.
///
/// For an installed copy it ends with the way out of a repository that
/// ships the installed tree and keeps the hub for something else: the
/// option, in both spellings, since the statement is the same whichever
/// command wrote the document. Not for a committed PyPI copy: there the
/// command wrote the document. A Maven patch has the same statement in
/// every mode, a committed copy included, in words that hold for each:
/// the patch is in what Maven or Gradle builds from, and that build is
/// what such a repository ships. Not for a committed PyPI copy: there the
/// build is broken or takes the registry's package, and the installed tree
/// is not the patched one either.
fn bazel_build_action(package: &Patched, call: &Unbuilt) -> String {
let Patched { uuid, pins, .. } = package;
let Patched { purl, uuid, pins } = package;
let Unbuilt {
call: tag,
file,
line,
lock,
remedy,
} = call;
match pins {
let maven = purl.starts_with(MAVEN);
let (only, ships) = match maven {
true => (
"what Maven or Gradle builds from",
"what Maven or Gradle builds",
),
false => ("the installed copy", "the installed tree"),
};
match pins.as_ref().filter(|_| !maven) {
None => format!(
"Bazel builds this package from {lock} (`{tag}`, {file}:{line}), which does not \
name Socket patch {uuid}: the patch is only in the installed copy. {remedy} \
{INSTALLED_TREE_SHIPS}"
name Socket patch {uuid}: the patch is only in {only}. {remedy} If what you ship \
is {ships} and not what Bazel builds, pass `--no-bazel` (`--vex-no-bazel` on scan, \
apply and vendor)."
),
Some(_) => format!(
"Bazel builds no package from the line of {lock} that points at the copy of Socket \
Expand Down
9 changes: 5 additions & 4 deletions crates/socket-patch-cli/tests/e2e_bazel_build/harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1452,7 +1452,7 @@ impl Cell {

/// Agent mode in this checkout, through `run`, for a package that its
/// package manager keeps outside the checkout, where `installed` is a
/// file of that copy: `scan --mode agent --yes` gives the file the text
/// file of that copy: `scan --mode agent --yes` gives the file the bytes
/// `patched`, from the record of the patch, and writes nothing into the
/// checkout but its own `.socket` directory, and the `apply` of a later
/// run passes. Then what the two say with `--vex`, and what `vex` and
Expand All @@ -1462,7 +1462,7 @@ impl Cell {
&self,
run: impl Fn(&Cell, &[&str]) -> Ran,
installed: &Path,
patched: &str,
patched: impl AsRef<[u8]>,
claim: &Claim,
) -> Tree {
let test = &self.test;
Expand All @@ -1478,8 +1478,9 @@ impl Cell {
let mut wrote = changed(&before, &left);
wrote.retain(|file| !file.starts_with(".socket/"));
assert_eq!(wrote, NOTHING, "{test}: {said}");
let holds = std::fs::read_to_string(installed).unwrap_or_default();
assert_eq!(holds, patched, "{test}: {}", installed.display());
let holds = std::fs::read(installed).unwrap_or_default();
let (at, shown) = (installed.display(), String::from_utf8_lossy(&holds));
assert!(holds == patched.as_ref(), "{test}: {at} holds:\n{shown}");

let again = self.document("apply");
let apply = run(self, &[&["apply"][..], &with_vex(&again)].concat());
Expand Down
Loading
Loading