Skip to content
Merged
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
30 changes: 21 additions & 9 deletions .github/workflows/bazel-maven.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
name: Bazel patch compatibility (Maven)

# The Maven flows of the real-Bazel tests (`maven::` in `e2e_bazel_build`):
# a hosted patch of an artifact in a workspace whose rules_jvm_external hub
# builds that artifact from a pinned lock, on each Bazel release below. The
# a hosted and a vendored patch of an artifact in a workspace whose
# rules_jvm_external hub builds that artifact from a pinned lock, on each
# Bazel release below. The
# patch is one block in MODULE.bazel that puts a repository with the
# patched jar in the place of the hub's own (`override_repo`): the flows
# hold the block's text, the patched build and its sha256 check, the undo,
# a hosted scan that finds the artifact in the hub's lock, a version bump
# of the patched artifact, and a hub the block cannot patch.
# bazel-compatibility.yml holds the legs and what every ecosystem
# of the patched artifact, and a hub the block cannot patch. In vendored
# 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
# every ecosystem
# shares; this file says when the Maven legs run and on which releases.
#
# Each major release has an era of its own, because the ruleset decides
Expand Down Expand Up @@ -58,11 +63,14 @@ on:
# 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`
# (for a pom and for the block of MODULE.bazel), 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, so a change to one ecosystem starts that
# ecosystem's legs only.
# (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.
#
# 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 @@ -88,6 +96,8 @@ on:
- '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/**'
push:
branches: [main]
Expand All @@ -114,6 +124,8 @@ on:
- '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-cli/tests/e2e_bazel_build/main.rs'
- 'crates/socket-patch-core/src/patch/redirect/**'
Expand Down
18 changes: 9 additions & 9 deletions crates/socket-patch-cli/CLI_CONTRACT.md

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion crates/socket-patch-cli/src/commands/apply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1985,7 +1985,8 @@ pub(crate) async fn run_locked(
run_warnings.extend(user_patch_warnings.iter().cloned());
run_warnings.extend(unsupported_warning);
let patched = results.iter().map(|r| r.package_key.as_str());
run_warnings.extend(super::bazel_maven_notices(&args.common, patched, false).await);
run_warnings
.extend(super::bazel_maven_notices(&args.common, patched, false, false).await);
run_warnings.extend(results.iter().flat_map(|r| {
let note = r.error.as_deref().filter(|_| r.success).unwrap_or_default();
socket_patch_core::patch::apply::advisory_warning_codes(note)
Expand Down
27 changes: 18 additions & 9 deletions crates/socket-patch-cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,14 @@ pub(crate) fn project_state_in_scope(common: &crate::args::GlobalArgs) -> bool {
}

/// In a Bazel workspace the root's `.bazelignore` names the directories of
/// the project's patched Go module copies, and of the vendored crates a
/// crate hub builds, so that Bazel and gazelle read no package there
/// the project's patched Go module copies, of the vendored crates a crate
/// hub builds, and of the patched Maven jars that vendored mode keeps for a
/// rules_jvm_external hub, so that Bazel and gazelle read no package there
/// (`socket_patch_core::bazel::ignore`). A command that can write or
/// remove such a copy calls this once, after the last step that can change
/// a copy or take one back and before it gives up its apply lock. Nothing
/// is done in a dry run or a `--global` run, and a run whose `--ecosystems`
/// leaves `golang` or `cargo` out only takes away that ecosystem's pair of
/// leaves `golang`, `cargo` or `maven` out only takes away that ecosystem's pair of
/// a copy that is gone. So does the prune pass of a scan, which comes here
/// after its scan has (`adds` false) and can only have removed a copy: a
/// file it cannot write is left to the next command's warning.
Expand All @@ -74,7 +75,7 @@ pub(crate) async fn sync_bazelignore(
adds: bool,
) -> Vec<crate::json_envelope::RunWarning> {
use socket_patch_core::bazel::ignore;
use socket_patch_core::crawlers::Ecosystem::{Cargo, Golang};
use socket_patch_core::crawlers::Ecosystem::{Cargo, Golang, Maven};
let mut warnings = Vec::new();
if common.dry_run || common.is_global() {
return warnings;
Expand All @@ -86,9 +87,10 @@ pub(crate) async fn sync_bazelignore(
projects.push(common.project_root());
}
let (loud, mut told) = (!common.json && !common.silent, Vec::new());
let [go, cargo] = [Golang, Cargo].map(|eco| adds && common.ecosystem_selected(eco));
let [go, cargo, maven] =
[Golang, Cargo, Maven].map(|eco| adds && common.ecosystem_selected(eco));
for project in projects {
match ignore::sync(&project, go, cargo).await {
match ignore::sync(&project, go, cargo, maven).await {
Ok(Some((file, copies))) if loud => {
// A root that both projects are under is named once for
// each kind of copy whose lines changed there.
Expand Down Expand Up @@ -135,24 +137,31 @@ pub(crate) async fn sync_bazelignore(
///
/// With `tell`, a human run is told here, as [`sync_bazelignore`] tells
/// it. A command that prints the warnings of its run itself passes
/// `false`.
/// `false`. A `vendored` run patches a pinned hub itself: it is warned of
/// the jars it wrote no entry for, each with the reason.
pub(crate) async fn bazel_maven_notices<'a>(
common: &crate::args::GlobalArgs,
purls: impl Iterator<Item = &'a str>,
tell: bool,
vendored: bool,
) -> Vec<crate::json_envelope::RunWarning> {
if common.is_global() {
return Vec::new();
}
let purls = purls.map(str::to_string).collect();
let said = socket_patch_core::bazel::maven::notices(&common.cwd, purls).await;
use socket_patch_core::bazel::maven::{notices, HUB_UNPATCHED};
let said = notices(&common.cwd, purls, vendored).await;
// A vendored dry run wrote no entry for any jar: the ones it would
// write are not unpatched.
let would_write = |code: &str| vendored && common.dry_run && code == HUB_UNPATCHED;
let said = said.into_iter().filter(|(code, _)| !would_write(code));
let warning = |(code, detail): (&str, String)| {
if tell && !common.json && !common.silent {
eprintln!("Warning: {detail}");
}
crate::json_envelope::RunWarning::new(code, detail)
};
said.into_iter().map(warning).collect()
said.map(warning).collect()
}

/// The vendor-ledger keys (`ledger`, the project's
Expand Down
10 changes: 10 additions & 0 deletions crates/socket-patch-cli/src/commands/rollback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2753,6 +2753,15 @@ async fn run_project(args: RollbackArgs, below: BelowNotes) -> i32 {
let gc_bytes_freed = gc.map_or(0, |gc| gc.bytes_freed);

// ── run-level warnings ───────────────────────────────────────
// The jar that vendored mode kept for a Bazel hub alone is in
// no installed tree: the next Bazel build takes the hub's own.
let of_hub = |key: &String| {
let flavor = socket_patch_core::vendor::maven_repo::HUB_FLAVOR;
let hub = |(k, e): &(String, socket_patch_core::vendor::VendorEntry)| {
k == key && e.flavor.as_deref() == Some(flavor)
};
vendor_entries.iter().any(hub)
};
let advised = ReinstallAdvised::of(
vendored_leg
.warnings
Expand All @@ -2775,6 +2784,7 @@ async fn run_project(args: RollbackArgs, below: BelowNotes) -> i32 {
let still_patched = vendored_leg
.reverted
.iter()
.filter(|key| !of_hub(key))
.chain(vendored_leg.preserved.iter())
.chain(hosted_leg.reverted.iter())
.filter(|key| {
Expand Down
5 changes: 3 additions & 2 deletions crates/socket-patch-cli/src/commands/scan/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,9 @@ pub(crate) async fn lockfile_supplement(
/// workspace fetch when `--cwd` is its root, what was not read of its hubs
/// and the entries of its block that are stale
/// ([`socket_patch_core::bazel::maven::hub_jars`]). Only for a hosted run
/// with Maven in scope: no other mode patches a hub. The callers are runs
/// of a project, never of the global installs.
/// with Maven in scope: a vendored scan does not look for a hub's jars,
/// and patches the hub of a package it found elsewhere. The callers are
/// runs of a project, never of the global installs.
pub(crate) async fn hub_jars(common: &GlobalArgs, hosted: bool) -> HubJars {
if !hosted || !common.ecosystem_selected(Ecosystem::Maven) {
return HubJars::default();
Expand Down
14 changes: 14 additions & 0 deletions crates/socket-patch-cli/src/commands/scan/hosted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2284,6 +2284,19 @@ async fn run_redirect_selected_untracked(
));
return 1;
}
// A hosted entry that took the place of a vendored one in the block of
// a Bazel hub leaves the directory of that entry without a reader.
let mut unit_warnings: Vec<RunWarning> = Vec::new();
if let (false, Some(module), Ok(state)) = (
common.dry_run,
rewrite.files.get(socket_patch_core::bazel::maven::FILE),
&vendor_state,
) {
let left =
socket_patch_core::vendor::maven_repo::drop_unnamed_units(&common.cwd, module, state);
let warning = |detail| RunWarning::new("cleanup_failed", detail);
unit_warnings.extend(left.await.into_iter().map(warning));
}
// A pnpm-workspace.yaml a hosted run created, which this run emptied of
// its registry route: deleted, not left as a bare `packages` list. The
// rewrite carries writes only, so the file goes once they have landed.
Expand Down Expand Up @@ -2635,6 +2648,7 @@ async fn run_redirect_selected_untracked(
warnings.extend(vlt_stale.warnings.iter().map(run_warning_of));
warnings.extend(takeover_pre_warnings.iter().map(run_warning_of));
warnings.extend(takeover_warnings.iter().cloned());
warnings.extend(unit_warnings);
warnings.extend(prune_warnings.iter().cloned());
warnings.extend(workspace_warning);

Expand Down
Loading
Loading