@@ -9,17 +9,67 @@ use std::sync::{LazyLock, Mutex};
99
1010use url:: Url ;
1111
12+ use super :: clitools:: hard_link;
13+ use super :: mock:: MockInstallerBuilder ;
14+ use super :: { CROSS_ARCH1 , CROSS_ARCH2 , MULTI_ARCH1 , create_hash, this_host_triple} ;
1215use crate :: dist:: {
13- Profile , TargetTriple ,
16+ DEFAULT_DIST_SERVER , Profile , TargetTriple ,
17+ component:: { Components , DirectoryPackage , Transaction } ,
1418 manifest:: {
1519 Component , CompressionKind , HashedBinary , Manifest , ManifestVersion , Package ,
1620 PackageTargets , Renamed , TargetedPackage ,
1721 } ,
22+ prefix:: InstallPrefix ,
23+ temp,
1824} ;
25+ use crate :: notifications:: Notification ;
26+ use crate :: process:: TestProcess ;
27+
28+ pub struct DistContext {
29+ pkg_dir : tempfile:: TempDir ,
30+ pub inst_dir : tempfile:: TempDir ,
31+ pub prefix : InstallPrefix ,
32+ _tmp_dir : tempfile:: TempDir ,
33+ pub cx : temp:: Context ,
34+ pub tp : TestProcess ,
35+ }
1936
20- use super :: clitools:: hard_link;
21- use super :: mock:: MockInstallerBuilder ;
22- use super :: { CROSS_ARCH1 , CROSS_ARCH2 , MULTI_ARCH1 , create_hash, this_host_triple} ;
37+ impl DistContext {
38+ pub fn new ( mock : MockInstallerBuilder ) -> anyhow:: Result < Self > {
39+ let pkg_dir = tempfile:: Builder :: new ( ) . prefix ( "rustup" ) . tempdir ( ) ?;
40+ mock. build ( pkg_dir. path ( ) ) ;
41+
42+ let inst_dir = tempfile:: Builder :: new ( ) . prefix ( "rustup" ) . tempdir ( ) ?;
43+ let prefix = InstallPrefix :: from ( inst_dir. path ( ) . to_owned ( ) ) ;
44+ let tmp_dir = tempfile:: Builder :: new ( ) . prefix ( "rustup" ) . tempdir ( ) ?;
45+
46+ Ok ( Self {
47+ pkg_dir,
48+ inst_dir,
49+ prefix,
50+ cx : temp:: Context :: new (
51+ tmp_dir. path ( ) . to_owned ( ) ,
52+ DEFAULT_DIST_SERVER ,
53+ Box :: new ( |_| ( ) ) ,
54+ ) ,
55+ tp : TestProcess :: default ( ) ,
56+ _tmp_dir : tmp_dir,
57+ } )
58+ }
59+
60+ pub fn start ( & self ) -> anyhow:: Result < ( Transaction < ' _ > , Components , DirectoryPackage ) > {
61+ let tx = Transaction :: new (
62+ self . prefix . clone ( ) ,
63+ & self . cx ,
64+ & |_: Notification < ' _ > | ( ) ,
65+ & self . tp . process ,
66+ ) ;
67+
68+ let components = Components :: open ( self . prefix . clone ( ) ) ?;
69+ let pkg = DirectoryPackage :: new ( self . pkg_dir . path ( ) . to_owned ( ) , true ) ?;
70+ Ok ( ( tx, components, pkg) )
71+ }
72+ }
2373
2474pub ( super ) struct Release {
2575 // Either "nightly", "stable", "beta", or an explicit version number
0 commit comments