Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

install::sanitize_sh(Path) breaks paths in Windows 10 #132507

Closed
Houtamelo opened this issue Nov 2, 2024 · 5 comments · Fixed by #134023
Closed

install::sanitize_sh(Path) breaks paths in Windows 10 #132507

Houtamelo opened this issue Nov 2, 2024 · 5 comments · Fixed by #134023
Labels
C-bug Category: This is a bug. O-windows Operating system: Windows T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)

Comments

@Houtamelo
Copy link
Contributor

When running x install, I was getting the following error:

Installing stage2 docs (x86_64-pc-windows-msvc)
sh: /C/Users/anton/Documents/rust_compilers/unchained/build/tmp/tarball/rust-docs/x86_64-pc-windows-msvc/rust-docs-nightly-x86_64-pc-windows-msvc/install.sh: No such file or directory

I found that the source of the issue was inside the function sanitize_sh, located in: "src/bootstrap/src/core/build_steps/install.rs":

fn sanitize_sh(path: &Path) -> String {
    let path = path.to_str().unwrap().replace('\\', "/");
    return change_drive(unc_to_lfs(&path)).unwrap_or(path);

    fn unc_to_lfs(s: &str) -> &str {
        s.strip_prefix("//?/").unwrap_or(s)
    }

    fn change_drive(s: &str) -> Option<String> {
        let mut ch = s.chars();
        let drive = ch.next().unwrap_or('C');
        if ch.next() != Some(':') {
            return None;
        }
        if ch.next() != Some('/') {
            return None;
        }
        Some(format!("/{}/{}", drive, &s[drive.len_utf8() + 2..]))
    }
}

change_drive turns paths such as "C:/user/foo" into "/C/user/foo", which makes those paths invalid, resulting in "No such file or directory" errors.

In my fork, I commented the call to change_drive and returned path directly:

let path = path.to_str().unwrap().replace('\\', "/");
return path;

Which fixed the issue, x install then ran without any problems, everything was installed correctly.

Meta

OS: Windows 10 x64
rust-lang commit: ef972a3

@Houtamelo Houtamelo added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 2, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Nov 2, 2024
@the8472 the8472 added T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) O-windows Operating system: Windows and removed T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Nov 2, 2024
@bjorn3
Copy link
Member

bjorn3 commented Nov 2, 2024

If the shell is provided by MinGW I think sanitize_sh is necessary in it's entirety. Where did you get the sh binary that is used to run the install script from?

@Houtamelo
Copy link
Contributor Author

If the shell is provided by MinGW I think sanitize_sh is necessary in it's entirety. Where did you get the sh binary that is used to run the install script from?

Mine is cygwin64

@bjorn3
Copy link
Member

bjorn3 commented Nov 2, 2024

Ah, it seems like cygwin expects paths in the format /cygdrive/c/ rather than the /c/ that mingw expects.

@onur-ozkan
Copy link
Member

Could you check if #134023 works for you? @Houtamelo

GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Dec 9, 2024
handle cygwin environment in `install::sanitize_sh`

Resolves rust-lang#132507
jieyouxu added a commit to jieyouxu/rust that referenced this issue Dec 9, 2024
handle cygwin environment in `install::sanitize_sh`

Resolves rust-lang#132507
jieyouxu added a commit to jieyouxu/rust that referenced this issue Dec 9, 2024
handle cygwin environment in `install::sanitize_sh`

Resolves rust-lang#132507
@Houtamelo
Copy link
Contributor Author

Could you check if #134023 works for you? @Houtamelo

Sadly no, I'm using Linux now.

fmease added a commit to fmease/rust that referenced this issue Dec 9, 2024
handle cygwin environment in `install::sanitize_sh`

Resolves rust-lang#132507
fmease added a commit to fmease/rust that referenced this issue Dec 10, 2024
handle cygwin environment in `install::sanitize_sh`

Resolves rust-lang#132507
@bors bors closed this as completed in 8e9953f Dec 10, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Dec 10, 2024
Rollup merge of rust-lang#134023 - onur-ozkan:132507, r=jieyouxu

handle cygwin environment in `install::sanitize_sh`

Resolves rust-lang#132507
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. O-windows Operating system: Windows T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants