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
5 changes: 4 additions & 1 deletion .github/workflows/bazel-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ on:
# 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
# command, and for the form vendored mode writes where a build takes
# a committed wheel (vendor/pypi_distdir.rs). 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 @@ -79,6 +80,7 @@ on:
- '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/pypi_distdir.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/**'
Expand Down Expand Up @@ -116,6 +118,7 @@ on:
- '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/pypi_distdir.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/**'
Expand Down
8 changes: 5 additions & 3 deletions crates/socket-patch-cli/CLI_CONTRACT.md

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions crates/socket-patch-cli/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,8 +435,9 @@ pub struct GlobalArgs {
/// (`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.
/// project's packages from that lock. A PyPI package is then written
/// by its path also where vendored mode would commit its wheel as a
/// download cache of Bazel. Other subcommands accept it silently.
#[arg(
help_heading = GLOBAL_OPTIONS,
long = "allow-vendored-in-bazel",
Expand Down
88 changes: 60 additions & 28 deletions crates/socket-patch-cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,28 @@ pub(crate) fn project_state_in_scope(common: &crate::args::GlobalArgs) -> bool {
/// 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`, `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.
/// (`socket_patch_core::bazel::ignore`), and the root's `.bazelrc` names
/// the directory of each patched wheel that vendored mode committed as a
/// download cache of Bazel, so that the build takes the wheel from there
/// (`socket_patch_core::vendor::pypi_distdir`). 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`, `cargo`, `maven` or `pypi` 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.
///
/// A human run is told here that the file changed, or why it could not be;
/// A human run is told here that a file changed, or why it could not be;
/// the result is that warning again, for the command's envelope.
pub(crate) async fn sync_bazelignore(
common: &crate::args::GlobalArgs,
adds: bool,
) -> Vec<crate::json_envelope::RunWarning> {
use socket_patch_core::bazel::ignore;
use socket_patch_core::crawlers::Ecosystem::{Cargo, Golang, Maven};
use socket_patch_core::bazel::{distdir, ignore};
use socket_patch_core::crawlers::Ecosystem::{Cargo, Golang, Maven, Pypi};
use socket_patch_core::vendor::pypi_distdir::sync_bazelrc;
let mut warnings = Vec::new();
if common.dry_run || common.is_global() {
return warnings;
Expand All @@ -87,13 +92,14 @@ pub(crate) async fn sync_bazelignore(
projects.push(common.project_root());
}
let (loud, mut told) = (!common.json && !common.silent, Vec::new());
let [go, cargo, maven] =
[Golang, Cargo, Maven].map(|eco| adds && common.ecosystem_selected(eco));
let [go, cargo, maven, pypi] =
[Golang, Cargo, Maven, Pypi].map(|eco| adds && common.ecosystem_selected(eco));
for project in projects {
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.
// For each file that changed: the line a person is told, and what
// that line is told once by.
let copies = ignore::sync(&project, go, cargo, maven).await;
let copies = copies.map(|changed| {
changed.map(|(file, copies)| {
let (shown, copies) = (file.display(), copies.join(" and "));
let line = match file.exists() {
true => format!(
Expand All @@ -104,21 +110,47 @@ pub(crate) async fn sync_bazelignore(
format!("Removed {shown}: no patched {copies} copy is left under .socket")
}
};
if !told.contains(&line) {
// A root that both projects are under is named once for
// each kind of copy whose lines changed there.
(line.clone(), line)
})
});
let wheels = sync_bazelrc(&project, pypi).await.map(|changed| {
changed.map(|file| {
let shown = file.display();
let line = match file.exists() {
true => format!(
"Updated {shown}: the lines that make Bazel take patched wheels from \
.socket/vendor/pypi"
),
false => format!(
"Removed {shown}: no patched wheel is left under .socket/vendor/pypi for \
Bazel to take"
),
};
// A root that both projects are under is named once.
(shown.to_string(), line)
})
});
let synced = [
(copies, ignore::NOT_UPDATED),
(wheels, distdir::NOT_UPDATED),
];
for (synced, not_updated) in synced {
match synced {
Ok(Some((once, line))) if loud && !told.contains(&once) => {
println!("{line}");
told.push(line);
told.push(once);
}
}
Err(detail) if adds => {
if loud {
eprintln!("Warning: {detail}");
Err(detail) if adds => {
if loud {
eprintln!("Warning: {detail}");
}
let warning = crate::json_envelope::RunWarning::new(not_updated, detail);
warnings.push(warning);
}
warnings.push(crate::json_envelope::RunWarning::new(
ignore::NOT_UPDATED,
detail,
));
_ => {}
}
_ => {}
}
}
warnings
Expand Down
8 changes: 7 additions & 1 deletion crates/socket-patch-cli/src/commands/vex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1950,7 +1950,13 @@ 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();
// A wheel committed as a download cache of Bazel is pinned in the
// file the hub reads as a hosted pin is: by its URL and sha256.
let cached = plan.vendor_entries.get(purl);
let cached = cached
.is_some_and(|entry| socket_patch_core::vendor::pypi_distdir::line_of(entry).is_some());
let pinned = cached || plan.hosted.contains_key(purl);
let judged = !pinned && !record.vulnerabilities.is_empty();
judged.then(|| Patched {
purl: purl.clone(),
uuid: record.uuid.clone(),
Expand Down
8 changes: 8 additions & 0 deletions crates/socket-patch-cli/tests/e2e_bazel_build/harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,14 @@ impl Cell {
Run::of(cmd).unwrap_or_else(|why| panic!("{}: {why}", self.test))
}

/// [`Cell::bazel`] from the directory `dir` of the workspace copy, as a
/// user who works below the root runs it.
pub fn bazel_below(&self, dir: &str, command: &str, args: &[&str]) -> Run {
let mut cmd = self.command("update", command, args);
cmd.current_dir(self.path(dir));
Run::of(cmd).unwrap_or_else(|why| panic!("{}: {why}", self.test))
}

/// `bazel build --lockfile_mode=error <targets>`: passes only when
/// `MODULE.bazel.lock` already holds what the build resolves.
fn frozen_build(&self, targets: &[&str]) -> Run {
Expand Down
Loading
Loading