1- use std:: fs;
21use std:: path:: PathBuf ;
32
43use crate :: utils:: ensure_empty_dir;
@@ -18,7 +17,6 @@ pub(crate) enum PathBase {
1817 Source ,
1918 Download ,
2019 Build ,
21- Dist ,
2220}
2321
2422impl PathBase {
@@ -27,39 +25,31 @@ impl PathBase {
2725 PathBase :: Source => dirs. source_dir . clone ( ) ,
2826 PathBase :: Download => dirs. download_dir . clone ( ) ,
2927 PathBase :: Build => dirs. build_dir . clone ( ) ,
30- PathBase :: Dist => dirs. dist_dir . clone ( ) ,
3128 }
3229 }
3330}
3431
3532#[ derive( Debug , Copy , Clone ) ]
36- pub ( crate ) enum RelPath {
37- Base ( PathBase ) ,
38- Join ( & ' static RelPath , & ' static str ) ,
33+ pub ( crate ) struct RelPath {
34+ base : PathBase ,
35+ suffix : & ' static str ,
3936}
4037
4138impl RelPath {
42- pub ( crate ) const SOURCE : RelPath = RelPath :: Base ( PathBase :: Source ) ;
43- pub ( crate ) const DOWNLOAD : RelPath = RelPath :: Base ( PathBase :: Download ) ;
44- pub ( crate ) const BUILD : RelPath = RelPath :: Base ( PathBase :: Build ) ;
45- pub ( crate ) const DIST : RelPath = RelPath :: Base ( PathBase :: Dist ) ;
46-
47- pub ( crate ) const SCRIPTS : RelPath = RelPath :: SOURCE . join ( "scripts" ) ;
48- pub ( crate ) const PATCHES : RelPath = RelPath :: SOURCE . join ( "patches" ) ;
39+ pub ( crate ) const fn source ( suffix : & ' static str ) -> RelPath {
40+ RelPath { base : PathBase :: Source , suffix }
41+ }
4942
50- pub ( crate ) const fn join ( & ' static self , suffix : & ' static str ) -> RelPath {
51- RelPath :: Join ( self , suffix)
43+ pub ( crate ) const fn download ( suffix : & ' static str ) -> RelPath {
44+ RelPath { base : PathBase :: Download , suffix }
5245 }
5346
54- pub ( crate ) fn to_path ( & self , dirs : & Dirs ) -> PathBuf {
55- match self {
56- RelPath :: Base ( base) => base. to_path ( dirs) ,
57- RelPath :: Join ( base, suffix) => base. to_path ( dirs) . join ( suffix) ,
58- }
47+ pub ( crate ) const fn build ( suffix : & ' static str ) -> RelPath {
48+ RelPath { base : PathBase :: Build , suffix }
5949 }
6050
61- pub ( crate ) fn ensure_exists ( & self , dirs : & Dirs ) {
62- fs :: create_dir_all ( self . to_path ( dirs) ) . unwrap ( ) ;
51+ pub ( crate ) fn to_path ( & self , dirs : & Dirs ) -> PathBuf {
52+ self . base . to_path ( dirs) . join ( self . suffix )
6353 }
6454
6555 pub ( crate ) fn ensure_fresh ( & self , dirs : & Dirs ) {
0 commit comments