@@ -34,11 +34,10 @@ pub(crate) const LOG_FILENAME: &str = "ghciwatch.json";
3434/// Builder for [`GhciWatch`].
3535pub struct GhciWatchBuilder {
3636 project_directory : PathBuf ,
37- copy_extra : Vec < PathBuf > ,
3837 ghciwatch_args : Vec < OsString > ,
39- make_args : Vec < String > ,
4038 ghc_args : Vec < String > ,
4139 cabal_args : Vec < String > ,
40+ cabal_target : String ,
4241 #[ allow( clippy:: type_complexity) ]
4342 before_start : Option < Box < dyn FnOnce ( PathBuf ) -> BoxFuture < ' static , miette:: Result < ( ) > > + Send > > ,
4443 default_timeout : Duration ,
@@ -51,12 +50,10 @@ impl GhciWatchBuilder {
5150 pub fn new ( project_directory : impl AsRef < Path > ) -> Self {
5251 Self {
5352 project_directory : project_directory. as_ref ( ) . to_owned ( ) ,
54- // Gonna need this for the `Makefile` in `tests/data/simple`.
55- copy_extra : vec ! [ "tests/data/common" . into( ) ] ,
5653 ghciwatch_args : Default :: default ( ) ,
5754 ghc_args : Default :: default ( ) ,
58- make_args : Default :: default ( ) ,
5955 cabal_args : Default :: default ( ) ,
56+ cabal_target : "my-simple-package" . into ( ) ,
6057 before_start : None ,
6158 default_timeout : Duration :: from_secs ( 10 ) ,
6259 startup_timeout : Duration :: from_secs ( 60 ) ,
@@ -90,19 +87,6 @@ impl GhciWatchBuilder {
9087 self
9188 }
9289
93- /// Add an argument to the `make` invocations.
94- pub fn with_make_arg ( mut self , arg : impl AsRef < str > ) -> Self {
95- self . make_args . push ( arg. as_ref ( ) . to_owned ( ) ) ;
96- self
97- }
98-
99- /// Add multiple arguments to the `make` invocations.
100- pub fn with_make_args ( mut self , args : impl IntoIterator < Item = impl AsRef < str > > ) -> Self {
101- self . make_args
102- . extend ( args. into_iter ( ) . map ( |s| s. as_ref ( ) . to_owned ( ) ) ) ;
103- self
104- }
105-
10690 /// Add an argument to the `cabal` invocations.
10791 pub fn with_cabal_arg ( mut self , arg : impl AsRef < str > ) -> Self {
10892 self . cabal_args . push ( arg. as_ref ( ) . to_owned ( ) ) ;
@@ -116,6 +100,12 @@ impl GhciWatchBuilder {
116100 self
117101 }
118102
103+ /// Set the Cabal target to open a `cabal v2-repl` for.
104+ pub fn with_cabal_target ( mut self , target : impl AsRef < str > ) -> Self {
105+ self . cabal_target = target. as_ref ( ) . to_owned ( ) ;
106+ self
107+ }
108+
119109 /// Add a hook to run after project files are copied to the temporary directory but before
120110 /// `ghciwatch` is started.
121111 pub fn before_start < F > ( mut self , before_start : impl Fn ( PathBuf ) -> F + Send + ' static ) -> Self
@@ -164,14 +154,6 @@ impl GhciWatchBuilder {
164154 . extend ( log_filters. into_iter ( ) . map ( |s| s. as_ref ( ) . to_owned ( ) ) ) ;
165155 self
166156 }
167-
168- /// Copy an extra directory or path to the temporary directory where tests are run.
169- ///
170- /// This will be copied as a sibling of the project directory.
171- pub fn copy_extra ( mut self , path : impl AsRef < Path > ) -> Self {
172- self . copy_extra . push ( path. as_ref ( ) . to_owned ( ) ) ;
173- self
174- }
175157}
176158
177159struct Session {
@@ -269,8 +251,10 @@ impl GhciWatch {
269251 write_cabal_config ( & fs, & tempdir) . await ?;
270252 check_ghc_version ( & tempdir, & ghc_version) . await ?;
271253
272- let mut paths_to_copy = vec ! [ & builder. project_directory] ;
273- paths_to_copy. extend ( builder. copy_extra . iter ( ) ) ;
254+ let inner_tempdir = tempdir. join ( "tmp" ) ;
255+ fs. create_dir ( & inner_tempdir) . await ?;
256+
257+ let paths_to_copy = vec ! [ & builder. project_directory] ;
274258 tracing:: info!( ?paths_to_copy, "Copying project files" ) ;
275259 fs_extra:: copy_items ( & paths_to_copy, & tempdir, & Default :: default ( ) )
276260 . into_diagnostic ( )
@@ -293,17 +277,16 @@ impl GhciWatch {
293277 let log_path = tempdir. join ( LOG_FILENAME ) ;
294278
295279 tracing:: info!( "Starting ghciwatch" ) ;
296- let repl_command = shell_words:: join (
297- [
298- "make" ,
299- "ghci" ,
300- & format ! ( "GHC=ghc-{ghc_version}" ) ,
301- & format ! ( "EXTRA_GHC_OPTS={}" , shell_words:: join( builder. ghc_args) ) ,
302- & format ! ( "CABAL_OPTS={}" , shell_words:: join( builder. cabal_args) ) ,
303- ]
304- . into_iter ( )
305- . chain ( builder. make_args . iter ( ) . map ( |s| s. as_str ( ) ) ) ,
306- ) ;
280+ let mut repl_command = vec ! [ "cabal" . into( ) , format!( "--with-compiler=ghc-{ghc_version}" ) ] ;
281+ repl_command. extend ( builder. cabal_args . iter ( ) . cloned ( ) ) ;
282+ repl_command. push ( format ! (
283+ "--repl-options={}" ,
284+ shell_words:: join( & builder. ghc_args)
285+ ) ) ;
286+ repl_command. push ( "v2-repl" . into ( ) ) ;
287+ repl_command. push ( builder. cabal_target . clone ( ) ) ;
288+
289+ let repl_command = shell_words:: join ( repl_command) ;
307290
308291 let log_filters = [ "ghciwatch::watcher=trace" , "ghciwatch=debug" ]
309292 . into_iter ( )
@@ -319,11 +302,7 @@ impl GhciWatch {
319302 "--watch" ,
320303 "src" ,
321304 "--watch" ,
322- "package.yaml" ,
323- "--restart-glob" ,
324- "**/package.yaml" ,
325- "--before-startup-shell" ,
326- "hpack --force ." ,
305+ "my-simple-package.cabal" , // This is going to get me in trouble.
327306 "--log-filter" ,
328307 & log_filters,
329308 "--trace-spans" ,
@@ -334,6 +313,8 @@ impl GhciWatch {
334313 . args ( builder. ghciwatch_args )
335314 . current_dir ( & cwd)
336315 . env ( "HOME" , & tempdir)
316+ . env ( "CABAL_DIR" , tempdir. join ( ".cabal" ) )
317+ . env ( "TMPDIR" , & inner_tempdir)
337318 // GHC will quote things with Unicode quotes unless we set this variable.
338319 // Very cute.
339320 // https://gitlab.haskell.org/ghc/ghc/-/blob/288235bbe5a59b8a1bda80aaacd59e5717417726/compiler/GHC/Driver/Session.hs#L1084-L1085
0 commit comments