Skip to content

Commit 8e9953f

Browse files
authored
Rollup merge of rust-lang#134023 - onur-ozkan:132507, r=jieyouxu
handle cygwin environment in `install::sanitize_sh` Resolves rust-lang#132507
2 parents 193a95d + d3b5340 commit 8e9953f

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

Diff for: src/bootstrap/src/core/build_steps/install.rs

+13-12
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ const SHELL: &str = "sh";
2121

2222
/// We have to run a few shell scripts, which choke quite a bit on both `\`
2323
/// characters and on `C:\` paths, so normalize both of them away.
24-
fn sanitize_sh(path: &Path) -> String {
24+
fn sanitize_sh(path: &Path, is_cygwin: bool) -> String {
2525
let path = path.to_str().unwrap().replace('\\', "/");
26-
return change_drive(unc_to_lfs(&path)).unwrap_or(path);
26+
return if is_cygwin { path } else { change_drive(unc_to_lfs(&path)).unwrap_or(path) };
2727

2828
fn unc_to_lfs(s: &str) -> &str {
2929
s.strip_prefix("//?/").unwrap_or(s)
@@ -71,6 +71,7 @@ fn install_sh(
7171
let prefix = default_path(&builder.config.prefix, "/usr/local");
7272
let sysconfdir = prefix.join(default_path(&builder.config.sysconfdir, "/etc"));
7373
let destdir_env = env::var_os("DESTDIR").map(PathBuf::from);
74+
let is_cygwin = builder.config.build.is_cygwin();
7475

7576
// Sanity checks on the write access of user.
7677
//
@@ -103,14 +104,14 @@ fn install_sh(
103104

104105
let mut cmd = command(SHELL);
105106
cmd.current_dir(&empty_dir)
106-
.arg(sanitize_sh(&tarball.decompressed_output().join("install.sh")))
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)))
107+
.arg(sanitize_sh(&tarball.decompressed_output().join("install.sh"), is_cygwin))
108+
.arg(format!("--prefix={}", prepare_dir(&destdir_env, prefix, is_cygwin)))
109+
.arg(format!("--sysconfdir={}", prepare_dir(&destdir_env, sysconfdir, is_cygwin)))
110+
.arg(format!("--datadir={}", prepare_dir(&destdir_env, datadir, is_cygwin)))
111+
.arg(format!("--docdir={}", prepare_dir(&destdir_env, docdir, is_cygwin)))
112+
.arg(format!("--bindir={}", prepare_dir(&destdir_env, bindir, is_cygwin)))
113+
.arg(format!("--libdir={}", prepare_dir(&destdir_env, libdir, is_cygwin)))
114+
.arg(format!("--mandir={}", prepare_dir(&destdir_env, mandir, is_cygwin)))
114115
.arg("--disable-ldconfig");
115116
cmd.run(builder);
116117
t!(fs::remove_dir_all(&empty_dir));
@@ -120,7 +121,7 @@ fn default_path(config: &Option<PathBuf>, default: &str) -> PathBuf {
120121
config.as_ref().cloned().unwrap_or_else(|| PathBuf::from(default))
121122
}
122123

123-
fn prepare_dir(destdir_env: &Option<PathBuf>, mut path: PathBuf) -> String {
124+
fn prepare_dir(destdir_env: &Option<PathBuf>, mut path: PathBuf, is_cygwin: bool) -> String {
124125
// The DESTDIR environment variable is a standard way to install software in a subdirectory
125126
// while keeping the original directory structure, even if the prefix or other directories
126127
// contain absolute paths.
@@ -146,7 +147,7 @@ fn prepare_dir(destdir_env: &Option<PathBuf>, mut path: PathBuf) -> String {
146147
assert!(path.is_absolute(), "could not make the path relative");
147148
}
148149

149-
sanitize_sh(&path)
150+
sanitize_sh(&path, is_cygwin)
150151
}
151152

152153
macro_rules! install {

Diff for: src/bootstrap/src/core/config/config.rs

+6
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,12 @@ impl TargetSelection {
565565
self.ends_with("windows-gnu")
566566
}
567567

568+
pub fn is_cygwin(&self) -> bool {
569+
self.is_windows() &&
570+
// ref. https://cygwin.com/pipermail/cygwin/2022-February/250802.html
571+
env::var("OSTYPE").is_ok_and(|v| v.to_lowercase().contains("cygwin"))
572+
}
573+
568574
/// Path to the file defining the custom target, if any.
569575
pub fn filepath(&self) -> Option<&Path> {
570576
self.file.as_ref().map(Path::new)

0 commit comments

Comments
 (0)