diff --git a/Cargo.toml b/Cargo.toml index f4d9c76ec..746fe8005 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -145,6 +145,7 @@ syn = { version = "2.0.106", features = ["full"] } [workspace.lints.rust] unsafe_code = "forbid" missing_docs = "warn" +unreachable_pub = "warn" [workspace.lints.clippy] all = { level = "warn", priority = -1 } diff --git a/apps/piquelctl/tests/support/mod.rs b/apps/piquelctl/tests/support/mod.rs index 88ff9549b..1361bfbec 100644 --- a/apps/piquelctl/tests/support/mod.rs +++ b/apps/piquelctl/tests/support/mod.rs @@ -4,7 +4,7 @@ use std::process::{Command, Output}; /// Builds a `piquelctl` command isolated from inherited connection, /// profile, and login configuration. -pub fn command() -> Command { +pub(crate) fn command() -> Command { let mut command = Command::new(env!("CARGO_BIN_EXE_piquelctl")); for name in [ "PIQUELD_PROFILE", @@ -36,7 +36,7 @@ pub fn command() -> Command { /// The one error event of a `--json` failure, checking that every stderr /// line is a JSON event and that stdout is empty. -pub fn json_error(output: &Output) -> Value { +pub(crate) fn json_error(output: &Output) -> Value { assert!(!output.status.success()); assert_eq!(output.stdout, b"", "a failure writes nothing on stdout"); let events: Vec = String::from_utf8_lossy(&output.stderr) diff --git a/apps/piqueld-ui/src/browser/mod.rs b/apps/piqueld-ui/src/browser/mod.rs index bb7025d9e..85af104be 100644 --- a/apps/piqueld-ui/src/browser/mod.rs +++ b/apps/piqueld-ui/src/browser/mod.rs @@ -349,7 +349,7 @@ struct DashboardContext { } /// Mounts the CSR application into the document body. -pub fn mount() { +pub(super) fn mount() { mount_to_body(|| view! { }); } diff --git a/apps/piqueld-ui/src/lib.rs b/apps/piqueld-ui/src/lib.rs index c4fa115b3..020d83bb5 100644 --- a/apps/piqueld-ui/src/lib.rs +++ b/apps/piqueld-ui/src/lib.rs @@ -16,6 +16,10 @@ pub mod timeline; pub mod traffic; #[cfg(target_arch = "wasm32")] +#[expect( + unreachable_pub, + reason = "Leptos's #[component] generates public builder methods on each component's props struct" +)] mod browser; /// Mounts the dashboard into the current document. diff --git a/apps/piqueld-ui/src/overview/fixtures.rs b/apps/piqueld-ui/src/overview/fixtures.rs index a4d274a7b..8f8230c37 100644 --- a/apps/piqueld-ui/src/overview/fixtures.rs +++ b/apps/piqueld-ui/src/overview/fixtures.rs @@ -5,7 +5,7 @@ use serde_json::json; /// An environment named `name`, `stopped` or running, with `status`, if one /// was recorded. -pub fn environment( +pub(super) fn environment( name: &str, stopped: bool, status: Option<(ApplicationState, Option<&str>)>, @@ -37,7 +37,7 @@ pub fn environment( /// Application `id` with `environments`, and one latest deployment per /// `(operation ID, requested at)`. -pub fn application( +pub(super) fn application( id: &str, environments: Vec, deployments: &[(&str, i64)], diff --git a/apps/piqueld/build/dashboard.rs b/apps/piqueld/build/dashboard.rs index 0d7774e59..94551a0af 100644 --- a/apps/piqueld/build/dashboard.rs +++ b/apps/piqueld/build/dashboard.rs @@ -36,7 +36,7 @@ const PACKAGED: &str = "Cargo.toml.orig"; /// Workspace builds ignore [`SHIPPED`], so they never embed one that /// `cargo xtask publish` is packaging or left behind. It isn't tracked: a /// package never changes. -pub fn embed(manifest_dir: &Path) -> Result<(), Box> { +pub(crate) fn embed(manifest_dir: &Path) -> Result<(), Box> { println!("cargo::rustc-check-cfg=cfg(embedded_dashboard)"); #[cfg(feature = "embedded-ui")] let dist = Some(Dashboard::new(manifest_dir)?.build()?); @@ -56,7 +56,7 @@ fn write_bundle_module(dist: &Path) -> Result<(), Box> { let mut module = String::from( "// Generated by the piqueld build script; do not edit.\n\ /// Dashboard bundle compiled by the piqueld build script.\n\ - pub static BUNDLE: &[(&str, &[u8])] = &[\n", + pub(crate) static BUNDLE: &[(&str, &[u8])] = &[\n", ); for file in walk_files(dist)? { let relative = file.strip_prefix(dist)?; diff --git a/apps/piqueld/examples/generate_openapi/settings_reference.rs b/apps/piqueld/examples/generate_openapi/settings_reference.rs index b39852c15..911f35d3c 100644 --- a/apps/piqueld/examples/generate_openapi/settings_reference.rs +++ b/apps/piqueld/examples/generate_openapi/settings_reference.rs @@ -19,7 +19,7 @@ use serde_json::Value; use std::{collections::BTreeMap, fmt::Write as _}; /// A settings reference page: where it goes, and its hand-written parts. -pub struct SettingsPage { +pub(crate) struct SettingsPage { /// Where the page is written, relative to the repository root. pub path: &'static str, /// What the page is generated from, named in its do-not-edit comment. @@ -31,7 +31,7 @@ pub struct SettingsPage { impl SettingsPage { /// Every setting of an application manifest. - pub const MANIFEST: Self = Self { + pub(crate) const MANIFEST: Self = Self { path: "docs/user/reference/manifest-settings.md", source: "the doc comments of the manifest types in `crates/piqueld-core/src/manifest`", title: "Manifest settings", @@ -63,7 +63,7 @@ start with a letter and end with a letter or digit."#, }; /// Every setting of the daemon's configuration file. - pub const CONFIG: Self = Self { + pub(crate) const CONFIG: Self = Self { path: "docs/user/reference/configuration-settings.md", source: "the configuration types in `crates/piqueld-config`", title: "Daemon configuration settings", @@ -91,7 +91,7 @@ stands for each entry of an array of tables: `dns.providers[].kind` is the /// # Errors /// If the schema has a shape the page cannot show, or lacks a /// description the page needs. - pub fn render(&self, schema: &Value) -> Result { + pub(crate) fn render(&self, schema: &Value) -> Result { let document = Document::deserialize(schema) .with_context(|| format!("read the JSON Schema of {}", self.path))?; Renderer { diff --git a/apps/piqueld/src/api/http/ui.rs b/apps/piqueld/src/api/http/ui.rs index f58a066bf..5bbc134d5 100644 --- a/apps/piqueld/src/api/http/ui.rs +++ b/apps/piqueld/src/api/http/ui.rs @@ -11,7 +11,7 @@ use std::path::Path; /// One embedded dashboard file: its bundle name relative to `/dashboard/`, /// plus its bytes. -pub type EmbeddedFile = (&'static str, &'static [u8]); +pub(super) type EmbeddedFile = (&'static str, &'static [u8]); /// The complete set of dashboard files compiled into the daemon binary. pub type EmbeddedBundle = [EmbeddedFile]; diff --git a/apps/piqueld/src/telemetry/sockets.rs b/apps/piqueld/src/telemetry/sockets.rs index f85c8a887..fa4d69769 100644 --- a/apps/piqueld/src/telemetry/sockets.rs +++ b/apps/piqueld/src/telemetry/sockets.rs @@ -11,7 +11,7 @@ use std::os::unix::fs::DirBuilderExt as _; use std::path::{Path, PathBuf}; /// The socket a receiver's collector listens on, inside its directory. -pub const SOCKET: &str = "otlp.sock"; +pub(super) const SOCKET: &str = "otlp.sock"; /// Where every receiver's directory lives. #[derive(Clone, Debug)] diff --git a/apps/piqueld/tests/support/application.rs b/apps/piqueld/tests/support/application.rs index 08924e128..a12554cce 100644 --- a/apps/piqueld/tests/support/application.rs +++ b/apps/piqueld/tests/support/application.rs @@ -10,7 +10,7 @@ use piqueld_store::{Store, StoreError}; use std::sync::Arc; /// An [`ApplicationService`] with shorthands for the daemon's own mutations. -pub struct TestApplications { +pub(crate) struct TestApplications { service: ApplicationService, store: Arc, } @@ -24,7 +24,7 @@ impl std::ops::Deref for TestApplications { } impl TestApplications { - pub fn new( + pub(crate) fn new( store: Arc, runtime: Arc, sources: Arc, @@ -36,7 +36,7 @@ impl TestApplications { } // Controller scenarios explicitly save and deploy in one acceptance. - pub async fn apply( + pub(crate) async fn apply( &self, manifest: ValidatedTemplate, expected_generation: Option, @@ -48,7 +48,7 @@ impl TestApplications { self.service.operation(&operation_id).await } - pub async fn save( + pub(crate) async fn save( &self, manifest: ValidatedTemplate, expected_generation: Option, @@ -77,7 +77,7 @@ impl TestApplications { Ok(saved) } - pub async fn deploy( + pub(crate) async fn deploy( &self, id: &EnvironmentId, expected_generation: Option, @@ -87,7 +87,7 @@ impl TestApplications { } /// Deletes the application of environment `id`, its only environment. - pub async fn delete( + pub(crate) async fn delete( &self, id: &EnvironmentId, expected_generation: Option, @@ -105,7 +105,7 @@ impl TestApplications { self.service.operation(&operation.operation_id).await } - pub async fn reconcile( + pub(crate) async fn reconcile( &self, id: &EnvironmentId, expected_generation: Option, @@ -115,12 +115,12 @@ impl TestApplications { } /// Stops environment `id`, returning its latest operation. - pub async fn stop(&self, id: &EnvironmentId) -> Result { + pub(crate) async fn stop(&self, id: &EnvironmentId) -> Result { self.submit(Mutation::Stop { id: id.clone() }, None).await } /// Accepts `mutation` and returns the operation it requested. - pub async fn submit( + pub(crate) async fn submit( &self, mutation: Mutation, expected_generation: Option, diff --git a/apps/piqueld/tests/support/daemon.rs b/apps/piqueld/tests/support/daemon.rs index 91fcf5caa..3a24b6cb0 100644 --- a/apps/piqueld/tests/support/daemon.rs +++ b/apps/piqueld/tests/support/daemon.rs @@ -2,7 +2,7 @@ /// Starts `piqueld` with the configuration at `config`, expects it to exit /// unsuccessfully, and returns what it wrote to standard error. -pub fn refused_start(config: &std::path::Path) -> String { +pub(crate) fn refused_start(config: &std::path::Path) -> String { let output = std::process::Command::new(env!("CARGO_BIN_EXE_piqueld")) .arg("--config") .arg(config) diff --git a/apps/piqueld/tests/support/docker_contract.rs b/apps/piqueld/tests/support/docker_contract.rs index 10776addd..d2335c964 100644 --- a/apps/piqueld/tests/support/docker_contract.rs +++ b/apps/piqueld/tests/support/docker_contract.rs @@ -19,13 +19,13 @@ use piqueld_docker::{DockerApi, DockerError, Exec, ExecIo, JobOutput, JobRuns, J use std::{collections::BTreeMap, time::Duration}; /// The image every service and job runs. -pub const IMAGE: &str = "alpine:3.20"; +pub(crate) const IMAGE: &str = "alpine:3.20"; /// A tag of [`IMAGE`]'s repository that doesn't exist. -pub const MISSING_IMAGE: &str = "alpine:piqueld-missing"; +pub(crate) const MISSING_IMAGE: &str = "alpine:piqueld-missing"; /// [`IMAGE`]'s repository, named by Docker Hub's registry endpoint. Docker /// doesn't normalize this name to [`IMAGE`]'s, so it is another repository /// serving the same images, from Docker Hub. -pub const HUB_ALIAS: &str = "registry-1.docker.io/library/alpine"; +pub(crate) const HUB_ALIAS: &str = "registry-1.docker.io/library/alpine"; /// How long a scenario waits for the Engine to apply a change; the fake /// applies each at once. @@ -57,7 +57,7 @@ pub(crate) use scenarios; /// One environment of the `integration-instance` installation, and the /// resources piqueld desires for it. -pub struct Environment { +pub(crate) struct Environment { /// Its ID, unique to this run. pub app: EnvironmentId, /// Ownership labels of its networks, volumes, and jobs. @@ -68,13 +68,13 @@ pub struct Environment { impl Environment { /// A new environment whose services run [`IMAGE`] as `docker` resolves it. - pub async fn new(docker: &impl DockerApi) -> Self { + pub(crate) async fn new(docker: &impl DockerApi) -> Self { Self::named(docker, format!("app-{}", uuid::Uuid::now_v7().simple())).await } /// A new environment whose ID starts with this one's, so its resources' /// names start with this one's readable name prefix. - pub async fn look_alike(&self, docker: &impl DockerApi) -> Self { + pub(crate) async fn look_alike(&self, docker: &impl DockerApi) -> Self { Self::named(docker, format!("{}-look-alike", self.app)).await } @@ -96,22 +96,22 @@ impl Environment { } /// The installation that owns its resources. - pub fn instance(&self) -> InstanceId { + pub(crate) fn instance(&self) -> InstanceId { InstanceId::parse(&self.labels[piqueld_core::resource::INSTANCE_LABEL]).unwrap() } /// The labels secrets of the environment carry. - pub fn secret_labels(&self) -> BTreeMap { + pub(crate) fn secret_labels(&self) -> BTreeMap { Ownership::scope(&self.instance(), &self.app) } /// The name of its secret. - pub fn secret_name(&self) -> String { + pub(crate) fn secret_name(&self) -> String { format!("piqueld-secret-{}", self.app) } /// Its private network. - pub fn network(&self) -> DesiredNetwork { + pub(crate) fn network(&self) -> DesiredNetwork { DesiredNetwork { name: piqueld_core::DockerNetworkName::parse(docker_resource_name( &self.app, @@ -124,7 +124,7 @@ impl Environment { } /// Its `data` volume. - pub fn volume(&self) -> DesiredVolume { + pub(crate) fn volume(&self) -> DesiredVolume { DesiredVolume { logical_name: piqueld_core::VolumeName::parse("data").unwrap(), name: piqueld_core::DockerVolumeName::parse(docker_resource_name( @@ -138,7 +138,7 @@ impl Environment { } /// Its `data` volume, mounted writable at `/data`. - pub fn data_mount(&self) -> piqueld_core::DesiredMount { + pub(crate) fn data_mount(&self) -> piqueld_core::DesiredMount { piqueld_core::DesiredMount { volume_name: self.volume().name, target: "/data".into(), @@ -148,7 +148,7 @@ impl Environment { /// Its service `name`: one healthy replica of [`IMAGE`] that sleeps, /// attached to its network. - pub fn service(&self, name: &str) -> DesiredService { + pub(crate) fn service(&self, name: &str) -> DesiredService { let mut labels = self.labels.clone(); labels.insert(SERVICE_LABEL.into(), name.into()); DesiredService { @@ -181,7 +181,7 @@ impl Environment { } /// A command health check that passes every second. - pub fn passing_healthcheck() -> ValidatedHealthCheck { + pub(crate) fn passing_healthcheck() -> ValidatedHealthCheck { ValidatedHealthCheck::Command { command: vec!["true".into()], interval_seconds: 1, @@ -195,7 +195,7 @@ impl Environment { /// piqueld derives jobs, running `script` with `volume_access` to the /// `data` volume, mounted writable at `/data`, and stopping `service` /// first when `stop_service` is set. - pub fn job( + pub(crate) fn job( &self, service: &DesiredService, operation: &str, @@ -224,7 +224,7 @@ impl Environment { } /// The `migrate` job's run by `operation`, which prints `migrated`. - pub fn migration(&self, operation: &str) -> piqueld_core::DesiredJobRun { + pub(crate) fn migration(&self, operation: &str) -> piqueld_core::DesiredJobRun { self.job( &self.service("web"), operation, @@ -236,14 +236,14 @@ impl Environment { } /// An adapter and the environment a scenario changes through it. -pub struct Contract { +pub(crate) struct Contract { docker: D, environment: Environment, } impl Contract { /// A scenario of a new environment in `docker`. - pub async fn new(docker: D) -> Self { + pub(crate) async fn new(docker: D) -> Self { let environment = Environment::new(&docker).await; Self { docker, @@ -254,7 +254,7 @@ impl Contract { /// Ensured resources are observed as desired, with their labels, and the /// service converged with healthy running tasks; ensuring them again /// changes nothing Docker reports. - pub async fn ensured_resources_are_observed_and_ensuring_again_changes_nothing(&self) { + pub(crate) async fn ensured_resources_are_observed_and_ensuring_again_changes_nothing(&self) { let service = self.ensure_web(&self.environment).await; let observed = self.converged(&service).await; let network = self.environment.network(); @@ -277,7 +277,7 @@ impl Contract { } /// An updated service is observed with the change once it converged. - pub async fn service_updates_are_observed(&self) { + pub(crate) async fn service_updates_are_observed(&self) { let service = self.ensure_web(&self.environment).await; self.converged(&service).await; let mut updated = service.clone(); @@ -293,7 +293,7 @@ impl Contract { /// Detaching a network changes only the service's networks. A missing /// service or network, or one already detached, counts as detached. - pub async fn detaching_a_network_changes_only_the_service_networks(&self) { + pub(crate) async fn detaching_a_network_changes_only_the_service_networks(&self) { let service = self.ensure_web(&self.environment).await; self.converged(&service).await; let network = self.environment.network(); @@ -325,7 +325,7 @@ impl Contract { /// releases the network, removing it fails with an error the controller /// retries for longer (see [`DockerError::releases_network`]); once that /// succeeds after the network was deleted, it is no longer observed. - pub async fn removing_services_and_networks_is_idempotent(&self) { + pub(crate) async fn removing_services_and_networks_is_idempotent(&self) { let service = self.ensure_web(&self.environment).await; self.converged(&service).await; let network = self.environment.network(); @@ -387,7 +387,7 @@ impl Contract { /// A secret keeps its owner: another environment can neither take it /// over nor remove it, and its owner can remove it once, after which its /// name is free. - pub async fn secrets_are_only_changed_by_their_owner(&self) { + pub(crate) async fn secrets_are_only_changed_by_their_owner(&self) { let name = self.environment.secret_name(); let names = std::slice::from_ref(&name); let owner = self.environment.secret_labels(); @@ -422,7 +422,7 @@ impl Contract { /// Resolving a tag the registry doesn't have is rejected, so the /// controller doesn't retry it. - pub async fn missing_images_are_rejected(&self) { + pub(crate) async fn missing_images_are_rejected(&self) { let error = self .docker .resolve_image(MISSING_IMAGE) @@ -437,7 +437,7 @@ impl Contract { /// A digest-pinned reference resolves to that digest, in [`IMAGE`]'s /// repository as in another one serving the image, as the controller /// pulls a stored digest again. - pub async fn pinned_references_resolve_to_their_digest(&self) { + pub(crate) async fn pinned_references_resolve_to_their_digest(&self) { let image = &self.environment.image; assert_eq!(self.docker.resolve_image(image).await.unwrap(), *image); let aliased = self.aliased(); @@ -446,7 +446,7 @@ impl Contract { /// An image pulled from two repositories is listed once, with both /// repositories' digests, from either image store. - pub async fn an_image_in_two_repositories_lists_both_digests(&self) { + pub(crate) async fn an_image_in_two_repositories_lists_both_digests(&self) { let aliased = self.docker.resolve_image(&self.aliased()).await.unwrap(); let resolved = [self.environment.image.as_str(), aliased.as_str()]; let images = self.docker.images().await.unwrap(); @@ -468,7 +468,7 @@ impl Contract { /// A job's run is missing, without output, until its operation starts /// it, then finishes with its exit code and output. Another operation's /// run replaces it, and removing every run leaves none. - pub async fn job_runs_report_their_status_and_output_per_operation(&self) { + pub(crate) async fn job_runs_report_their_status_and_output_per_operation(&self) { self.ensure_storage(&self.environment).await; let first = self.environment.migration("operation-1"); let second = self.environment.migration("operation-2"); @@ -489,7 +489,9 @@ impl Contract { /// Removing job runs removes only the selected runs of the environment /// the ownership labels name, so other environments keep theirs. - pub async fn removing_job_runs_removes_only_the_selected_runs_of_their_environment(&self) { + pub(crate) async fn removing_job_runs_removes_only_the_selected_runs_of_their_environment( + &self, + ) { let other = Environment::new(&self.docker).await; let ours = self.environment.migration("operation-1"); let theirs = other.migration("operation-1"); @@ -508,7 +510,7 @@ impl Contract { } /// Observing an environment reports none of another's resources. - pub async fn observations_report_only_their_environment(&self) { + pub(crate) async fn observations_report_only_their_environment(&self) { let other = Environment::new(&self.docker).await; assert_ne!(other.app, self.environment.app); let service = self.ensure_web(&self.environment).await; @@ -529,7 +531,7 @@ impl Contract { /// planning sees the foreign volume (and ignores it, as its name isn't /// one this environment wants). That environment's network and service, /// named for their owner, aren't reported. - pub async fn observations_report_volumes_named_like_their_environment(&self) { + pub(crate) async fn observations_report_volumes_named_like_their_environment(&self) { let look_alike = self.environment.look_alike(&self.docker).await; self.ensure_web(&look_alike).await; assert_eq!( @@ -541,7 +543,7 @@ impl Contract { /// A command runs in its service's running task: `true` prints nothing /// and exits with 0. A service the environment doesn't have, or that /// another installation owns, has no task to run one in. - pub async fn commands_run_in_a_running_task_of_their_own_service(&self) { + pub(crate) async fn commands_run_in_a_running_task_of_their_own_service(&self) { let service = self.ensure_web(&self.environment).await; self.converged(&service).await; let instance = self.environment.instance(); @@ -565,7 +567,7 @@ impl Contract { /// A service with no running task, once scaled to zero replicas, has no /// task to run a command in. - pub async fn commands_need_a_running_task(&self) { + pub(crate) async fn commands_need_a_running_task(&self) { let mut service = self.ensure_web(&self.environment).await; self.converged(&service).await; service.replicas = 0; diff --git a/apps/piqueld/tests/support/fixture_dir.rs b/apps/piqueld/tests/support/fixture_dir.rs index b64568448..79f062af4 100644 --- a/apps/piqueld/tests/support/fixture_dir.rs +++ b/apps/piqueld/tests/support/fixture_dir.rs @@ -7,13 +7,13 @@ use std::path::Path; /// checks inspect only the owned fixture tree, never the synthetic root or /// `/tmp` of a Nix build sandbox, whose owners are unmapped in its user /// namespace. -pub fn relative(path: &Path) -> &Path { +pub(crate) fn relative(path: &Path) -> &Path { let cwd = std::env::current_dir().expect("working directory"); path.strip_prefix(cwd).unwrap_or(path) } /// The permission bits of `path`, without following a symlink. -pub fn mode(path: &Path) -> u32 { +pub(crate) fn mode(path: &Path) -> u32 { std::fs::symlink_metadata(path) .expect("fixture metadata") .permissions() @@ -22,7 +22,7 @@ pub fn mode(path: &Path) -> u32 { } /// Sets the permission bits of `path` to `mode`. -pub fn set_mode(path: &Path, mode: u32) { +pub(crate) fn set_mode(path: &Path, mode: u32) { std::fs::set_permissions(path, std::fs::Permissions::from_mode(mode)) .expect("fixture permissions are set"); } diff --git a/apps/piqueld/tests/support/git.rs b/apps/piqueld/tests/support/git.rs index 767d1d78d..05bcd28fa 100644 --- a/apps/piqueld/tests/support/git.rs +++ b/apps/piqueld/tests/support/git.rs @@ -4,13 +4,13 @@ use super::repository::Repository; /// A repository whose `Dockerfile` builds a long-running Alpine image and /// whose `Failfile` fails to build, with the Git source building the former. -pub struct GitBuildFixture { +pub(crate) struct GitBuildFixture { _repository: Repository, pub source: piqueld_core::Source, } impl GitBuildFixture { - pub fn new() -> Self { + pub(crate) fn new() -> Self { let repository = Repository::new(); repository.commit(&[ ( @@ -36,7 +36,7 @@ impl GitBuildFixture { } /// [`Self::source`], building the `Failfile` instead. - pub fn failing_source(&self) -> piqueld_core::Source { + pub(crate) fn failing_source(&self) -> piqueld_core::Source { let mut source = self.source.clone(); let piqueld_core::Source::Git { build, .. } = &mut source else { unreachable!("the fixture builds from Git") @@ -48,7 +48,7 @@ impl GitBuildFixture { } /// Builds the repository root's `Dockerfile`, without arguments or a target. -pub fn dockerfile_build() -> piqueld_core::manifest::Build { +pub(crate) fn dockerfile_build() -> piqueld_core::manifest::Build { piqueld_core::manifest::Build::Docker { dockerfile: "Dockerfile".into(), context: ".".into(), diff --git a/apps/piqueld/tests/support/poll.rs b/apps/piqueld/tests/support/poll.rs index a952fede6..51ceb1286 100644 --- a/apps/piqueld/tests/support/poll.rs +++ b/apps/piqueld/tests/support/poll.rs @@ -4,7 +4,7 @@ use std::time::Duration; /// Runs `check` every `interval` until it returns `Some`, giving up with /// `None` once `timeout` passed. -pub async fn eventually( +pub(crate) async fn eventually( timeout: Duration, interval: Duration, mut check: impl AsyncFnMut() -> Option, diff --git a/apps/piqueld/tests/support/prebuilt.rs b/apps/piqueld/tests/support/prebuilt.rs index c5549f592..d6676eed8 100644 --- a/apps/piqueld/tests/support/prebuilt.rs +++ b/apps/piqueld/tests/support/prebuilt.rs @@ -8,10 +8,10 @@ use piqueld_core::resource::{ use piqueld_core::{ApplicationId, EnvironmentId, InstanceId, NormalizedApplication}; /// The image every fixture service runs. -pub const IMAGE: &str = "ghcr.io/example/notes:1.4.0"; +pub(crate) const IMAGE: &str = "ghcr.io/example/notes:1.4.0"; /// The fixture manifest, as written. -pub fn manifest() -> ApplicationManifest { +pub(crate) fn manifest() -> ApplicationManifest { toml::from_str(include_str!( "../../../../crates/piqueld-core/tests/fixtures/manifests/prebuilt.toml" )) @@ -19,7 +19,7 @@ pub fn manifest() -> ApplicationManifest { } /// The fixture saved as application `id`. -pub fn application(id: &str) -> NormalizedApplication { +pub(crate) fn application(id: &str) -> NormalizedApplication { manifest() .validate() .expect("fixture is valid") @@ -27,7 +27,7 @@ pub fn application(id: &str) -> NormalizedApplication { } /// Resolves every service of `application` to [`IMAGE`], pinned to `a`s. -pub fn resolutions(application: &NormalizedApplication) -> ResolutionSet { +pub(crate) fn resolutions(application: &NormalizedApplication) -> ResolutionSet { let pinned = format!("ghcr.io/example/notes@sha256:{}", "a".repeat(64)); let source = ResolvedSource::parse_image(IMAGE, pinned).expect("fixture digest is valid"); ResolutionSet { @@ -43,7 +43,7 @@ pub fn resolutions(application: &NormalizedApplication) -> ResolutionSet { /// The runtime target of `application`'s environment `environment`, owned by /// installation `instance`, with [`resolutions`]. -pub fn resolve( +pub(crate) fn resolve( application: &NormalizedApplication, environment: &EnvironmentId, instance: &InstanceId, @@ -59,7 +59,7 @@ pub fn resolve( /// [`resolve`] for whichever environment of `application` it is given, as /// `Store::save_application` imports a prepared target. -pub fn resolver<'a>( +pub(crate) fn resolver<'a>( application: &'a NormalizedApplication, instance: &'a InstanceId, ) -> impl Fn(&EnvironmentId) -> ResolvedApplication + Sync + 'a { diff --git a/apps/piqueld/tests/support/repository.rs b/apps/piqueld/tests/support/repository.rs index 91b122d0e..7af74c9f7 100644 --- a/apps/piqueld/tests/support/repository.rs +++ b/apps/piqueld/tests/support/repository.rs @@ -4,13 +4,13 @@ use std::path::Path; /// A Git repository in a temporary directory of its own, committing as a /// fixed test identity. -pub struct Repository { +pub(crate) struct Repository { directory: tempfile::TempDir, } impl Repository { /// An empty repository on `main`. - pub fn new() -> Self { + pub(crate) fn new() -> Self { let repository = Self::empty(); repository.git(&["init", "--initial-branch=main"]); repository @@ -22,12 +22,12 @@ impl Repository { } } - pub fn path(&self) -> &Path { + pub(crate) fn path(&self) -> &Path { self.directory.path() } /// Runs `git` with `args` in the repository and returns its trimmed output. - pub fn git(&self, args: &[&str]) -> String { + pub(crate) fn git(&self, args: &[&str]) -> String { let output = std::process::Command::new("git") .current_dir(self.path()) .args(["-c", "user.name=Test", "-c", "user.email=test@example.com"]) @@ -47,7 +47,7 @@ impl Repository { /// Writes `files` and commits everything, even nothing, returning the /// commit. - pub fn commit(&self, files: &[(&str, &[u8])]) -> String { + pub(crate) fn commit(&self, files: &[(&str, &[u8])]) -> String { for (name, contents) in files { std::fs::write(self.path().join(name), contents).expect("fixture file is written"); } @@ -57,14 +57,14 @@ impl Repository { } /// A clone of this repository, like a developer's working copy. - pub fn working_copy(&self) -> Self { + pub(crate) fn working_copy(&self) -> Self { let clone = Self::empty(); clone.git(&["clone", "-q", &self.path().display().to_string(), "."]); clone } /// A bundle of `branch`, without `excluded` and its history when given. - pub fn bundle(&self, branch: &str, excluded: Option<&str>) -> Vec { + pub(crate) fn bundle(&self, branch: &str, excluded: Option<&str>) -> Vec { let path = self.path().join(".git/fixture.bundle"); let path_argument = path.display().to_string(); let reference = format!("refs/heads/{branch}"); diff --git a/apps/piqueld/tests/support/sqlite.rs b/apps/piqueld/tests/support/sqlite.rs index 067ad7115..985e9f6ce 100644 --- a/apps/piqueld/tests/support/sqlite.rs +++ b/apps/piqueld/tests/support/sqlite.rs @@ -7,7 +7,7 @@ use sqlx::{ /// Opens the SQLite database at `path`, creating it if missing. Like /// `Store::open_unsynced`, it never waits on the disk to sync a commit. -pub async fn connect(path: &std::path::Path) -> SqliteConnection { +pub(crate) async fn connect(path: &std::path::Path) -> SqliteConnection { SqliteConnectOptions::new() .filename(path) .create_if_missing(true) diff --git a/crates/piqueld-client/src/lib.rs b/crates/piqueld-client/src/lib.rs index e17cb9283..53023bde0 100644 --- a/crates/piqueld-client/src/lib.rs +++ b/crates/piqueld-client/src/lib.rs @@ -49,6 +49,10 @@ pub mod system; mod builds; mod client; mod editing; +#[expect( + unreachable_pub, + reason = "Progenitor writes the generated client with `pub` items" +)] mod generated; mod secrets; mod sse; diff --git a/crates/piqueld-config/src/dns/provider/mod.rs b/crates/piqueld-config/src/dns/provider/mod.rs index 6bc9f50e4..8e5eb5f9f 100644 --- a/crates/piqueld-config/src/dns/provider/mod.rs +++ b/crates/piqueld-config/src/dns/provider/mod.rs @@ -496,7 +496,7 @@ pub(crate) mod tests { use tokio::sync::Mutex; /// One request received by [`Recorded`]. - pub struct Request { + pub(crate) struct Request { pub method: Method, /// Path with its query. pub path: String, @@ -506,7 +506,7 @@ pub(crate) mod tests { } impl Request { - pub fn header(&self, name: &str) -> Option<&str> { + pub(crate) fn header(&self, name: &str) -> Option<&str> { self.headers.get(name).and_then(|value| value.to_str().ok()) } } @@ -517,14 +517,14 @@ pub(crate) mod tests { /// A local HTTP server replaying recorded provider responses by method and /// path, and recording what it received. - pub struct Recorded { + pub(crate) struct Recorded { pub url: String, requests: Arc>>, _server: tokio::task::JoinHandle<()>, } impl Recorded { - pub async fn serve(responses: Responses) -> Self { + pub(crate) async fn serve(responses: Responses) -> Self { let requests = Arc::new(Mutex::new(Vec::new())); let state = (Arc::new(responses), Arc::clone(&requests)); let app = axum::Router::new().fallback( @@ -565,7 +565,7 @@ pub(crate) mod tests { } /// Requests received so far, in order. - pub async fn requests(&self) -> Vec { + pub(crate) async fn requests(&self) -> Vec { std::mem::take(&mut *self.requests.lock().await) } } diff --git a/crates/piqueld-docker/build/probe.rs b/crates/piqueld-docker/build/probe.rs index 65a0b5055..3c7e7c6f1 100644 --- a/crates/piqueld-docker/build/probe.rs +++ b/crates/piqueld-docker/build/probe.rs @@ -12,7 +12,7 @@ use piqueld_build::NestedCargo; /// `DEP_PIQUELD_PROBE_DIR`, so this works from the published crates too. /// docs.rs builds have neither the musl target nor the network, and embed an /// empty file instead. -pub fn embed(manifest_dir: &Path) -> Result<(), Box> { +pub(crate) fn embed(manifest_dir: &Path) -> Result<(), Box> { let copy = crate::out_dir()?.join("piqueld-probe"); println!("cargo:rustc-env=PIQUELD_PROBE_BINARY={}", copy.display()); if env::var_os("DOCS_RS").is_some() { diff --git a/crates/piqueld-store/src/auth/access.rs b/crates/piqueld-store/src/auth/access.rs index fcdbea80c..3a0b2cc58 100644 --- a/crates/piqueld-store/src/auth/access.rs +++ b/crates/piqueld-store/src/auth/access.rs @@ -11,7 +11,7 @@ use sqlx::SqliteConnection; /// Who a set of grants belongs to. #[derive(Clone, Copy, Debug)] -pub enum Holder<'a> { +pub(crate) enum Holder<'a> { /// An account's own access. User(&'a str), /// The grants a scoped credential is limited to. @@ -226,7 +226,7 @@ impl Visibility { clippy::expect_used, reason = "A list of strings always serializes to JSON." )] -pub fn scope_json(scope: &Scope) -> Option { +pub(crate) fn scope_json(scope: &Scope) -> Option { scope.applications().map(|ids| { serde_json::to_string(&ids.iter().map(ApplicationId::as_str).collect::>()) .expect("application IDs are serialized as a list of strings") @@ -355,7 +355,7 @@ impl Holder<'_> { } /// Reads the holder's grants. - pub async fn grants(self, db: &mut SqliteConnection) -> Result { + pub(crate) async fn grants(self, db: &mut SqliteConnection) -> Result { let (user, credential, invitation) = self.ids(); let rows = sqlx::query!( "SELECT permission,application_id FROM auth_grants WHERE user_id IS ?1 AND credential_id IS ?2 AND invitation_id IS ?3", @@ -382,7 +382,7 @@ impl Holder<'_> { /// Replaces the holder's grants. A grant on an unknown application fails /// with `NotFound`. - pub async fn replace( + pub(crate) async fn replace( self, db: &mut SqliteConnection, grants: &Grants, @@ -421,7 +421,7 @@ impl Holder<'_> { } /// Adds `grants` to the holder's existing grants. - pub async fn extend( + pub(crate) async fn extend( self, db: &mut SqliteConnection, grants: &Grants, diff --git a/crates/piqueld-store/src/auth/lineage/mod.rs b/crates/piqueld-store/src/auth/lineage/mod.rs index 2c697072e..ad07fe190 100644 --- a/crates/piqueld-store/src/auth/lineage/mod.rs +++ b/crates/piqueld-store/src/auth/lineage/mod.rs @@ -85,7 +85,7 @@ impl std::fmt::Display for Revoked { /// A credential, invitation or passkey, as a node of the issuance tree. #[derive(Clone, Copy, Debug, PartialEq, Eq)] -pub enum Issued<'a> { +pub(super) enum Issued<'a> { /// A browser session, CLI login or API token, by ID. Credential(&'a str), /// An account invitation or enrollment link, by ID. diff --git a/tools/xtask/src/boundary.rs b/tools/xtask/src/boundary.rs index faa322dec..1465bb079 100644 --- a/tools/xtask/src/boundary.rs +++ b/tools/xtask/src/boundary.rs @@ -67,7 +67,7 @@ const BOUNDARIES: [Boundary; 4] = [ }, ]; -pub fn check(workspace: &Workspace) -> Result { +pub(crate) fn check(workspace: &Workspace) -> Result { let mut crossed = false; for boundary in &BOUNDARIES { let output = workspace diff --git a/tools/xtask/src/check_changed/mod.rs b/tools/xtask/src/check_changed/mod.rs index 3c216c4f9..b5d779254 100644 --- a/tools/xtask/src/check_changed/mod.rs +++ b/tools/xtask/src/check_changed/mod.rs @@ -30,7 +30,7 @@ const BUILDS: [(&str, &str); 1] = [("piqueld", "piqueld-ui")]; /// Runs the checks the change since the merge base of HEAD and `base` needs, /// and prints a summary of each check CI could run. -pub fn run(workspace: &Workspace, base: &str) -> Result { +pub(crate) fn run(workspace: &Workspace, base: &str) -> Result { let filters = Filters::load(workspace.root())?; let (merge_base, paths) = workspace.changed_paths(base)?; if paths.is_empty() { diff --git a/tools/xtask/src/coverage.rs b/tools/xtask/src/coverage.rs index b8a9bc88b..fd7ab605c 100644 --- a/tools/xtask/src/coverage.rs +++ b/tools/xtask/src/coverage.rs @@ -17,7 +17,7 @@ use crate::process::exit_code; /// Runs the tests `just test` runs under coverage instrumentation, writes the /// HTML report to target/llvm-cov/html, and prints each crate's totals. /// `args` go on to `cargo nextest run`. -pub fn run(workspace: &Workspace, args: &[String]) -> Result { +pub(crate) fn run(workspace: &Workspace, args: &[String]) -> Result { let status = workspace .cargo() .args([ diff --git a/tools/xtask/src/dev/mod.rs b/tools/xtask/src/dev/mod.rs index dc27bfccd..52b055f77 100644 --- a/tools/xtask/src/dev/mod.rs +++ b/tools/xtask/src/dev/mod.rs @@ -53,7 +53,7 @@ const DATA_LABEL: &str = "io.piqueld.dev.data"; const RUNTIME_LABEL: &str = "io.piqueld.dev.runtime"; #[derive(Subcommand)] -pub enum Command { +pub(crate) enum Command { /// Watch the sources, rebuilding and restarting the daemon on every change. Run, /// Run in the background, then wait until ready. @@ -91,7 +91,7 @@ pub enum Command { } impl Command { - pub async fn run(self, workspace: Workspace) -> Result { + pub(crate) async fn run(self, workspace: Workspace) -> Result { match self { Self::Config { force } => { if !Instance::configure(&workspace, force)? { @@ -183,7 +183,7 @@ struct State { } /// This worktree's instance, as configured by piqueld.local.toml. -pub struct Instance { +pub(crate) struct Instance { workspace: Workspace, config: Config, } diff --git a/tools/xtask/src/dist.rs b/tools/xtask/src/dist.rs index d23c8ea09..861975fbe 100644 --- a/tools/xtask/src/dist.rs +++ b/tools/xtask/src/dist.rs @@ -96,7 +96,7 @@ impl Archive { /// Builds the binaries for [`TARGET`], with the embedded dashboard, then /// writes their [`Archive`]. -pub fn run(workspace: &Workspace) -> Result { +pub(crate) fn run(workspace: &Workspace) -> Result { let status = workspace .cargo() .args(["build", "--release", "--locked", "--target", TARGET]) diff --git a/tools/xtask/src/docker.rs b/tools/xtask/src/docker.rs index da7c35928..f7fbd16ec 100644 --- a/tools/xtask/src/docker.rs +++ b/tools/xtask/src/docker.rs @@ -33,7 +33,7 @@ const REGISTRY_MIRROR: &str = "https://mirror.gcr.io"; const DIND_SOCKET_DIR: &str = "/piqueld-socket"; /// A Docker engine client, connected to the host's engine by [`Engine::host`]. -pub struct Engine(Docker); +pub(crate) struct Engine(Docker); impl Deref for Engine { type Target = Docker; @@ -47,7 +47,7 @@ impl Engine { /// Connects to the engine the Docker CLI uses: `DOCKER_HOST`, else the /// current context, else `/var/run/docker.sock`. It must be local, since /// xtask bind-mounts host directories into its containers. - pub async fn host() -> Result { + pub(crate) async fn host() -> Result { let endpoint = match std::env::var("DOCKER_HOST") { Ok(host) => host, Err(_) => Self::context_endpoint()?, @@ -82,7 +82,7 @@ impl Engine { } } - pub fn dind_image() -> String { + pub(crate) fn dind_image() -> String { std::env::var("PIQUELD_DIND_IMAGE").unwrap_or_else(|_| DIND_IMAGE.to_owned()) } @@ -90,7 +90,7 @@ impl Engine { /// listens in `socket_dir`, a private host directory, as `docker.sock`, /// and pulls through [`REGISTRY_MIRROR`]. `binds` mounts more host paths /// or volumes. - pub fn dind_container( + pub(crate) fn dind_container( image: String, socket_dir: impl Display, binds: impl IntoIterator, @@ -117,7 +117,7 @@ impl Engine { } /// Pulls `image` unless the engine has it. - pub async fn pull_missing(&self, image: &str) -> Result<()> { + pub(crate) async fn pull_missing(&self, image: &str) -> Result<()> { if self.inspect_image(image).await.is_err() { let options = CreateImageOptionsBuilder::new().from_image(image).build(); self.create_image(Some(options), None, None) @@ -129,7 +129,11 @@ impl Engine { } /// Creates and starts a container, returning its ID. - pub async fn launch(&self, name: Option<&str>, body: ContainerCreateBody) -> Result { + pub(crate) async fn launch( + &self, + name: Option<&str>, + body: ContainerCreateBody, + ) -> Result { let image = body.image.clone().unwrap_or_default(); let options = name.map(|name| CreateContainerOptionsBuilder::new().name(name).build()); let id = self @@ -144,7 +148,7 @@ impl Engine { } /// Runs a container to completion, then removes it. - pub async fn run_once(&self, body: ContainerCreateBody) -> Result<()> { + pub(crate) async fn run_once(&self, body: ContainerCreateBody) -> Result<()> { let id = self.launch(None, body).await?; let result = self .wait_container(&id, None::) @@ -156,7 +160,7 @@ impl Engine { } /// Removes a container and its anonymous volumes, if it exists. - pub async fn remove(&self, container: &str) -> Result<()> { + pub(crate) async fn remove(&self, container: &str) -> Result<()> { let options = RemoveContainerOptionsBuilder::new() .force(true) .v(true) @@ -168,7 +172,7 @@ impl Engine { /// The outcome of a request about a container or volume, with one that /// doesn't exist as `None`. - pub fn found( + pub(crate) fn found( result: Result, ) -> Result, bollard::errors::Error> { match result { @@ -180,7 +184,7 @@ impl Engine { } } - pub async fn running(&self, container: &str) -> Result { + pub(crate) async fn running(&self, container: &str) -> Result { let state = self .inspect_container(container, None::) .await @@ -207,7 +211,7 @@ impl Engine { } /// Prints a container's output, for diagnosing startup failures. - pub async fn print_logs(&self, container: &str) { + pub(crate) async fn print_logs(&self, container: &str) { let options = LogsOptionsBuilder::new().stdout(true).stderr(true).build(); let mut logs = self.logs(container, Some(options)); while let Some(Ok(output)) = logs.next().await { @@ -217,7 +221,7 @@ impl Engine { /// Waits up to 60 seconds for the Docker-in-Docker engine in `container`, /// then gives its socket to the host user, in their private directory. - pub async fn wait_for_dind(&self, container: &str) -> Result<()> { + pub(crate) async fn wait_for_dind(&self, container: &str) -> Result<()> { let ready = format!( "docker -H unix://{DIND_SOCKET_DIR}/docker.sock info >/dev/null 2>&1 \ && chown {uid} {DIND_SOCKET_DIR}/docker.sock", @@ -234,7 +238,7 @@ impl Engine { /// Waits up to 60 seconds for `container`, on the host network, to accept /// connections on `port` on loopback. - pub async fn wait_for_port(&self, container: &str, port: u16) -> Result<()> { + pub(crate) async fn wait_for_port(&self, container: &str, port: u16) -> Result<()> { let what = format!("a listener on port {port}"); self.wait_until(container, &what, Duration::from_millis(250), || async { TcpStream::connect((Ipv4Addr::LOCALHOST, port)) diff --git a/tools/xtask/src/docker_test.rs b/tools/xtask/src/docker_test.rs index 3f4b8c2e2..8b0ed0036 100644 --- a/tools/xtask/src/docker_test.rs +++ b/tools/xtask/src/docker_test.rs @@ -18,7 +18,7 @@ use crate::process::{Job, Shutdown, exit_code}; /// A group of Docker integration tests, run by one nextest invocation. #[derive(Clone, Copy, PartialEq, Eq, clap::ValueEnum)] -pub enum Suite { +pub(crate) enum Suite { /// The daemon library's `ingress_caddy` tests, against Caddy, Pebble and /// challtestsrv in the engine. // They reach them on the ports of `PUBLISHED`. @@ -43,7 +43,7 @@ impl Suite { /// Where the engine keeps images. Docker reports the same images /// differently from each store, and hosts use both. #[derive(Clone, Copy, Default, PartialEq, Eq, clap::ValueEnum)] -pub enum Store { +pub(crate) enum Store { /// The classic image store, on the overlay2 graph driver: older engines' /// default, and engines upgraded from them. #[default] @@ -55,7 +55,7 @@ pub enum Store { /// Runs `suite`, or every suite, against one engine keeping images in /// `store`. `partition`, nextest's `--partition` such as `count:1/2`, selects /// a shard of each suite's tests. -pub async fn run( +pub(crate) async fn run( workspace: &Workspace, suite: Option, partition: Option<&str>, diff --git a/tools/xtask/src/metadata.rs b/tools/xtask/src/metadata.rs index df3b72db5..6ef735a2f 100644 --- a/tools/xtask/src/metadata.rs +++ b/tools/xtask/src/metadata.rs @@ -9,13 +9,13 @@ use crate::Workspace; /// The workspace's crates, as `cargo metadata --no-deps` lists them. #[derive(Deserialize)] -pub struct Metadata { +pub(crate) struct Metadata { pub packages: Vec, } /// A workspace crate. #[derive(Deserialize)] -pub struct Package { +pub(crate) struct Package { pub name: String, pub manifest_path: PathBuf, /// Of every kind: normal, development and build. @@ -25,19 +25,19 @@ pub struct Package { /// A crate a package depends on, named as its package is. #[derive(Deserialize)] -pub struct Dependency { +pub(crate) struct Dependency { pub name: String, } /// A package's library, binary, test, example, benchmark or build script. #[derive(Deserialize)] -pub struct Target { +pub(crate) struct Target { /// Such as `lib`, `rlib`, `bin` or `test`. pub kind: Vec, } impl Workspace { - pub fn metadata(&self) -> Result { + pub(crate) fn metadata(&self) -> Result { self.cargo_json(&["metadata", "--locked", "--no-deps", "--format-version", "1"]) } } @@ -45,7 +45,7 @@ impl Workspace { impl Metadata { /// The crate whose directory holds `file`, an absolute path: the deepest, /// since a crate's directory may contain another's. - pub fn package_of(&self, file: &Path) -> Option<&Package> { + pub(crate) fn package_of(&self, file: &Path) -> Option<&Package> { self.packages .iter() .filter_map(|package| Some((package, package.manifest_path.parent()?))) @@ -57,7 +57,7 @@ impl Metadata { impl Package { /// Whether the crate has a library, which doc tests need. - pub fn has_library(&self) -> bool { + pub(crate) fn has_library(&self) -> bool { self.targets .iter() .flat_map(|target| &target.kind) diff --git a/tools/xtask/src/playwright.rs b/tools/xtask/src/playwright.rs index fa270e83b..e39a98b3d 100644 --- a/tools/xtask/src/playwright.rs +++ b/tools/xtask/src/playwright.rs @@ -11,7 +11,7 @@ use crate::Workspace; use crate::docker::Engine; use crate::process::{Job, Shutdown, exit_code}; -pub async fn run(workspace: &Workspace, args: &[String]) -> Result { +pub(crate) async fn run(workspace: &Workspace, args: &[String]) -> Result { let tests = workspace.root().join("tests/playwright"); let package: serde_json::Value = serde_json::from_slice( &std::fs::read(tests.join("package.json")).context("read package.json")?, diff --git a/tools/xtask/src/process.rs b/tools/xtask/src/process.rs index 8162c3701..67ca642ef 100644 --- a/tools/xtask/src/process.rs +++ b/tools/xtask/src/process.rs @@ -14,14 +14,14 @@ use tokio::signal::unix::{SignalKind, signal}; /// xtask, which stops the whole group, so no build script, test, or daemon /// child outlives it. A job dropped without being waited for, such as on an /// error, is killed. -pub struct Job { +pub(crate) struct Job { name: String, child: Child, group: Pid, } impl Job { - pub fn spawn(command: &mut Command) -> Result { + pub(crate) fn spawn(command: &mut Command) -> Result { let name = command .as_std() .get_program() @@ -37,7 +37,7 @@ impl Job { Ok(Self { name, child, group }) } - pub async fn wait(&mut self) -> Result { + pub(crate) async fn wait(&mut self) -> Result { self.child .wait() .await @@ -46,7 +46,7 @@ impl Job { /// Waits for the job to exit. When `limit` elapses or a shutdown signal /// arrives first, stops it, allowing 30 seconds to exit, and fails. - pub async fn finish( + pub(crate) async fn finish( mut self, limit: Option, shutdown: &mut Shutdown, @@ -68,7 +68,7 @@ impl Job { /// Asks the group to terminate, kills it after `grace`, and returns the /// leader's status. Descendants outliving the leader are killed too. - pub async fn stop(mut self, grace: Duration) -> Result { + pub(crate) async fn stop(mut self, grace: Duration) -> Result { self.signal(Signal::TERM); let status = if let Ok(status) = tokio::time::timeout(grace, self.child.wait()).await { status? @@ -87,7 +87,7 @@ impl Job { /// Copies the job's piped stderr to ours and, without color codes, to /// `log`, until the job closes it. - pub fn tee_stderr(&mut self, mut log: std::fs::File) -> Result<()> { + pub(crate) fn tee_stderr(&mut self, mut log: std::fs::File) -> Result<()> { let stderr = self.child.stderr.take().context("stderr is not piped")?; tokio::spawn(async move { let mut reader = BufReader::new(stderr); @@ -125,7 +125,7 @@ fn strip_color(line: &[u8]) -> Vec { } /// The exit code that reports `status` to our caller. -pub fn exit_code(status: ExitStatus) -> ExitCode { +pub(crate) fn exit_code(status: ExitStatus) -> ExitCode { status .code() .and_then(|code| u8::try_from(code).ok()) @@ -134,7 +134,7 @@ pub fn exit_code(status: ExitStatus) -> ExitCode { /// The trimmed standard output of `name`, a finished command, or an error /// with its status and standard error when it failed. -pub fn checked_stdout(name: &str, output: Output) -> Result { +pub(crate) fn checked_stdout(name: &str, output: Output) -> Result { ensure!( output.status.success(), "{name} failed ({}): {}", @@ -149,14 +149,14 @@ pub fn checked_stdout(name: &str, output: Output) -> Result { /// SIGINT, SIGTERM, and SIGHUP, each asking xtask to stop its jobs and clean /// up before exiting. -pub struct Shutdown { +pub(crate) struct Shutdown { interrupt: tokio::signal::unix::Signal, terminate: tokio::signal::unix::Signal, hangup: tokio::signal::unix::Signal, } impl Shutdown { - pub fn listen() -> Result { + pub(crate) fn listen() -> Result { let listen = |kind| signal(kind).context("listen for signals"); Ok(Self { interrupt: listen(SignalKind::interrupt())?, @@ -166,7 +166,7 @@ impl Shutdown { } /// Resolves when a shutdown signal arrives. - pub async fn requested(&mut self) { + pub(crate) async fn requested(&mut self) { tokio::select! { _ = self.interrupt.recv() => {} _ = self.terminate.recv() => {} diff --git a/tools/xtask/src/publish.rs b/tools/xtask/src/publish.rs index 5fd8dcb0a..a2cbf672f 100644 --- a/tools/xtask/src/publish.rs +++ b/tools/xtask/src/publish.rs @@ -147,7 +147,7 @@ impl Release<'_> { } /// Runs [`Release::run`] for `cargo xtask release`, for the workspace version. -pub fn release(workspace: &Workspace, dry_run: bool) -> Result { +pub(crate) fn release(workspace: &Workspace, dry_run: bool) -> Result { Release { workspace, version: workspace.version()?, @@ -157,7 +157,7 @@ pub fn release(workspace: &Workspace, dry_run: bool) -> Result { } /// Runs [`publish`] for `cargo xtask publish`. -pub fn run(workspace: &Workspace, args: &[String]) -> Result { +pub(crate) fn run(workspace: &Workspace, args: &[String]) -> Result { publish(workspace, args).map(exit_code) }