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
11 changes: 10 additions & 1 deletion .github/workflows/bazel-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ on:
# files and decides whether Bazel builds what was patched. Every flow
# holds the exact document socket-patch writes about its build, patched
# or not, so a change to how a document is built or worded
# starts the legs of every ecosystem. Nothing else that
# starts the legs of every ecosystem. `bazel/` also says which lock a
# hub reads, for the refusal of vendored mode beside such a hub
# (vendor/bazel_hub.rs), which vendor/refusals.rs hands to every
# command. Nothing else that
# another ecosystem's flow owns is here, so any other change to one
# ecosystem starts that ecosystem's legs only.
#
Expand Down Expand Up @@ -71,9 +74,12 @@ on:
- 'crates/socket-patch-core/src/utils/python_lock.rs'
- 'crates/socket-patch-core/src/utils/requirements.rs'
- 'crates/socket-patch-core/src/vendor/lock_inventory/pypi.rs'
- 'crates/socket-patch-core/src/vendor/pypi.rs'
- 'crates/socket-patch-core/src/vendor/pypi_distribution.rs'
- 'crates/socket-patch-core/src/vendor/pypi_requirements.rs'
- 'crates/socket-patch-core/src/vendor/pypi_wheel.rs'
- 'crates/socket-patch-core/src/vendor/bazel_hub.rs'
- 'crates/socket-patch-core/src/vendor/refusals.rs'
- 'crates/socket-patch-core/src/vex/discover/pypi_other.rs'
- 'crates/socket-patch-core/src/bazel/**'
- 'crates/socket-patch-core/src/vex/**'
Expand Down Expand Up @@ -105,9 +111,12 @@ on:
- 'crates/socket-patch-core/src/utils/python_lock.rs'
- 'crates/socket-patch-core/src/utils/requirements.rs'
- 'crates/socket-patch-core/src/vendor/lock_inventory/pypi.rs'
- 'crates/socket-patch-core/src/vendor/pypi.rs'
- 'crates/socket-patch-core/src/vendor/pypi_distribution.rs'
- 'crates/socket-patch-core/src/vendor/pypi_requirements.rs'
- 'crates/socket-patch-core/src/vendor/pypi_wheel.rs'
- 'crates/socket-patch-core/src/vendor/bazel_hub.rs'
- 'crates/socket-patch-core/src/vendor/refusals.rs'
- 'crates/socket-patch-core/src/vex/discover/pypi_other.rs'
- 'crates/socket-patch-core/src/bazel/**'
- 'crates/socket-patch-core/src/vex/**'
Expand Down
49 changes: 29 additions & 20 deletions .github/workflows/bazel-ruby.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: Bazel patch compatibility (RubyGems)

# The RubyGems flow of the real-Bazel tests (`ruby::` in `e2e_bazel_build`):
# hosted mode for a gem that rules_ruby's `ruby.bundle_fetch` reads from
# `Gemfile` and `Gemfile.lock`, on each Bazel release below.
# The RubyGems flows of the real-Bazel tests (`ruby::` in `e2e_bazel_build`):
# hosted and vendored mode for a gem that rules_ruby's `ruby.bundle_fetch`
# reads from `Gemfile` and `Gemfile.lock`, on each Bazel release below.
# bazel-compatibility.yml holds the legs and what every ecosystem shares;
# this file says when the Ruby legs run and on which releases.
#
Expand All @@ -24,14 +24,18 @@ name: Bazel patch compatibility (RubyGems)
on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
# What a pull request run covers: the RubyGems flow and its fixture, the
# harness and the workflows that run it, the Bazel installer and its
# pins, and the RubyGems files that `scan --mode hosted` and `rollback`
# run through in the fixture, each by its own path: the readers of a
# Bundler lock and a Gemfile with the lock half of the hosted rewrite
# (formats/gem), lock discovery, the lock inventory, the Ruby crawler
# (it says which lock Bundler loads), the upstream restore of
# `rollback`, and the stale-install guard that both commands end with.
# What a pull request run covers: the RubyGems flows and their fixture,
# the harness and the workflows that run it, the Bazel installer and its
# pins, and the RubyGems files that `scan --mode hosted`, `rollback`,
# `scan --mode vendored` and `vendor --revert` run through in the
# fixture, each by its own path: the readers of a Bundler lock and a
# Gemfile with the lock half of the hosted rewrite (formats/gem), lock
# discovery, the lock inventory, the Ruby crawler (it says which lock
# Bundler loads), the upstream restore of `rollback`, the stale-install
# guard that those commands end with, the vendored backend
# (vendor/gem.rs), and the refusal of vendored mode beside a hub that
# reads the lock (vendor/bazel_hub.rs), which vendor/refusals.rs hands
# to every command.
# Last, the VEX code: `vex/` of the core, the files of the `vex`
# command, and `bazel/` of the core, which reads the workspace files and
# decides whether Bazel builds what was patched. Every flow holds the
Expand All @@ -45,13 +49,13 @@ on:
# hosted rewrite is there (`rewrite_gem` and its planner in
# patch/redirect/mod.rs, the file of every ecosystem's rewriter), and
# so are patch/redirect/grant.rs, hosted/engine.rs and
# commands/scan/hosted.rs, the shared test helpers and the toolchain
# files. vendor/gem.rs is the vendored backend, which the flow only
# borrows two readers of a `gem` line from. A change to one of those
# commands/scan/hosted.rs, the rest of vendored mode (the download from
# the patch service, the ledger, the `vendor` command), the shared test
# helpers and the toolchain files. A change to one of those
# gets its run on the push to main (when the file is in the list below)
# or in the nightly run, not on the pull request: that is the price of
# not running every ecosystem's legs on every shared change. The flow
# does not run the native extension rebuild of agent mode
# not running every ecosystem's legs on every shared change. No flow
# runs the native extension rebuild of agent mode
# (patch/gem_ext.rs, patch/gem_source.rs), which is in neither list. On
# demand, workflow_dispatch runs the legs on any branch.
paths:
Expand All @@ -68,6 +72,9 @@ on:
- 'crates/socket-patch-core/src/crawlers/ruby_crawler.rs'
- 'crates/socket-patch-core/src/patch/redirect/upstream/gem.rs'
- 'crates/*/src/**/gem_refresh.rs'
- 'crates/socket-patch-core/src/vendor/gem.rs'
- 'crates/socket-patch-core/src/vendor/bazel_hub.rs'
- 'crates/socket-patch-core/src/vendor/refusals.rs'
- 'crates/socket-patch-core/src/bazel/**'
- 'crates/socket-patch-core/src/vex/**'
- 'crates/socket-patch-cli/src/commands/vex*.rs'
Expand All @@ -76,9 +83,9 @@ on:
# The pull request paths, and what only a push to main covers: the
# root of the test target (it changes when an ecosystem's module is
# added; ci.yml builds the target and runs its hermetic tests on every
# pull request), the vendored backend, the shared engine code and test
# helpers the flow runs through, and the toolchain files. A main push
# outside this list waits for the nightly run below.
# pull request), the shared engine code and test helpers the flows run
# through, and the toolchain files. A main push outside this list waits
# for the nightly run below.
paths:
- '.github/workflows/bazel-ruby.yml'
- '.github/workflows/bazel-compatibility.yml'
Expand All @@ -93,11 +100,13 @@ on:
- 'crates/socket-patch-core/src/crawlers/ruby_crawler.rs'
- 'crates/socket-patch-core/src/patch/redirect/upstream/gem.rs'
- 'crates/*/src/**/gem_refresh.rs'
- 'crates/socket-patch-core/src/vendor/gem.rs'
- 'crates/socket-patch-core/src/vendor/bazel_hub.rs'
- 'crates/socket-patch-core/src/vendor/refusals.rs'
- 'crates/socket-patch-core/src/bazel/**'
- 'crates/socket-patch-core/src/vex/**'
- 'crates/socket-patch-cli/src/commands/vex*.rs'
- 'crates/socket-patch-cli/tests/e2e_bazel_build/main.rs'
- 'crates/socket-patch-core/src/vendor/gem.rs'
- 'crates/socket-patch-core/src/patch/redirect/**'
- 'crates/socket-patch-core/src/hosted/**'
- 'crates/socket-patch-cli/src/commands/**'
Expand Down
9 changes: 5 additions & 4 deletions crates/socket-patch-cli/CLI_CONTRACT.md

Large diffs are not rendered by default.

11 changes: 8 additions & 3 deletions crates/socket-patch-cli/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,11 +427,16 @@ pub struct GlobalArgs {
/// Vendored mode (`vendor`, `scan`/`get --mode vendored`): write for a
/// package although the project is in a Bazel workspace, where the
/// build may not find the vendored copy. Vendored mode declines such
/// a package by default; today that is a Composer package
/// a package by default: a Composer package
/// (`vendor_composer_bazel_workspace`), whose lock names the copy by a
/// path that a Bazel rule running `composer install` in another
/// directory does not find. Pass it when the build does find the
/// copy. Other subcommands accept it silently.
/// directory does not find, and a PyPI or RubyGems package whose lock
/// a rules_python or rules_ruby hub of the workspace reads
/// (`vendor_pypi_bazel_hub`, `vendor_gem_bazel_hub`), which builds
/// nothing from a lock that names a copy under `.socket/vendor`. Pass
/// it when the build does find the copy, or does not take the
/// project's packages from that lock. Other subcommands accept it
/// silently.
#[arg(
help_heading = GLOBAL_OPTIONS,
long = "allow-vendored-in-bazel",
Expand Down
48 changes: 39 additions & 9 deletions crates/socket-patch-cli/tests/e2e_bazel_build/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,12 @@
//! the same.
//! - Bazel would read that file as a package of the user's workspace. The
//! crate has a dependency ([`DEP`]), so the file names a repository of
//! the hub, which the main repository does not see, and the commands
//! that analyse every target fail on it: `bazel cquery //...` and
//! `bazel query 'deps(//...)'` ([`analyses`]). The line that the scan
//! wrote into `.bazelignore` keeps the copies out of Bazel's packages:
//! the hub, which the main repository does not see, as it does not see
//! `platforms`, which the file names too. The commands that analyse
//! every target fail on the first of the two that Bazel meets:
//! `bazel cquery //...` and `bazel query 'deps(//...)'` ([`analyses`]).
//! The line that the scan wrote into `.bazelignore` keeps the copies out
//! of Bazel's packages:
//! `//...` is the user's own target ([`every_target`]), both commands
//! pass, and the build is the patched one, because the hub reads the
//! copy by its path, not as a package. A user who comments the line out
Expand Down Expand Up @@ -872,15 +874,42 @@ fn every_target(cell: &Cell) -> Vec<String> {
targets
}

/// Whether `stderr` says that the main repository does not see a
/// repository that the build file in the copy names: one of the hub, or
/// `platforms`. Bazel names the first one it meets, and which one that is
/// differs from run to run. The same words about another repository's view
/// are another failure.
fn unseen(stderr: &str) -> bool {
(stderr.split("No repository visible as '@").skip(1))
.filter_map(|rest| rest.split_once("' from main repository"))
.any(|(repo, _)| {
!repo.contains('\'') && (repo == "platforms" || repo.starts_with("crates__"))
})
}

/// [`unseen`] takes the two messages Bazel was seen to print, and neither
/// another repository's name nor another repository's view.
#[test]
fn an_unseen_repository_is_one_the_copy_names_and_the_main_repository_misses() {
let said = |repo: &str, from: &str| {
format!("ERROR: no such package: No repository visible as '@{repo}' from {from}\n")
};
assert!(unseen(&said("platforms", "main repository")));
assert!(unseen(&said("crates__dep-1.0.0", "main repository")));
assert!(!unseen(&said("rules_cc", "main repository")));
assert!(!unseen(&said("platforms", "repository '@@rules_rust+'")));
assert!(!unseen("Loading: 0 packages loaded\n"));
}

/// Whether the commands that analyse every target of the checkout of
/// `cell` pass: `bazel cquery //...` and `bazel query 'deps(//...)'`, which
/// agree. One that fails has met a repository of the hub, which the main
/// repository does not see.
/// agree. One that fails has met a repository that the build file in the
/// copy names and the main repository does not see ([`unseen`]).
fn analyses(cell: &Cell) -> bool {
let runs = [("cquery", "//..."), ("query", "deps(//...)")];
let runs = runs.map(|(command, targets)| cell.bazel(command, &[targets]));
for run in &runs {
let unseen = run.stderr().contains("No repository visible as '@crates__");
let unseen = unseen(&run.stderr());
assert_ne!(run.ok(), unseen, "{}: {}", cell.test, run.dump());
}
assert_eq!(runs[0].ok(), runs[1].ok(), "{}", cell.test);
Expand Down Expand Up @@ -1194,8 +1223,9 @@ fn vendored_from_cargo_with_config() {
// package: `//...` is the consumer alone, and the commands that analyse
// every target pass. A user who comments the line out has the package
// back, where the ruleset writes the build file: `//...` names targets
// there, those commands fail on the repository of the dependency, and
// the file Bazel now reads is a change of the copy again.
// there, those commands fail on a repository that the file names and
// the main repository does not see, and the file Bazel now reads is a
// change of the copy again.
assert_eq!(every_target(&cell), [CONSUMER], "{test}");
assert!(analyses(&cell), "{test}: under the line of the scan");
cell.write(".bazelignore", DECLINED);
Expand Down
Loading
Loading