@@ -111,38 +111,8 @@ use std::path::{Path, PathBuf};
111111///
112112/// See module docs for more information.
113113pub struct Layout {
114- /// The root directory: `/path/to/target`.
115- /// If cross compiling: `/path/to/target/$TRIPLE`.
116- root : PathBuf ,
117- /// The final artifact destination: `$root/debug` (or `release`).
118- dest : PathBuf ,
119- /// The directory with rustc artifacts: `$dest/deps`
120- deps : PathBuf ,
121- /// The directory for build scripts: `$dest/build`
122- build : PathBuf ,
123- /// The directory for artifacts, i.e. binaries, cdylibs, staticlibs: `$dest/deps/artifact`
124- artifact : PathBuf ,
125- /// The directory for incremental files: `$dest/incremental`
126- incremental : PathBuf ,
127- /// The directory for fingerprints: `$dest/.fingerprint`
128- fingerprint : PathBuf ,
129- /// The directory for examples: `$dest/examples`
130- examples : PathBuf ,
131- /// The directory for pre-uplifted examples: `$build-dir/debug/examples`
132- build_examples : PathBuf ,
133- /// The directory for rustdoc output: `$root/doc`
134- doc : PathBuf ,
135- /// The directory for temporary data of integration tests and benches: `$dest/tmp`
136- tmp : PathBuf ,
137- /// The lockfile for a build (`.cargo-lock`). Will be unlocked when this
138- /// struct is `drop`ped.
139- _lock : FileLock ,
140- /// Same as `_lock` but for the build directory.
141- ///
142- /// Will be `None` when the build-dir and target-dir are the same path as we cannot
143- /// lock the same path twice.
144- _build_lock : Option < FileLock > ,
145- is_new_layout : bool ,
114+ artifact_dir : ArtifactDirLayout ,
115+ build_dir : BuildDirLayout ,
146116}
147117
148118impl Layout {
@@ -182,9 +152,10 @@ impl Layout {
182152 // For now we don't do any more finer-grained locking on the artifact
183153 // directory, so just lock the entire thing for the duration of this
184154 // compile.
185- let lock = dest. open_rw_exclusive_create ( ".cargo-lock" , ws. gctx ( ) , "build directory" ) ?;
155+ let artifact_dir_lock =
156+ dest. open_rw_exclusive_create ( ".cargo-lock" , ws. gctx ( ) , "build directory" ) ?;
186157
187- let build_lock = if root != build_root {
158+ let build_dir_lock = if root != build_root {
188159 Some ( build_dest. open_rw_exclusive_create (
189160 ".cargo-lock" ,
190161 ws. gctx ( ) ,
@@ -201,23 +172,112 @@ impl Layout {
201172 let artifact = deps. join ( "artifact" ) ;
202173
203174 Ok ( Layout {
204- deps,
205- build : build_dest. join ( "build" ) ,
206- artifact,
207- incremental : build_dest. join ( "incremental" ) ,
208- fingerprint : build_dest. join ( ".fingerprint" ) ,
209- examples : dest. join ( "examples" ) ,
210- build_examples : build_dest. join ( "examples" ) ,
211- doc : root. join ( "doc" ) ,
212- tmp : build_root. join ( "tmp" ) ,
213- root,
214- dest,
215- _lock : lock,
216- _build_lock : build_lock,
217- is_new_layout,
175+ artifact_dir : ArtifactDirLayout {
176+ dest : dest. clone ( ) ,
177+ examples : dest. join ( "examples" ) ,
178+ doc : root. join ( "doc" ) ,
179+ timings : root. join ( "cargo-timings" ) ,
180+ _lock : artifact_dir_lock,
181+ } ,
182+ build_dir : BuildDirLayout {
183+ root : build_root. clone ( ) ,
184+ deps,
185+ build : build_dest. join ( "build" ) ,
186+ artifact,
187+ incremental : build_dest. join ( "incremental" ) ,
188+ fingerprint : build_dest. join ( ".fingerprint" ) ,
189+ examples : build_dest. join ( "examples" ) ,
190+ tmp : build_root. join ( "tmp" ) ,
191+ _lock : build_dir_lock,
192+ is_new_layout,
193+ } ,
218194 } )
219195 }
220196
197+ /// Makes sure all directories stored in the Layout exist on the filesystem.
198+ pub fn prepare ( & mut self ) -> CargoResult < ( ) > {
199+ self . artifact_dir . prepare ( ) ?;
200+ self . build_dir . prepare ( ) ?;
201+
202+ Ok ( ( ) )
203+ }
204+
205+ pub fn artifact_dir ( & self ) -> & ArtifactDirLayout {
206+ & self . artifact_dir
207+ }
208+
209+ pub fn build_dir ( & self ) -> & BuildDirLayout {
210+ & self . build_dir
211+ }
212+ }
213+
214+ pub struct ArtifactDirLayout {
215+ /// The final artifact destination: `<artifact-dir>/debug` (or `release`).
216+ dest : PathBuf ,
217+ /// The directory for examples
218+ examples : PathBuf ,
219+ /// The directory for rustdoc output
220+ doc : PathBuf ,
221+ /// The directory for --timings output
222+ timings : PathBuf ,
223+ /// The lockfile for a build (`.cargo-lock`). Will be unlocked when this
224+ /// struct is `drop`ped.
225+ _lock : FileLock ,
226+ }
227+
228+ impl ArtifactDirLayout {
229+ /// Makes sure all directories stored in the Layout exist on the filesystem.
230+ pub fn prepare ( & mut self ) -> CargoResult < ( ) > {
231+ paths:: create_dir_all ( & self . examples ) ?;
232+
233+ Ok ( ( ) )
234+ }
235+ /// Fetch the destination path for final artifacts (`/…/target/debug`).
236+ pub fn dest ( & self ) -> & Path {
237+ & self . dest
238+ }
239+ /// Fetch the examples path.
240+ pub fn examples ( & self ) -> & Path {
241+ & self . examples
242+ }
243+ /// Fetch the doc path.
244+ pub fn doc ( & self ) -> & Path {
245+ & self . doc
246+ }
247+ /// Fetch the cargo-timings path.
248+ pub fn timings ( & self ) -> & Path {
249+ & self . timings
250+ }
251+ }
252+
253+ pub struct BuildDirLayout {
254+ /// The root directory: `/path/to/build-dir`.
255+ /// If cross compiling: `/path/to/build-dir/$TRIPLE`.
256+ root : PathBuf ,
257+ /// The directory with rustc artifacts
258+ deps : PathBuf ,
259+ /// The primary directory for build files
260+ build : PathBuf ,
261+ /// The directory for artifacts, i.e. binaries, cdylibs, staticlibs
262+ artifact : PathBuf ,
263+ /// The directory for incremental files
264+ incremental : PathBuf ,
265+ /// The directory for fingerprints
266+ fingerprint : PathBuf ,
267+ /// The directory for pre-uplifted examples: `build-dir/debug/examples`
268+ examples : PathBuf ,
269+ /// The directory for temporary data of integration tests and benches
270+ tmp : PathBuf ,
271+ /// The lockfile for a build (`.cargo-lock`). Will be unlocked when this
272+ /// struct is `drop`ped.
273+ ///
274+ /// Will be `None` when the build-dir and target-dir are the same path as we cannot
275+ /// lock the same path twice.
276+ _lock : Option < FileLock > ,
277+ is_new_layout : bool ,
278+ }
279+
280+ impl BuildDirLayout {
221281 /// Makes sure all directories stored in the Layout exist on the filesystem.
222282 pub fn prepare ( & mut self ) -> CargoResult < ( ) > {
223283 if !self . is_new_layout {
@@ -226,16 +286,10 @@ impl Layout {
226286 }
227287 paths:: create_dir_all ( & self . incremental ) ?;
228288 paths:: create_dir_all ( & self . examples ) ?;
229- paths:: create_dir_all ( & self . build_examples ) ?;
230289 paths:: create_dir_all ( & self . build ) ?;
231290
232291 Ok ( ( ) )
233292 }
234-
235- /// Fetch the destination path for final artifacts (`/…/target/debug`).
236- pub fn dest ( & self ) -> & Path {
237- & self . dest
238- }
239293 /// Fetch the deps path.
240294 pub fn deps ( & self , pkg_dir : & str ) -> PathBuf {
241295 if self . is_new_layout {
@@ -248,22 +302,13 @@ impl Layout {
248302 pub fn legacy_deps ( & self ) -> & Path {
249303 & self . deps
250304 }
251- /// Fetch the examples path.
252- pub fn examples ( & self ) -> & Path {
253- & self . examples
254- }
255- /// Fetch the build examples path.
256- pub fn build_examples ( & self ) -> & Path {
257- & self . build_examples
258- }
259- /// Fetch the doc path.
260- pub fn doc ( & self ) -> & Path {
261- & self . doc
262- }
263- /// Fetch the root path (`/…/target`).
264305 pub fn root ( & self ) -> & Path {
265306 & self . root
266307 }
308+ /// Fetch the build examples path.
309+ pub fn examples ( & self ) -> & Path {
310+ & self . examples
311+ }
267312 /// Fetch the incremental path.
268313 pub fn incremental ( & self ) -> & Path {
269314 & self . incremental
0 commit comments