From 749d9f423ad39ac71cc79d11013342d65b452059 Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Mon, 29 Jun 2026 18:55:09 -0500 Subject: [PATCH 1/3] Warn when build cache is inside source --- crates/uv/src/commands/build_frontend.rs | 8 +++-- crates/uv/tests/build/cache.rs | 40 ++++++++++++++++-------- 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/crates/uv/src/commands/build_frontend.rs b/crates/uv/src/commands/build_frontend.rs index 84d97b1d9344a..05c73fb5ee8c4 100644 --- a/crates/uv/src/commands/build_frontend.rs +++ b/crates/uv/src/commands/build_frontend.rs @@ -39,6 +39,7 @@ use uv_requirements::RequirementsSource; use uv_resolver::{ExcludeNewer, FlatIndex}; use uv_settings::PythonInstallMirrors; use uv_types::{AnyErrorBuild, BuildContext, BuildStack, HashStrategy, SourceTreeEditablePolicy}; +use uv_warnings::warn_user; use uv_workspace::pyproject::ExtraBuildDependencies; use uv_workspace::{DiscoveryOptions, Workspace, WorkspaceCache, WorkspaceError}; @@ -372,16 +373,17 @@ async fn build_impl( }; // Build backends can include arbitrary files from the source directory in the distribution. - // Reject an active cache within the source to avoid including cache contents in the build. + // Warn if the active cache is within the source since cache contents may be included in the + // build. for source in &packages { if let Source::Directory(source_dir) = &source.source && is_path_within(cache.root(), source_dir) { - return Err(anyhow::anyhow!( + warn_user!( "The cache directory `{}` is inside the build source directory `{}`", cache.root().user_display(), source_dir.user_display() - )); + ); } } diff --git a/crates/uv/tests/build/cache.rs b/crates/uv/tests/build/cache.rs index 30ce8ad9ff3cf..9546124bae832 100644 --- a/crates/uv/tests/build/cache.rs +++ b/crates/uv/tests/build/cache.rs @@ -7,10 +7,10 @@ use std::process::Command; use uv_fs::create_symlink; use uv_test::{get_bin, uv_snapshot}; -/// When the active cache directory is inside an explicit build source, we should error before -/// invoking the build backend or creating the output directory. +/// When the active cache directory is inside an explicit build source, we should warn and continue +/// the build. #[test] -fn build_rejects_cache_inside_source() -> Result<()> { +fn build_warns_cache_inside_source() -> Result<()> { let mut context = uv_test::test_context!("3.12"); let project = context.temp_dir.child("project"); @@ -24,6 +24,9 @@ fn build_rejects_cache_inside_source() -> Result<()> { [build-system] requires = ["uv_build>=0.5.15,<10000"] build-backend = "uv_build" + + [tool.uv.build-backend] + source-exclude = [".uv-cache"] "#, )?; project.child("src/project/__init__.py").touch()?; @@ -31,24 +34,28 @@ fn build_rejects_cache_inside_source() -> Result<()> { context.cache_dir = project.child(".uv-cache"); uv_snapshot!(context.filters(), context.build().arg("--sdist").arg("project"), @" - success: false - exit_code: 2 + success: true + exit_code: 0 ----- stdout ----- ----- stderr ----- - error: The cache directory `project/.uv-cache` is inside the build source directory `project` + warning: The cache directory `project/.uv-cache` is inside the build source directory `project` + Building source distribution (uv build backend)... + Successfully built project/dist/project-0.1.0.tar.gz "); - project.child("dist").assert(predicate::path::missing()); + project + .child("dist/project-0.1.0.tar.gz") + .assert(predicate::path::is_file()); Ok(()) } -/// When the canonical cache directory is inside an explicit build source, we should error even if +/// When the canonical cache directory is inside an explicit build source, we should warn even if /// the configured cache path itself is outside the source. #[test] #[cfg(unix)] -fn build_rejects_symlinked_cache_inside_source() -> Result<()> { +fn build_warns_symlinked_cache_inside_source() -> Result<()> { let context = uv_test::test_context!("3.12"); let project = context.temp_dir.child("project"); @@ -62,6 +69,9 @@ fn build_rejects_symlinked_cache_inside_source() -> Result<()> { [build-system] requires = ["uv_build>=0.5.15,<10000"] build-backend = "uv_build" + + [tool.uv.build-backend] + source-exclude = [".uv-cache"] "#, )?; project.child("src/project/__init__.py").touch()?; @@ -82,15 +92,19 @@ fn build_rejects_symlinked_cache_inside_source() -> Result<()> { command.current_dir(context.temp_dir.path()); uv_snapshot!(context.filters(), command, @" - success: false - exit_code: 2 + success: true + exit_code: 0 ----- stdout ----- ----- stderr ----- - error: The cache directory `cache-link` is inside the build source directory `project` + warning: The cache directory `cache-link` is inside the build source directory `project` + Building source distribution (uv build backend)... + Successfully built project/dist/project-0.1.0.tar.gz "); - project.child("dist").assert(predicate::path::missing()); + project + .child("dist/project-0.1.0.tar.gz") + .assert(predicate::path::is_file()); Ok(()) } From a383f59503e5feb63b6ce57bebb830487b4da881 Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Mon, 29 Jun 2026 19:00:37 -0500 Subject: [PATCH 2/3] Clarify build cache warning --- crates/uv/src/commands/build_frontend.rs | 2 +- crates/uv/tests/build/cache.rs | 10 ++-------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/crates/uv/src/commands/build_frontend.rs b/crates/uv/src/commands/build_frontend.rs index 05c73fb5ee8c4..1bfccd07e3549 100644 --- a/crates/uv/src/commands/build_frontend.rs +++ b/crates/uv/src/commands/build_frontend.rs @@ -380,7 +380,7 @@ async fn build_impl( && is_path_within(cache.root(), source_dir) { warn_user!( - "The cache directory `{}` is inside the build source directory `{}`", + "The cache directory `{}` is inside the build source directory `{}` and may be included in the distributions", cache.root().user_display(), source_dir.user_display() ); diff --git a/crates/uv/tests/build/cache.rs b/crates/uv/tests/build/cache.rs index 9546124bae832..d0588e8e299b8 100644 --- a/crates/uv/tests/build/cache.rs +++ b/crates/uv/tests/build/cache.rs @@ -24,9 +24,6 @@ fn build_warns_cache_inside_source() -> Result<()> { [build-system] requires = ["uv_build>=0.5.15,<10000"] build-backend = "uv_build" - - [tool.uv.build-backend] - source-exclude = [".uv-cache"] "#, )?; project.child("src/project/__init__.py").touch()?; @@ -39,7 +36,7 @@ fn build_warns_cache_inside_source() -> Result<()> { ----- stdout ----- ----- stderr ----- - warning: The cache directory `project/.uv-cache` is inside the build source directory `project` + warning: The cache directory `project/.uv-cache` is inside the build source directory `project` and may be included in the distributions Building source distribution (uv build backend)... Successfully built project/dist/project-0.1.0.tar.gz "); @@ -69,9 +66,6 @@ fn build_warns_symlinked_cache_inside_source() -> Result<()> { [build-system] requires = ["uv_build>=0.5.15,<10000"] build-backend = "uv_build" - - [tool.uv.build-backend] - source-exclude = [".uv-cache"] "#, )?; project.child("src/project/__init__.py").touch()?; @@ -97,7 +91,7 @@ fn build_warns_symlinked_cache_inside_source() -> Result<()> { ----- stdout ----- ----- stderr ----- - warning: The cache directory `cache-link` is inside the build source directory `project` + warning: The cache directory `cache-link` is inside the build source directory `project` and may be included in the distributions Building source distribution (uv build backend)... Successfully built project/dist/project-0.1.0.tar.gz "); From 85505515686d845b653880a83d8a48600c60bb15 Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Mon, 29 Jun 2026 19:01:50 -0500 Subject: [PATCH 3/3] Refine build cache warning wording --- crates/uv/src/commands/build_frontend.rs | 2 +- crates/uv/tests/build/cache.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/uv/src/commands/build_frontend.rs b/crates/uv/src/commands/build_frontend.rs index 1bfccd07e3549..fdcdc349e72b7 100644 --- a/crates/uv/src/commands/build_frontend.rs +++ b/crates/uv/src/commands/build_frontend.rs @@ -380,7 +380,7 @@ async fn build_impl( && is_path_within(cache.root(), source_dir) { warn_user!( - "The cache directory `{}` is inside the build source directory `{}` and may be included in the distributions", + "The cache directory `{}` is inside the build source directory `{}` and may be included in distributions", cache.root().user_display(), source_dir.user_display() ); diff --git a/crates/uv/tests/build/cache.rs b/crates/uv/tests/build/cache.rs index d0588e8e299b8..f3e09fef53c6f 100644 --- a/crates/uv/tests/build/cache.rs +++ b/crates/uv/tests/build/cache.rs @@ -36,7 +36,7 @@ fn build_warns_cache_inside_source() -> Result<()> { ----- stdout ----- ----- stderr ----- - warning: The cache directory `project/.uv-cache` is inside the build source directory `project` and may be included in the distributions + warning: The cache directory `project/.uv-cache` is inside the build source directory `project` and may be included in distributions Building source distribution (uv build backend)... Successfully built project/dist/project-0.1.0.tar.gz "); @@ -91,7 +91,7 @@ fn build_warns_symlinked_cache_inside_source() -> Result<()> { ----- stdout ----- ----- stderr ----- - warning: The cache directory `cache-link` is inside the build source directory `project` and may be included in the distributions + warning: The cache directory `cache-link` is inside the build source directory `project` and may be included in distributions Building source distribution (uv build backend)... Successfully built project/dist/project-0.1.0.tar.gz ");