@@ -71,16 +71,26 @@ fn install_sh(
71
71
72
72
let prefix = default_path ( & builder. config . prefix , "/usr/local" ) ;
73
73
let sysconfdir = prefix. join ( default_path ( & builder. config . sysconfdir , "/etc" ) ) ;
74
+ let destdir_env = env:: var_os ( "DESTDIR" ) . map ( PathBuf :: from) ;
74
75
75
- // Sanity check for the user write access on prefix and sysconfdir
76
- assert ! (
77
- is_dir_writable_for_user( & prefix) ,
78
- "User doesn't have write access on `install.prefix` path in the `config.toml`." ,
79
- ) ;
80
- assert ! (
81
- is_dir_writable_for_user( & sysconfdir) ,
82
- "User doesn't have write access on `install.sysconfdir` path in `config.toml`."
83
- ) ;
76
+ // When the `DESTDIR` environment variable is present, there is no point to
77
+ // check write access for `prefix` and `sysconfdir` individually, as they
78
+ // are combined with the path from the `DESTDIR` environment variable. In
79
+ // this case, we only need to check the `DESTDIR` path, disregarding the
80
+ // `prefix` and `sysconfdir` paths.
81
+ if let Some ( destdir) = & destdir_env {
82
+ assert ! ( is_dir_writable_for_user( destdir) , "User doesn't have write access on DESTDIR." ) ;
83
+ } else {
84
+ // Sanity check for the user write access on prefix and sysconfdir.
85
+ assert ! (
86
+ is_dir_writable_for_user( & prefix) ,
87
+ "User doesn't have write access on `install.prefix` path in the `config.toml`." ,
88
+ ) ;
89
+ assert ! (
90
+ is_dir_writable_for_user( & sysconfdir) ,
91
+ "User doesn't have write access on `install.sysconfdir` path in `config.toml`."
92
+ ) ;
93
+ }
84
94
85
95
let datadir = prefix. join ( default_path ( & builder. config . datadir , "share" ) ) ;
86
96
let docdir = prefix. join ( default_path ( & builder. config . docdir , "share/doc/rust" ) ) ;
@@ -94,13 +104,13 @@ fn install_sh(
94
104
let mut cmd = Command :: new ( SHELL ) ;
95
105
cmd. current_dir ( & empty_dir)
96
106
. arg ( sanitize_sh ( & tarball. decompressed_output ( ) . join ( "install.sh" ) ) )
97
- . arg ( format ! ( "--prefix={}" , prepare_dir( prefix) ) )
98
- . arg ( format ! ( "--sysconfdir={}" , prepare_dir( sysconfdir) ) )
99
- . arg ( format ! ( "--datadir={}" , prepare_dir( datadir) ) )
100
- . arg ( format ! ( "--docdir={}" , prepare_dir( docdir) ) )
101
- . arg ( format ! ( "--bindir={}" , prepare_dir( bindir) ) )
102
- . arg ( format ! ( "--libdir={}" , prepare_dir( libdir) ) )
103
- . arg ( format ! ( "--mandir={}" , prepare_dir( mandir) ) )
107
+ . arg ( format ! ( "--prefix={}" , prepare_dir( & destdir_env , prefix) ) )
108
+ . arg ( format ! ( "--sysconfdir={}" , prepare_dir( & destdir_env , sysconfdir) ) )
109
+ . arg ( format ! ( "--datadir={}" , prepare_dir( & destdir_env , datadir) ) )
110
+ . arg ( format ! ( "--docdir={}" , prepare_dir( & destdir_env , docdir) ) )
111
+ . arg ( format ! ( "--bindir={}" , prepare_dir( & destdir_env , bindir) ) )
112
+ . arg ( format ! ( "--libdir={}" , prepare_dir( & destdir_env , libdir) ) )
113
+ . arg ( format ! ( "--mandir={}" , prepare_dir( & destdir_env , mandir) ) )
104
114
. arg ( "--disable-ldconfig" ) ;
105
115
builder. run ( & mut cmd) ;
106
116
t ! ( fs:: remove_dir_all( & empty_dir) ) ;
@@ -110,19 +120,16 @@ fn default_path(config: &Option<PathBuf>, default: &str) -> PathBuf {
110
120
config. as_ref ( ) . cloned ( ) . unwrap_or_else ( || PathBuf :: from ( default) )
111
121
}
112
122
113
- fn prepare_dir ( mut path : PathBuf ) -> String {
123
+ fn prepare_dir ( destdir_env : & Option < PathBuf > , mut path : PathBuf ) -> String {
114
124
// The DESTDIR environment variable is a standard way to install software in a subdirectory
115
125
// while keeping the original directory structure, even if the prefix or other directories
116
126
// contain absolute paths.
117
127
//
118
128
// More information on the environment variable is available here:
119
129
// https://www.gnu.org/prep/standards/html_node/DESTDIR.html
120
- if let Some ( destdir) = env:: var_os ( "DESTDIR" ) . map ( PathBuf :: from) {
121
- // Sanity check for the user write access on DESTDIR
122
- assert ! ( is_dir_writable_for_user( & destdir) , "User doesn't have write access on DESTDIR." ) ;
123
-
130
+ if let Some ( destdir) = destdir_env {
124
131
let without_destdir = path. clone ( ) ;
125
- path = destdir;
132
+ path = destdir. clone ( ) ;
126
133
// Custom .join() which ignores disk roots.
127
134
for part in without_destdir. components ( ) {
128
135
if let Component :: Normal ( s) = part {
0 commit comments