@@ -4,10 +4,13 @@ use std::{
44 path:: { Path , PathBuf } ,
55 str:: FromStr ,
66 sync:: LazyLock ,
7+ time:: Duration ,
78} ;
89
910use dunce:: canonicalize;
1011use fs_err:: tokio as tokio_fs;
12+ use pixi_build_backend_passthrough:: { BackendEvent , ObservableBackend , PassthroughBackend } ;
13+ use pixi_build_frontend:: BackendOverride ;
1114use pixi_cli:: run:: { self , Args } ;
1215use pixi_cli:: {
1316 LockFileUsageConfig ,
@@ -43,6 +46,78 @@ use crate::common::{
4346use crate :: setup_tracing;
4447use pixi_test_utils:: { MockRepoData , Package } ;
4548
49+ fn count_build_events ( events : & [ BackendEvent ] ) -> usize {
50+ events
51+ . iter ( )
52+ . filter ( |event| matches ! ( event, BackendEvent :: CondaBuildV1Called ) )
53+ . count ( )
54+ }
55+
56+ #[ tokio:: test]
57+ async fn install_with_relative_exclude_newer_does_not_rebuild_unchanged_source_packages ( ) {
58+ setup_tracing ( ) ;
59+
60+ let ( instantiator, mut observer) =
61+ ObservableBackend :: instantiator ( PassthroughBackend :: instantiator ( ) ) ;
62+ let backend_override = BackendOverride :: from_memory ( instantiator) ;
63+ let pixi = PixiControl :: new ( )
64+ . unwrap ( )
65+ . with_backend_override ( backend_override) ;
66+
67+ let source_dir = pixi. workspace_path ( ) . join ( "my-package" ) ;
68+ fs_err:: create_dir_all ( & source_dir) . unwrap ( ) ;
69+
70+ fs_err:: write (
71+ source_dir. join ( "pixi.toml" ) ,
72+ r#"
73+ [package]
74+ name = "my-package"
75+ version = "0.0.0"
76+
77+ [package.build]
78+ backend = { name = "in-memory", version = "0.1.0" }
79+ "# ,
80+ )
81+ . unwrap ( ) ;
82+
83+ fs_err:: write (
84+ pixi. manifest_path ( ) ,
85+ format ! (
86+ r#"
87+ [workspace]
88+ name = "my-package"
89+ channels = []
90+ # exclude-newer = "7d"
91+ platforms = ["{}"]
92+ preview = ["pixi-build"]
93+
94+ [dependencies]
95+ my-package = {{ path = "./my-package" }}
96+ "# ,
97+ Platform :: current( )
98+ ) ,
99+ )
100+ . unwrap ( ) ;
101+
102+ pixi. install ( ) . await . unwrap ( ) ;
103+ let first_build_events = observer. events ( ) ;
104+ assert_eq ! (
105+ count_build_events( & first_build_events) ,
106+ 1 ,
107+ "first install should build the source package once"
108+ ) ;
109+
110+ tokio:: time:: sleep ( Duration :: from_millis ( 10 ) ) . await ;
111+
112+ pixi. install ( ) . await . unwrap ( ) ;
113+ let second_build_events = observer. events ( ) ;
114+ assert_eq ! (
115+ count_build_events( & second_build_events) ,
116+ 0 ,
117+ "second install should reuse the existing build cache for an unchanged source package"
118+ ) ;
119+ }
120+
46121/// Should add a python version to the environment and lock file that matches
47122/// the specified version and run it
48123#[ tokio:: test]
0 commit comments